From 96adc295cb04fd135d63d3a907f2732274f90965 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 21 四月 2026 01:11:21 +0800
Subject: [PATCH] feat: 添加MES异步上传辅助服务并重构相关代码

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs |   80 +++++++++++----------------------------
 1 files changed, 23 insertions(+), 57 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs
index c8a798c..1a731c9 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Inbound.cs
@@ -1,6 +1,4 @@
-using Microsoft.AspNetCore.Http.HttpResults;
 using Newtonsoft.Json;
-using System.Diagnostics;
 using WIDESEA_Common.Constants;
 using WIDESEA_Common.LocationEnum;
 using WIDESEA_Common.StockEnum;
@@ -122,7 +120,6 @@
         /// </summary>
         public async Task<WebResponseContent> InboundFinishTaskAsync(CreateTaskDto taskDto)
         {
-            var stopwatch = Stopwatch.StartNew();
             try
             {
                 var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode);
@@ -153,8 +150,6 @@
                 }
                 else
                 {
-
-
                     // 鍒ゆ柇鏄笉鏄瀬鍗峰簱浠诲姟
                     if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1)
                     {
@@ -188,62 +183,33 @@
                         string token = mesConfig?.Token;
 
                         // 寮傛璋冪敤MES鎵樼洏杩涚珯锛屼笉闃诲涓婚�昏緫
-                        var palletCode = taskDto.PalletCode;
-                        var localEquipmentCode = equipmentCode;
-                        var localResourceCode = resourceCode;
-                        var localToken = token;
-                        _ = Task.Run(async () =>
+                        var inboundRequest = new InboundInContainerRequest
                         {
-                            var localStopwatch = Stopwatch.StartNew();
-                            try
+                            EquipmentCode = equipmentCode,
+                            ResourceCode = resourceCode,
+                            LocalTime = DateTime.Now,
+                            ContainerCode = taskDto.PalletCode
+                        };
+                        string requestJson = inboundRequest.ToJson();
+                        var palletCode = taskDto.PalletCode;
+
+                        _mesUploadHelper.FireAndForget(
+                            palletCode,
+                            MesUploadStatusEnum.杩涚珯涓婁紶鎴愬姛,
+                            "InboundInContainer",
+                            requestJson,
+                            () =>
                             {
-                                var inboundRequest = new InboundInContainerRequest
-                                {
-                                    EquipmentCode = localEquipmentCode,
-                                    ResourceCode = localResourceCode,
-                                    LocalTime = DateTime.Now,
-                                    ContainerCode = palletCode
-                                };
-                                string localRequestJson = inboundRequest.ToJson();
-                                var inboundResult = string.IsNullOrWhiteSpace(localToken)
+                                var result = string.IsNullOrWhiteSpace(token)
                                     ? _mesService.InboundInContainer(inboundRequest)
-                                    : _mesService.InboundInContainer(inboundRequest, localToken);
-                                localStopwatch.Stop();
+                                    : _mesService.InboundInContainer(inboundRequest, token);
+                                return (
+                                    result?.Data?.IsSuccess ?? false,
+                                    JsonConvert.SerializeObject(result),
+                                    result?.Data?.Msg ?? result?.ErrorMessage ?? "鏈煡閿欒"
+                                );
+                            });
 
-                                bool isSuccess = inboundResult?.Data?.IsSuccess ?? false;
-                                int status = isSuccess
-                                    ? (int)MesUploadStatusEnum.杩涚珯涓婁紶鎴愬姛
-                                    : (int)MesUploadStatusEnum.杩涚珯涓婁紶澶辫触;
-
-                                await _stockInfoService.UpdateMesUploadStatusAsync(palletCode, status);
-
-                                await _mesLogService.LogAsync(new MesApiLogDto
-                                {
-                                    PalletCode = palletCode,
-                                    ApiType = "InboundInContainer",
-                                    RequestJson = localRequestJson,
-                                    ResponseJson = JsonConvert.SerializeObject(inboundResult),
-                                    IsSuccess = isSuccess,
-                                    ErrorMessage = inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "鏈煡閿欒",
-                                    ElapsedMs = (int)localStopwatch.ElapsedMilliseconds,
-                                    Creator = "systeam"
-                                });
-                            }
-                            catch (Exception ex)
-                            {
-                                localStopwatch.Stop();
-                                await _stockInfoService.UpdateMesUploadStatusAsync(palletCode, (int)MesUploadStatusEnum.杩涚珯涓婁紶澶辫触);
-                                await _mesLogService.LogAsync(new MesApiLogDto
-                                {
-                                    PalletCode = palletCode,
-                                    ApiType = "InboundInContainer",
-                                    IsSuccess = false,
-                                    ErrorMessage = ex.Message,
-                                    ElapsedMs = (int)localStopwatch.ElapsedMilliseconds,
-                                    Creator = "systeam"
-                                });
-                            }
-                        });
                         return await CompleteTaskAsync(task, "鍏ュ簱瀹屾垚");
                     });
                 }

--
Gitblit v1.9.3