From 4a8f16f0d07d67098e538c6a03bdc979b04af9bc Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期一, 15 九月 2025 16:16:10 +0800
Subject: [PATCH] 1111

---
 MES.Service/service/BasicData/MesRohInManager.cs |  249 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 226 insertions(+), 23 deletions(-)

diff --git a/MES.Service/service/BasicData/MesRohInManager.cs b/MES.Service/service/BasicData/MesRohInManager.cs
index b6a6442..043fab3 100644
--- a/MES.Service/service/BasicData/MesRohInManager.cs
+++ b/MES.Service/service/BasicData/MesRohInManager.cs
@@ -97,41 +97,168 @@
         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;
@@ -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,
@@ -213,25 +371,70 @@
                 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();
+            }
 
             var single = rohInDataManager.GetSingle(it =>
                 it.EbelnK3id == entity.EbelnK3id);
             if (single != null) entity.Guid = single.Guid;
-           
+
             return entity;
         }).ToList();
     }

--
Gitblit v1.9.3