From 5f0b86328b2678a326166e84b461e9ede3dc4715 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期一, 01 十二月 2025 21:03:46 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs |   70 ++++++++++++++++++++++++++++-------
 1 files changed, 56 insertions(+), 14 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_TaskInfoService/TaskService_Outbound.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_TaskInfoService/TaskService_Outbound.cs"
index 6cbf577..8f26611 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_TaskInfoService/TaskService_Outbound.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_TaskInfoService/TaskService_Outbound.cs"
@@ -19,6 +19,7 @@
 using WIDESEA_DTO.Stock;
 using WIDESEA_Model.Models;
 using WIDESEA_Model.Models.Basic;
+using WIDESEA_Model.Models.Check;
 using WIDESEA_Model.Models.Outbound;
 
 namespace WIDESEA_TaskInfoService
@@ -143,14 +144,22 @@
             {
                 throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
             }
-            if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null)
+            //if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null)
+            //{
+            //    throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
+            //}
+
+            if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.Outbound.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null)
             {
-                throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
+                throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪宸插畬鎴愮姸鎬侊紝鏃犳硶閲嶆柊鍒嗛厤");
             }
+
             List<Dt_StockInfo>? stockInfos = null;
             List<Dt_OutboundOrderDetail>? orderDetails = null;
             List<Dt_OutStockLockInfo>? outStockLockInfos = null;
             List<Dt_LocationInfo>? locationInfos = null;
+
+            CleanupPreviousInvalidLocks(outboundOrderDetails);
 
             (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
             if (result.Item1 != null && result.Item1.Count > 0)
@@ -188,7 +197,31 @@
             }
             return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos);
         }
+        /// <summary>
+        /// 娓呯悊涔嬪墠鐨勬棤鏁堥攣瀹氳褰�
+        /// </summary>
+        private  void  CleanupPreviousInvalidLocks(List<Dt_OutboundOrderDetail> orderDetails)
+        {
+            var orderIds = orderDetails.Select(x => x.OrderId).Distinct().ToList();
+            var orderNos =  _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+                .Where(x => orderIds.Contains(x.Id))
+                .Select(x => x.OrderNo)
+                .ToList();
 
+            // 娓呯悊鐘舵�佷负"宸查噴鏀�"鎴�"鍥炲簱涓�"鐨勬棫閿佸畾璁板綍
+            foreach (var orderNo in orderNos)
+            {
+               _outStockLockInfoService.Db.Updateable<Dt_OutStockLockInfo>()
+                    .SetColumns(x => new Dt_OutStockLockInfo
+                    {
+                        Status = (int)OutLockStockStatusEnum.宸查噴鏀�
+                    })
+                    .Where(x => x.OrderNo == orderNo &&
+                               (x.Status == (int)OutLockStockStatusEnum.鍥炲簱涓� ||
+                                x.Status == (int)OutLockStockStatusEnum.宸查噴鏀�))
+                    .ExecuteCommand();
+            }
+        }
 
         /// <summary>
         /// 鐢熸垚鍑哄簱浠诲姟鍚庢暟鎹洿鏂板埌鏁版嵁搴�
@@ -444,7 +477,7 @@
             }
         }
 
-
+       
         /// <summary>
         /// 鐢熸垚鍑哄簱浠诲姟
         /// </summary>
@@ -455,7 +488,13 @@
         {
             try
             {
-                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(orderDetailId, stockSelectViews);
+                var orderNo = _reCheckOrderRepository.Db.Queryable<Dt_ReCheckOrder>().First(x => x.Id == orderDetailId)?.OrderNo;
+               var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Includes(x => x.Details).First(x => x.UpperOrderNo == orderNo);
+                if(outboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error("鎵句笉鍒板崟鎹�");
+                }
+                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(outboundOrder.Details.First().Id, stockSelectViews);
 
                 WebResponseContent content = GenerateOutboundTaskDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5);
 
@@ -605,7 +644,7 @@
         /// <summary>
         /// 鍒嗘壒鍒嗛厤搴撳瓨
         /// </summary>
-        public async Task<WebResponseContent> BatchAllocateStock(string orderNo, int orderDetailId, decimal batchQuantity, string outStation)
+        public async Task<WebResponseContent> GenerateOutboundBatchTasksAsync(int orderDetailId, decimal batchQuantity, string outStation) 
         {
             try
             {
@@ -615,7 +654,7 @@
                 List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
                 List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
 
-                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = await BatchAllocateStockDataHandle(orderNo, orderDetailId, batchQuantity, outStation);
+                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = await BatchAllocateStockDataHandle(orderDetailId, batchQuantity, outStation);
 
                 if (result.Item2 != null && result.Item2.Count > 0)
                 {
@@ -644,7 +683,7 @@
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
-                _logger.LogError($"鍒嗘壒鍒嗛厤搴撳瓨澶辫触 - OrderNo: {orderNo}, OrderDetailId: {orderDetailId}, Quantity: {batchQuantity}, Error: {ex.Message}");
+                _logger.LogError($"鍒嗘壒鍒嗛厤搴撳瓨澶辫触 -  OrderDetailId: {orderDetailId}, Quantity: {batchQuantity}, Error: {ex.Message}");
                 return WebResponseContent.Instance.Error($"鍒嗘壒鍒嗛厤澶辫触锛歿ex.Message}");
             }
         }
@@ -653,7 +692,7 @@
         /// 鍒嗘壒鍒嗛厤搴撳瓨鏁版嵁澶勭悊
         /// </summary>
         public async Task<(List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?)>
-            BatchAllocateStockDataHandle(string orderNo, int orderDetailId, decimal batchQuantity, string outStation)
+            BatchAllocateStockDataHandle( int orderDetailId, decimal batchQuantity, string outStation)
         {
             List<Dt_Task> tasks = new List<Dt_Task>();
 
@@ -665,14 +704,18 @@
             {
                 throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
             }
-
+            var  outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().FirstAsync(x => x.Id == outboundOrderDetail.OrderId);
+            if(outboundOrder == null)
+            {
+                throw new Exception("鏈壘鍒板嚭搴撳崟淇℃伅");
+            }
             // 楠岃瘉璁㈠崟鏄庣粏鐘舵��
-            if (outboundOrderDetail.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() &&
+            if (outboundOrderDetail.OrderDetailStatus > OrderDetailStatusEnum.Outbound.ObjToInt() &&
                 outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt())
             {
                 throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
             }
-
+               
             // 楠岃瘉鍒嗛厤鏁伴噺
             decimal allocatedQty = outboundOrderDetail.AllocatedQuantity;
             decimal overOutQty = outboundOrderDetail.OverOutQuantity;
@@ -700,9 +743,8 @@
             if (allocateResult.Item1 != null && allocateResult.Item1.Count > 0)
             {
                 // 鍒涘缓鍒嗘壒璁板綍
-                await CreateBatchRecord(orderNo, orderDetailId, batchQuantity, batchNo);
-
-                Dt_OutboundOrder outboundOrder = await _outboundOrderService.Repository.QueryFirstAsync(x => x.Id == outboundOrderDetail.OrderId);
+                await CreateBatchRecord(outboundOrder.OrderNo, orderDetailId, batchQuantity, batchNo);
+ 
                 TaskTypeEnum typeEnum = outboundOrder.OrderType switch
                 {
                     (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,

--
Gitblit v1.9.3