From 96ee6437185cc02f17a8286967fd0f0eb88d9328 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期一, 15 九月 2025 19:23:46 +0800
Subject: [PATCH] 111

---
 MES.Service/service/BasicData/SalesOrderManager.cs |  171 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 145 insertions(+), 26 deletions(-)

diff --git a/MES.Service/service/BasicData/SalesOrderManager.cs b/MES.Service/service/BasicData/SalesOrderManager.cs
index ff6b3f2..3a0dcec 100644
--- a/MES.Service/service/BasicData/SalesOrderManager.cs
+++ b/MES.Service/service/BasicData/SalesOrderManager.cs
@@ -57,17 +57,17 @@
         int update = 0;
         int insertOrUpdate = 0;
 
-        if (mesSalesOrder.ErpID != null)
+        if (mesSalesOrder.ErpId != null)
         {
             update = db.Deleteable<SalesOrder>()
-                .Where(s => s.ErpID == mesSalesOrder.ErpID)
+                .Where(s => s.ErpId == mesSalesOrder.ErpId)
                 .ExecuteCommand();
         }
 
-        if (mesSalesOrderDatas.Count > 0 && mesSalesOrder.ErpID != null)
+        if (mesSalesOrderDatas.Count > 0 && mesSalesOrder.ErpId != null)
         {
             insertOrUpdate = db.Deleteable<SalesOrderDetail>()
-                .Where(s => s.EHID == mesSalesOrder.ErpID)
+                .Where(s => s.EHid == mesSalesOrder.ErpId)
                 .ExecuteCommand();
         }
 
@@ -86,13 +86,13 @@
     {
         //if (mesSalesOrder.Id != null) base.DeleteById(mesSalesOrder.Id);
 
-        if (mesSalesOrder.ErpID != null)
+        if (mesSalesOrder.ErpId != null)
             db.Deleteable<SalesOrder>()
-                .Where(s => s.ErpID == mesSalesOrder.ErpID).ExecuteCommand();
+                .Where(s => s.ErpId == mesSalesOrder.ErpId).ExecuteCommand();
 
         if (mesSalesOrderDatas.Count > 0)
             db.Deleteable<SalesOrderDetail>()
-                .Where(s => s.EHID == mesSalesOrder.ErpID).ExecuteCommand();
+                .Where(s => s.EHid == mesSalesOrder.ErpId).ExecuteCommand();
 
         //var orUpdate = base.Insert(mesSalesOrder);
         //var baOrUpdate = _SalesOrderDetailManager.InsertRange(mesSalesOrderDatas);
@@ -138,7 +138,7 @@
         {
             Id = Guid.NewGuid(),
             BillNo = erpDto.FBillNo,
-            ErpID = Convert.ToDecimal(erpDto.ErpID),
+            ErpId = Convert.ToDecimal(erpDto.ErpID),
             FDate = ParseDateTime(erpDto.FDate) ?? null,
             BillTypeId = erpDto.FBillTypeID, // 鍗曟嵁绫诲瀷
             DocumentStatus = erpDto.FDocumentStatus, // 鍗曟嵁鐘舵��
@@ -180,7 +180,9 @@
                 : null,  // 鍙樻洿鏃ユ湡
             CancelStatus = erpDto.FCancelStatus, // 浣滃簾鐘舵��
             CancellerId = erpDto.FCancellerId, // 浣滃簾浜�
-            VersionNo = Convert.ToDouble(erpDto.FVersionNo), // 鐗堟湰鍙�
+            VersionNo = !string.IsNullOrEmpty(erpDto.FVersionNo)
+                ? Convert.ToInt32(erpDto.FVersionNo)
+                : 0, // 鐗堟湰鍙�
             ChangerId = erpDto.FChangerId, // 鍙樻洿浜�
             SynchronousDate = DateTime.Now
             //EntryNote = erpDto.FEntryNote // 澶囨敞
@@ -195,8 +197,37 @@
             ? (DateTime?)null
             : DateTime.ParseExact(erpDto.FCloseDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
 
-        var single = base.GetSingle(it => it.ErpID == Convert.ToDecimal(erpDto.ErpID));
+        var single = base.GetSingle(it => it.ErpId == Convert.ToDecimal(erpDto.ErpID));
         if (single != null) salesOrder.Id = single.Id;
+
+        // CUST_ID => MES_CUSTOMER.id
+        if (!string.IsNullOrEmpty(salesOrder.CustId))
+        {
+            var customer = Db.Queryable<MesCustomer>()
+                .Where(c => c.CustNo == salesOrder.CustId)
+                .Select(c => c.Id)
+                .First();
+            if (customer != null)
+            {
+                salesOrder.CustId = customer.ToString();
+            }
+        }
+
+        // SALE_DEPT_ID => SYS_DEPARTMENT.id
+        if (!string.IsNullOrEmpty(salesOrder.SaleDeptId))
+        {
+            var department = Db.Queryable<SysDepartment>()
+                .Where(d => d.Departmentcode == salesOrder.SaleDeptId)
+                .Select(d => d.Id)
+                .First();
+            if (department != null)
+            {
+                salesOrder.SaleDeptId = department.ToString();
+            }
+        }
+
+        // SALE_ORG_ID => 1 (鍥哄畾鍊�)
+        salesOrder.SaleOrgId = "1";
 
         return salesOrder;
     }
@@ -213,18 +244,30 @@
             var salesOrderSub = new SalesOrderDetail
             {
                 Pid = salesOrder.Id,
-                ErpID = Convert.ToDecimal(erpDto.ErpID),
-                EHID = Convert.ToDecimal(erpDto.EHID),
+                ErpId = !string.IsNullOrEmpty(erpDto.ErpID)
+                    ? Convert.ToInt32(erpDto.ErpID)
+                    : 0,
+                EHid = !string.IsNullOrEmpty(erpDto.EHID)
+                    ? Convert.ToInt32(erpDto.EHID)
+                    : 0,
                 MaterialId = erpDto.FMaterialId,
                 MapId = erpDto.FMapId,
                 MapName = erpDto.FMapName,
                 MapSpec = erpDto.FMapSpec,
-                Seq = Convert.ToInt32(erpDto.Seq),
+                Seq = !string.IsNullOrEmpty(erpDto.Seq)
+                    ? Convert.ToInt32(erpDto.Seq)
+                    : 0,
                 UnitId = erpDto.FUnitID,
-                Qty = Convert.ToDecimal(erpDto.FQty),
+                Qty = !string.IsNullOrEmpty(erpDto.FQty)
+                    ? Convert.ToDecimal(erpDto.FQty)
+                    : 0,
                 PriceUnitId = erpDto.FPriceUnitId,
-                PriceUnitQty = Convert.ToDecimal(erpDto.FPriceUnitQty),
-                DeliveryDate = Convert.ToDateTime(erpDto.FDeliveryDate),
+                PriceUnitQty = !string.IsNullOrEmpty(erpDto.FPriceUnitQty)
+                    ? Convert.ToDecimal(erpDto.FPriceUnitQty)
+                    : 0,
+                DeliveryDate = !string.IsNullOrEmpty(erpDto.FDeliveryDate)
+                    ? Convert.ToDateTime(erpDto.FDeliveryDate)
+                    : DateTime.MinValue,
                 IsFree = erpDto.FIsFree,
                 SupplyOrgId = erpDto.FSupplyOrgId,
                 StockOrgId = erpDto.FStockOrgId,
@@ -236,8 +279,12 @@
                 EntryNote = erpDto.FEntryNote,
                 MtoNo = erpDto.FMtoNo,
                 Lot = erpDto.FLot,
-                DeliveryMaxQty = Convert.ToDecimal(erpDto.FDeliveryMaxQty),
-                DeliveryMinQty = Convert.ToDecimal(erpDto.FDeliveryMinQty),
+                DeliveryMaxQty = !string.IsNullOrEmpty(erpDto.FDeliveryMaxQty)
+                    ? Convert.ToDecimal(erpDto.FDeliveryMaxQty)
+                    : 0,
+                DeliveryMinQty = !string.IsNullOrEmpty(erpDto.FDeliveryMinQty)
+                    ? Convert.ToDecimal(erpDto.FDeliveryMinQty)
+                    : 0,
                 OutLmtUnitId = erpDto.FOutLmtUnitID,
                 MrpCloseStatus = erpDto.FMrpCloseStatus,
                 MrpTerminateStatus = erpDto.FMrpTerminateStatus,
@@ -245,13 +292,24 @@
                 TerminaterId = erpDto.FTerminatorId,
                 SrcType = erpDto.FSrcType,
                 SrcBillNo = erpDto.FSrcBillNo,
-                DeliQty = Convert.ToDecimal(erpDto.FDeliQty),
-                StockOutQty = Convert.ToDecimal(erpDto.FStockOutQty),
-                BaseRetNoticeQty = Convert.ToDecimal(erpDto.FBaseRetNoticeQty),
-                BaseReturnQty = Convert.ToDecimal(erpDto.FBaseReturnQty),
-                BaseRemainOutQty = Convert.ToDecimal(erpDto.FBaseRemainOutQty),
-                BASEARQTY = Convert.ToDecimal(erpDto.FBASEARQTY),
-
+                DeliQty = !string.IsNullOrEmpty(erpDto.FDeliQty)
+                    ? Convert.ToDecimal(erpDto.FDeliQty)
+                    : 0,
+                StockOutQty = !string.IsNullOrEmpty(erpDto.FStockOutQty)
+                    ? Convert.ToDecimal(erpDto.FStockOutQty)
+                    : 0,
+                BaseRetNoticeQty = !string.IsNullOrEmpty(erpDto.FBaseRetNoticeQty)
+                    ? Convert.ToDecimal(erpDto.FBaseRetNoticeQty)
+                    : 0,
+                BaseReturnQty = !string.IsNullOrEmpty(erpDto.FBaseReturnQty)
+                    ? Convert.ToDecimal(erpDto.FBaseReturnQty)
+                    : 0,
+                BaseRemainOutQty = !string.IsNullOrEmpty(erpDto.FBaseRemainOutQty)
+                    ? Convert.ToDecimal(erpDto.FBaseRemainOutQty)
+                    : 0,
+                Basearqty = !string.IsNullOrEmpty(erpDto.FBASEARQTY)
+                    ? Convert.ToDecimal(erpDto.FBASEARQTY)
+                    : 0,
             };
 
             if (!string.IsNullOrEmpty(salesOrderSub.TerminaterId))
@@ -260,9 +318,70 @@
                 : DateTime.ParseExact(erpDto.FTerminateDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
 
             var single = _SalesOrderDetailManager.GetSingle(it =>
-                it.ErpID == Convert.ToDecimal(salesOrderSub.ErpID));
+                it.ErpId == Convert.ToDecimal(salesOrderSub.ErpId));
             if (single != null) salesOrderSub.Id = single.Id;
 
+            // material_id => MES_ITEMS.id
+            if (!string.IsNullOrEmpty(salesOrderSub.MaterialId))
+            {
+                var item = Db.Queryable<MesItems>()
+                    .Where(i => i.ItemNo == salesOrderSub.MaterialId)
+                    .Select(i => i.Id)
+                    .First();
+                if (item != null)
+                {
+                    salesOrderSub.MaterialId = item.ToString();
+                }
+            }
+
+            // UNIT_ID => MES_UNIT.id
+            if (!string.IsNullOrEmpty(salesOrderSub.UnitId))
+            {
+                var unit = Db.Queryable<MesUnit>()
+                    .Where(u => u.Fnumber == salesOrderSub.UnitId)
+                    .Select(u => u.Id)
+                    .First();
+                if (unit != null)
+                {
+                    salesOrderSub.UnitId = unit.ToString();
+                }
+            }
+
+            // PRICE_UNIT_ID => MES_UNIT.id
+            if (!string.IsNullOrEmpty(salesOrderSub.PriceUnitId))
+            {
+                var priceUnit = Db.Queryable<MesUnit>()
+                    .Where(u => u.Fnumber == salesOrderSub.PriceUnitId)
+                    .Select(u => u.Id)
+                    .First();
+                if (priceUnit != null)
+                {
+                    salesOrderSub.PriceUnitId = priceUnit.ToString();
+                }
+            }
+
+            // OUT_LMT_UNIT_ID => MES_UNIT.id
+            if (!string.IsNullOrEmpty(salesOrderSub.OutLmtUnitId))
+            {
+                var outLmtUnit = Db.Queryable<MesUnit>()
+                    .Where(u => u.Fnumber == salesOrderSub.OutLmtUnitId)
+                    .Select(u => u.Id)
+                    .First();
+                if (outLmtUnit != null)
+                {
+                    salesOrderSub.OutLmtUnitId = outLmtUnit.ToString();
+                }
+            }
+
+            // SUPPLY_ORG_ID => 1 (鍥哄畾鍊�)
+            salesOrderSub.SupplyOrgId = "1";
+
+            // STOCK_ORG_ID => 1 (鍥哄畾鍊�)
+            salesOrderSub.StockOrgId = "1";
+
+            // SETTLE_ORG_IDS => 1 (鍥哄畾鍊�)
+            salesOrderSub.SettleOrgIds = "1";
+
             salesOrderSubList.Add(salesOrderSub);
         }
 

--
Gitblit v1.9.3