From 011ca316e6ec2ed93e31c45a9ebd9d3c66664871 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 17 四月 2026 11:47:03 +0800
Subject: [PATCH] 代码更新

---
 项目代码/WMS/WMSServices/WIDESEA_OutboundService/ProDeliveryOrderService.cs |  195 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 194 insertions(+), 1 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/ProDeliveryOrderService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/ProDeliveryOrderService.cs"
index 2b3e28c..e1ccebd 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/ProDeliveryOrderService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/ProDeliveryOrderService.cs"
@@ -4,7 +4,13 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.MaterielEnum;
+using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.WareHouseEnum;
+using WIDESEA_Core;
 using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Helper;
+using WIDESEA_DTO.ERP;
 using WIDESEA_IBasicRepository;
 using WIDESEA_IOutboundRepository;
 using WIDESEA_IOutboundService;
@@ -17,10 +23,197 @@
         public IProDeliveryOrderRepository Repository => BaseDal;
         private readonly IBasicRepository _basicRepository;
         private readonly IMapper _mapper;
-        public ProDeliveryOrderService(IProDeliveryOrderRepository BaseDal, IBasicRepository basicRepository, IMapper mapper) : base(BaseDal)
+        private readonly IProDeliveryOrderDetailRepository _proDeliveryOrderDetailRepository;
+        public ProDeliveryOrderService(IProDeliveryOrderRepository BaseDal, IBasicRepository basicRepository, IMapper mapper, IProDeliveryOrderDetailRepository proDeliveryOrderDetailRepository) : base(BaseDal)
         {
             _basicRepository = basicRepository;
             _mapper = mapper;
+            _proDeliveryOrderDetailRepository = proDeliveryOrderDetailRepository;
+        }
+        /// <summary>
+        /// 鎺ユ敹ERP鎴愬搧閿�鍞嚭搴撲俊鎭�
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent ReceiveProDeliveryOrder(ERPProDeliveryDTO eRPProDeliveryDTO)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (eRPProDeliveryDTO == null)
+                {
+                    return content.Error("閿�鍞嚭搴撲俊鎭笉鑳戒负绌�");
+                }
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == eRPProDeliveryDTO.WarehouseCode);
+                if (warehouse == null)
+                {
+                    return content.Error($"浠撳簱淇℃伅涓嶅瓨鍦▄eRPProDeliveryDTO.WarehouseCode}");
+                }
+                //鑾峰彇鎵�鏈夌墿鏂� 
+                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x => x.WarehouseId == warehouse.WarehouseId && x.MaterielInvOrgId == MaterielInvOrgEnum.鏂板巶.ObjToInt());
+
+                //鑾峰彇鎵�鏈夊鎴�
+                List<Dt_CustomerInfo> customerInfos = _basicRepository.CustomerInfoRepository.QueryData();
+
+                //鍒ゆ柇鏄惁瀛樺湪鐗╂枡
+                DeliveryDetailItem? deliveryDetailItem = eRPProDeliveryDTO.DeliveryDetail.FirstOrDefault(x => !materielInfos.Select(x => x.MaterielCode).Contains(x.MaterialCode));
+                if (deliveryDetailItem != null)
+                {
+                    return content.Error($"鐗╂枡淇℃伅{deliveryDetailItem.MaterialCode}涓嶅瓨鍦�");
+                }
+
+                //鍒ゆ柇鏄惁瀛樺湪瀹㈡埛
+                DeliveryDetailItem? deliveryDetailCustom = eRPProDeliveryDTO.DeliveryDetail.FirstOrDefault(x => !customerInfos.Select(x => x.CustomerCode).Contains(x.Customer));
+
+                if (deliveryDetailCustom != null)
+                {
+                    return content.Error($"瀹㈡埛淇℃伅{deliveryDetailCustom.Customer}涓嶅瓨鍦�");
+                }
+
+                //鑾峰彇鎵�鏈夐攢鍞嚭搴撲俊鎭�
+                List<Dt_ProDeliveryOrder> proDeliveryOrdersOld = BaseDal.Db.Queryable<Dt_ProDeliveryOrder>().Includes(x => x.Details).ToList();
+
+                if (eRPProDeliveryDTO.OperateType == 1)
+                {
+                    //鍒ゆ柇閲嶅鎻掑叆
+                    Dt_ProDeliveryOrder? proDeliveryOrderOld = proDeliveryOrdersOld.FirstOrDefault(x => x.DeliveryCode == eRPProDeliveryDTO.DeliveryCode);
+                    if (proDeliveryOrderOld != null)
+                    {
+                        return content.Error($"閿�鍞嚭搴撳崟鍙穥proDeliveryOrderOld.DeliveryCode}淇℃伅宸插瓨鍦�");
+                    }
+                    List<Dt_ProDeliveryOrderDetail> proDeliveryOrderDetails = eRPProDeliveryDTO.DeliveryDetail.Select(x => _mapper.Map<Dt_ProDeliveryOrderDetail>(x)).ToList();
+                    Dt_ProDeliveryOrder proDeliveryOrderAdd = _mapper.Map<Dt_ProDeliveryOrder>(eRPProDeliveryDTO);
+                    proDeliveryOrderDetails.ForEach(x =>
+                    {
+                        Dt_MaterielInfo? materielInfo = materielInfos.FirstOrDefault(t => t.MaterielCode == x.MaterialCode);
+                        x.MaterielName = materielInfo?.MaterielName;
+                        x.Unit = materielInfo?.MaterielUnit;
+                    });
+                    proDeliveryOrderAdd.Details = proDeliveryOrderDetails;
+                    proDeliveryOrderAdd.WarehouseId = warehouse.WarehouseId;
+                    //鏂板
+                    BaseDal.Db.InsertNav(proDeliveryOrderAdd).Include(x => x.Details).ExecuteCommand();
+
+                }
+                else if (eRPProDeliveryDTO.OperateType == 2)
+                {
+                    //鍒ゆ柇鏄惁瀛樺湪
+                    Dt_ProDeliveryOrder? proDeliveryOrderOld = proDeliveryOrdersOld.FirstOrDefault(x => x.DeliveryCode == eRPProDeliveryDTO.DeliveryCode);
+                    if (proDeliveryOrderOld == null)
+                    {
+                        return content.Error($"閿�鍞嚭搴撳崟鍙穥eRPProDeliveryDTO.DeliveryCode}淇℃伅涓嶅瓨鍦�");
+                    }
+                    if (proDeliveryOrderOld.ProDeliveryStatus != OutOrderStatusEnum.鏈紑濮�.ObjToInt())
+                    {
+                        return content.Error($"閿�鍞嚭搴撳崟鍙穥proDeliveryOrderOld.DeliveryCode}鐘舵�佷负{(OutOrderStatusEnum)proDeliveryOrderOld.ProDeliveryStatus}");
+                    }
+                    List<Dt_ProDeliveryOrderDetail> proDeliveryOrderDetails = eRPProDeliveryDTO.DeliveryDetail.Select(x => _mapper.Map<Dt_ProDeliveryOrderDetail>(x)).ToList();
+                    Dt_ProDeliveryOrder proDeliveryOrder = _mapper.Map<Dt_ProDeliveryOrder>(eRPProDeliveryDTO);
+                    proDeliveryOrder.Id = proDeliveryOrderOld.Id;
+                    proDeliveryOrderDetails.ForEach(x =>
+                    {
+                        Dt_MaterielInfo? materielInfo = materielInfos.FirstOrDefault(t => t.MaterielCode == x.MaterialCode);
+                        x.MaterielName = materielInfo?.MaterielName;
+                        x.Unit = materielInfo?.MaterielUnit;
+                    });
+                    proDeliveryOrder.Details = proDeliveryOrderDetails;
+                    proDeliveryOrder.WarehouseId = warehouse.WarehouseId;
+                    //鏇存柊
+                    BaseDal.Db.UpdateNav(proDeliveryOrder).Include(x => x.Details).ExecuteCommand();
+                }
+                else if (eRPProDeliveryDTO.OperateType == 3)
+                {
+                    //鍒ゆ柇鏄惁瀛樺湪
+                    Dt_ProDeliveryOrder? proDeliveryOrderOld = proDeliveryOrdersOld.FirstOrDefault(x => x.DeliveryCode == eRPProDeliveryDTO.DeliveryCode);
+                    if (proDeliveryOrderOld == null)
+                    {
+                        return content.Error($"閿�鍞嚭搴撳崟鍙穥eRPProDeliveryDTO.DeliveryCode}淇℃伅涓嶅瓨鍦�");
+                    }
+                    if (proDeliveryOrderOld.ProDeliveryStatus != OutOrderStatusEnum.鏈紑濮�.ObjToInt())
+                    {
+                        return content.Error($"閿�鍞嚭搴撳崟鍙穥proDeliveryOrderOld.DeliveryCode}鐘舵�佷负{(OutOrderStatusEnum)proDeliveryOrderOld.ProDeliveryStatus}");
+                    }
+                    //鍒犻櫎
+                    BaseDal.Db.DeleteNav(proDeliveryOrderOld).Include(x => x.Details).ExecuteCommand();
+                }
+                else
+                {
+                    return content.Error("鏈壘鍒版搷浣滅被鍨�");
+                }
+                //鏇存柊鏁版嵁
+                return content.OK("鎺ユ敹鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// ERP鎴愬搧閿�鍞嚭搴撳垎閰嶅簱瀛�
+        /// </summary>
+        public (List<Dt_ProStockInfo>, List<Dt_ProDeliveryOrder>, List<Dt_ProDeliveryOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignProStockOutbound(List<Dt_ProDeliveryOrder> proDeliveryOrders,List<Dt_ProDeliveryOrderDetail> deliveryOrderDetails)
+        {
+            List<Dt_ProStockInfo> outStocks = new List<Dt_ProStockInfo>();
+
+            //鍑哄簱璇︽儏
+            List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+            //璐т綅瀛樺偍
+            List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+
+            //foreach (var item in )
+            //{
+
+            //}
+
+            //foreach (var item in deliveryOrderDetails)
+            //{
+            //    decimal needQuantity = item.ReqQuantity;
+            //    //鑾峰彇鍙敤搴撳瓨
+            //    List<Dt_ProStockInfo> stockInfos = _stockService.ProStockInfoService.GetUseableStocks(item.MaterialCode, WarehouseEnum.LLDCP.ObjToInt()).Where(x => !outStocks.Select(x => x.PalletCode).Contains(x.PalletCode)).ToList();
+            //    if (!stockInfos.Any())
+            //    {
+            //        continue;
+            //    }
+            //    //鍒嗛厤瀹為檯搴撳瓨
+            //    List<Dt_ProStockInfo> autoAssignStocks = _stockService.ProStockInfoService.GetOutboundStocks(stockInfos, needQuantity);
+            //    //娣诲姞搴撳瓨鍒嗛厤
+            //    outStocks.AddRange(autoAssignStocks);
+            //    //璁㈠崟鏁伴噺
+            //    decimal orderQuantity = item.ReqQuantity;
+            //    bool assignStop = true;
+            //    while (assignStop)
+            //    {
+            //        //鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲�
+            //        decimal detailAssignQuantity = outStockLockInfos.Where(x => x.OrderDetailId == item.OutDetailId).Sum(x => x.AssignQuantity);
+
+            //        decimal orderDetailNeedQuantity = item.ReqQuantity - detailAssignQuantity;
+
+            //        decimal useStockLength = autoAssignStocks[0].proStockInfoDetails
+            //            .Sum(x => x.StockQty);
+            //        if (orderDetailNeedQuantity > useStockLength)
+            //        {
+
+            //            //鐢熸垚璇︽儏
+            //            Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(item, autoAssignStocks[0], useStockLength);
+            //            outStockLockInfos.Add(outStockLockInfo);
+            //            item.AssignTotalUsage += useStockLength;
+            //            autoAssignStocks.Remove(autoAssignStocks[0]);
+            //        }
+            //        else
+            //        {
+            //            //鐢熸垚璇︽儏
+            //            Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(item, autoAssignStocks[0], orderDetailNeedQuantity);
+            //            outStockLockInfos.Add(outStockLockInfo);
+            //            item.AssignTotalUsage = orderQuantity;
+            //            autoAssignStocks.Remove(autoAssignStocks[0]);
+            //            assignStop = false;
+            //        }
+            //    }
+            //    item.OutMESOrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+            //    locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()));
+            //}
+
+            return (outStocks, proDeliveryOrders, deliveryOrderDetails, outStockLockInfos, locationInfos);
         }
     }
 }

--
Gitblit v1.9.3