From 96c9142944da3b9f6ebfc63e17451b9b330e5a72 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 31 三月 2026 09:28:35 +0800
Subject: [PATCH] docs: 添加 TaskService 重构设计文档

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  184 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 170 insertions(+), 14 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index f5768dd..933b1e7 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -15,6 +15,7 @@
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
 using WIDESEA_DTO.GradingMachine;
+using WIDESEA_DTO.MES;
 using WIDESEA_DTO.Stock;
 using WIDESEA_DTO.Task;
 using WIDESEA_IBasicService;
@@ -32,6 +33,9 @@
         private readonly HttpClientHelper _httpClientHelper;
         private readonly IConfiguration _configuration;
         private readonly RoundRobinService _roundRobinService;
+        private readonly IMesService _mesService;
+        private readonly ITask_HtyService _task_HtyService;
+        private readonly IStockInfo_HtyService _stockInfo_HtyService;
         private readonly IUnitOfWorkManage _unitOfWorkManage;
 
         public IRepository<Dt_Task> Repository => BaseDal;
@@ -53,6 +57,9 @@
             HttpClientHelper httpClientHelper,
             IConfiguration configuration,
             RoundRobinService roundRobinService,
+            IMesService mesService,
+            ITask_HtyService task_HtyService,
+            IStockInfo_HtyService stockInfo_HtyService,
             IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
         {
             _mapper = mapper;
@@ -61,6 +68,9 @@
             _httpClientHelper = httpClientHelper;
             _configuration = configuration;
             _roundRobinService = roundRobinService;
+            _mesService = mesService;
+            _task_HtyService = task_HtyService;
+            _stockInfo_HtyService = stockInfo_HtyService;
             _unitOfWorkManage = unitOfWorkManage;
         }
 
@@ -226,6 +236,7 @@
 
                 return await ExecuteWithinTransactionAsync(async () =>
                 {
+                    WebResponseContent content = new WebResponseContent();
                     stockInfo.LocationCode = location.LocationCode;
                     stockInfo.LocationId = location.Id;
                     stockInfo.OutboundDate = task.Roadway switch
@@ -242,7 +253,20 @@
                     var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
                     if (!updateLocationResult || !updateStockResult)
                         return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
-                    return await CompleteTaskAsync(task);
+                    // 璋冪敤MES鎵樼洏杩涚珯
+                    var inboundRequest = new InboundInContainerRequest
+                    {
+                        EquipmentCode = "STK-GROUP-001",
+                        ResourceCode = "STK-GROUP-001",
+                        LocalTime = DateTime.Now,
+                        ContainerCode = taskDto.PalletCode
+                    };
+                    var inboundResult = _mesService.InboundInContainer(inboundRequest);
+                    if (inboundResult == null || inboundResult.Data == null || !inboundResult.Data.IsSuccess)
+                    {
+                        return content.Error($"浠诲姟瀹屾垚澶辫触锛歁ES杩涚珯澶辫触: {inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "鏈煡閿欒"}");
+                    }
+                    return await CompleteTaskAsync(task, "鍏ュ簱瀹屾垚");
                 });
             }
             catch (Exception ex)
@@ -279,6 +303,7 @@
                     return await OutTaskComplete(outTaskCompleteDto);
                 }
 
+                WebResponseContent content = new WebResponseContent();
                 return await ExecuteWithinTransactionAsync(async () =>
                 {
                     stockInfo.LocationId = 0;
@@ -291,7 +316,23 @@
                     var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
                     if (!updateLocationResult || !updateStockResult)
                         return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
-                    return await CompleteTaskAsync(task);
+
+                    // 璋冪敤MES鎵樼洏鍑虹珯
+                    var outboundRequest = new OutboundInContainerRequest
+                    {
+                        EquipmentCode = "STK-GROUP-001",
+                        ResourceCode = "STK-GROUP-001",
+                        LocalTime = DateTime.Now,
+                        ContainerCode = taskDto.PalletCode,
+                        ParamList = new List<ParamItem>()
+                    };
+                    var outboundResult = _mesService.OutboundInContainer(outboundRequest);
+                    if (outboundResult == null || outboundResult.Data == null || !outboundResult.Data.IsSuccess)
+                    {
+                        return content.Error($"浠诲姟瀹屾垚澶辫触锛歁ES鍑虹珯澶辫触: {outboundResult?.Data?.Msg ?? outboundResult?.ErrorMessage ?? "鏈煡閿欒"}");
+                    }
+
+                    return await CompleteTaskAsync(task, "鍑哄簱瀹屾垚");
                 });
             }
             catch (Exception ex)
@@ -337,7 +378,7 @@
                     if (!updateSourceResult || !updateTargetResult || !updateStockResult)
                         return WebResponseContent.Instance.Error("绉诲簱浠诲姟瀹屾垚澶辫触");
 
-                    return await CompleteTaskAsync(task);
+                    return await CompleteTaskAsync(task, "绉诲簱瀹屾垚");
                 });
             }
             catch (Exception ex)
@@ -374,6 +415,61 @@
         }
 
         /// <summary>
+        /// 绌烘墭鐩樺叆搴撳畬鎴�
+        /// </summary>
+        public async Task<WebResponseContent> InboundFinishTaskTrayAsync(CreateTaskDto taskDto)
+        {
+            try
+            {
+                var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode);
+                if (task == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑浠诲姟");
+
+                var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.TargetAddress);
+                if (location == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑璐т綅");
+
+                var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
+                if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴斿簱瀛樹俊鎭�");
+
+                return await ExecuteWithinTransactionAsync(async () =>
+                {
+                    stockInfo.LocationCode = location.LocationCode;
+                    stockInfo.LocationId = location.Id;
+                    stockInfo.StockStatus = StockStatusEmun.绌烘墭鐩樺簱瀛�.GetHashCode();
+
+                    location.LocationStatus = LocationStatusEnum.InStock.GetHashCode();
+
+                    var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
+                    var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
+                    if (!updateLocationResult || !updateStockResult)
+                        return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
+
+                    // 淇濆瓨浠诲姟鍘嗗彶
+                    var historyTask = _mapper.Map<Dt_Task_Hty>(task);
+                    historyTask.InsertTime = DateTime.Now;
+                    historyTask.OperateType = "绌烘墭鐩樺叆搴撳畬鎴�";
+                    if (await _task_HtyService.Repository.AddDataAsync(historyTask) <= 0)
+                        return WebResponseContent.Instance.Error("浠诲姟鍘嗗彶淇濆瓨澶辫触");
+
+                    // 淇濆瓨搴撳瓨鍘嗗彶
+                    var historyStock = _mapper.Map<Dt_StockInfo_Hty>(stockInfo);
+                    historyStock.InsertTime = DateTime.Now;
+                    historyStock.OperateType = "绌烘墭鐩樺叆搴撳畬鎴�";
+                    if (await _stockInfo_HtyService.Repository.AddDataAsync(historyStock) <= 0)
+                        return WebResponseContent.Instance.Error("搴撳瓨鍘嗗彶淇濆瓨澶辫触");
+
+                    var deleteResult = await BaseDal.DeleteDataAsync(task);
+                    if (!deleteResult) return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
+
+                    return WebResponseContent.Instance.OK("浠诲姟瀹屾垚");
+                });
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error($"瀹屾垚浠诲姟澶辫触: {ex.Message}");
+            }
+        }
+
+        /// <summary>
         /// 鍒涘缓绌烘墭鐩樺嚭搴撲换鍔�
         /// </summary>
         /// <param name="taskDto"></param>
@@ -382,7 +478,6 @@
         {
             try
             {
-
                 var stockInfo = await _stockInfoService.Repository.QueryDataNavFirstAsync(x => x.LocationDetails.WarehouseId == taskDto.WarehouseId && x.LocationDetails.LocationStatus == LocationStatusEnum.InStock.GetHashCode() && x.StockStatus == StockStatusEmun.绌烘墭鐩樺簱瀛�.GetHashCode());
                 if (stockInfo == null)
                     return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑搴撳瓨淇℃伅");
@@ -417,6 +512,61 @@
         }
 
         /// <summary>
+        /// 绌烘墭鐩樺嚭搴撳畬鎴�
+        /// </summary>
+        public async Task<WebResponseContent> OutboundFinishTaskTrayAsync(CreateTaskDto taskDto)
+        {
+            try
+            {
+                var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode);
+                if (task == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑浠诲姟");
+
+                var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.SourceAddress);
+                if (location == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑璐т綅");
+
+                var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
+                if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴斿簱瀛樹俊鎭�");
+
+                return await ExecuteWithinTransactionAsync(async () =>
+                {
+                    stockInfo.LocationId = 0;
+                    stockInfo.LocationCode = null;
+                    stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.GetHashCode();
+
+                    location.LocationStatus = LocationStatusEnum.Free.GetHashCode();
+
+                    var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
+                    var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
+                    if (!updateLocationResult || !updateStockResult)
+                        return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
+
+                    // 淇濆瓨浠诲姟鍘嗗彶
+                    var historyTask = _mapper.Map<Dt_Task_Hty>(task);
+                    historyTask.InsertTime = DateTime.Now;
+                    historyTask.OperateType = "绌烘墭鐩樺嚭搴撳畬鎴�";
+                    if (await _task_HtyService.Repository.AddDataAsync(historyTask) <= 0)
+                        return WebResponseContent.Instance.Error("浠诲姟鍘嗗彶淇濆瓨澶辫触");
+
+                    // 淇濆瓨搴撳瓨鍘嗗彶
+                    var historyStock = _mapper.Map<Dt_StockInfo_Hty>(stockInfo);
+                    historyStock.InsertTime = DateTime.Now;
+                    historyStock.OperateType = "绌烘墭鐩樺嚭搴撳畬鎴�";
+                    if (await _stockInfo_HtyService.Repository.AddDataAsync(historyStock) <= 0)
+                        return WebResponseContent.Instance.Error("搴撳瓨鍘嗗彶淇濆瓨澶辫触");
+
+                    var deleteResult = await BaseDal.DeleteDataAsync(task);
+                    if (!deleteResult) return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
+
+                    return WebResponseContent.Instance.OK("浠诲姟瀹屾垚");
+                });
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error($"瀹屾垚浠诲姟澶辫触: {ex.Message}");
+            }
+        }
+
+        /// <summary>
         /// 淇敼浠诲姟鐘舵�侊紙鏍规嵁浠诲姟ID淇敼涓烘寚瀹氱姸鎬侊級
         /// </summary>
         /// <param name="taskId"></param>
@@ -436,11 +586,10 @@
                 return WebResponseContent.Instance.OK("淇敼鎴愬姛", tasks);
             }
             catch (Exception ex)
-            { 
+            {
                 return WebResponseContent.Instance.Error($"淇敼澶辫触: {ex.Message}");
             }
         }
-
 
         /// <summary>
         /// 鏌ユ壘鎵樼洏鏄惁鏈変换鍔�
@@ -466,14 +615,16 @@
         /// <summary>
         /// 瀹屾垚浠诲姟鍚庣粺涓�澶勭悊锛堝垹闄や换鍔℃暟鎹級
         /// </summary>
-        private async Task<WebResponseContent> CompleteTaskAsync(Dt_Task task)
+        private async Task<WebResponseContent> CompleteTaskAsync(Dt_Task task, string operateType = "")
         {
             var deleteTaskResult = await BaseDal.DeleteDataAsync(task);
             if (!deleteTaskResult) return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
 
-            // 淇濈暀鍘嗗彶瀵硅薄鏋勫缓閫昏緫锛屽悗缁彲鎺ュ叆鍘嗗彶琛ㄨ惤搴�
             var historyTask = _mapper.Map<Dt_Task_Hty>(task);
             historyTask.InsertTime = DateTime.Now;
+            historyTask.OperateType = operateType;
+            var saveResult = await _task_HtyService.Repository.AddDataAsync(historyTask) > 0;
+            if (!saveResult) return WebResponseContent.Instance.Error("浠诲姟鍘嗗彶淇濆瓨澶辫触");
 
             return WebResponseContent.Instance.OK("浠诲姟瀹屾垚");
         }
@@ -968,10 +1119,11 @@
 
         #endregion 鍒嗗鏌滄帴鍙�
 
-
         #region 鏋佸嵎搴撲换鍔℃ā鍧�
+
         public string AGV_OutTaskComplete = WIDESEA_Core.Helper.AppSettings.Configuration["AGV_OutTaskComplete"]; // 涓婃姤AGV鍑哄簱杈撻�佺嚎瀹屾垚
         public string WCS_ReceiveTask = WIDESEA_Core.Helper.AppSettings.Configuration["WCS_ReceiveTask"]; // WMS杈撻�佺嚎浠诲姟涓嬪彂
+
         /// <summary>
         /// 鍑哄叆搴撶敵璇�
         /// </summary>
@@ -1091,6 +1243,7 @@
                 return aGVResponse.Error($"WMS浠诲姟鍒涘缓鎺ュ彛閿欒: {ex.Message}");
             }
         }
+
         /// <summary>
         /// 鎵嬪姩鍑哄簱瀹屾垚鍙嶉缁橝GV
         /// </summary>
@@ -1107,7 +1260,7 @@
                 var task = await BaseDal.QueryFirstAsync(x => x.OrderNo == outTaskCompleteDto.TaskId);
                 if (task == null) return webResponse.Error("鏈壘鍒颁换鍔′俊鎭�");
                 outTaskCompleteDto.ReqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
-                var httpResponse = _httpClientHelper.Post<AGVResponse>(AGV_OutTaskComplete, JsonSerializer.Serialize(outTaskCompleteDto)).Data;
+                var httpResponse = _httpClientHelper.Post<AGVResponse>(AGV_OutTaskComplete, outTaskCompleteDto.ToJson()).Data;
                 // 鍒ゆ柇杩滅▼鎺ュ彛杩斿洖鏄惁鎴愬姛
                 if (httpResponse != null && httpResponse.Data != null)
                 {
@@ -1151,6 +1304,7 @@
                 return webResponse.Error($"WMS浠诲姟瀹屾垚鎺ュ彛閿欒锛歿ex.Message}");
             }
         }
+
         ///// <summary>
         ///// 浠诲姟瀹屾垚鎺ュ彛
         ///// </summary>
@@ -1200,7 +1354,7 @@
                 {
                     aGVResponse.OK();
                 }
-                else if(applyEnterDto.InOut == 2 && task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TaskStatus == (int)TaskStatusEnum.Line_Finish)
+                else if (applyEnterDto.InOut == 2 && task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TaskStatus == (int)TaskStatusEnum.Line_Finish)
                 {
                     aGVResponse.OK();
                 }
@@ -1227,6 +1381,7 @@
                 return aGVResponse.Error($"WMS杈撻�佺嚎鐢宠鎺ュ彛閿欒锛歿ex.Message}");
             }
         }
+
         /// <summary>
         /// 鍙栨斁璐у畬鎴�
         /// </summary>
@@ -1306,6 +1461,7 @@
                 return aGVResponse.Error($"WMS鍙栨斁璐у畬鎴愭帴鍙i敊璇細{ex.Message}");
             }
         }
+
         /// <summary>
         /// 浠诲姟鍙栨秷
         /// </summary>
@@ -1322,7 +1478,7 @@
                 var task = await BaseDal.QueryFirstAsync(x => x.OrderNo == taskCancelDto.TaskId);
                 // 娌℃湁浠诲姟寮哄埗鍙栨秷
                 if (task == null) return aGVResponse.OK();
-                
+
                 if (task.TaskStatus == (int)TaskInStatusEnum.InNew)
                 {
                     task.TaskStatus = (int)TaskInStatusEnum.InCancel;
@@ -1332,7 +1488,7 @@
                     _unitOfWorkManage.CommitTran();
                     return aGVResponse.OK();
                 }
-                else if(task.TaskStatus == (int)TaskOutStatusEnum.OutNew)
+                else if (task.TaskStatus == (int)TaskOutStatusEnum.OutNew)
                 {
                     // 鍑哄簱浠诲姟鎭㈠搴撳瓨
                     var stockInfo = await _stockInfoService.GetStockInfoAsync(task.PalletCode);
@@ -1364,4 +1520,4 @@
 
         #endregion 鏋佸嵎搴撲换鍔℃ā鍧�
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3