From 531c6e89dc07bb6997e6249a6cd9f53a9bd474a5 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期一, 23 三月 2026 10:31:54 +0800
Subject: [PATCH] 出库逻辑变更

---
 项目代码/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs |   44 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 37 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs"
index 59292fb..685fdff 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs"
@@ -5,6 +5,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseServices;
@@ -45,13 +46,13 @@
         /// <summary>
         /// 鍒嗛厤搴撳瓨
         /// </summary>
-        public (List<Dt_StockInfo>, List<Dt_OutSGOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(List<Dt_OutSGOrderDetail> outboundOrderDetails)
+        public (List<Dt_StockInfo>, List<Dt_OutSGOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>,string) AssignStockOutbound(List<Dt_OutSGOrderDetail> outboundOrderDetails)
         {
             if (!outboundOrderDetails.Any())
             {
                 throw new Exception($"鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
             }
-
+            string message = "";
             //鑾峰彇鎵�鏈夋帓绋嬩富琛�
             List<Dt_OutSGOrder> outBSTOrders = _outboundRepository.OutSGOrderRepository.QueryData(x => outboundOrderDetails.Select(x=>x.OutSGOrderId).Distinct().Contains(x.Id));
             List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
@@ -74,20 +75,32 @@
             foreach (var item in groupDetails)
             {
                 decimal needQuantity = item.XqLen;
+                //鑾峰彇鎵�鏈夋潯鐮�
+                List<string> palletCodes = outStocks.Select(x => x.PalletCode).ToList();
                 //鑾峰彇鑰佸巶缂撳瓨鍙敤搴撳瓨
-                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseOldCacheStocks(item.MaterialNo, item.Width) ?? new List<Dt_StockInfo>();
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseOldCacheStocks(item.MaterialNo, item.Width).Where(x => !palletCodes.Contains(x.PalletCode)).ToList() ?? new List<Dt_StockInfo>();
                 //鑾峰彇绔嬪簱鍙敤搴撳瓨
-                stockInfos.AddRange(_stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId).Where(x=>!outStocks.Select(x=>x.PalletCode).Contains(x.PalletCode)).ToList());
+                stockInfos.AddRange(_stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId).Where(x=>!palletCodes.Contains(x.PalletCode)).ToList());
+                
+                //鑾峰彇鎵�鏈夎鐗╂枡鍗曟嵁
+                List<Dt_OutSGOrderDetail> details = outboundOrderDetails.Where(x => x.MaterialNo == item.MaterialNo && x.Width == item.Width && x.MachineName == item.MachineName).ToList();
+
                 if (!stockInfos.Any())
                 {
+                    //娌℃湁鍙敤搴撳瓨锛屾爣璁颁负缂烘枡
+                    foreach (var detail in details)
+                    {
+                        detail.OutSGOrderDetailStatus = OutOrderStatusEnum.缂烘枡.ObjToInt();
+                    }
+                    message += $"鐗╂枡锛歿item.MaterialNo},骞呭锛歿item.Width}鏃犲簱瀛橈紱";
                     continue;
                 }
+
                 //鍒嗛厤瀹為檯搴撳瓨
                 List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutOldStocks(stockInfos, needQuantity).ToList();
                 //娣诲姞搴撳瓨鍒嗛厤
                 outStocks.AddRange(autoAssignStocks);
-                //鑾峰彇鎵�鏈夎鐗╂枡鍗曟嵁
-                List<Dt_OutSGOrderDetail> details = outboundOrderDetails.Where(x => x.MaterialNo == item.MaterialNo && x.Width == item.Width && x.MachineName == item.MachineName).ToList();
+                
                 autoAssignStocks.ForEach(x =>
                 {
                     x.StockOutLength = 0;
@@ -140,10 +153,27 @@
                     
                 }
 
+                // 鍒嗛厤瀹屾垚鍚庯紝妫�鏌ユ瘡涓鍗曟槑缁嗙殑鍒嗛厤鎯呭喌锛岃缃纭殑鐘舵��
+                foreach (var detail in details)
+                {
+                    decimal assignedQuantity = outStockLockInfos.Where(x => x.OrderDetailId == detail.Id).Sum(x => x.AssignQuantity);
+                    if (assignedQuantity > 0)
+                    {
+                        // 宸茬粡鍒嗛厤鍒板簱瀛橈紝鏍囪涓洪潪缂烘枡鐘舵�侊紙鏈紑濮嬶級
+                        detail.OutSGOrderDetailStatus = OutOrderStatusEnum.鏈紑濮�.ObjToInt();
+                    }
+                    else
+                    {
+                        // 鏈垎閰嶅埌搴撳瓨锛屾爣璁颁负缂烘枡
+                        detail.OutSGOrderDetailStatus = OutOrderStatusEnum.缂烘枡.ObjToInt();
+                    }
+                }
+
                 locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Where(x=>!x.LocationCode.IsNullOrEmpty() && !locationInfos.Select(x=>x.LocationCode).Contains(x.LocationCode)).Select(x => x.LocationCode).ToList()));
+
             }
 
-            return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos);
+            return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos, message);
         }
         /// <summary>
         /// 鍑哄簱搴撳瓨鍒嗛厤鍚庯紝鏇存柊鏁版嵁搴撴暟鎹�

--
Gitblit v1.9.3