From 4b483d9d06bead231b88ca212fd799196668a057 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 28 四月 2026 22:58:27 +0800
Subject: [PATCH] fix(任务服务): 修复出库任务选择逻辑和货位分配问题

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs |   47 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
index 53ef4b5..9594985 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
@@ -133,22 +133,43 @@
 
         /// <summary>
         /// 鏍规嵁宸烽亾鑾峰彇绌洪棽璐т綅淇℃伅
+        /// 鎺掑簭绛栫暐锛氭繁搴︿紭鍏堬紙浜屾繁浣嶄紭鍏堬級锛屽叾娆℃寜灞傘�佸垪銆佽鍗囧簭
         /// </summary>
         /// <param name="roadwayNo">宸烽亾缂栧彿</param>
-        /// <returns>绌洪棽璐т綅淇℃伅锛屽鏋滄湭鎵惧埌鍒欒繑鍥瀗ull</returns>
+        /// <returns>绌洪棽璐т綅淇℃伅锛屽鏋滅┖闂茶揣浣嶄笉瓒冲垯杩斿洖null</returns>
         public async Task<Dt_LocationInfo?> GetLocationInfo(string roadwayNo)
         {
-            var locations = await BaseDal.QueryDataAsync(x =>
-                x.EnableStatus == EnableStatusEnum.Normal.GetHashCode() &&
-                x.RoadwayNo == roadwayNo &&
-                x.LocationStatus == LocationStatusEnum.Free.GetHashCode());
+            // HC 宸烽亾浣跨敤 Capacity 绫诲瀷锛屽叾浠栧贩閬撲娇鐢� ShelfCapacity 绫诲瀷
+            var locationType = roadwayNo.Contains("HC")
+                ? (int)LocationTypeEnum.Capacity
+                : (int)LocationTypeEnum.ShelfCapacity;
 
-            return locations?
-                .OrderByDescending(x => x.Depth)  // 1. 娣卞害浼樺厛锛堜粠澶у埌灏忥級
-                .ThenBy(x => x.Layer)             // 2. 灞傛暟
-                .ThenBy(x => x.Column)            // 3. 鍒�
-                .ThenBy(x => x.Row)               // 4. 琛�
-                .FirstOrDefault();
+            var enableStatus = EnableStatusEnum.Normal.GetHashCode();
+            var freeStatus = LocationStatusEnum.Free.GetHashCode();
+
+            // 鏁版嵁搴撶 COUNT 妫�鏌ョ┖闂茶揣浣嶆暟閲忥紙浠呰繑鍥炰竴涓暟瀛楋紝鏃犳暟鎹紶杈撳紑閿�锛�
+            var freeCount = await BaseDal.Db.Queryable<Dt_LocationInfo>()
+                .Where(x => x.EnableStatus == enableStatus
+                    && x.RoadwayNo == roadwayNo
+                    && x.LocationStatus == freeStatus
+                    && x.LocationType == locationType)
+                .CountAsync();
+
+            // 绌洪棽璐т綅涓嶈冻鏈�浣庝繚鐣欐暟閲忔椂杩斿洖null锛岄伩鍏嶅皢宸烽亾鍒嗛厤鑰楀敖
+            const int minFreeLocationThreshold = 5;
+            if (freeCount < minFreeLocationThreshold) return null;
+
+            // 鏁版嵁搴撶鎺掑簭鍙栫涓�鏉★紙鍙紶杈撳崟琛屾暟鎹級
+            return await BaseDal.Db.Queryable<Dt_LocationInfo>()
+                .Where(x => x.EnableStatus == enableStatus
+                    && x.RoadwayNo == roadwayNo
+                    && x.LocationStatus == freeStatus
+                    && x.LocationType == locationType)
+                .OrderByDescending(x => x.Depth)
+                .OrderBy(x => x.Layer)
+                .OrderBy(x => x.Column)
+                .OrderBy(x => x.Row)
+                .FirstAsync();
         }
 
         /// <summary>
@@ -308,7 +329,7 @@
             // 鍒ゆ柇璇ヤ綅缃槸鍚︽湁搴撳瓨
             var stockInfo = await _stockInfoRepository.QueryDataNavFirstAsync(x =>
                             x.LocationCode == newLocationID &&
-                            x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode() &&
+                            (x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode() || x.StockStatus == StockStatusEmun.绌烘墭鐩樺簱瀛�.GetHashCode()) &&
                             x.LocationDetails.LocationStatus == LocationStatusEnum.InStock.GetHashCode());
             if (stockInfo == null)
             {
@@ -535,4 +556,4 @@
 
         #endregion 绉佹湁鏂规硶
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3