From ce3b28cdcdb2b6a912413cd9e744d0ecadcb78a0 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期二, 13 一月 2026 17:47:30 +0800
Subject: [PATCH] 优化成品出入库流程代码

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs |   48 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
index 1542a16..1ab57a2 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
@@ -29,19 +29,37 @@
                 {
                     throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
                 }
-                List<Dt_NewOutboundOrder> outboundOrders = _outboundService.NewOutboundOrderService.Repository.QueryData(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId);
-                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.QueryData(x => outboundOrderDetails.Select(s => s.LPNNo).Contains(x.PalletCode));
-                if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
+                var lpngroup = outboundOrderDetails.GroupBy(x => x.LPNNo);
+
+
+                List<Dt_NewOutboundOrderDetail> newOutboundOrderDetails = new List<Dt_NewOutboundOrderDetail>();
+                List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
+
+                foreach (var lpngroups in lpngroup)
                 {
-                    throw new Exception("鏈壘鍒板簱瀛樹俊鎭�");
+                    string lpn = lpngroups.Key;
+                    List<Dt_NewOutboundOrderDetail> detailsForThisLPN = _outboundService.NewOutboundOrderDetailService.Repository.QueryData(x => x.LPNNo == lpn && x.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt());
+                    if (detailsForThisLPN.Count == 0) continue;
+                    newOutboundOrderDetails.AddRange(detailsForThisLPN);
+                    Dt_StockInfo? stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == lpn);
+                    if (stockInfo == null)
+                    {
+                        throw new Exception($"鏈壘鍒板簱瀛樹俊鎭紝鎵樼洏鍙穥lpn}");
+                    }
+                    stockInfos.Add(stockInfo);
+
                 }
+
                 if (stockInfos == null || stockInfos.Count == 0)
                 {
                     throw new Exception("鏈壘鍒板簱瀛樹俊鎭�");
                 }
+                List<int> orderId = newOutboundOrderDetails.Select(x => x.OrderId).Distinct().ToList();
+                List<Dt_NewOutboundOrder> outboundOrders = _outboundService.NewOutboundOrderService.Repository.QueryData(x => orderId.Contains(x.Id));
                 var Newtasks = GetTasks(stockInfos, TaskTypeEnum.OutProduct);
                 List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => stockInfos.Select(x => x.Id).Contains(x.StockId));
-                foreach (var item in outboundOrderDetails)
+                List<string> palletcodelpn = new List<string>();
+                foreach (var item in newOutboundOrderDetails)
                 {
                     Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.PalletCode == item.LPNNo);
                     if (stockInfo == null) continue;
@@ -49,6 +67,7 @@
                     if (stockInfoDetail == null) continue;
                     stockInfoDetail.OutboundQuantity += item.OrderQuantity;
                     item.LockQuantity += item.OrderQuantity;
+                    item.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                     var outboundOrder = outboundOrders.FirstOrDefault(x => x.Id == item.OrderId);
                     Dt_OutStockLockInfo outStockLockInfo = _outboundService.OutboundStockLockInfoService.GetOutStockLockInfo(outboundOrder, item, stockInfo, stockInfoDetail, item.OrderQuantity);
                     outStockLockInfo.Status = OutStockStatus.鍑哄簱涓�.ObjToInt();
@@ -56,8 +75,20 @@
                     outboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
                     stockInfo.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
                     var task = Newtasks.FirstOrDefault(x => x.PalletCode == item.LPNNo);
-                    task.OrderNo = outboundOrder.OrderNo;
-                    tasks.Add(task);
+                    if (task != null && !palletcodelpn.Contains(item.LPNNo))
+                    {
+                        if (outboundOrder.OrderType == 1)
+                        {
+                            task.TaskType = TaskTypeEnum.OutProduct.ObjToInt();
+                        }
+                        else if (outboundOrder.OrderType == 2)
+                        {
+                            task.TaskType = TaskTypeEnum.OutAllocate.ObjToInt();
+                        }
+                        task.OrderNo = outboundOrder.OrderNo;
+                        tasks.Add(task);
+                        palletcodelpn.Add(task.PalletCode);
+                    }
                     outStockLockInfo.TaskNum = task.TaskNum;
                     outStockLockInfos.Add(outStockLockInfo);
                 }
@@ -68,7 +99,7 @@
                 BaseDal.AddData(tasks);
                 _stockService.StockInfoService.Repository.UpdateData(stockInfos);
                 _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails);
-                _outboundService.NewOutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
+                _outboundService.NewOutboundOrderDetailService.Repository.UpdateData(newOutboundOrderDetails);
                 _outboundService.NewOutboundOrderService.Repository.UpdateData(outboundOrders);
                 _outboundService.OutboundStockLockInfoService.Repository.AddData(outStockLockInfos);
                 _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList());
@@ -99,6 +130,7 @@
                 {
                     throw new Exception("鏈壘鍒板簱瀛樹俊鎭�,鎴栧簱瀛樼姸鎬佷笉涓哄叆搴撳畬鎴�");
                 }
+
                 var Newtasks = GetTasks(stockInfos, TaskTypeEnum.OutSyncretism);
                 List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => stockInfos.Select(x => x.Id).Contains(x.StockId));
                 foreach (var item in stockInfos)

--
Gitblit v1.9.3