From d8db1698c125618c1b5f62b009204ddc5d4eed5a Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 19 三月 2025 20:34:08 +0800
Subject: [PATCH] 成品代码更新....

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 1 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs"
index 4508b4f..876025c 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs"
@@ -3,7 +3,11 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.StockEnum;
+using WIDESEA_Core;
 using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Helper;
 using WIDESEA_IBasicRepository;
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundRepository;
@@ -22,16 +26,127 @@
         private readonly IOutStockLockInfoService _outStockLockInfoService;
         private readonly IBasicService _basicService;
         private readonly IRecordService _recordService;
+        private readonly IOutProStockInfoService _outProStockInfoService;
 
         public IMesRworkOutboundOrderRepository Repository => BaseDal;
 
-        public MesRworkOutboundOrderService(IMesRworkOutboundOrderRepository BaseDal, IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService) : base(BaseDal)
+        public MesRworkOutboundOrderService(IMesRworkOutboundOrderRepository BaseDal, IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService, IOutProStockInfoService outProStockInfoService) : base(BaseDal)
         {
             _basicRepository = basicRepository;
             _stockService = stockService;
             _outStockLockInfoService = outStockLockInfoService;
             _basicService = basicService;
             _recordService = recordService;
+            _outProStockInfoService = outProStockInfoService;
+        }
+        /// <summary>
+        /// 鎻愬簱浠诲姟鍒嗛厤搴撳瓨
+        /// </summary>
+        public (List<Dt_ProStockInfo>?,Dt_MesRworkOutboundOrder?,List<Dt_OutProStockInfo>?,List<Dt_LocationInfo>) AssignMesStocks(Dt_MesRworkOutboundOrder mesRworkOutboundOrder)
+        {
+            List<Dt_ProStockInfo> proStockInfos = new List<Dt_ProStockInfo>();
+            Dt_MesRworkOutboundOrder assignOutOrder= new Dt_MesRworkOutboundOrder();
+            List<Dt_OutProStockInfo> outProStockInfos=new List<Dt_OutProStockInfo>();
+            List<Dt_LocationInfo> locationInfos=new List<Dt_LocationInfo>();
+            float originalNeedQuantity = mesRworkOutboundOrder.RequiredQuantity;
+
+            float needQuantity = originalNeedQuantity;
+
+            //鏌ユ壘鍙敤搴撳瓨
+            List<Dt_ProStockInfo> stockInfoss = _stockService.ProStockInfoService.GetUseableStocks(mesRworkOutboundOrder);
+            if (!stockInfoss.Any())
+            {
+                throw new Exception("鏈壘鍒板彲鍒嗛厤搴撳瓨");
+            }
+            List<Dt_ProStockInfo> autoAssignStocks = _stockService.ProStockInfoService.GetOutboundStocks(stockInfoss,mesRworkOutboundOrder, needQuantity,out float residueQuantity);
+            mesRworkOutboundOrder.LockQuantity += needQuantity - residueQuantity;
+            autoAssignStocks.OrderBy(x => x.proStockInfoDetails.FirstOrDefault()?.StockPcsQty).ToList();
+            proStockInfos.AddRange(autoAssignStocks);
+            float assignQuantity = needQuantity - residueQuantity;
+
+            float orderQuantity = mesRworkOutboundOrder.RequiredQuantity;
+            for (int j = 0; j < autoAssignStocks.Count; j++)
+            {
+                //鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲�
+                float detailAssignQuantity = outProStockInfos
+                    .Where(x => x.SaleOrder == mesRworkOutboundOrder.SaleOrder 
+                    && x.PCode == mesRworkOutboundOrder.ProductCode 
+                    && x.PVer == mesRworkOutboundOrder.ProductVersion)
+                    .Sum(x => x.AssignQuantity);
+
+                //鍑哄簱璇︽儏宸插垎閰嶆暟閲�
+                float palletAssignQuantity = outProStockInfos
+                    .Where(x => x.SaleOrder == mesRworkOutboundOrder.SaleOrder 
+                    && x.PCode == mesRworkOutboundOrder.ProductCode 
+                    && x.PVer == mesRworkOutboundOrder.ProductVersion 
+                    && x.PalletCode == autoAssignStocks[j].PalletCode)
+                    .Sum(x => x.AssignQuantity);
+
+                float palletOutboundQuantity = autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity);
+                if (palletAssignQuantity < palletOutboundQuantity)//濡傛灉鍑哄簱璇︽儏宸插垎閰嶆暟閲忓皬浜庢墭鐩樺凡鍒嗛厤鏁伴噺锛屽垯鍙互缁х画娣诲姞璇ユ墭鐩樺嚭搴撲俊鎭�
+                {
+                    float orderDetailNeedQuantity = mesRworkOutboundOrder.RequiredQuantity - detailAssignQuantity;
+                    if (orderDetailNeedQuantity > autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity)
+                    {
+                        mesRworkOutboundOrder.LockQuantity += autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity;
+                        Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(mesRworkOutboundOrder, autoAssignStocks[j], autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity);
+                        outProStockInfos.Add(outStockLockInfo);
+                    }
+                    else
+                    {
+                        Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(mesRworkOutboundOrder, autoAssignStocks[j], mesRworkOutboundOrder.RequiredQuantity-mesRworkOutboundOrder.LockQuantity);
+                        outProStockInfos.Add(outStockLockInfo);
+                        mesRworkOutboundOrder.LockQuantity = mesRworkOutboundOrder.RequiredQuantity;
+                        break;
+                    }
+                }
+            }
+            locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(proStockInfos.Select(x => x.LocationCode).ToList()));
+
+            return (proStockInfos, assignOutOrder, outProStockInfos, locationInfos);
+        }
+        public WebResponseContent LockOutboundStockDataUpdate(List<Dt_ProStockInfo> stockInfos, List<Dt_OutProStockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null)
+        {
+            try
+            {
+                stockInfos.ForEach(x => {
+                    x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                });
+                _stockService.ProStockInfoService.Repository.UpdateData(stockInfos);
+                List<Dt_ProStockInfoDetail> stockInfoDetails = new List<Dt_ProStockInfoDetail>();
+                foreach (var item in stockInfos)
+                {
+                    stockInfoDetails.AddRange(item.proStockInfoDetails);
+                }
+                _stockService.ProStockInfoDetailService.Repository.UpdateData(stockInfoDetails);
+
+                List<Dt_OutProStockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList();
+                if (addOutStockLockInfos != null && addOutStockLockInfos.Any())
+                {
+                    if (tasks != null)
+                    {
+                        addOutStockLockInfos.ForEach(x =>
+                        {
+                            x.TaskNum = tasks.FirstOrDefault(v => v.PalletCode == x.PalletCode)?.TaskNum;
+                        });
+                    }
+
+                    _outProStockInfoService.Repository.AddData(addOutStockLockInfos);
+                }
+                List<Dt_OutProStockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList();
+                if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any())
+                {
+                    _outProStockInfoService.Repository.UpdateData(updateOutStockLockInfos);
+                }
+
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, locationStatus, LocationChangeType.OutboundAssignLocation, "", tasks?.Select(x => x.TaskNum).ToList());
+                _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
         }
     }
 }

--
Gitblit v1.9.3