From f1deb7b024e17cba204de5fcb0dac15801436b90 Mon Sep 17 00:00:00 2001
From: sjz <1240968267@qq.com>
Date: 星期一, 28 七月 2025 20:56:41 +0800
Subject: [PATCH] 多组织修改

---
 MES.Service/service/WomcaaWWManager.cs |  125 ++++++++++++++++++++++++++++++++---------
 1 files changed, 98 insertions(+), 27 deletions(-)

diff --git a/MES.Service/service/WomcaaWWManager.cs b/MES.Service/service/WomcaaWWManager.cs
index 2acad32..ad77733 100644
--- a/MES.Service/service/WomcaaWWManager.cs
+++ b/MES.Service/service/WomcaaWWManager.cs
@@ -2,8 +2,6 @@
 using MES.Service.Dto.webApi;
 using MES.Service.Modes;
 using SqlSugar;
-using System;
-using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
 namespace MES.Service.service;
 
@@ -15,8 +13,8 @@
 
     private readonly WomcabManager _womcabWWManager = new();
     private decimal?[] decimals;
-    private bool update;
     private bool insertOrUpdate;
+    private bool update;
 
     public bool SaveList(List<ErpWOM> rohIns)
     {
@@ -35,33 +33,97 @@
             switch (womErpCaa.Type)
             {
                 case "3":
-                    return UpdateData(db, mesWomcaa, mesWomcabs) ? 1 : 0;
+                    return DeleteData(db, mesWomcaa, mesWomcabs) ? 1 : 0;
                 case "1":
                 case "2":
                 case "4":
+                    return SaveOrUpdateDataWw(db, mesWomcaa, mesWomcabs)
+                        ? 1
+                        : 0;
                 case "5":
-                    return SaveOrUpdateDataWw(db, mesWomcaa, mesWomcabs) ? 1 : 0;
+                    return UpdateData(db, mesWomcaa, mesWomcabs) ? 1 : 0;
                 default:
-                    throw new NotImplementedException(
-                        $"type娌℃湁{womErpCaa.Type}杩欎釜绫诲瀷");
+                    throw new NotImplementedException($"type娌℃湁{womErpCaa.Type}杩欎釜绫诲瀷");
             }
         }) > 0;
     }
 
-    private bool SaveOrUpdateDataWw(SqlSugarScope db, Womcaa mesWomcaa, List<Womcab> mesWomcabss)
+    private bool UpdateData(SqlSugarScope db, Womcaa mesWomcaa,List<Womcab> mesWomcabs)
     {
         if (mesWomcaa.Id != null) base.DeleteById(mesWomcaa.Id);
-
-        if (mesWomcabss.Count > 0)
+        if (mesWomcabs.Count > 0)
+        {
             db.Deleteable<Womcab>().Where(s => s.Eid == mesWomcaa.Erpid).ExecuteCommand();
-
+        }
         var orUpdate = base.Insert(mesWomcaa);
-        var baOrUpdate = _womcabWWManager.InsertRange(mesWomcabss);
-        if (orUpdate && baOrUpdate) return true;
+        var baOrUpdate = _womcabWWManager.InsertRange(mesWomcabs);
+        db.Ado.CommitTran();
+        if (orUpdate && baOrUpdate)
+        {
+            //瀹氫箟杈撳叆鍙傛暟
+            var inputParam1 = new SugarParameter("P_WORK_NO", mesWomcaa.Caa001);
+            // 瀹氫箟杈撳嚭鍙傛暟
+            var outParam1 = new SugarParameter("c_Result", null, true);
+            var outParam2 = new SugarParameter("C_MSG", null, true);
+            // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼
+            Db.Ado.ExecuteCommand("BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;",inputParam1, outParam1, outParam2);
+            // 鑾峰彇杈撳嚭鍙傛暟鐨勫��
+            var result = int.Parse((string)outParam1.Value);
+            var message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value;
+            if (result == 1)
+            {
+                //瀛樺偍杩囩▼澶辫触鍒欎簨鍔¤繘琛屽洖婊�
+                //db.Ado.RollbackTran();
+                throw new Exception(message);
+            }
+            // 鎻愪氦浜嬪姟
+            //db.Ado.CommitTran();
+            return true;
+        }
+
         throw new NotImplementedException("鎻掑叆鎴栨洿鏂板け璐�");
     }
 
-    private bool UpdateData(SqlSugarScope db, Womcaa mesWomcaa,List<Womcab> mesWomcabs)
+    private bool SaveOrUpdateDataWw(SqlSugarScope db, Womcaa mesWomcaa,List<Womcab> mesWomcabss)
+    {
+        if (mesWomcaa.Id != null)
+        {
+            base.DeleteById(mesWomcaa.Id);
+        }
+        if (mesWomcabss.Count > 0)
+        {
+            db.Deleteable<Womcab>().Where(s => s.Eid == mesWomcaa.Erpid).ExecuteCommand();
+        }
+        var orUpdate = base.Insert(mesWomcaa);
+        var baOrUpdate = _womcabWWManager.InsertRange(mesWomcabss);
+        db.Ado.CommitTran();
+        if (orUpdate && baOrUpdate)
+        {
+            //瀹氫箟杈撳叆鍙傛暟
+            var inputParam1 = new SugarParameter("P_WORK_NO", mesWomcaa.Caa001);
+            // 瀹氫箟杈撳嚭鍙傛暟
+            var outParam1 = new SugarParameter("c_Result", null, true);
+            var outParam2 = new SugarParameter("C_MSG", null, true);
+            // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼
+            Db.Ado.ExecuteCommand("BEGIN PRC_UPDATE_DAA(:P_WORK_NO,:c_Result,:C_MSG); END;",inputParam1, outParam1, outParam2);
+            // 鑾峰彇杈撳嚭鍙傛暟鐨勫��
+            var result = int.Parse((string)outParam1.Value);
+            var message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value;
+            if (result == 1)
+            {
+                //瀛樺偍杩囩▼澶辫触鍒欎簨鍔¤繘琛屽洖婊�
+                //db.Ado.RollbackTran();
+                throw new Exception(message);
+            }
+            // 鎻愪氦浜嬪姟
+            //db.Ado.CommitTran();
+            return true;
+        }
+
+        throw new NotImplementedException("鎻掑叆鎴栨洿鏂板け璐�");
+    }
+
+    private bool DeleteData(SqlSugarScope db, Womcaa mesWomcaa,List<Womcab> mesWomcabs)
     {
         if (mesWomcaa.Id != null)
         {
@@ -74,7 +136,11 @@
             update = true;
             insertOrUpdate = true;
         }
-        if (update && insertOrUpdate) return true;
+
+        if (update && insertOrUpdate)
+        {
+            return true;
+        }
         throw new NotImplementedException("鏇存柊澶辫触");
     }
 
@@ -93,6 +159,7 @@
             Caa012 = Convert.ToDecimal(dto.FQty),
             Caa013 = dto.FBomId,
             Caa015 = dto.FXSHTH,
+            Caa015Head = dto.FSaleOrderEntrySeq,
             Caa016 = dto.FDescription,
             Caa017 = 0,
             Caa018 = Convert.ToDecimal(dto.PLAN_ID),
@@ -104,7 +171,7 @@
             Caa023 = dto.FStatus,
             Caa024 = 0,
             RoutingId = dto.FRoutingId,
-            WorkShopId = dto.FREMWorkShopId,
+            WorkShopId = dto.FremWorkShopId,
             DepotCode = dto.FStockId,
             CreateDate = dto.FDate,
             WorkGroupId = dto.FWorkGroupId,
@@ -117,31 +184,29 @@
             SrcBillType = dto.FSrcBillType,
             SrcBillNo = dto.FSrcBillNo,
             SrcBillentryseq = dto.FSrcBillEntrySeq,
-            SaleOrderNo = dto.FSaleOrderNo,
+            SaleOrderNo = dto.FXSHTH,
             SaleOrderEntryseq = dto.FSaleOrderEntrySeq,
             ForceCloserid = dto.FForceCloserId,
             CloseType = dto.FCloseType,
             SrcSplitBillno = dto.FSrcSplitBillNo,
             F_ZSXG_KH = dto.F_ZJXF_BASE_KH,
             F_ZJXF_YHRQ = dto.F_ZJXF_DATETIME_YHRQ,
-            PrdOrg = dto.erP_SCZZ,
-            TrustOrg = dto.erP_WTZZ,
+            PrdOrg = dto.ErpRkhz,  //鍏ュ簱璐т富
+            TrustOrg = dto.ErpRkzz, //鍏ュ簱缁勭粐
             TbTime = DateTime.Now,
             JaBs = "0",
             FPURORDERNO = dto.FPurOrderNo,
             FPURORDERENTRYSEQ = Convert.ToDecimal(dto.FPurOrderEntrySeq),
             FSUBENTRYID = Convert.ToDecimal(dto.fsubentryid),
             FSTOCKINQTY = Convert.ToDecimal(dto.Caa024),
-            FNOSTOCKINQTY = Convert.ToDecimal(dto.Caa025)
+            FNOSTOCKINQTY = Convert.ToDecimal(dto.Caa025),
+            SupplierId = dto.SupplierId,
+            FinishedProduct = dto.FinishedProduct
         };
         if (dto.Type == "5")
-        {
             entity.IsXg = 1;
-        }
         else
-        {
             entity.IsXg = 0;
-        }
 
         if (dto.FStatus == "6" || dto.FStatus == "7")
         {
@@ -150,7 +215,10 @@
         }
 
         var single = base.GetSingle(it => it.Erpid == entity.Erpid);
-        if (single != null) entity.Id = single.Id;
+        if (single != null)
+        {
+            entity.Id = single.Id;
+        }
 
         return entity;
     }
@@ -186,11 +254,14 @@
                 Denominator = Convert.ToDecimal(dto.FDenominator),
                 SCRAPQTY = Convert.ToDecimal(dto.FFixScrapQty),
                 SCRAPRATE = Convert.ToDecimal(dto.FScrapRate),
-                SalesOrder = dto.FXSHTBH,
+                SalesOrder = dto.F_WWC_TEXT
             };
 
             var entity = Db.Queryable<Womcab>().Where(s => s.Erpid == womcab.Erpid).Single();
-            if (entity != null) womcab.Id = entity.Id;
+            if (entity != null)
+            {
+                womcab.Id = entity.Id;
+            }
 
             womcabList.Add(womcab);
         }

--
Gitblit v1.9.3