From 4598e856759f043f203d45a0674626b9e2ff89b8 Mon Sep 17 00:00:00 2001
From: hao <1836460075@qq.com>
Date: 星期四, 18 九月 2025 10:29:29 +0800
Subject: [PATCH] 组装拆卸

---
 StandardInterface/MES.Service/service/ZZCXDManager.cs |   74 ++++++++++++++++++++++++-------------
 1 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/StandardInterface/MES.Service/service/ZZCXDManager.cs b/StandardInterface/MES.Service/service/ZZCXDManager.cs
index ecbfdae..733be1c 100644
--- a/StandardInterface/MES.Service/service/ZZCXDManager.cs
+++ b/StandardInterface/MES.Service/service/ZZCXDManager.cs
@@ -44,8 +44,9 @@
             var entity = new ZZCX
             {
                 BillNo = dto.bill_no,   // 鍗曟嵁缂栫爜
-                Erpid = dto.erpid ,      // ERP 涓昏〃 ID
-                 DjLx = dto.dj_lx,
+                Erpid = string.IsNullOrEmpty(dto.erpid) ? (decimal?)null : Convert.ToDecimal(dto.erpid),
+                // ERP 涓昏〃 ID
+                DjLx = dto.dj_lx,
                 KcZz = dto.kc_zz,
                 SwLx = dto.sw_lx,
                 // Time = string.IsNullOrEmpty(dto.time) ? (DateTime?)null : DateTime.Parse(dto.time),
@@ -78,27 +79,28 @@
             {
                 var item = new ZZCXA
                 {
-                    Erpid = dto.erpid,
-                 /*   BillNo = dto.bill_no,
-                    DjLx = dto.dj_lx,
-                    KcZz = dto.kc_zz,
-                    SwLx = dto.sw_lx,
-                   // Time = string.IsNullOrEmpty(dto.time) ? (DateTime?)null : DateTime.Parse(dto.time),
-                    Time = dto.time,
-                    Bm = dto.bm,
-                    Cgy = dto.cgy,
-                    Kcz = dto.kcz,
-                    DjZt = dto.dj_zt,
-                    Memo = dto.memo,
-                    Cphzlx = dto.cphzlx,
-                    Cphz = dto.cphz,
-                    Zjhzlx = dto.zjhzlx,
-                    Zjhz = dto.zjhz,*/
-                    ItemId = dto.item_id,
+                       /*   BillNo = dto.bill_no,
+                       DjLx = dto.dj_lx,
+                       KcZz = dto.kc_zz,
+                       SwLx = dto.sw_lx,
+                      // Time = string.IsNullOrEmpty(dto.time) ? (DateTime?)null : DateTime.Parse(dto.time),
+                       Time = dto.time,
+                       Bm = dto.bm,
+                       Cgy = dto.cgy,
+                       Kcz = dto.kcz,
+                       DjZt = dto.dj_zt,
+                       Memo = dto.memo,
+                       Cphzlx = dto.cphzlx,
+                       Cphz = dto.cphz,
+                       Zjhzlx = dto.zjhzlx,
+                       Zjhz = dto.zjhz,*/ 
+                    Erpid = string.IsNullOrEmpty(dto.erpid) ? (decimal?)null : Convert.ToDecimal(dto.erpid),
+                    YdId = string.IsNullOrEmpty(dto.yd_id) ? (decimal?)null : Convert.ToDecimal(dto.yd_id),
+                    ItemId = string.IsNullOrEmpty(dto.item_id) ? (decimal?)null : Convert.ToDecimal(dto.item_id),
                     Qty = string.IsNullOrEmpty(dto.qty) ? (decimal?)null : Convert.ToDecimal(dto.qty),
                     Unit = dto.unit,
-                    DepotId = dto.depot_id,
-                    YdId = mainErpId
+                    DepotId = string.IsNullOrEmpty(dto.depot_id) ? (decimal?)null : Convert.ToDecimal(dto.depot_id)
+
                 };
 
                 var existing = Db.Queryable<ZZCXA>().Where(s => s.Erpid == item.Erpid).Single();
@@ -113,14 +115,15 @@
                     {
                         var subEntity = new ZZCXB
                         {
-                            Eid = subDto.eid,
-                            ItemId = subDto.item_id,
+                            Eid = string.IsNullOrEmpty(subDto.eid) ? (decimal?)null : Convert.ToDecimal(subDto.eid),
+                            Erpid = string.IsNullOrEmpty(subDto.erpid) ? (decimal?)null : Convert.ToDecimal(subDto.erpid),
+                            YdId = string.IsNullOrEmpty(subDto.yd_id) ? (decimal?)null : Convert.ToDecimal(subDto.yd_id),
+                            ItemId = string.IsNullOrEmpty(subDto.item_id) ? (decimal?)null : Convert.ToDecimal(subDto.item_id),
                             Qty = string.IsNullOrEmpty(subDto.qty) ? (decimal?)null : Convert.ToDecimal(subDto.qty),
                             Unit = subDto.unit,
-                            DepotId = subDto.depot_id,
+                            DepotId = string.IsNullOrEmpty(subDto.depot_id) ? (decimal?)null : Convert.ToDecimal(subDto.depot_id),
                             LotNo = subDto.lot_no,
-                            Memo = subDto.memo,
-                            Erpid = mainErpId
+                            Memo = subDto.memo
                         };
 
                         var existingSub = Db.Queryable<ZZCXB>().Where(s => s.Eid == subEntity.Eid).Single();
@@ -137,6 +140,15 @@
 
         private bool SaveOrUpdateData(SqlSugarScope db, ZZCX head, List<ZZCXA> children)
         {
+            // 1. 鏍¢獙鏄惁瀛樺湪棰嗘枡璁板綍锛圡ES_INV_ITEM_OUTS锛�
+            var hasMaterialOut = db.Queryable<MesInvItemOuts>()
+                                   .Any(x => x.WorkNo == head.BillNo);
+
+            if (hasMaterialOut)
+            {
+                throw new Exception($"MES宸叉湁棰嗘枡璁板綍锛屽崟鍙凤細{head.BillNo}锛屼笉鑳芥洿鏂帮紒");
+            }
+
             if (head.Id != null)
                 base.DeleteById(head.Id);
 
@@ -180,6 +192,16 @@
 
         private bool UpdateData(SqlSugarScope db, ZZCX head, List<ZZCXA> children)
         {
+
+            // 1. 鏍¢獙鏄惁瀛樺湪棰嗘枡璁板綍锛圡ES_INV_ITEM_OUTS锛�
+            var hasMaterialOut = db.Queryable<MesInvItemOuts>()
+                                   .Any(x => x.WorkNo == head.BillNo);
+
+            if (hasMaterialOut)
+            {
+                throw new Exception($"MES宸叉湁棰嗘枡璁板綍锛屽崟鍙凤細{head.BillNo}锛屼笉鑳藉垹闄わ紒");
+            }
+
             // 鍒犻櫎涓昏〃
             var deletedHead = db.Deleteable<ZZCX>()
                                 .Where(d => d.Erpid == head.Erpid)

--
Gitblit v1.9.3