From 834294889ab62bafaf034b1b87c2ead961c33476 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 05 十二月 2025 09:37:46 +0800
Subject: [PATCH] 更新最新代码

---
 项目代码/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 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 374b95b..eb116ca 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"
@@ -73,13 +73,13 @@
             {
                 decimal needQuantity = item.XqLen;
                 //鑾峰彇鍙敤搴撳瓨
-                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId);
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId).Where(x=>!outStocks.Select(x=>x.PalletCode).Contains(x.PalletCode)).ToList();
                 if (!stockInfos.Any())
                 {
-                    throw new Exception($"鏈壘鍒板彲鍒嗛厤搴撳瓨");
+                    continue;
                 }
                 //鍒嗛厤瀹為檯搴撳瓨
-                List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, needQuantity).OrderBy(x => x.StockLength - x.StockOutLength).ToList();
+                List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutOldStocks(stockInfos, needQuantity).ToList();
                 //娣诲姞搴撳瓨鍒嗛厤
                 outStocks.AddRange(autoAssignStocks);
                 //鑾峰彇鎵�鏈夎鐗╂枡鍗曟嵁
@@ -100,17 +100,20 @@
 
                         decimal orderDetailNeedQuantity = details[i].XqLen - detailAssignQuantity;
 
+                        if (autoAssignStocks.Count==0)
+                        {
+                            break;
+                        }
+
                         decimal useStockLength = autoAssignStocks[0].StockLength- autoAssignStocks[0].StockOutLength;
                         Dt_OutSGOrder? sGOrder = outBSTOrders.FirstOrDefault(x => x.Id == details[i].OutSGOrderId);
                         if (orderDetailNeedQuantity > useStockLength)
                         {
-                             
                             //鐢熸垚璇︽儏
                             Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], useStockLength);
                             outStockLockInfos.Add(outStockLockInfo);
                             details[i].AssignTotalUsage += useStockLength;
                             autoAssignStocks.Remove(autoAssignStocks[0]);
-
                         }
                         else
                         {
@@ -118,7 +121,11 @@
                             Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], orderDetailNeedQuantity);
                             outStockLockInfos.Add(outStockLockInfo);
                             details[i].AssignTotalUsage = orderQuantity;
-                            autoAssignStocks[0].StockOutLength-= orderDetailNeedQuantity;
+                            autoAssignStocks[0].StockOutLength+= orderDetailNeedQuantity;
+                            if (autoAssignStocks[0].StockOutLength== autoAssignStocks[0].StockLength)
+                            {
+                                autoAssignStocks.Remove(autoAssignStocks[0]);
+                            }
                             assignStop =false;
                         }
                     }

--
Gitblit v1.9.3