From aa4aa67abfdf69e30d5076451716e5aba11d5ec0 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期二, 14 四月 2026 16:12:40 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs |   58 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
index f4ff4bf..94278e9 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
@@ -412,39 +412,41 @@
                     if (stockInfoDetailCPList != null)
                     {
                         _stockInfoDetailCPRepository.DeleteAndMoveIntoHty(stockInfoDetailCPList, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                        foreach(var stockLPNO in houseStockDetail.DetailList)
+
+                        for (int i = 0; i < stockInfoDetailCPList.Count(); i++)
                         {
-                            Dt_StockInfo dt_StockInfo = BaseDal.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == stockLPNO.LPNNo).Includes(x => x.Details).First();
-                            for (int i = 0; i<stockInfoDetailCPList.Count(); i++)
+                            Dt_StockInfo dt_StockInfo = BaseDal.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == item.LPNNo).Includes(x => x.Details).First();
+                            if (dt_StockInfo == null)
                             {
-                                foreach (var item1 in dt_StockInfo.Details)
+                                return WebResponseContent.Instance.Error($"鎵樼洏{item.LPNNo}鏃犵鐮佹槑缁嗕俊鎭�");
+                            }
+                            List<Dt_StockInfoDetail> stockdetails = dt_StockInfo.Details;
+
+                            var matchedDetail = stockdetails.FirstOrDefault(d => d.MaterielCode.Contains(stockInfoDetailCPList[i].PartNum) && d.BatchNo.Contains(item.BatchNo));
+                            if (matchedDetail != null)
+                            {
+                                matchedDetail.StockQuantity -= (decimal)stockInfoDetailCPList[i].QtyOfpcs;
+                                matchedDetail.OutboundQuantity += (decimal)stockInfoDetailCPList[i].QtyOfpcs;
+                                _stockInfoDetailRepository.UpdateData(matchedDetail);
+
+                                if (matchedDetail.StockQuantity == 0)
                                 {
-                                    foreach (var batchNos in houseStockDetail.DetailList)
-                                    {
-                                        if (stockInfoDetailCPList[i].PartNum == item1.MaterielCode && batchNos.BatchNo == item.BatchNo)
-                                        {
-                                            item1.StockQuantity-=(decimal)stockInfoDetailCPList[i].QtyOfpcs;
-                                            item1.OutboundQuantity = 0;
-                                            _stockInfoDetailRepository.UpdateData(item1);
-                                        }
-                                        if (item1.StockQuantity == 0)
-                                        {
-                                            _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(item1, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                                        }
-                                        //鍏ㄩ儴閮藉嚭搴� 鍒犻櫎搴撳瓨
-                                        if (dt_StockInfo.Details.Sum(x => x.StockQuantity) == 0)
-                                        {
-                                            _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(dt_StockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
-                                        }
-                                    }
+                                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(matchedDetail, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
                                 }
                             }
+                            else
+                            {
+                                return WebResponseContent.Instance.Error($"鎵樼洏{item.LPNNo}涓湭鎵惧埌鐗╂枡{stockInfoDetailCPList[i].PartNum}鍜屾壒娆item.BatchNo}鐨勬槑缁�");
+                            }
+                            if (dt_StockInfo.Details.Sum(x => x.StockQuantity) == 0)
+                            {
+                                _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(dt_StockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                            }
                         }
-                       
-
                     }
-                    _unitOfWorkManage.CommitTran();
+
                 }
+                _unitOfWorkManage.CommitTran();
             }
             catch (Exception ex)
             {
@@ -496,14 +498,14 @@
                     });
                     result.Item2.ForEach(x =>
                     {
-                        foreach(var item in result.Item2)
+                        foreach (var item in result.Item2)
                         {
-                            if(item.LockQuantity > 0)
+                            if (item.LockQuantity > 0)
                             {
                                 item.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                             }
                         }
-                        
+
                     });
                     result.Item3.ForEach(x =>
                     {

--
Gitblit v1.9.3