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 |  268 +++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 239 insertions(+), 29 deletions(-)

diff --git a/MES.Service/service/BasicData/MesRohInManager.cs b/MES.Service/service/BasicData/MesRohInManager.cs
index b6a6442..213d614 100644
--- a/MES.Service/service/BasicData/MesRohInManager.cs
+++ b/MES.Service/service/BasicData/MesRohInManager.cs
@@ -94,44 +94,169 @@
         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)
-            mesRohIn.PurchaseDate = DateTime.ParseExact(rohIn.FDate,
-                "yyyy-MM-dd HH:mm:ss", null);
-        mesRohIn.Supplier = rohIn.FSupplierId;
+        /*if (rohIn.FDate != null)
+           mesRohIn.PurchaseDate = DateTime.ParseExact(rohIn.FDate,
+                "yyyy-MM-d H:m:s", null);*/
+
+        // 1. 澶勭悊 fDate锛堥噰璐棩鏈燂級
+        if (!rohIn.FDate.IsNullOrEmpty())
+        {
+            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");
+            }
+
+            mesRohIn.PurchaseDate = purchaseDate;
+        }
+        else
+        {
+            mesRohIn.PurchaseDate = null;
+        }
+
+
+        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 (rohIn.FCancelDate != null)
             if (!mesRohIn.CancellationPerson.IsNullOrEmpty())
                 mesRohIn.CancellationDate =
                     DateTime.ParseExact(rohIn.FCancelDate,
-                        "yyyy-MM-dd HH:mm:ss", null);
+                        "yyyy-MM-d H:m:s", null);
         mesRohIn.CreateBy = rohIn.FCreatorId;
         if (rohIn.FCreateDate != null)
             mesRohIn.CreateDate = DateTime.ParseExact(rohIn.FCreateDate,
-                "yyyy-MM-dd HH:mm:ss", null);
+                "yyyy-MM-d H:m:s", null);
         mesRohIn.LastupdateBy = rohIn.FModifierId;
         if (rohIn.FModifyDate != null)
             mesRohIn.LastupdateDate = DateTime.ParseExact(rohIn.FModifyDate,
-                "yyyy-MM-dd HH:mm:ss", null);
+                "yyyy-MM-d H:m:s", null);
+        mesRohIn.Prearrivaldate = rohIn.Prearrivaldate != null
+            ? DateTime.ParseExact(rohIn.Prearrivaldate,
+                "yyyy-MM-d H:m:s", null)
+            : null;*/
+        if (!rohIn.FCancelDate.IsNullOrEmpty() &&
+            !mesRohIn.CancellationPerson.IsNullOrEmpty())
+        {
+            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");
+            }
+
+            mesRohIn.CancellationDate = cancelDate;
+        }
+        else
+        {
+            mesRohIn.CancellationDate = null;
+        }
+
+        // 3. 澶勭悊 fCreateDate锛堝垱寤烘棩鏈燂級
+        if (!rohIn.FCreateDate.IsNullOrEmpty())
+        {
+            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");
+            }
+
+            mesRohIn.CreateDate = createDate;
+        }
+        else
+        {
+            mesRohIn.CreateDate = null;
+        }
+
+        // 4. 澶勭悊 fModifyDate锛堜慨鏀规棩鏈燂級
+        if (!rohIn.FModifyDate.IsNullOrEmpty())
+        {
+            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");
+            }
+
+            mesRohIn.LastupdateDate = modifyDate;
+        }
+        else
+        {
+            mesRohIn.LastupdateDate = null;
+        }
+
+
+        // 6. 澶勭悊 prearrivaldate锛堥璁″埌璐ф棩鏈燂級
+        if (!rohIn.Prearrivaldate.IsNullOrEmpty())
+        {
+            if (!DateTime.TryParseExact(rohIn.Prearrivaldate, "yyyy-MM-d H:m:s",
+                    CultureInfo.InvariantCulture,
+                    DateTimeStyles.None, out DateTime preArrivalDate))
+            {
+                throw new FormatException(
+                    $"棰勮鍒拌揣鏃ユ湡锛圥rearrivaldate锛夎В鏋愬け璐ワ紒鍊硷細銆恵rohIn.Prearrivaldate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s");
+            }
+
+            mesRohIn.Prearrivaldate = preArrivalDate;
+        }
+        else
+        {
+            mesRohIn.Prearrivaldate = null;
+        }
+
         mesRohIn.ErpCheckBy = rohIn.FApproverId;
         mesRohIn.ErpCheckDate = rohIn.FApproveDate;
         mesRohIn.Changereason = rohIn.FChangeReason;
-        mesRohIn.Prearrivaldate = rohIn.Prearrivaldate != null
-            ? DateTime.ParseExact(rohIn.Prearrivaldate,
-                "yyyy-MM-dd HH:mm:ss", null)
-            : null;
+
         mesRohIn.ReceiveOrgId = rohIn.FReceiveOrgId;
         mesRohIn.ProviderId = rohIn.FProviderId;
         mesRohIn.Anred = rohIn.FTContact;
@@ -140,6 +265,8 @@
         mesRohIn.Address = rohIn.Address;
         mesRohIn.Acctype = rohIn.Acctype;
         mesRohIn.SynchronousDate = DateTime.Now;
+        mesRohIn.DocumentStatus = "C";
+        mesRohIn.CancellationStatus = "A";
 
         return mesRohIn;
     }
@@ -161,17 +288,48 @@
                 InventoryUnit = s.FStockUnitID,
                 PricingUnit = s.FPriceUnitId,
                 PricingQty = Convert.ToDecimal(s.FPriceUnitQty),
+                /*
                 DeliveryDate = s.FDeliveryDate != null
                     ? DateTime.ParseExact(s.FDeliveryDate,
-                        "yyyy-MM-dd HH:mm:ss", null)
+                        "yyyy-MM-d H:m:s", null)
                     : null,
                 EarliestDeliveryDate = s.FDeliveryEarlyDate != null
                     ? DateTime.ParseExact(s.FDeliveryEarlyDate,
-                        "yyyy-MM-dd HH:mm:ss", null)
+                        "yyyy-MM-d H:m:s", null)
                     : null,
                 LatestDeliveryDate = s.FDeliveryLastDate != null
                     ? DateTime.ParseExact(s.FDeliveryLastDate,
-                        "yyyy-MM-dd HH:mm:ss", null)
+                        "yyyy-MM-d H:m:s", null)
+                    : null,
+                    */
+                // 1. 澶勭悊 fDeliveryDate锛堜氦璐ф棩鏈燂級
+                DeliveryDate = !s.FDeliveryDate.IsNullOrEmpty()
+                    ? (DateTime.TryParseExact(s.FDeliveryDate,
+                        "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                        DateTimeStyles.None, out DateTime deliveryDate)
+                        ? deliveryDate
+                        : throw new FormatException(
+                            $"浜よ揣鏃ユ湡锛團DeliveryDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵s.FDeliveryDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s"))
+                    : null,
+
+                // 2. 澶勭悊 fDeliveryEarlyDate锛堟渶鏃╀氦璐ф棩鏈燂級
+                EarliestDeliveryDate = !s.FDeliveryEarlyDate.IsNullOrEmpty()
+                    ? (DateTime.TryParseExact(s.FDeliveryEarlyDate,
+                        "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                        DateTimeStyles.None, out DateTime earlyDate)
+                        ? earlyDate
+                        : throw new FormatException(
+                            $"鏈�鏃╀氦璐ф棩鏈燂紙FDeliveryEarlyDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵s.FDeliveryEarlyDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s"))
+                    : null,
+
+                // 3. 澶勭悊 fDeliveryLastDate锛堟渶鏅氫氦璐ф棩鏈燂級
+                LatestDeliveryDate = !s.FDeliveryLastDate.IsNullOrEmpty()
+                    ? (DateTime.TryParseExact(s.FDeliveryLastDate,
+                        "yyyy-MM-d H:m:s", CultureInfo.InvariantCulture,
+                        DateTimeStyles.None, out DateTime lastDate)
+                        ? lastDate
+                        : throw new FormatException(
+                            $"鏈�鏅氫氦璐ф棩鏈燂紙FDeliveryLastDate锛夎В鏋愬け璐ワ紒鍊硷細銆恵s.FDeliveryLastDate}銆戯紝鏀寔鏍煎紡锛歽yyy-MM-d H:m:s"))
                     : null,
                 IsGift = s.FGiveAway,
                 Remarks = s.FEntryNote,
@@ -179,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 =
@@ -202,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,
@@ -213,25 +375,73 @@
                 SalesOrderId = s.SalesOrderId,
                 OrderLineId = s.OrderLineId,
                 FSUBREQENTRYID = s.FSUBREQENTRYID
-               
             };
 
-            if (s.FFreezeDate != null)
+            /*if (s.FFreezeDate != null)
                 if (!s.FFreezerId.IsNullOrEmpty())
                     entity.FreezeTime =
                         DateTime.ParseExact(s.FFreezeDate,
-                            "yyyy-MM-dd HH:mm:ss", null);
+                            "yyyy-MM-d H:m:s", null);
 
             if (s.FTerminateDate != null)
                 if (!s.FTerminaterId.IsNullOrEmpty())
                     entity.TerminateTime =
                         DateTime.ParseExact(s.FTerminateDate,
-                            "yyyy-MM-dd HH:mm:ss", null);
+                            "yyyy-MM-d H:m:s", null);*/
+// 4. 澶勭悊 fFreezeDate锛堝喕缁撴棩鏈燂級
+            if (!s.FFreezeDate.IsNullOrEmpty() && !s.FFreezerId.IsNullOrEmpty())
+            {
+                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");
+                }
+
+                entity.FreezeTime = freezeTime;
+            }
+            else
+            {
+                entity.FreezeTime = null;
+            }
+
+            // 5. 澶勭悊 fTerminateDate锛堢粓姝㈡棩鏈燂級
+            if (!s.FTerminateDate.IsNullOrEmpty() &&
+                !s.FTerminaterId.IsNullOrEmpty())
+            {
+                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");
+                }
+
+                entity.TerminateTime = terminateTime;
+            }
+            else
+            {
+                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;
-           
+
             return entity;
         }).ToList();
     }

--
Gitblit v1.9.3