From fbd1dae61bb8eeccd303341ff3b5290d805a8155 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期五, 19 十二月 2025 18:40:25 +0800
Subject: [PATCH] 111

---
 StandardPda/MES.Service/service/BasicData/SalesDeliveryNoticeManager.cs |  579 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 298 insertions(+), 281 deletions(-)

diff --git a/StandardPda/MES.Service/service/BasicData/SalesDeliveryNoticeManager.cs b/StandardPda/MES.Service/service/BasicData/SalesDeliveryNoticeManager.cs
index 34d57b6..51dedf3 100644
--- a/StandardPda/MES.Service/service/BasicData/SalesDeliveryNoticeManager.cs
+++ b/StandardPda/MES.Service/service/BasicData/SalesDeliveryNoticeManager.cs
@@ -1,306 +1,323 @@
-锘縰sing SqlSugar;
-using System;
-using System.Collections.Generic;
+锘縰sing System.Globalization;
 using MES.Service.DB;
-using MES.Service.Modes;
 using MES.Service.Dto.webApi;
-using MES.Service.service.BasicData;
-using System.Globalization;
+using MES.Service.Modes;
+using SqlSugar;
 
-namespace MES.Service.service
+namespace MES.Service.service;
+
+public class SalesDeliveryNoticeManager : Repository<SalesDeliveryNotice>
 {
-    public class SalesDeliveryNoticeManager : Repository<SalesDeliveryNotice>
+    //褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉�
+
+    private readonly SalesDeliveryNoticeDetailManager
+        _SalesDeliveryDetailManager =
+            new();
+
+    //ErpSalesRerurn
+    public bool Save(ErpSalesDelivery SalesDelivery)
+    {
+        var erpSalesDeliveryDto = SalesDelivery.OrderDto;
+        var mesSalesDelivery =
+            ConvertErpToSalesDelivery(SalesDelivery.OrderDto);
+        var mesSalesDeliveryDatas =
+            ConvertErpToSalesDeliveryDetail(SalesDelivery.Items);
+
+        return UseTransaction(db =>
+        {
+            switch (erpSalesDeliveryDto.Type)
+            {
+                // case "2":
+                //     return InsertData(db, mesSalesReturn, mesSalesReturnDatas,
+                //         rohInErpRohIn.FBILLTYPE)
+                //         ? 1
+                //         : 0;
+                case "3":
+                    return UpdateData(db, mesSalesDelivery,
+                        mesSalesDeliveryDatas)
+                        ? 1
+                        : 0;
+                case "2":
+                case "4":
+                    return SaveOrUpdateData(db, mesSalesDelivery,
+                        mesSalesDeliveryDatas, erpSalesDeliveryDto.Type)
+                        ? 1
+                        : 0;
+                default:
+                    throw new NotImplementedException(
+                        $"type娌℃湁{erpSalesDeliveryDto.Type}杩欎釜绫诲瀷");
+            }
+        }) > 0;
+    }
+
+    private bool UpdateData(SqlSugarScope db,
+        SalesDeliveryNotice mesSalesDelivery,
+        List<SalesDeliveryNoticeDetail> mesSalesDeliveryDatas)
+    {
+        var decimals = mesSalesDeliveryDatas.Select(s => s.Id).ToArray();
+        var XS_OUT_COUNT =
+    Db.Ado.SqlQuery<decimal>("SELECT count(*) FROM MES_INV_ITEM_OUTS A where A.WORK_NO = '"+ mesSalesDelivery.BillNo+ "'  and A.BILL_TYPE_ID = 200  AND A.TRANSACTION_NO = 250")
+        .First();
+
+        if (XS_OUT_COUNT > 0)
+        {
+            throw new NotImplementedException("璇ラ攢鍞氦浠橀�氱煡鍗曞凡鐢熸垚鍑哄簱鍗曪紝涓嶈兘淇敼锛�");
+        }
+        
+        var update = base.DeleteById(mesSalesDelivery.Id);
+        var insertOrUpdate = db
+            .Deleteable<SalesDeliveryNoticeDetail>().In(decimals)
+            .ExecuteCommand() > 0;
+
+        if (update && insertOrUpdate) return true;
+        throw new NotImplementedException("鏇存柊澶辫触");
+    }
+
+    // 鎻掑叆鎴栨洿鏂版暟鎹殑鏂规硶
+    private bool SaveOrUpdateData(SqlSugarScope db,
+        SalesDeliveryNotice mesSalesDelivery,
+        List<SalesDeliveryNoticeDetail> mesSalesDeliveryDatas, string type)
     {
 
-        //褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉�
+        var XS_OUT_COUNT =
+    Db.Ado.SqlQuery<decimal>("SELECT count(*) FROM MES_INV_ITEM_OUTS A where A.WORK_NO = '" + mesSalesDelivery.BillNo + "'  and A.BILL_TYPE_ID = 200  AND A.TRANSACTION_NO = 250")
+        .First();
 
-        private readonly SalesDeliveryNoticeDetailManager _SalesDeliveryDetailManager =
-            new();
-        //ErpSalesRerurn
-        public bool Save(ErpSalesDelivery SalesDelivery)
+        if (XS_OUT_COUNT > 0)
         {
-            var erpSalesDeliveryDto = SalesDelivery.OrderDto;
-            var mesSalesDelivery = ConvertErpToSalesDelivery(SalesDelivery.OrderDto);
-            var mesSalesDeliveryDatas = ConvertErpToSalesDeliveryDetail(SalesDelivery.Items);
+            throw new NotImplementedException("璇ラ攢鍞氦浠橀�氱煡鍗曞凡鐢熸垚鍑哄簱鍗曪紝涓嶈兘淇敼锛�");
+        }
+        if (mesSalesDelivery.Id != null) base.DeleteById(mesSalesDelivery.Id);
 
-            return UseTransaction(db =>
-            {
-                switch (erpSalesDeliveryDto.Type)
-                {
-                    // case "2":
-                    //     return InsertData(db, mesSalesReturn, mesSalesReturnDatas,
-                    //         rohInErpRohIn.FBILLTYPE)
-                    //         ? 1
-                    //         : 0;
-                    case "3":
-                        return UpdateData(db, mesSalesDelivery, mesSalesDeliveryDatas) ? 1 : 0;
-                    case "2":
-                    case "4":
-                        return SaveOrUpdateData(db, mesSalesDelivery, mesSalesDeliveryDatas, erpSalesDeliveryDto.Type)
-                            ? 1
-                            : 0;
-                    default:
-                        throw new NotImplementedException(
-                            $"type娌℃湁{erpSalesDeliveryDto.Type}杩欎釜绫诲瀷");
-                }
-            }) > 0;
+        if (mesSalesDeliveryDatas.Count > 0)
+            db.Deleteable<SalesDeliveryNoticeDetail>()
+                .Where(s => s.ErpHeadId == mesSalesDelivery.ErpId)
+                .ExecuteCommand();
+
+        var orUpdate = base.Insert(mesSalesDelivery);
+        //var baOrUpdate = _SalesDeliveryDetailManager.InsertRange(mesSalesDeliveryDatas);
+        foreach (var item in mesSalesDeliveryDatas)
+            _SalesDeliveryDetailManager.Insert(item);
+
+        //if (orUpdate && baOrUpdate) return true;
+        return orUpdate;
+
+
+        throw new NotImplementedException("鎻掑叆鎴栨洿鏂板け璐�");
+    }
+
+    // 鎵归噺淇濆瓨璁板綍鐨勬柟娉�
+    public bool SaveList(List<ErpSalesDelivery> salesOrder)
+    {
+        var result = salesOrder.Select(Save).ToList();
+        return result.All(b => b);
+    }
+
+    private SalesDeliveryNotice ConvertErpToSalesDelivery(
+        ErpSalesDeliveryDto erpDto)
+    {
+        DateTime parsedDate;
+
+        // 鏃堕棿鏍煎紡杞崲鍑芥暟锛孍RP鏃堕棿鏍煎紡涓� "yyyy-MM-dd HH:mm:ss"
+        DateTime? ParseDateTime(string dateStr)
+        {
+            if (DateTime.TryParseExact(dateStr, "yyyy-MM-dd HH:mm:ss",
+                    CultureInfo.InvariantCulture,
+                    DateTimeStyles.None,
+                    out parsedDate))
+                return parsedDate;
+
+            return null; // 濡傛灉杞崲澶辫触锛岃繑鍥瀗ull
         }
 
-        private bool UpdateData(SqlSugarScope db, SalesDeliveryNotice mesSalesDelivery,
-            List<SalesDeliveryNoticeDetail> mesSalesDeliveryDatas)
+        var salesOrder = new SalesDeliveryNotice
         {
-            var decimals = mesSalesDeliveryDatas.Select(s => s.Id).ToArray();
-            var update = base.DeleteById(mesSalesDelivery.Id);
-            var insertOrUpdate = db
-                .Deleteable<SalesDeliveryNoticeDetail>().In(decimals)
-                .ExecuteCommand() > 0;
+            BillNo = erpDto.FBillNo,
+            ErpId = erpDto.ErpID,
+            FDate = ParseDateTime(erpDto.FDate) ?? null,
+            BillType = erpDto.FBillTypeID, // 鍗曟嵁绫诲瀷
+            //Currency = erpDto.FSettleCurrld, // 缁撶畻甯佸埆
+            SalesDept = erpDto.FSaleDeptId, //閿�鍞儴闂�
+            //Customer = erpDto.FCustomerID, // 瀹㈡埛
+            DeliveryMethod = erpDto.FHeadDeliveryWay, // 浜よ揣鏂瑰紡
+            //DeliveryLocation = erpDto.FHeadLocId, // 浜よ揣鍦扮偣
+            //Carrier = erpDto.FCarrierID, // 鎵胯繍鍟�
+            //TransportNo = erpDto.FCarriageNO, // 杩愯緭鍗曞彿
+            //BillNoType = erpDto.FCarriageNO, // 鍗曟嵁鐘舵��
+            //DeliveryDept = erpDto.FDeliveryDeptID, // 鍙戣揣閮ㄩ棬
+            //InventoryGroup = erpDto.FStockerGroupId, // 搴撳瓨缁�
+            //WarehouseManager = erpDto.FStockerId, // 浠撶鍛�
+            //SalesGroup = erpDto.FSaleGroupId, // 閿�鍞粍
+            SalesPerson = erpDto.FSalerId, //閿�鍞憳
+            //Receiver = erpDto.FReceiveCusId, // 鏀惰揣鏂�
+            //ReceiverContact = erpDto.FReceiveCusContact, // 鏀惰揣鏂硅仈绯讳汉
+            ReceiverAddress = erpDto.FReceiveAddress, // 鏀惰揣鏂瑰湴鍧�
+            //ReceiverName = erpDto.FLinkMan, // 鏀惰揣鏂瑰鍚�
+            //LinkPhone    = erpDto.FLinkPhone,//鑱旂郴鐢佃瘽
+            //SettleParty = erpDto.FSettleID, // 缁撶畻鏂�
+            //PayerParty = erpDto.FPayerID,//浠樻鏂�
+            //CreatedBy = erpDto.FCreatorId, // 鍒涘缓浜�
+            CreatedDate = ParseDateTime(erpDto.FCreateDate) ?? null, // 鍒涘缓鏃堕棿
+            //ModifiedBy = erpDto.FModifierId, // 淇敼浜�
+            //ModifiedDate = ParseDateTime(erpDto.FModifyDate) ?? null, // 淇敼鏃堕棿
+            //ClosedBy = erpDto.FCloserId, // 鍏抽棴浜�
+            //CloseReason = erpDto.FCloseReason, // 鍏抽棴鍘熷洜
+            // CloseDate = ParseDateTime(erpDto.FCloseDate) ?? null, // 鍏抽棴鏃ユ湡
+            ApprovedBy = erpDto.FApproverId, // 瀹℃牳浜�
+            ApprovedDate = ParseDateTime(erpDto.FApproveDate) ?? null, // 瀹℃牳鏃ユ湡
+            //CancelStatus = erpDto.FCancelStatus, // 浣滃簾鐘舵��
+            //CancelledBy = erpDto.FCancellerId, // 浣滃簾浜�
+            //CancelDate = ParseDateTime(erpDto.FCancelDate) ?? null, // 浣滃簾鏃ユ湡
+            //CloseStatus = erpDto.FBillCloseStatus, // 鍏抽棴鐘舵��
+            BillStatus = erpDto.FDocumentStatus, //鍗曟嵁鐘舵��
+            DeliveryOrg = erpDto.FDeliveryOrgID, //鍙戣揣缁勭粐
+            //SalesOrg    = erpDto.FSaleOrgId //閿�鍞粍缁�
+            FSourceCategory = erpDto.FSourceCategory,
+            FSourceDocument = erpDto.FSourceDocument,
+            FDeliveryDate = erpDto.FDeliveryDate,
+            FProject = erpDto.FProject,
+            FCustomerPo = erpDto.FCustomerPo,
+            FShippingPolicy = erpDto.FShippingPolicy,
+            FShippingPort = erpDto.FShippingPort,
+            FDestinationPort = erpDto.FDestinationPort,
+            FReceiverContactID = erpDto.FReceiverContactID,
+            FEntryNote = erpDto.FEntryNote,
+            FVersionNo = erpDto.FVersionNo,
+            FBusinessType = erpDto.FBusinessType,
+            FHEADLOCID = erpDto.FHEADLOCID,
+            FCustId = erpDto.FCustId,
+            FNote = erpDto.FNote
+        };
 
-            if (update && insertOrUpdate) return true;
-            throw new NotImplementedException("鏇存柊澶辫触");
+        var single = base.GetSingle(it => it.ErpId == erpDto.ErpID);
+        if (single != null) salesOrder.Id = single.Id;
+
+        if (salesOrder.ErpId is null || salesOrder.ErpId == "")
+            throw new NotImplementedException(
+                "琛ㄥごErpID涓嶈兘涓虹┖");
+        return salesOrder;
+    }
+
+    private List<SalesDeliveryNoticeDetail> ConvertErpToSalesDeliveryDetail(
+        List<ErpSalesDeliveryDetailDto> erpDtoList)
+
+    {
+        var salesOrderSubList =
+            new List<SalesDeliveryNoticeDetail>();
+
+        DateTime parsedDate;
+
+        // 鏃堕棿鏍煎紡杞崲鍑芥暟锛孍RP鏃堕棿鏍煎紡涓� "yyyy-MM-dd HH:mm:ss"
+        DateTime? ParseDateTime(string dateStr)
+        {
+            if (DateTime.TryParseExact(dateStr, "yyyy-MM-dd HH:mm:ss",
+                    CultureInfo.InvariantCulture,
+                    DateTimeStyles.None,
+                    out parsedDate))
+                return parsedDate;
+
+            return null; // 濡傛灉杞崲澶辫触锛岃繑鍥瀗ull
         }
 
-        // 鎻掑叆鎴栨洿鏂版暟鎹殑鏂规硶
-        private bool SaveOrUpdateData(SqlSugarScope db, SalesDeliveryNotice mesSalesDelivery,
-            List<SalesDeliveryNoticeDetail> mesSalesDeliveryDatas, string type)
+
+        foreach (var erpDto in erpDtoList)
         {
-            if (mesSalesDelivery.Id != null) base.DeleteById(mesSalesDelivery.Id);
-
-            if (mesSalesDeliveryDatas.Count > 0)
-                db.Deleteable<SalesDeliveryNoticeDetail>()
-                    .Where(s => s.ErpHeadId == mesSalesDelivery.ErpId).ExecuteCommand();
-
-            var orUpdate = base.Insert(mesSalesDelivery);
-            //var baOrUpdate = _SalesDeliveryDetailManager.InsertRange(mesSalesDeliveryDatas);
-            foreach (var item in mesSalesDeliveryDatas)
+            var salesOrderSub = new SalesDeliveryNoticeDetail
             {
-                _SalesDeliveryDetailManager.Insert(item);
-            }
-
-            //if (orUpdate && baOrUpdate) return true;
-            return orUpdate;
-
-
-            throw new NotImplementedException("鎻掑叆鎴栨洿鏂板け璐�");
-        }
-
-        // 鎵归噺淇濆瓨璁板綍鐨勬柟娉�
-        public bool SaveList(List<ErpSalesDelivery> salesOrder)
-        {
-            var result = salesOrder.Select(Save).ToList();
-            return result.All(b => b);
-        }
-
-        private SalesDeliveryNotice ConvertErpToSalesDelivery(
-            ErpSalesDeliveryDto erpDto)
-        {
-            DateTime parsedDate;
-
-            // 鏃堕棿鏍煎紡杞崲鍑芥暟锛孍RP鏃堕棿鏍煎紡涓� "yyyy-MM-dd HH:mm:ss"
-            DateTime? ParseDateTime(string dateStr)
-            {
-                if (DateTime.TryParseExact(dateStr, "yyyy-MM-dd HH:mm:ss",
-                        CultureInfo.InvariantCulture,
-                        DateTimeStyles.None,
-                        out parsedDate))
-                    return parsedDate;
-
-                return null; // 濡傛灉杞崲澶辫触锛岃繑鍥瀗ull
-            }
-
-            var salesOrder = new SalesDeliveryNotice
-            {
-                BillNo = erpDto.FBillNo,
-                ErpId = erpDto.ErpID,
-                FDate = ParseDateTime(erpDto.FDate) ?? null,
-                BillType = erpDto.FBillTypeID, // 鍗曟嵁绫诲瀷
-                //Currency = erpDto.FSettleCurrld, // 缁撶畻甯佸埆
-                SalesDept = erpDto.FSaleDeptId, //閿�鍞儴闂�
-                //Customer = erpDto.FCustomerID, // 瀹㈡埛
-                DeliveryMethod = erpDto.FHeadDeliveryWay, // 浜よ揣鏂瑰紡
-                //DeliveryLocation = erpDto.FHeadLocId, // 浜よ揣鍦扮偣
-                //Carrier = erpDto.FCarrierID, // 鎵胯繍鍟�
-                //TransportNo = erpDto.FCarriageNO, // 杩愯緭鍗曞彿
-                //BillNoType = erpDto.FCarriageNO, // 鍗曟嵁鐘舵��
-                //DeliveryDept = erpDto.FDeliveryDeptID, // 鍙戣揣閮ㄩ棬
-                //InventoryGroup = erpDto.FStockerGroupId, // 搴撳瓨缁�
-                //WarehouseManager = erpDto.FStockerId, // 浠撶鍛�
-                //SalesGroup = erpDto.FSaleGroupId, // 閿�鍞粍
-                SalesPerson = erpDto.FSalerId,//閿�鍞憳
-                //Receiver = erpDto.FReceiveCusId, // 鏀惰揣鏂�
-                //ReceiverContact = erpDto.FReceiveCusContact, // 鏀惰揣鏂硅仈绯讳汉
-                ReceiverAddress = erpDto.FReceiveAddress, // 鏀惰揣鏂瑰湴鍧�
-                //ReceiverName = erpDto.FLinkMan, // 鏀惰揣鏂瑰鍚�
-                //LinkPhone    = erpDto.FLinkPhone,//鑱旂郴鐢佃瘽
-                //SettleParty = erpDto.FSettleID, // 缁撶畻鏂�
-                //PayerParty = erpDto.FPayerID,//浠樻鏂�
-                //CreatedBy = erpDto.FCreatorId, // 鍒涘缓浜�
-                CreatedDate = ParseDateTime(erpDto.FCreateDate) ?? null, // 鍒涘缓鏃堕棿
-                                                                         //ModifiedBy = erpDto.FModifierId, // 淇敼浜�
-                                                                         //ModifiedDate = ParseDateTime(erpDto.FModifyDate) ?? null, // 淇敼鏃堕棿
-                                                                         //ClosedBy = erpDto.FCloserId, // 鍏抽棴浜�
-                                                                         //CloseReason = erpDto.FCloseReason, // 鍏抽棴鍘熷洜
-                                                                         // CloseDate = ParseDateTime(erpDto.FCloseDate) ?? null, // 鍏抽棴鏃ユ湡
-                ApprovedBy = erpDto.FApproverId, // 瀹℃牳浜�
-                ApprovedDate = ParseDateTime(erpDto.FApproveDate) ?? null, // 瀹℃牳鏃ユ湡
-                //CancelStatus = erpDto.FCancelStatus, // 浣滃簾鐘舵��
-                //CancelledBy = erpDto.FCancellerId, // 浣滃簾浜�
-                //CancelDate = ParseDateTime(erpDto.FCancelDate) ?? null, // 浣滃簾鏃ユ湡
-                //CloseStatus = erpDto.FBillCloseStatus, // 鍏抽棴鐘舵��
-                BillStatus = erpDto.FDocumentStatus, //鍗曟嵁鐘舵��
-                DeliveryOrg = erpDto.FDeliveryOrgID, //鍙戣揣缁勭粐
-                //SalesOrg    = erpDto.FSaleOrgId //閿�鍞粍缁�
-                FSourceCategory = erpDto.FSourceCategory,
-                FSourceDocument = erpDto.FSourceDocument,
+                ErpLineId = erpDto.ErpID, //ERP琛孖D
+                ErpHeadId = erpDto.EHID, //ERP澶碔D
+                MaterialId = erpDto.FMaterialId, //鐗╂枡缂栧彿
+                //MaterialName = erpDto.FMaterialName,// 鐗╂枡鍚嶇О
+                //MaterialSpecification = erpDto.FMaterialModel,//瑙勬牸鍨嬪彿
+                SalesUnitId = erpDto.FUnitID, //閿�鍞崟浣�
+                SalesQuantity = Convert.ToDecimal(erpDto.FQty), //閿�鍞暟閲�
+                //IsFree = erpDto.FIsFree,//鏄惁璧犲搧
+                //DeliveryDate = ParseDateTime(erpDto.FDeliverydate),//瑕佽揣鏃ユ湡
+                //Warehouse = erpDto.FStockId,//鍑鸿揣浠撳簱
+                //PlanTrackingNumber = erpDto.FMtoNo,//璁″垝璺熻釜鍙�
+                //LotNumber = erpDto.FLot,//鎵瑰彿
+                SrcBillNo = erpDto.FSrcBillNo, //婧愬崟缂栧彿
+                //PriceQty = erpDto.FPriceUnitQty,//璁′环鏁伴噺
+                OwnerId = erpDto.FOwnerIdHead, //璐т富
+                //InventoryUnit = erpDto.FStockUnitID,//搴撳瓨鍗曚綅
+                //InventoryQuantity = Convert.ToDecimal(erpDto.FStockQty),//搴撳瓨鏁伴噺
+                //MaterialCategory = erpDto.FMaterialType,//鐗╂枡绫诲埆
+                PlanDeliveryDate =
+                    ParseDateTime(erpDto.FPlanDeliveryDate), //璁″垝鍙戣揣鏃ユ湡
+                //OutLmtUnit = erpDto.FOutLmtUnit,//瓒呭彂鎺у埗鍗曚綅
+                //OutMaxQty = erpDto.FOutMaxQty,//鍑哄簱涓婇檺
+                //OutMinQty = erpDto.FOutMinQty,//鍑哄簱涓嬮檺
+                DeliveryLoc = erpDto.FDeliveryLoc, //浜よ揣鍦扮偣
+                DeliverylAddress = erpDto.FDeliveryLAddress, //浜よ揣鍦板潃
+                SourceBillNo = erpDto.FSrcBillNo, //鍘熷崟鍗曞彿
+                //OrderBillNo = erpDto.FOrderNo,//璁㈠崟鍗曞彿
+                //TerminationStatus = erpDto.FTerminationStatus,//缁堟鐘舵��
+                //TerminationDate = ParseDateTime(erpDto.FTerminateDate),//涓氬姟缁堟鏃ユ湡
+                //SumOutQty = erpDto.FSumOutQty,//绱鍑哄簱鏁伴噺
+                //RemainOutQty = erpDto.FRemainOutQty,//鏈嚭搴撴暟閲�
+                //NOTE = erpDto.FEntrynote//澶囨敞
                 FDeliveryDate = erpDto.FDeliveryDate,
+                FMapId = erpDto.FMapId,
+                FMapName = erpDto.FMapName,
+                FMapId2 = erpDto.FMapId2,
                 FProject = erpDto.FProject,
-                FCustomerPo = erpDto.FCustomerPo,
-                FShippingPolicy = erpDto.FShippingPolicy,
-                FShippingPort = erpDto.FShippingPort,
-                FDestinationPort = erpDto.FDestinationPort,
-                FReceiverContactID = erpDto.FReceiverContactID,
-                FEntryNote = erpDto.FEntryNote,
-                FVersionNo = erpDto.FVersionNo,
-                FBusinessType = erpDto.FBusinessType,
-                FHEADLOCID = erpDto.FHEADLOCID,
-                FCustId = erpDto.FCustId,
-                FNote = erpDto.FNote
+                FStorageLocation = erpDto.FStorageLocation,
+                FFreeItemType = erpDto.FFreeItemType,
+                FBodyNote = erpDto.FBodyNote,
+                FAvailableStock = erpDto.FAvailableStock,
+                FInventoryQueryTime = erpDto.FInventoryQueryTime,
+                FLineStatus = erpDto.FLineStatus,
+                FReceiveAddressFull = erpDto.FReceiveAddressFull,
+                FReceiverContact = erpDto.FReceiverContact,
+                FReturnExchangeAllowed = erpDto.FReturnExchangeAllowed,
+                FOutsourcedProcessQty = erpDto.FOutsourcedProcessQty,
+                FAvailableDate = erpDto.FAvailableDate,
+                FCommitmentDate = erpDto.FCommitmentDate,
+                FCustomerConfirmShipDate = erpDto.FCustomerConfirmShipDate,
+                FPlannedOrg = erpDto.FPlannedOrg,
+                FVendorDirectShip = erpDto.FVendorDirectShip,
+                FSupplySource = erpDto.FSupplySource,
+                FSupplyType = erpDto.FSupplyType,
+                FSupplyOrg = erpDto.FSupplyOrg,
+                FSupplier = erpDto.FSupplier,
+                FShippingMethod = erpDto.FShippingMethod,
+                FMRPDR = erpDto.FMRPDR,
+                FDemandCategory = erpDto.FDemandCategory,
+                FInventoryPlanning = erpDto.FInventoryPlanning,
+                FLineRemark = erpDto.FLineRemark,
+                FSourceDocCategory = erpDto.FSourceDocCategory,
+                FSourceDocNo = erpDto.FSourceDocNo,
+                FSourceDocLineNo = erpDto.FSourceDocLineNo,
+                FLINE_NO = erpDto.FLINE_NO
             };
-
-            var single = base.GetSingle(it => it.ErpId == erpDto.ErpID);
-            if (single != null) salesOrder.Id = single.Id;
-
-            if (salesOrder.ErpId is null || salesOrder.ErpId=="")
-            {
+            if (salesOrderSub.ErpLineId is null ||
+                salesOrderSub.ErpLineId == "")
                 throw new NotImplementedException(
-    $"琛ㄥごErpID涓嶈兘涓虹┖");
-            }
-            return salesOrder;
+                    "鏄庣粏琛孍rpID锛圗RP琛孖D锛変笉鑳戒负绌�");
+            if (salesOrderSub.ErpHeadId is null ||
+                salesOrderSub.ErpHeadId == "")
+                throw new NotImplementedException(
+                    "鏄庣粏琛孍HID锛圗RP澶碔D锛変笉鑳戒负绌�");
+            var single = _SalesDeliveryDetailManager.GetSingle(it =>
+                it.ErpLineId == salesOrderSub.ErpLineId);
+            if (single != null) salesOrderSub.Id = single.Id;
+            var mesLinkU9 = Db.Queryable<MesLinkU9>()
+                .Where(x => x.U9Id == erpDto.FMaterialId
+                            && x.OrgId == erpDto.FSupplyOrg
+                            && x.TableType == "MES_ITEMS").First();
+
+            if (mesLinkU9 != null) salesOrderSub.MaterialId = mesLinkU9.MesId;
+
+
+            var mesLinkU92 = Db.Queryable<MesLinkU9>()
+                .Where(x => x.U9Id == erpDto.FProject
+                            && x.OrgId == erpDto.FSupplyOrg
+                            && x.TableType == "MES_PROJECT").First();
+
+            if (mesLinkU92 != null) salesOrderSub.FProject = mesLinkU92.MesId;
+            salesOrderSubList.Add(salesOrderSub);
         }
 
-        private List<SalesDeliveryNoticeDetail> ConvertErpToSalesDeliveryDetail(
-            List<ErpSalesDeliveryDetailDto> erpDtoList)
-
-        {
-            var salesOrderSubList =
-                new List<SalesDeliveryNoticeDetail>();
-
-            DateTime parsedDate;
-            // 鏃堕棿鏍煎紡杞崲鍑芥暟锛孍RP鏃堕棿鏍煎紡涓� "yyyy-MM-dd HH:mm:ss"
-            DateTime? ParseDateTime(string dateStr)
-            {
-                if (DateTime.TryParseExact(dateStr, "yyyy-MM-dd HH:mm:ss",
-                        CultureInfo.InvariantCulture,
-                        DateTimeStyles.None,
-                        out parsedDate))
-                    return parsedDate;
-
-                return null; // 濡傛灉杞崲澶辫触锛岃繑鍥瀗ull
-            }
-
-
-
-            foreach (var erpDto in erpDtoList)
-            {
-                var salesOrderSub = new SalesDeliveryNoticeDetail
-                {
-                    ErpLineId = erpDto.ErpID,//ERP琛孖D
-                    ErpHeadId = erpDto.EHID,//ERP澶碔D
-                    MaterialId = erpDto.FMaterialId,//鐗╂枡缂栧彿
-                    //MaterialName = erpDto.FMaterialName,// 鐗╂枡鍚嶇О
-                    //MaterialSpecification = erpDto.FMaterialModel,//瑙勬牸鍨嬪彿
-                    SalesUnitId = erpDto.FUnitID,//閿�鍞崟浣�
-                    SalesQuantity = Convert.ToDecimal(erpDto.FQty),//閿�鍞暟閲�
-                    //IsFree = erpDto.FIsFree,//鏄惁璧犲搧
-                    //DeliveryDate = ParseDateTime(erpDto.FDeliverydate),//瑕佽揣鏃ユ湡
-                    //Warehouse = erpDto.FStockId,//鍑鸿揣浠撳簱
-                    //PlanTrackingNumber = erpDto.FMtoNo,//璁″垝璺熻釜鍙�
-                    //LotNumber = erpDto.FLot,//鎵瑰彿
-                    SrcBillNo = erpDto.FSrcBillNo,//婧愬崟缂栧彿
-                    //PriceQty = erpDto.FPriceUnitQty,//璁′环鏁伴噺
-                    OwnerId = erpDto.FOwnerIdHead,//璐т富
-                    //InventoryUnit = erpDto.FStockUnitID,//搴撳瓨鍗曚綅
-                    //InventoryQuantity = Convert.ToDecimal(erpDto.FStockQty),//搴撳瓨鏁伴噺
-                    //MaterialCategory = erpDto.FMaterialType,//鐗╂枡绫诲埆
-                    PlanDeliveryDate = ParseDateTime(erpDto.FPlanDeliveryDate),//璁″垝鍙戣揣鏃ユ湡
-                    //OutLmtUnit = erpDto.FOutLmtUnit,//瓒呭彂鎺у埗鍗曚綅
-                    //OutMaxQty = erpDto.FOutMaxQty,//鍑哄簱涓婇檺
-                    //OutMinQty = erpDto.FOutMinQty,//鍑哄簱涓嬮檺
-                    DeliveryLoc = erpDto.FDeliveryLoc,//浜よ揣鍦扮偣
-                    DeliverylAddress = erpDto.FDeliveryLAddress,//浜よ揣鍦板潃
-                    SourceBillNo = erpDto.FSrcBillNo,//鍘熷崟鍗曞彿
-                    //OrderBillNo = erpDto.FOrderNo,//璁㈠崟鍗曞彿
-                    //TerminationStatus = erpDto.FTerminationStatus,//缁堟鐘舵��
-                    //TerminationDate = ParseDateTime(erpDto.FTerminateDate),//涓氬姟缁堟鏃ユ湡
-                    //SumOutQty = erpDto.FSumOutQty,//绱鍑哄簱鏁伴噺
-                    //RemainOutQty = erpDto.FRemainOutQty,//鏈嚭搴撴暟閲�
-                    //NOTE = erpDto.FEntrynote//澶囨敞
-                    FDeliveryDate = erpDto.FDeliveryDate,
-                    FMapId = erpDto.FMapId,
-                    FMapName = erpDto.FMapName,
-                    FMapId2 = erpDto.FMapId2,
-                    FProject = erpDto.FProject,
-                    FStorageLocation = erpDto.FStorageLocation,
-                    FFreeItemType = erpDto.FFreeItemType,
-                    FBodyNote = erpDto.FBodyNote,
-                    FAvailableStock = erpDto.FAvailableStock,
-                    FInventoryQueryTime = erpDto.FInventoryQueryTime,
-                    FLineStatus = erpDto.FLineStatus,
-                    FReceiveAddressFull = erpDto.FReceiveAddressFull,
-                    FReceiverContact = erpDto.FReceiverContact,
-                    FReturnExchangeAllowed = erpDto.FReturnExchangeAllowed,
-                    FOutsourcedProcessQty = erpDto.FOutsourcedProcessQty,
-                    FAvailableDate = erpDto.FAvailableDate,
-                    FCommitmentDate = erpDto.FCommitmentDate,
-                    FCustomerConfirmShipDate = erpDto.FCustomerConfirmShipDate,
-                    FPlannedOrg = erpDto.FPlannedOrg,
-                    FVendorDirectShip = erpDto.FVendorDirectShip,
-                    FSupplySource = erpDto.FSupplySource,
-                    FSupplyType = erpDto.FSupplyType,
-                    FSupplyOrg = erpDto.FSupplyOrg,
-                    FSupplier = erpDto.FSupplier,
-                    FShippingMethod = erpDto.FShippingMethod,
-                    FMRPDR = erpDto.FMRPDR,
-                    FDemandCategory = erpDto.FDemandCategory,
-                    FInventoryPlanning = erpDto.FInventoryPlanning,
-                    FLineRemark = erpDto.FLineRemark,
-                    FSourceDocCategory = erpDto.FSourceDocCategory,
-                    FSourceDocNo = erpDto.FSourceDocNo,
-                    FSourceDocLineNo = erpDto.FSourceDocLineNo,
-                    FLINE_NO = erpDto.FLINE_NO
-
-                };
-                if (salesOrderSub.ErpLineId is null || salesOrderSub.ErpLineId=="")
-                {
-                    throw new NotImplementedException(
-    $"鏄庣粏琛孍rpID锛圗RP琛孖D锛変笉鑳戒负绌�");
-                }
-                if (salesOrderSub.ErpHeadId is null || salesOrderSub.ErpHeadId == "")
-                {
-                    throw new NotImplementedException(
-    $"鏄庣粏琛孍HID锛圗RP澶碔D锛変笉鑳戒负绌�");
-                }
-                var single = _SalesDeliveryDetailManager.GetSingle(it =>
-                    it.ErpLineId == salesOrderSub.ErpLineId);
-                if (single != null) salesOrderSub.Id = single.Id;
-                var mesLinkU9 = Db.Queryable<MesLinkU9>()
-.Where(x => x.U9Id == erpDto.FMaterialId
-    && x.OrgId == erpDto.FSupplyOrg
-    && x.TableType == "MES_ITEMS").First();
-
-                if (mesLinkU9 != null) salesOrderSub.MaterialId = mesLinkU9.MesId;
-
-
-                var mesLinkU92 = Db.Queryable<MesLinkU9>()
-                    .Where(x => x.U9Id == erpDto.FProject
-                                && x.OrgId == erpDto.FSupplyOrg
-                                && x.TableType == "MES_PROJECT").First();
-
-                if (mesLinkU92 != null) salesOrderSub.FProject = mesLinkU92.MesId;
-                salesOrderSubList.Add(salesOrderSub);
-            }
-
-            return salesOrderSubList;
-        }
-
+        return salesOrderSubList;
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3