From b4dfb1c5a0a3e6a682a98483e80ff372086aee8d Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期三, 03 十二月 2025 10:04:31 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs                   |   11 ++++-
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Outbound/PickingReturnController.cs |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/TaskInfo/TaskController.cs          |    4 +-
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_ITaskInfoService/ITaskService.cs                          |    2 
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs             |   91 ++++++++++++++++++++++++++-------------------
 5 files changed, 65 insertions(+), 45 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_ITaskInfoService/ITaskService.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_ITaskInfoService/ITaskService.cs"
index 73495a8..7f01bf2 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_ITaskInfoService/ITaskService.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_ITaskInfoService/ITaskService.cs"
@@ -50,6 +50,6 @@
 
         Task<WebResponseContent> GenerateOutboundBatchTasksAsync(int orderDetailId, decimal batchQuantity, string outStation);
 
-        Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews);
+        Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews, string station);
     }
 }
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/OutboundOrderDetailService.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/OutboundOrderDetailService.cs"
index d222228..a47f0c3 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/OutboundOrderDetailService.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/OutboundOrderDetailService.cs"
@@ -558,8 +558,7 @@
         }
 
 
-        public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>)
-       AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
+        public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>)AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
         {
             // 楠岃瘉鐢ㄦ埛閫夋嫨
             (bool, string) checkResult = CheckSelectStockDeital(outboundOrderDetail, stockSelectViews);
@@ -575,12 +574,9 @@
             decimal totalAssignedFromUserSelection = 0;
 
             // 鎸夊厛杩涘厛鍑烘帓搴忕敤鎴烽�夋嫨鐨勫簱瀛�
-            var userSelectedStocks = _stockService.StockInfoService.GetStockInfosByPalletCodes(
-                stockSelectViews.Select(x => x.PalletCode).ToList());
+            var userSelectedStocks = _stockService.StockInfoService.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList());
 
-            var sortedUserSelectedStocks = userSelectedStocks
-                .OrderBy(x => x.CreateDate)
-                .ToList();
+            var sortedUserSelectedStocks = userSelectedStocks.OrderBy(x => x.CreateDate).ToList();
 
             // 鍒嗛厤鐢ㄦ埛閫夋嫨鐨勫簱瀛�
             foreach (var stock in sortedUserSelectedStocks)
@@ -596,9 +592,7 @@
                     outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode);
 
                 // 纭畾鍒嗛厤鏁伴噺锛氬彇鐢ㄦ埛閫夋嫨鏁伴噺銆佸彲鐢ㄦ暟閲忓拰鍓╀綑闇�姹傜殑鏈�灏忓��
-                var assignQuantity = Math.Min(
-                    Math.Min(userSelection.UseableQuantity, availableQuantity),
-                    remainingNeedQuantity);
+                var assignQuantity = Math.Min(Math.Min(userSelection.UseableQuantity, availableQuantity),remainingNeedQuantity);
 
                 if (assignQuantity <= 0) continue;
 
@@ -623,42 +617,57 @@
             }
 
             // 濡傛灉鐢ㄦ埛閫夋嫨鐨勫簱瀛樹笉澶燂紝鑷姩鍒嗛厤鍓╀綑閮ㄥ垎
-            decimal autoAssignedQuantity = 0;
+          
             if (remainingNeedQuantity > 0)
             {
-                List<Dt_StockInfo> autoStocks = _stockService.StockInfoService.GetUseableStocks(
-                    outboundOrderDetail.MaterielCode, outboundOrderDetail.BatchNo, "");
+                //// 鍙�夛細杩欓噷鍙互鏍规嵁涓氬姟闇�姹傚喅瀹氭槸鍚﹀厑璁歌嚜鍔ㄥ垎閰�
+                //// 濡傛灉瑕佹眰涓ユ牸鎸夌敤鎴烽�夋嫨鍑哄簱锛屽彲浠ユ姏鍑哄紓甯�
+                //// throw new Exception($"鐢ㄦ埛閫夋嫨鐨勫簱瀛樻暟閲忎笉瓒筹紝杩橀渶{remainingNeedQuantity}锛岃閲嶆柊閫夋嫨");
 
-                // 鎺掗櫎鐢ㄦ埛宸查�夋嫨鐨勬墭鐩�
-                autoStocks = autoStocks
-                    .Where(x => !stockSelectViews.Select(v => v.PalletCode).Contains(x.PalletCode))
-                    .ToList();
+                //// 濡傛灉闇�瑕佽嚜鍔ㄥ垎閰嶏紝璁板綍鏃ュ織
+                //_logger.LogInformation($"鐢ㄦ埛閫夋嫨鐨勫簱瀛樻暟閲忎笉瓒筹紝杩橀渶{remainingNeedQuantity}锛岀郴缁熷皢鑷姩鍒嗛厤");
 
-                var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(
-                    autoStocks, outboundOrderDetail.MaterielCode, remainingNeedQuantity, out decimal residueQuantity);
+                //List<Dt_StockInfo> autoStocks = _stockService.StockInfoService.GetUseableStocks(
+                //    outboundOrderDetail.MaterielCode,
+                //    outboundOrderDetail.BatchNo,
+                //    "");
 
-                // 妫�鏌ヨ嚜鍔ㄥ垎閰嶇粨鏋�
-                autoAssignedQuantity = remainingNeedQuantity - residueQuantity;
-                if (autoAssignedQuantity <= 0 && remainingNeedQuantity > 0)
-                {
-                    // 閮ㄥ垎鍒嗛厤鏄彲浠ユ帴鍙楃殑锛岃褰曡鍛婁絾涓嶆姤閿�
-                    _logger.LogWarning($"鑷姩鍒嗛厤澶辫触锛屽墿浣欓渶姹倇remainingNeedQuantity}鏃犳硶婊¤冻");
-                }
-                else if (autoAssignedQuantity > 0)
-                {
-                    outStocks.AddRange(autoAssignStocks);
+                //// 鎺掗櫎鐢ㄦ埛宸查�夋嫨涓斿凡鍒嗛厤鐨勬墭鐩�
+                //var assignedPalletCodes = outStocks.Select(x => x.PalletCode).ToList();
+                //autoStocks = autoStocks
+                //    .Where(x => !assignedPalletCodes.Contains(x.PalletCode))
+                //    .ToList();
 
-                    // 涓鸿嚜鍔ㄥ垎閰嶇殑搴撳瓨鍒涘缓閿佸畾璁板綍
-                    var autoLockInfos = CreateLockInfosForAutoAssign(outboundOrder, outboundOrderDetail, autoAssignStocks, stockAllocations);
-                    outStockLockInfos.AddRange(autoLockInfos);
-                }
+                //var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(
+                //    autoStocks,
+                //    outboundOrderDetail.MaterielCode,
+                //    remainingNeedQuantity,
+                //    out decimal residueQuantity);
+
+                //if (autoAssignStocks != null && autoAssignStocks.Any())
+                //{
+                //    outStocks.AddRange(autoAssignStocks);
+
+                //    // 涓鸿嚜鍔ㄥ垎閰嶇殑搴撳瓨鍒涘缓閿佸畾璁板綍
+                //    var autoLockInfos = CreateLockInfosForAutoAssign(outboundOrder, outboundOrderDetail, autoAssignStocks, stockAllocations);
+                //    outStockLockInfos.AddRange(autoLockInfos);
+
+                //    // 鏇存柊宸插垎閰嶆暟閲�
+                //    decimal autoAssignedQuantity = remainingNeedQuantity - residueQuantity;
+                //    totalAssignedFromUserSelection += autoAssignedQuantity;
+                //    remainingNeedQuantity = residueQuantity; // 鏇存柊鍓╀綑闇�姹�
+                //}
+                //else if (remainingNeedQuantity > 0)
+                //{
+                //    _logger.LogWarning($"鑷姩鍒嗛厤澶辫触锛屽墿浣欓渶姹倇remainingNeedQuantity}鏃犳硶婊¤冻");
+                //}
             }
 
             // 鏇存柊閿佸畾鏁伴噺
-            outboundOrderDetail.LockQuantity += totalAssignedFromUserSelection + autoAssignedQuantity;
+            outboundOrderDetail.LockQuantity += totalAssignedFromUserSelection + totalAssignedFromUserSelection;
 
             // 鏇存柊鐘舵��
-            UpdateOrderDetailStatus(outboundOrderDetail, remainingNeedQuantity - autoAssignedQuantity);
+            UpdateOrderDetailStatus(outboundOrderDetail, remainingNeedQuantity);
 
             List<Dt_LocationInfo> locationInfos = _locationInfoService.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList());
 
@@ -682,17 +691,21 @@
             decimal remainingAssign = assignQuantity;
 
             // 鎸夊厛杩涘厛鍑哄垎閰嶅簱瀛樻槑缁�
-            var sorteds = stock.Details
+            var query = stock.Details.AsQueryable()
                 .Where(d => d.MaterielCode == detail.MaterielCode &&
                            (d.StockQuantity - d.OutboundQuantity) > 0);
                // .OrderBy(d => d.CreateDate);             
 
             if (!string.IsNullOrEmpty(detail.BatchNo))
             {
-                sorteds= stock.Details.Where(x => x.BatchNo == detail.BatchNo);
+                query = query.Where(x => x.BatchNo == detail.BatchNo);
             }
-
-            var sortedDetails= sorteds.ToList().OrderBy(d => d.CreateDate);
+            // 濡傛灉鍑哄簱鍗曟湁渚涘簲鍟嗚姹傦紝鎸変緵搴斿晢杩囨护
+            if (!string.IsNullOrEmpty(detail.SupplyCode))
+            {
+                query = query.Where(d => d.SupplyCode == detail.SupplyCode);
+            }
+            var sortedDetails= query.ToList().OrderBy(d => d.CreateDate);
 
 
             foreach (var stockDetail in sortedDetails)
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 5f04e43..db099ac 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"
@@ -465,7 +465,14 @@
             }
         }
 
-        public async Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews)
+        /// <summary>
+        /// 鏅轰粨璋冩櫤浠�
+        /// </summary>
+        /// <param name="orderDetailId"></param>
+        /// <param name="stockSelectViews"></param>
+        /// <param name="station"></param>
+        /// <returns></returns>
+        public async Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews, string station = null)
         {
             try
             {
@@ -492,7 +499,7 @@
                     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);
+                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(outboundOrder.Details.First().Id, stockSelectViews,station);
 
                 WebResponseContent content =await GenerateOutboundTaskDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5);
 
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_WMSServer/Controllers/Outbound/PickingReturnController.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_WMSServer/Controllers/Outbound/PickingReturnController.cs"
index e048964..d51d094 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_WMSServer/Controllers/Outbound/PickingReturnController.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_WMSServer/Controllers/Outbound/PickingReturnController.cs"
@@ -26,7 +26,7 @@
         }
 
         /// <summary>
-        /// 閲嶆缁勭洏鍏ュ簱
+        /// 閲嶆  鏅轰粨璋冩櫤浠�   缁勭洏鍏ュ簱
         /// </summary>
         /// <param name="materielGroupDTO"></param>
         /// <returns></returns>
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_WMSServer/Controllers/TaskInfo/TaskController.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_WMSServer/Controllers/TaskInfo/TaskController.cs"
index b97da04..a8b86b7 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_WMSServer/Controllers/TaskInfo/TaskController.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_WMSServer/Controllers/TaskInfo/TaskController.cs"
@@ -92,9 +92,9 @@
         /// <param name="stockSelectViews"></param>
         /// <returns></returns>
         [HttpPost, HttpGet, Route("GenerateAllocatOutboundTask"), AllowAnonymous]
-        public async Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, [FromBody] List<StockSelectViewDTO> stockSelectViews)
+        public async Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, string station, [FromBody] List<StockSelectViewDTO> stockSelectViews)
         {
-            return await Service.GenerateAllocatOutboundTask(orderDetailId, stockSelectViews);
+            return await Service.GenerateAllocatOutboundTask(orderDetailId, stockSelectViews,station);
         }
 
         /// <summary>

--
Gitblit v1.9.3