From fe256a7afaa132910875d3dc73783d9ab2d7ace5 Mon Sep 17 00:00:00 2001
From: liulijun <liulijun@hnkhzn.com>
Date: 星期四, 12 三月 2026 18:57:44 +0800
Subject: [PATCH] 老厂排程单页面增加用纸顺序号和是否缺料

---
 项目代码/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs |   53 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 12 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 d7168ca..37383cd 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,8 +5,11 @@
 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;
+using WIDESEA_Core.Helper;
 using WIDESEA_IBasicRepository;
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundRepository;
@@ -72,25 +75,37 @@
             foreach (var item in groupDetails)
             {
                 decimal needQuantity = item.XqLen;
-                //鑾峰彇鍙敤搴撳瓨
-                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($"鏈壘鍒板彲鍒嗛厤搴撳瓨");
-                }
-                //鍒嗛厤瀹為檯搴撳瓨
-                List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, needQuantity).ToList();
-                //娣诲姞搴撳瓨鍒嗛厤
-                outStocks.AddRange(autoAssignStocks);
+                //鑾峰彇鑰佸巶缂撳瓨鍙敤搴撳瓨
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseOldCacheStocks(item.MaterialNo, item.Width) ?? 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());
                 //鑾峰彇鎵�鏈夎鐗╂枡鍗曟嵁
                 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();
+                    }
+                    continue;
+                }
+                //鍒嗛厤瀹為檯搴撳瓨
+                List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutOldStocks(stockInfos, needQuantity).ToList();
+                //娣诲姞搴撳瓨鍒嗛厤
+                outStocks.AddRange(autoAssignStocks);
                 autoAssignStocks.ForEach(x =>
                 {
                     x.StockOutLength = 0;
                 });
                 for (int i = 0; i < details.Count; i++)
                 {
-                    //璁㈠崟鏁伴噺
+                    ////璁㈠崟鏁伴噺
+                    //if ((details.Count-1) == i)
+                    //{
+
+                    //}
                     decimal orderQuantity = details[i].XqLen;
                     bool assignStop = true;
                     while (assignStop)
@@ -99,6 +114,11 @@
                         decimal detailAssignQuantity = outStockLockInfos.Where(x => x.OrderDetailId == details[i].Id).Sum(x => x.AssignQuantity);
 
                         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);
@@ -116,6 +136,8 @@
                             Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], orderDetailNeedQuantity);
                             outStockLockInfos.Add(outStockLockInfo);
                             details[i].AssignTotalUsage = orderQuantity;
+                            //鍒嗛厤鎴愬姛锛岀姸鎬佽涓烘湭寮�濮�
+                            details[i].OutSGOrderDetailStatus = OutOrderStatusEnum.鏈紑濮�.ObjToInt();
                             autoAssignStocks[0].StockOutLength+= orderDetailNeedQuantity;
                             if (autoAssignStocks[0].StockOutLength== autoAssignStocks[0].StockLength)
                             {
@@ -127,7 +149,7 @@
                     
                 }
 
-                locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList()));
+                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);
@@ -139,6 +161,10 @@
         {
             try
             {
+                stockInfos.Where(x => x.LocationCode.IsNullOrEmpty()).ToList().ForEach(x =>
+                {
+                    x.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+                });
                 _stockService.StockInfoService.Repository.UpdateData(stockInfos);
                 BaseDal.UpdateData(outboundOrderDetails);
 
@@ -154,6 +180,9 @@
                     }
 
                     _outStockLockInfoService.Repository.AddData(addOutStockLockInfos);
+                    List<Dt_OutStockLockInfo> addOutCacheInfos = addOutStockLockInfos.Where(x => x.LocationCode.Contains("鑰佸巶缂撳瓨鍖�")).ToList();
+                    List<Dt_OutLineView> outLineViewsAdd = addOutCacheInfos.Select(x => _mapper.Map<Dt_OutLineView>(x)).ToList();
+                    _outboundRepository.OutLineViewRepository.AddData(outLineViewsAdd);
                 }
                 List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList();
                 if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any())

--
Gitblit v1.9.3