From 9d296c888a8ac49f606c0a3ebd843e617cfc0a40 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期二, 16 九月 2025 11:39:07 +0800
Subject: [PATCH] 11

---
 MES.Service/service/BasicData/MesRohInManager.cs |  124 ++++++++++++++++++++++++++++++++---------
 1 files changed, 96 insertions(+), 28 deletions(-)

diff --git a/MES.Service/service/BasicData/MesRohInManager.cs b/MES.Service/service/BasicData/MesRohInManager.cs
index c1be11a..213d614 100644
--- a/MES.Service/service/BasicData/MesRohInManager.cs
+++ b/MES.Service/service/BasicData/MesRohInManager.cs
@@ -94,7 +94,6 @@
         if (single != null) mesRohIn.Guid = single.Guid;
         mesRohIn.EbelnK3id = eid;
         mesRohIn.BillNo = rohIn.FBillNo;
-        mesRohIn.DocumentStatus = rohIn.FDocumentStatus;
         mesRohIn.DocumentType = rohIn.FBillTypeID;
         mesRohIn.BusinessType = rohIn.FBusinessType;
         /*if (rohIn.FDate != null)
@@ -104,10 +103,12 @@
         // 1. 澶勭悊 fDate锛堥噰璐棩鏈燂級
         if (!rohIn.FDate.IsNullOrEmpty())
         {
-            if (!DateTime.TryParseExact(rohIn.FDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+            if (!DateTime.TryParseExact(rohIn.FDate, "yyyy-MM-d H:m:s",
+                    CultureInfo.InvariantCulture,
                     DateTimeStyles.None, out DateTime purchaseDate))
             {
-                throw new FormatException($"閲囪喘鏃ユ湡锛團Date锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
+                throw new FormatException(
+                    $"閲囪喘鏃ユ湡锛團Date锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
             }
 
             mesRohIn.PurchaseDate = purchaseDate;
@@ -118,17 +119,49 @@
         }
 
 
-        mesRohIn.Supplier = rohIn.FSupplierId;
+        var mesSupplier = Db.Queryable<MesSupplier>()
+            .Where(s => s.SuppNo == rohIn.FSupplierId)
+            .First();
+
+        if (mesSupplier != null)
+        {
+            mesRohIn.Supplier = mesSupplier.Id.ToString();
+        }
+
+        // SETTLEMENT_PARTY -> MesSupplier.id
+        if (!string.IsNullOrEmpty(rohIn.FSettleId))
+        {
+            var settlementSupplier = Db.Queryable<MesSupplier>()
+                .Where(s => s.SuppNo == rohIn.FSettleId)
+                .Select(s => s.Id)
+                .First();
+            if (settlementSupplier != null)
+            {
+                mesRohIn.SettlementParty = settlementSupplier.ToString();
+            }
+        }
+
+        // PURCHASE_DEPT -> SYS_DEPARTMENT.DEPARTMENTID
+        if (!string.IsNullOrEmpty(rohIn.FPurchaseDeptId))
+        {
+            var department = Db.Queryable<SysDepartment>()
+                .Where(d => d.Departmentcode == rohIn.FPurchaseDeptId)
+                .Select(d => d.Id)
+                .First();
+            if (department != null)
+            {
+                mesRohIn.PurchaseDept = department.ToString();
+            }
+        }
+
         mesRohIn.CloseStatus = rohIn.FCloseStatus;
-        mesRohIn.PurchaseOrg = rohIn.FPurchaseOrgId;
-        mesRohIn.PurchaseDept = rohIn.FPurchaseDeptId;
+        // mesRohIn.PurchaseOrg = rohIn.FPurchaseOrgId;
+        mesRohIn.PurchaseOrg = "1";
         mesRohIn.PurchaseGroup = rohIn.FPurchaserGroupId;
         mesRohIn.Purchaser = rohIn.FPurchaserId;
-        mesRohIn.SettlementParty = rohIn.FSettleId;
         mesRohIn.PaymentParty = rohIn.FChargeId;
         mesRohIn.Email = rohIn.FProviderEMail;
         mesRohIn.Remarks = rohIn.Remarks;
-        mesRohIn.CancellationStatus = rohIn.FCancelStatus;
         mesRohIn.CancellationPerson = rohIn.FCancellerId;
         /*if (rohIn.FCancelDate != null)
             if (!mesRohIn.CancellationPerson.IsNullOrEmpty())
@@ -147,12 +180,15 @@
             ? DateTime.ParseExact(rohIn.Prearrivaldate,
                 "yyyy-MM-d H:m:s", null)
             : null;*/
-        if (!rohIn.FCancelDate.IsNullOrEmpty() && !mesRohIn.CancellationPerson.IsNullOrEmpty())
+        if (!rohIn.FCancelDate.IsNullOrEmpty() &&
+            !mesRohIn.CancellationPerson.IsNullOrEmpty())
         {
-            if (!DateTime.TryParseExact(rohIn.FCancelDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+            if (!DateTime.TryParseExact(rohIn.FCancelDate, "yyyy-MM-d H:m:s",
+                    CultureInfo.InvariantCulture,
                     DateTimeStyles.None, out DateTime cancelDate))
             {
-                throw new FormatException($"鍙栨秷鏃ユ湡锛團CancelDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FCancelDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
+                throw new FormatException(
+                    $"鍙栨秷鏃ユ湡锛團CancelDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FCancelDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
             }
 
             mesRohIn.CancellationDate = cancelDate;
@@ -165,10 +201,12 @@
         // 3. 澶勭悊 fCreateDate锛堝垱寤烘棩鏈燂級
         if (!rohIn.FCreateDate.IsNullOrEmpty())
         {
-            if (!DateTime.TryParseExact(rohIn.FCreateDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+            if (!DateTime.TryParseExact(rohIn.FCreateDate, "yyyy-MM-d H:m:s",
+                    CultureInfo.InvariantCulture,
                     DateTimeStyles.None, out DateTime createDate))
             {
-                throw new FormatException($"鍒涘缓鏃ユ湡锛團CreateDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FCreateDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
+                throw new FormatException(
+                    $"鍒涘缓鏃ユ湡锛團CreateDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FCreateDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
             }
 
             mesRohIn.CreateDate = createDate;
@@ -181,10 +219,12 @@
         // 4. 澶勭悊 fModifyDate锛堜慨鏀规棩鏈燂級
         if (!rohIn.FModifyDate.IsNullOrEmpty())
         {
-            if (!DateTime.TryParseExact(rohIn.FModifyDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+            if (!DateTime.TryParseExact(rohIn.FModifyDate, "yyyy-MM-d H:m:s",
+                    CultureInfo.InvariantCulture,
                     DateTimeStyles.None, out DateTime modifyDate))
             {
-                throw new FormatException($"淇敼鏃ユ湡锛團ModifyDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FModifyDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
+                throw new FormatException(
+                    $"淇敼鏃ユ湡锛團ModifyDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.FModifyDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
             }
 
             mesRohIn.LastupdateDate = modifyDate;
@@ -198,7 +238,8 @@
         // 6. 澶勭悊 prearrivaldate锛堥璁″埌璐ф棩鏈燂級
         if (!rohIn.Prearrivaldate.IsNullOrEmpty())
         {
-            if (!DateTime.TryParseExact(rohIn.Prearrivaldate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+            if (!DateTime.TryParseExact(rohIn.Prearrivaldate, "yyyy-MM-d H:m:s",
+                    CultureInfo.InvariantCulture,
                     DateTimeStyles.None, out DateTime preArrivalDate))
             {
                 throw new FormatException(
@@ -224,6 +265,8 @@
         mesRohIn.Address = rohIn.Address;
         mesRohIn.Acctype = rohIn.Acctype;
         mesRohIn.SynchronousDate = DateTime.Now;
+        mesRohIn.DocumentStatus = "C";
+        mesRohIn.CancellationStatus = "A";
 
         return mesRohIn;
     }
@@ -261,7 +304,8 @@
                     */
                 // 1. 澶勭悊 fDeliveryDate锛堜氦璐ф棩鏈燂級
                 DeliveryDate = !s.FDeliveryDate.IsNullOrEmpty()
-                    ? (DateTime.TryParseExact(s.FDeliveryDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                    ? (DateTime.TryParseExact(s.FDeliveryDate,
+                        "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
                         DateTimeStyles.None, out DateTime deliveryDate)
                         ? deliveryDate
                         : throw new FormatException(
@@ -270,7 +314,8 @@
 
                 // 2. 澶勭悊 fDeliveryEarlyDate锛堟渶鏃╀氦璐ф棩鏈燂級
                 EarliestDeliveryDate = !s.FDeliveryEarlyDate.IsNullOrEmpty()
-                    ? (DateTime.TryParseExact(s.FDeliveryEarlyDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                    ? (DateTime.TryParseExact(s.FDeliveryEarlyDate,
+                        "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
                         DateTimeStyles.None, out DateTime earlyDate)
                         ? earlyDate
                         : throw new FormatException(
@@ -279,7 +324,8 @@
 
                 // 3. 澶勭悊 fDeliveryLastDate锛堟渶鏅氫氦璐ф棩鏈燂級
                 LatestDeliveryDate = !s.FDeliveryLastDate.IsNullOrEmpty()
-                    ? (DateTime.TryParseExact(s.FDeliveryLastDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                    ? (DateTime.TryParseExact(s.FDeliveryLastDate,
+                        "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
                         DateTimeStyles.None, out DateTime lastDate)
                         ? lastDate
                         : throw new FormatException(
@@ -291,10 +337,13 @@
                 SupplierItemName = s.FSupMatName,
                 OutsourcingOrderId = s.FSUBREQBILLNO,
                 BatchNumber = s.FLot,
-                BusinessClose = s.FMRPCloseStatus,
-                BusinessFreeze = s.FMRPFreezeStatus,
+                // BusinessClose = s.FMRPCloseStatus,
+                // BusinessFreeze = s.FMRPFreezeStatus,
+                BusinessClose = "A",
+                BusinessFreeze = "A",
                 Freezer = s.FFreezerId,
-                BusinessTerminate = s.FMRPTerminateStatus,
+                // BusinessTerminate = s.FMRPTerminateStatus,
+                BusinessTerminate = "A",
                 Terminator = s.FTerminaterId,
                 TotalReceivedQty = Convert.ToDecimal(s.FReceiveQty), //绱鏀舵枡鏁�
                 RemainingReceivedQty =
@@ -314,7 +363,8 @@
                 DemandDocumentId = s.FDEMANDBILLNO,
                 DemandDocumentLineId = s.FDEMANDBILLENTRYSEQ,
                 DemandOrg = s.FRequireOrgId,
-                ReceivingOrg = s.FReceiveOrgId,
+                // ReceivingOrg = s.FReceiveOrgId,
+                ReceivingOrg = "1",
                 SettlementOrg = s.FEntrySettleOrgId,
                 PurchaseOrderLineNumber = s.FSEQ,
                 Demand = s.FRequireOrgId,
@@ -341,10 +391,12 @@
 // 4. 澶勭悊 fFreezeDate锛堝喕缁撴棩鏈燂級
             if (!s.FFreezeDate.IsNullOrEmpty() && !s.FFreezerId.IsNullOrEmpty())
             {
-                if (!DateTime.TryParseExact(s.FFreezeDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                if (!DateTime.TryParseExact(s.FFreezeDate, "yyyy-MM-d H:m:s",
+                        CultureInfo.InvariantCulture,
                         DateTimeStyles.None, out DateTime freezeTime))
                 {
-                    throw new FormatException($"鍐荤粨鏃ユ湡锛團FreezeDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵s.FFreezeDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
+                    throw new FormatException(
+                        $"鍐荤粨鏃ユ湡锛團FreezeDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵s.FFreezeDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
                 }
 
                 entity.FreezeTime = freezeTime;
@@ -355,12 +407,15 @@
             }
 
             // 5. 澶勭悊 fTerminateDate锛堢粓姝㈡棩鏈燂級
-            if (!s.FTerminateDate.IsNullOrEmpty() && !s.FTerminaterId.IsNullOrEmpty())
+            if (!s.FTerminateDate.IsNullOrEmpty() &&
+                !s.FTerminaterId.IsNullOrEmpty())
             {
-                if (!DateTime.TryParseExact(s.FTerminateDate, "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                if (!DateTime.TryParseExact(s.FTerminateDate, "yyyy-MM-d H:m:s",
+                        CultureInfo.InvariantCulture,
                         DateTimeStyles.None, out DateTime terminateTime))
                 {
-                    throw new FormatException($"缁堟鏃ユ湡锛團TerminateDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵s.FTerminateDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
+                    throw new FormatException(
+                        $"缁堟鏃ユ湡锛團TerminateDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵s.FTerminateDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
                 }
 
                 entity.TerminateTime = terminateTime;
@@ -370,6 +425,19 @@
                 entity.TerminateTime = null;
             }
 
+            //ItemId
+            var mesItems = Db.Queryable<MesItems>()
+                .Where(s => s.ItemNo == entity.ItemId)
+                .First();
+
+            if (mesItems != null)
+            {
+                entity.ItemId = mesItems.Id.ToString();
+            }
+            
+            //BUSINESS_TERMINATE = 'A',RECEIVING_ORG = 1
+            
+
             var single = rohInDataManager.GetSingle(it =>
                 it.EbelnK3id == entity.EbelnK3id);
             if (single != null) entity.Guid = single.Guid;

--
Gitblit v1.9.3