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/Dto/webApi/ERPZZCXD.cs  |    3 
 StandardInterface/MES.Service/Modes/ZZCX.cs           |   10 +-
 StandardInterface/MES.Service/service/ZZCXDManager.cs |   74 ++++++++++++------
 StandardInterface/MES.Service/Modes/Zzcxa.cs          |  105 +++----------------------
 StandardInterface/MES.Service/Modes/Zzcxb.cs          |   26 ++++--
 StandardInterface/MESApplication/appsettings.json     |    2 
 6 files changed, 87 insertions(+), 133 deletions(-)

diff --git a/StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs b/StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs
index 1a0703d..e833c91 100644
--- a/StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs
+++ b/StandardInterface/MES.Service/Dto/webApi/ERPZZCXD.cs
@@ -25,7 +25,7 @@
     public class ERPZZCXMain
     {
         public string? erpid { get; set; }     // ERP 涓昏〃id锛堜富琛ㄧ殑 ERPID锛�
-        public string? bill_no { get; set; }   // 鍗曟嵁缂栫爜
+        public string bill_no { get; set; }   // 鍗曟嵁缂栫爜
         public string? type { get; set; }   //  
         public string? dj_lx { get; set; }       // 鍗曟嵁绫诲瀷
         public string? kc_zz { get; set; }       // 搴撳瓨缁勭粐
@@ -91,5 +91,6 @@
         public string? depot_id { get; set; }  // 浠撳簱
         public string? lot_no { get; set; }    // 鎵瑰彿
         public string? memo { get; set; }      // 澶囨敞
+        public string? yd_id { get; set; }      // 澶囨敞
     }
 }
diff --git a/StandardInterface/MES.Service/Modes/ZZCX.cs b/StandardInterface/MES.Service/Modes/ZZCX.cs
index 6e1faa0..aa04545 100644
--- a/StandardInterface/MES.Service/Modes/ZZCX.cs
+++ b/StandardInterface/MES.Service/Modes/ZZCX.cs
@@ -1,5 +1,4 @@
 锘�// 鏂囦欢: MES.Service.Modes/ZZCX.cs
-using System;
 using SqlSugar;
 
 namespace MES.Service.Modes
@@ -11,7 +10,7 @@
     public class ZZCX
     {
         /// <summary>
-        /// 涓婚敭 ID
+        /// 涓婚敭 ID锛圤racle 搴忓垪锛�
         /// </summary>
         [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_ZZCX")]
         public decimal? Id { get; set; }
@@ -20,18 +19,19 @@
         /// ERP 涓昏〃 ID
         /// </summary>
         [SugarColumn(ColumnName = "ERPID")]
-        public string Erpid { get; set; }
+        public decimal? Erpid { get; set; }
 
         /// <summary>
         /// 鍗曟嵁缂栫爜
         /// </summary>
         [SugarColumn(ColumnName = "BILL_NO")]
         public string BillNo { get; set; }
+
         /// <summary>
-        /// 鍗曟嵁缂栫爜
+        /// 绫诲瀷
         /// </summary>
         [SugarColumn(ColumnName = "TYPE")]
-        public string Type { get; set; } 
+        public string Type { get; set; }
 
         /// <summary>
         /// 鍗曟嵁绫诲瀷
diff --git a/StandardInterface/MES.Service/Modes/Zzcxa.cs b/StandardInterface/MES.Service/Modes/Zzcxa.cs
index d46aa3f..e2a3003 100644
--- a/StandardInterface/MES.Service/Modes/Zzcxa.cs
+++ b/StandardInterface/MES.Service/Modes/Zzcxa.cs
@@ -1,38 +1,38 @@
 锘�// 鏂囦欢: MES.Service.Modes/ZZCXA.cs
-using System;
 using SqlSugar;
+using System.Collections.Generic;
 
 namespace MES.Service.Modes
 {
     /// <summary>
-    /// ZZCXA - 缁勮鎷嗗嵏 瀛愯〃锛堜箣鍓嶇殑 ZZCXA 瀛楁闆嗗悎锛夛紝鏂板 YD_ID 瀛楁鏉ヨ褰曚富琛� ERPID
+    /// ZZCXA - 缁勮鎷嗗嵏 瀛愯〃
     /// </summary>
     [SugarTable("ZZCXA")]
     public class ZZCXA
     {
         /// <summary>
-        /// 涓婚敭 ID
+        /// 涓婚敭 ID锛圤racle 搴忓垪锛�
         /// </summary>
         [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_ZZCXA")]
         public decimal? Id { get; set; }
 
         /// <summary>
-        /// 鐖惰〃 ID (瀵瑰簲 ZZCX.ID) 鈥斺�� 鍙敤浜庡叧绯绘煡璇�
+        /// 鐖惰〃 ID (瀵瑰簲 ZZCX.ID)
         /// </summary>
         [SugarColumn(ColumnName = "PID")]
         public decimal? Pid { get; set; }
 
         /// <summary>
-        /// YD_ID锛氬啓鍏ヤ富琛ㄧ殑 ERPID锛堜綘瑕佹眰锛氬瓙琛ㄧ殑 yd_id 瀛樹富琛ㄧ殑 erpid锛�
+        /// YD_ID锛氬啓鍏ヤ富琛ㄧ殑 ERPID
         /// </summary>
         [SugarColumn(ColumnName = "YD_ID")]
-        public string YdId { get; set; }
+        public decimal? YdId { get; set; }
 
         /// <summary>
-        /// ERP 瀛愯〃/琛� id锛坋rpid/eid 绛� ERP 琛屾爣璇嗭級
+        /// ERP 瀛愯〃 ID
         /// </summary>
         [SugarColumn(ColumnName = "ERPID")]
-        public string Erpid { get; set; }
+        public decimal? Erpid { get; set; }
 
         /// <summary>
         /// 鍗曟嵁缂栫爜
@@ -41,88 +41,10 @@
         public string BillNo { get; set; }
 
         /// <summary>
-        /// 鍗曟嵁绫诲瀷
-        /// </summary>
-        [SugarColumn(ColumnName = "DJ_LX")]
-        public string DjLx { get; set; }
-
-        /// <summary>
-        /// 搴撳瓨缁勭粐
-        /// </summary>
-        [SugarColumn(ColumnName = "KC_ZZ")]
-        public string KcZz { get; set; }
-
-        /// <summary>
-        /// 浜嬪姟绫诲瀷
-        /// </summary>
-        [SugarColumn(ColumnName = "SW_LX")]
-        public string SwLx { get; set; }
-
-        /// <summary>
-        /// 鏃ユ湡
-        /// </summary>
-        [SugarColumn(ColumnName = "TIME")]
-        public string Time { get; set; }
-
-        /// <summary>
-        /// 閮ㄩ棬
-        /// </summary>
-        [SugarColumn(ColumnName = "BM")]
-        public string Bm { get; set; }
-
-        /// <summary>
-        /// 浠撶鍛�
-        /// </summary>
-        [SugarColumn(ColumnName = "CGY")]
-        public string Cgy { get; set; }
-
-        /// <summary>
-        /// 搴撳瓨缁�
-        /// </summary>
-        [SugarColumn(ColumnName = "KCZ")]
-        public string Kcz { get; set; }
-
-        /// <summary>
-        /// 鍗曟嵁鐘舵��
-        /// </summary>
-        [SugarColumn(ColumnName = "DJ_ZT")]
-        public string DjZt { get; set; }
-
-        /// <summary>
-        /// 澶囨敞
-        /// </summary>
-        [SugarColumn(ColumnName = "MEMO")]
-        public string Memo { get; set; }
-
-        /// <summary>
-        /// 鎴愬搧璐т富绫诲瀷
-        /// </summary>
-        [SugarColumn(ColumnName = "CPHZLX")]
-        public string Cphzlx { get; set; }
-
-        /// <summary>
-        /// 鎴愬搧璐т富
-        /// </summary>
-        [SugarColumn(ColumnName = "CPHZ")]
-        public string Cphz { get; set; }
-
-        /// <summary>
-        /// 瀛愪欢璐т富绫诲瀷
-        /// </summary>
-        [SugarColumn(ColumnName = "ZJHZLX")]
-        public string Zjhzlx { get; set; }
-
-        /// <summary>
-        /// 瀛愪欢璐т富
-        /// </summary>
-        [SugarColumn(ColumnName = "ZJHZ")]
-        public string Zjhz { get; set; }
-
-        /// <summary>
-        /// 鐗╂枡缂栫爜 id
+        /// 鐗╂枡缂栫爜 ID
         /// </summary>
         [SugarColumn(ColumnName = "ITEM_ID")]
-        public string ItemId { get; set; }
+        public decimal? ItemId { get; set; }
 
         /// <summary>
         /// 鏁伴噺
@@ -137,11 +59,14 @@
         public string Unit { get; set; }
 
         /// <summary>
-        /// 浠撳簱
+        /// 浠撳簱 ID
         /// </summary>
         [SugarColumn(ColumnName = "DEPOT_ID")]
-        public string DepotId { get; set; }
+        public decimal? DepotId { get; set; }
 
+        /// <summary>
+        /// 瀛欒〃闆嗗悎
+        /// </summary>
         [SugarColumn(IsIgnore = true)]
         public List<ZZCXB> SubItems { get; set; } = new List<ZZCXB>();
 
diff --git a/StandardInterface/MES.Service/Modes/Zzcxb.cs b/StandardInterface/MES.Service/Modes/Zzcxb.cs
index a70d778..40b52d1 100644
--- a/StandardInterface/MES.Service/Modes/Zzcxb.cs
+++ b/StandardInterface/MES.Service/Modes/Zzcxb.cs
@@ -4,13 +4,13 @@
 namespace MES.Service.Modes
 {
     /// <summary>
-    /// ZZCXB - 缁勮鎷嗗嵏 瀛欒〃锛堜笌瀛愯〃涓�瀵瑰锛�
+    /// ZZCXB - 缁勮鎷嗗嵏 瀛欒〃
     /// </summary>
     [SugarTable("ZZCXB")]
     public class ZZCXB
     {
         /// <summary>
-        /// 涓婚敭 ID
+        /// 涓婚敭 ID锛圤racle 搴忓垪锛�
         /// </summary>
         [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_ZZCXB")]
         public decimal? Id { get; set; }
@@ -22,22 +22,28 @@
         public decimal? Pid { get; set; }
 
         /// <summary>
-        /// ERP 涓昏〃 id锛堝啑浣欙級
+        /// ERP 涓昏〃 ID锛堝啑浣欙級
         /// </summary>
         [SugarColumn(ColumnName = "ERPID")]
-        public string Erpid { get; set; }
+        public decimal? Erpid { get; set; }
 
         /// <summary>
-        /// ERP 瀛愯〃琛� id (EID)
+        /// YD_ID锛氫富琛� ERPID锛堝啑浣欙級
+        /// </summary>
+        [SugarColumn(ColumnName = "YD_ID")]
+        public decimal? YdId { get; set; }
+
+        /// <summary>
+        /// ERP 瀛愯〃琛� ID (EID)
         /// </summary>
         [SugarColumn(ColumnName = "EID")]
-        public string Eid { get; set; }
+        public decimal? Eid { get; set; }
 
         /// <summary>
-        /// 鐗╂枡缂栫爜 id
+        /// 鐗╂枡缂栫爜 ID
         /// </summary>
         [SugarColumn(ColumnName = "ITEM_ID")]
-        public string ItemId { get; set; }
+        public decimal? ItemId { get; set; }
 
         /// <summary>
         /// 鏁伴噺
@@ -52,10 +58,10 @@
         public string Unit { get; set; }
 
         /// <summary>
-        /// 浠撳簱
+        /// 浠撳簱 ID
         /// </summary>
         [SugarColumn(ColumnName = "DEPOT_ID")]
-        public string DepotId { get; set; }
+        public decimal? DepotId { get; set; }
 
         /// <summary>
         /// 鎵瑰彿
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)
diff --git a/StandardInterface/MESApplication/appsettings.json b/StandardInterface/MESApplication/appsettings.json
index 28cfc2a..59a3601 100644
--- a/StandardInterface/MESApplication/appsettings.json
+++ b/StandardInterface/MESApplication/appsettings.json
@@ -10,6 +10,6 @@
   "AppSettings": {
     "TestErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfo",
     "ProductionErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfoFormal",
-    "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = hm_prd; Password=hmprd"
+    "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = test_dev; Password=hmprd"
   }
 }

--
Gitblit v1.9.3