From 70ae387bfb08b5734215711018a0f832e4ac6a41 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期五, 21 十一月 2025 14:50:38 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs |   91 +++++++++++++++++++++------------------------
 1 files changed, 43 insertions(+), 48 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
index 5cf4570..b511d51 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
@@ -251,6 +251,9 @@
             }
         }
 
+  
+   
+
         public async Task<WebResponseContent> ConfirmPicking(string orderNo, string palletCode, string barcode)
         {
             #region "娴嬭瘯鎵撳嵃"
@@ -283,25 +286,25 @@
             {
                 _unitOfWorkManage.BeginTran();
 
+                // 1. 鏌ユ壘鍑哄簱閿佸畾淇℃伅
                 var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
-           .Where(it => it.OrderNo == orderNo &&
-                      it.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� &&
-                      it.PalletCode == palletCode &&
-                      it.CurrentBarcode == barcode &&
-                      it.AssignQuantity > it.PickedQty) // 澧炲姞锛氬彧鏈夋湭瀹屾垚鍒嗘嫞鐨勬墠鑳界户缁�
-           .FirstAsync();
+                    .Where(it => it.OrderNo == orderNo &&
+                               it.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� &&
+                               it.PalletCode == palletCode &&
+                               it.CurrentBarcode == barcode &&
+                               it.AssignQuantity > it.PickedQty)
+                    .FirstAsync();
 
                 if (lockInfo == null)
                 {
                     lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                         .Where(it => it.CurrentBarcode == barcode &&
                                    it.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� &&
-                                   it.AssignQuantity > it.PickedQty) // 澧炲姞锛氭鏌ュ垎鎷h繘搴�
+                                   it.AssignQuantity > it.PickedQty)
                         .FirstAsync();
 
                     if (lockInfo == null)
                     {
-                        // 妫�鏌ユ槸鍚﹀凡缁忓畬鎴愬垎鎷�
                         var completedLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                             .Where(it => it.CurrentBarcode == barcode &&
                                        (it.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴� ||
@@ -318,12 +321,7 @@
                 if (lockInfo.PalletCode != palletCode)
                     throw new Exception($"鏉$爜{barcode}涓嶅睘浜庢墭鐩榹palletCode}");
 
-                if (lockInfo.PickedQty >= lockInfo.AssignQuantity)
-                {
-                    throw new Exception($"鏉$爜{barcode}宸茬粡瀹屾垚鍒嗘嫞锛屼笉鑳介噸澶嶅垎鎷�");
-                }
-
-                //  妫�鏌ユ嫞閫夊巻鍙诧紝闃叉閲嶅鍒嗘嫞
+                // 妫�鏌ユ嫞閫夊巻鍙诧紝闃叉閲嶅鍒嗘嫞
                 var existingPicking = await Db.Queryable<Dt_PickingRecord>()
                     .Where(x => x.Barcode == barcode &&
                                x.OrderNo == orderNo &&
@@ -336,16 +334,17 @@
                     throw new Exception($"鏉$爜{barcode}宸茬粡鍒嗘嫞杩囷紝涓嶈兘閲嶅鍒嗘嫞");
                 }
 
+                var outorderdetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+                    .FirstAsync(x => x.Id == lockInfo.OrderDetailId);
 
-                var outorderdetail = _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().First(x => x.Id == lockInfo.OrderDetailId);
-                if (outorderdetail != null && lockInfo.AssignQuantity > outorderdetail.OrderQuantity)
+                if (outorderdetail != null && (lockInfo.AssignQuantity + outorderdetail.OverOutQuantity) > outorderdetail.NeedOutQuantity)
                 {
-                    throw new Exception($"鏉$爜{barcode}鐨勫嚭搴撴暟閲忓ぇ浜庤鍗曠殑鏁伴噺");
+                    throw new Exception($"鏉$爜{barcode}鐨勫嚭搴撴暟閲忓皢瀵艰嚧璁㈠崟鏄庣粏宸插嚭搴撴暟閲忚秴杩囬渶姹傛暟閲�");
                 }
 
                 var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-                        .Where(x => x.Barcode == barcode && x.StockId == lockInfo.StockId)
-                        .FirstAsync();
+                    .Where(x => x.Barcode == barcode && x.StockId == lockInfo.StockId)
+                    .FirstAsync();
 
                 if (stockDetail == null)
                     return WebResponseContent.Instance.Error("鏃犳晥鐨勬潯鐮佹垨鐗╂枡缂栫爜");
@@ -357,23 +356,20 @@
                 Dt_OutStockLockInfo finalLockInfo = lockInfo;
                 var finalBarcode = barcode;
                 var finalStockId = stockDetail.Id;
+                decimal actualPickedQty = actualQty; // 瀹為檯鎷i�夋暟閲�
 
                 if (actualQty < stockQuantity)
                 {
                     // 鎯呭喌1: 鍒嗛厤鏁伴噺灏忎簬搴撳瓨鏁伴噺锛岄渶瑕佽嚜鍔ㄦ媶鍖�
-                    // 璁$畻鍓╀綑搴撳瓨鏁伴噺
                     decimal remainingStockQty = stockQuantity - actualQty;
 
-                    // 鏇存柊鍘熸潯鐮佸簱瀛樹负鍓╀綑鏁伴噺
                     stockDetail.StockQuantity = remainingStockQty;
                     stockDetail.OutboundQuantity = remainingStockQty;
                     await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
 
-                    // 鐢熸垚鏂版潯鐮佺敤浜庤褰曟嫞閫夋暟閲忥紙浣嗕笉鍒涘缓搴撳瓨璁板綍锛�
                     var seq = await _dailySequenceService.GetNextSequenceAsync();
                     string newBarcode = "WSLOT" + DateTime.Now.ToString("yyyyMMdd") + seq.ToString()?.PadLeft(5, '0');
 
-                    // 涓烘柊鏉$爜鍒涘缓鍑哄簱閿佸畾淇℃伅锛堢敤浜庤褰曟嫞閫夛級
                     var newLockInfo = new Dt_OutStockLockInfo
                     {
                         OrderNo = lockInfo.OrderNo,
@@ -398,11 +394,10 @@
                         IsSplitted = 1,
                         ParentLockId = lockInfo.Id
                     };
-                    // 鎻掑叆鏂伴攣瀹氫俊鎭苟鑾峰彇ID
-                    var newLockId = await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteReturnIdentityAsync();
-                    newLockInfo.Id = newLockId; // 纭繚ID琚纭缃�
 
-                    // 璁板綍鎷嗗寘鍘嗗彶锛堢敤浜庤拷韪級
+                    var newLockId = await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteReturnIdentityAsync();
+                    newLockInfo.Id = newLockId;
+
                     var splitHistory = new Dt_SplitPackageRecord
                     {
                         FactoryArea = lockInfo.FactoryArea,
@@ -423,10 +418,8 @@
                     };
                     await _splitPackageService.Db.Insertable(splitHistory).ExecuteCommandAsync();
 
-                    // 鏇存柊鍘熼攣瀹氫俊鎭负鍓╀綑搴撳瓨鏁伴噺
                     lockInfo.AssignQuantity = remainingStockQty;
                     lockInfo.PickedQty = 0;
-
                     await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
 
                     splitResults.Add(new SplitResult
@@ -438,8 +431,8 @@
                         batch = lockInfo.BatchNo,
                         factory = lockInfo.FactoryArea,
                         date = DateTime.Now.ToString("yyyy-MM-dd"),
-
                     });
+
                     splitResults.Add(new SplitResult
                     {
                         materialCode = lockInfo.MaterielCode,
@@ -450,12 +443,12 @@
                         factory = lockInfo.FactoryArea,
                         date = DateTime.Now.ToString("yyyy-MM-dd"),
                     });
-                    // 鏇存柊鎷i�夎褰曚腑鐨勬潯鐮佷负鏂版潯鐮�
+
                     barcode = newBarcode;
                     lockInfo = newLockInfo;
                     finalLockInfo = newLockInfo;
                     finalBarcode = newBarcode;
-                    finalStockId = stockDetail.Id; // 浣跨敤鍘熷簱瀛業D
+                    finalStockId = stockDetail.Id;
                 }
                 else if (actualQty == stockQuantity)
                 {
@@ -467,6 +460,7 @@
                     lockInfo.PickedQty += actualQty;
                     lockInfo.Status = (int)OutLockStockStatusEnum.鎷i�夊畬鎴�;
                     await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+
                     finalLockInfo = lockInfo;
                     finalBarcode = barcode;
                     finalStockId = stockDetail.Id;
@@ -474,51 +468,53 @@
                 else
                 {
                     // 鎯呭喌3: 鍒嗛厤鏁伴噺澶т簬搴撳瓨鏁伴噺锛屽簱瀛樻暣鍖呭嚭搴�
-                    // 鏁村寘鍑哄簱褰撳墠搴撳瓨
                     decimal stockOutQty = stockQuantity;
                     stockDetail.StockQuantity = 0;
                     stockDetail.OutboundQuantity = 0;
                     await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
 
-                    // 璁$畻鍓╀綑鍒嗛厤鏁伴噺
                     decimal remainingAssignQty = actualQty - stockQuantity;
-
-                    // 鏇存柊閿佸畾淇℃伅锛堝彧瀹屾垚搴撳瓨閮ㄥ垎锛�
                     lockInfo.PickedQty += stockOutQty;
                     lockInfo.AssignQuantity = remainingAssignQty;
-
                     await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
 
                     var _relatedSplitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
-                                                .Where(it => it.OriginalBarcode == barcode || it.NewBarcode == barcode)
-                                                .Where(it => !it.IsReverted)
-                                                .ToListAsync();
+                        .Where(it => it.OriginalBarcode == barcode || it.NewBarcode == barcode)
+                        .Where(it => !it.IsReverted)
+                        .ToListAsync();
 
                     foreach (var record in _relatedSplitRecords)
                     {
                         record.Status = (int)SplitPackageStatusEnum.宸叉嫞閫�;
                         await _splitPackageService.Db.Updateable(record).ExecuteCommandAsync();
                     }
+
                     finalLockInfo = lockInfo;
                     finalBarcode = barcode;
                     finalStockId = stockDetail.Id;
+                    actualPickedQty = stockOutQty; // 瀹為檯鎷i�夋暟閲忚皟鏁翠负搴撳瓨鏁伴噺
                 }
 
-
-
+                // 鏇存柊璁㈠崟鏄庣粏鐨勬嫞閫夋暟閲忓拰宸插嚭搴撴暟閲�
                 await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
-                    .SetColumns(it => it.PickedQty == it.PickedQty + actualQty)
+                    .SetColumns(it => new Dt_OutboundOrderDetail
+                    {
+                        PickedQty = it.PickedQty + actualPickedQty,
+                        OverOutQuantity = it.OverOutQuantity + actualPickedQty
+                    })
                     .Where(it => it.Id == lockInfo.OrderDetailId)
                     .ExecuteCommandAsync();
 
                 await CheckAndUpdateOrderStatus(orderNo);
 
-                // 鏌ヨ浠诲姟琛� 
+                // 鏌ヨ浠诲姟琛�
                 var task = _taskRepository.QueryData(x => x.OrderNo == orderNo && x.PalletCode == palletCode).FirstOrDefault();
+
                 if (finalLockInfo.Id <= 0)
                 {
                     throw new Exception($"閿佸畾淇℃伅ID鏃犳晥: {finalLockInfo.Id}锛屾棤娉曡褰曟嫞閫夊巻鍙�");
                 }
+
                 // 璁板綍鎷i�夊巻鍙�
                 var pickingHistory = new Dt_PickingRecord
                 {
@@ -531,7 +527,7 @@
                     PalletCode = palletCode,
                     Barcode = finalBarcode,
                     MaterielCode = finalLockInfo.MaterielCode,
-                    PickQuantity = actualQty,
+                    PickQuantity = actualPickedQty,
                     PickTime = DateTime.Now,
                     Operator = App.User.UserName,
                     OutStockLockId = finalLockInfo.Id
@@ -540,22 +536,21 @@
 
                 _unitOfWorkManage.CommitTran();
 
-                // 濡傛灉鏈夋媶鍖呯粨鏋滐紝杩斿洖鎷嗗寘淇℃伅
                 if (splitResults.Any())
                 {
                     return WebResponseContent.Instance.OK("鎷i�夌‘璁ゆ垚鍔燂紝宸茶嚜鍔ㄦ媶鍖�", new { SplitResults = splitResults });
                 }
 
-                return WebResponseContent.Instance.OK("鎷i�夌‘璁ゆ垚鍔�", new { SplitResults = splitResults });
+                return WebResponseContent.Instance.OK("鎷i�夌‘璁ゆ垚鍔�");
 
             }
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
+                _logger.LogError($"ConfirmPicking澶辫触 - OrderNo: {orderNo}, PalletCode: {palletCode}, Barcode: {barcode}, Error: {ex.Message}");
                 return WebResponseContent.Instance.Error($"鎷i�夌‘璁ゅけ璐ワ細{ex.Message}");
             }
         }
-
         /// <summary>
         /// 鍥炲簱鎿嶄綔  
         /// </summary>

--
Gitblit v1.9.3