From f56441867f2cc77567f97a92348a5d878f0dca05 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 12 三月 2026 18:24:15 +0800
Subject: [PATCH] Add AGENTS instructions and updates

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs |   63 ++++++++++++++++++++++---------
 1 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
index aeff75f..af5cc9a 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs
@@ -1,13 +1,17 @@
+using Mapster;
+using MapsterMapper;
+using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Utilities;
 using WIDESEA_DTO.Basic;
+using WIDESEA_DTO.Task;
 using WIDESEA_IBasicService;
 using WIDESEA_Model.Models;
-using WIDESEA_Common.CommonEnum;
 
 namespace WIDESEA_BasicService
 {
@@ -16,6 +20,7 @@
     /// </summary>
     public partial class LocationInfoService : ServiceBase<Dt_LocationInfo, IRepository<Dt_LocationInfo>>, ILocationInfoService
     {
+        private readonly IMapper _mapper;
         private readonly IRepository<Dt_Task> _taskRepository;
         private readonly IRepository<Dt_StockInfo> _stockInfoRepository;
 
@@ -28,10 +33,12 @@
         public LocationInfoService(
             IRepository<Dt_LocationInfo> baseDal,
             IRepository<Dt_Task> taskRepository,
-            IRepository<Dt_StockInfo> stockInfoRepository) : base(baseDal)
+            IRepository<Dt_StockInfo> stockInfoRepository,
+            IMapper mapper) : base(baseDal)
         {
             _taskRepository = taskRepository;
             _stockInfoRepository = stockInfoRepository;
+            _mapper = mapper;
         }
 
         /// <summary>
@@ -197,7 +204,7 @@
                     // 濡傛灉鏂扮殑搴撲綅娌℃湁鎵惧埌瀵瑰簲鐨勪换鍔�
                     if (internalTransferTask == null)
                     {
-                        return content.OK("鑾峰彇鍒扮Щ搴撲换鍔�", await HandleNoTaskAtLocation(outboundTask.SourceAddress, newLocationID, outboundTask));
+                        return content.OK("鑾峰彇鍒扮Щ搴撲换鍔�", await HandleNoTaskAtLocation(newLocationID, outboundTask));
                     }
 
                     // 鐩存帴杩斿洖涓�娣变綅鍑哄簱浠诲姟
@@ -228,27 +235,23 @@
             int relativeLine = line % 2 == 1 ? line + 1 : line - 1;
 
             // 鏋勫缓鏂扮殑搴撲綅ID
-            string[] newLocationParts = new string[] { relativeLine.ToString().PadLeft(3, '0'), locationInfo.Column.ToString(), locationInfo.Layer.ToString() };
+            string[] newLocationParts = new string[] { relativeLine.ToString().PadLeft(3, '0'), locationInfo.Column.ToString().PadLeft(3, '0'), locationInfo.Layer.ToString().PadLeft(3, '0') };
             return string.Join("-", newLocationParts);
         }
 
         /// <summary>
         /// 澶勭悊娌℃湁浠诲姟鐨勫簱浣嶆儏鍐�
         /// </summary>
-        /// <param name="originalLocationID">鍘熷搴撲綅ID</param>
         /// <param name="newLocationID">鏂扮殑搴撲綅ID</param>
         /// <param name="outboundTask">鍑哄簱浠诲姟</param>
         /// <returns>鐢熸垚鐨勭Щ搴撲换鍔℃垨鍘熷鍑哄簱浠诲姟</returns>
-        private async Task<Dt_Task> HandleNoTaskAtLocation(string originalLocationID, string newLocationID, Dt_Task outboundTask)
+        private async Task<Dt_Task> HandleNoTaskAtLocation(string newLocationID, Dt_Task outboundTask)
         {
             // 鍒ゆ柇璇ヤ綅缃槸鍚︽湁搴撳瓨
-            var stockInfo = await _stockInfoRepository.QueryFirstAsync(x => x.LocationCode == newLocationID);
-            if (stockInfo == null)
-            {
-                // 濡傛灉娌℃湁搴撳瓨锛岀洿鎺ヨ繑鍥炲綋鍓嶅嚭搴撲换鍔�
-                return outboundTask;
-            }
-
+            var stockInfo = await _stockInfoRepository.QueryDataNavFirstAsync(x =>
+                            x.LocationCode == newLocationID &&
+                            x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode() &&
+                            x.LocationDetails.LocationStatus == LocationStatusEnum.InStock.GetHashCode());
             if (stockInfo == null)
             {
                 // 濡傛灉娌℃湁搴撳瓨锛岀洿鎺ヨ繑鍥炲綋鍓嶅嚭搴撲换鍔�
@@ -262,20 +265,44 @@
             var newTransferTask = new Dt_Task
             {
                 CreateDate = DateTime.Now,
-                Creater = App.User.UserName,
-                CurrentAddress = originalLocationID,
+                Creater = App.User.UserName ?? "system",
+                CurrentAddress = newLocationID,
                 Grade = 99,
                 NextAddress = emptyLocation.LocationCode,
                 PalletCode = stockInfo.PalletCode,
                 Remark = "绉诲簱",
                 Roadway = stockInfo.LocationDetails.RoadwayNo,
-                SourceAddress = originalLocationID,
+                SourceAddress = newLocationID,
                 TaskNum = taskNo,
                 TargetAddress = emptyLocation.LocationCode,
-                TaskType = TaskTypeEnum.Relocation.GetHashCode()
+                TaskType = TaskRelocationTypeEnum.Relocation.GetHashCode(),
+                TaskStatus = TaskRelocationStatusEnum.RelocationNew.GetHashCode(),
+                WarehouseId = stockInfo.WarehouseId
             };
 
-            return await _taskRepository.Db.Insertable(newTransferTask).ExecuteReturnEntityAsync();
+            var createdTask = await _taskRepository.Db.Insertable(newTransferTask).ExecuteReturnEntityAsync();
+
+            // 鍒涘缓绉诲簱浠诲姟鍚庯紝绔嬪嵆閿佸畾搴撳瓨鍜岀浉鍏宠揣浣嶏紝閬垮厤骞跺彂閲嶅鍒嗛厤
+            stockInfo.StockStatus = StockStatusEmun.绉诲簱閿佸畾.GetHashCode();
+            var updateStockResult = await _stockInfoRepository.UpdateDataAsync(stockInfo);
+
+            var locationsToUpdate = new List<Dt_LocationInfo>();
+            if (stockInfo.LocationDetails != null)
+            {
+                stockInfo.LocationDetails.LocationStatus = LocationStatusEnum.InStockLock.GetHashCode();
+                locationsToUpdate.Add(stockInfo.LocationDetails);
+            }
+
+            emptyLocation.LocationStatus = LocationStatusEnum.FreeLock.GetHashCode();
+            locationsToUpdate.Add(emptyLocation);
+
+            var updateLocationResult = await BaseDal.UpdateDataAsync(locationsToUpdate);
+            if (!updateStockResult || !updateLocationResult)
+            {
+                throw new Exception("鍒涘缓绉诲簱浠诲姟鍚庢洿鏂板簱瀛樼姸鎬佹垨璐т綅鐘舵�佸け璐�");
+            }
+
+            return createdTask;
         }
 
         /// <summary>

--
Gitblit v1.9.3