From 37acb8358f5602a9013ee29c04a45e33483c2329 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 09 四月 2026 15:21:40 +0800
Subject: [PATCH] fix: 修复PLC字符串解析和任务处理逻辑

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
index aff926c..53ef4b5 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
@@ -25,6 +25,7 @@
         private readonly IRepository<Dt_Task> _taskRepository;
         private readonly IRepository<Dt_StockInfo> _stockInfoRepository;
         private readonly IRecordService _recordService;
+        private readonly IRepository<Dt_Warehouse> _warehouseRepository;
 
         /// <summary>
         /// 鏋勯�犲嚱鏁�
@@ -36,6 +37,7 @@
             IRepository<Dt_LocationInfo> baseDal,
             IRepository<Dt_Task> taskRepository,
             IRepository<Dt_StockInfo> stockInfoRepository,
+            IRepository<Dt_Warehouse> warehouseRepository,
             IMapper mapper,
             IRecordService recordService) : base(baseDal)
         {
@@ -43,6 +45,7 @@
             _stockInfoRepository = stockInfoRepository;
             _mapper = mapper;
             _recordService = recordService;
+            _warehouseRepository = warehouseRepository;
         }
 
         /// <summary>
@@ -141,10 +144,10 @@
                 x.LocationStatus == LocationStatusEnum.Free.GetHashCode());
 
             return locations?
-                .OrderBy(x => x.Layer)
-                .ThenByDescending(x => x.Depth)
-                .ThenBy(x => x.Column)
-                .ThenBy(x => x.Row)
+                .OrderByDescending(x => x.Depth)  // 1. 娣卞害浼樺厛锛堜粠澶у埌灏忥級
+                .ThenBy(x => x.Layer)             // 2. 灞傛暟
+                .ThenBy(x => x.Column)            // 3. 鍒�
+                .ThenBy(x => x.Row)               // 4. 琛�
                 .FirstOrDefault();
         }
 
@@ -167,6 +170,16 @@
         public async Task<Dt_LocationInfo> GetLocationInfoAsync(string locationCode)
         {
             return await BaseDal.QueryFirstAsync(x => x.LocationCode == locationCode);
+        }
+
+        /// <summary>
+        /// 鏍规嵁璐т綅ID鑾峰彇璐т綅淇℃伅
+        /// </summary>
+        /// <param name="id">璐т綅id</param>
+        /// <returns>璐т綅淇℃伅</returns>
+        public async Task<Dt_LocationInfo> GetLocationInfoAsync(int id)
+        {
+            return await BaseDal.QueryFirstAsync(x => x.Id == id);
         }
 
         /// <summary>
@@ -494,11 +507,18 @@
         /// <param name="layer">灞傛暟</param>
         /// <param name="depth">娣卞害</param>
         /// <returns>璐т綅淇℃伅瀵硅薄</returns>
-        private static Dt_LocationInfo CreateLocationInfo(string roadwayNo, int row, int col, int layer, int depth)
+        private Dt_LocationInfo CreateLocationInfo(string roadwayNo, int row, int col, int layer, int depth)
         {
+            var warehouse = _warehouseRepository.QueryData(x => x.WarehouseCode == roadwayNo).FirstOrDefault();
+
+            if (warehouse == null)
+            {
+                throw new InvalidOperationException($"鏈壘鍒板贩閬撶紪鍙蜂负 {roadwayNo} 鐨勪粨搴撲俊鎭�");
+            }
+
             return new Dt_LocationInfo
             {
-                WarehouseId = 0,
+                WarehouseId = warehouse.WarehouseId,
                 Row = row,
                 Column = col,
                 Layer = layer,
@@ -507,6 +527,7 @@
                 EnableStatus = EnableStatusEnum.Normal.GetHashCode(),
                 LocationStatus = LocationStatusEnum.Free.GetHashCode(),
                 LocationType = LocationTypeEnum.Undefined.GetHashCode(),
+                //LocationCode = $"{roadwayNo}-{row:D3}-{col:D3}-{layer:D3}",
                 LocationCode = $"{row:D3}-{col:D3}-{layer:D3}",
                 LocationName = $"{roadwayNo}宸烽亾{row:D3}琛寋col:D3}鍒梴layer:D3}灞倇depth:D2}娣�"
             };

--
Gitblit v1.9.3