wanshenmean
5 小时以前 96adc295cb04fd135d63d3a907f2732274f90965
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs
@@ -11,7 +11,6 @@
using WIDESEA_Model.Models;
using WIDESEA_Common.Constants;
using WIDESEA_Common.StockEnum;
using System.Diagnostics;
namespace WIDESEA_WMSServer.Controllers.Stock
{
@@ -22,25 +21,22 @@
    [ApiController]
    public class StockInfoController : ApiBaseController<IStockInfoService, Dt_StockInfo>
    {
        private readonly IMesLogService _mesLogService;
        private readonly IMesService _mesService;
        private readonly IMESDeviceConfigService _mesDeviceConfigService;
        private readonly ISys_DictionaryService _sysDictionaryService;
        private readonly IStockInfoService _stockInfoService;
        private readonly IMesUploadHelper _mesUploadHelper;
        public StockInfoController(
            IStockInfoService service,
            IMesLogService mesLogService,
            IMesService mesService,
            IMESDeviceConfigService mesDeviceConfigService,
            ISys_DictionaryService sysDictionaryService,
            IStockInfoService stockInfoService) : base(service)
            IMesUploadHelper mesUploadHelper) : base(service)
        {
            _mesLogService = mesLogService;
            _mesService = mesService;
            _mesDeviceConfigService = mesDeviceConfigService;
            _sysDictionaryService = sysDictionaryService;
            _stockInfoService = stockInfoService;
            _mesUploadHelper = mesUploadHelper;
        }
        /// <summary>
@@ -106,50 +102,23 @@
                string palletCode = stockInfo.PalletCode;
                // 5. 异步执行MES调用(fire-and-forget)
                _ = Task.Run(async () =>
                {
                    var localStopwatch = Stopwatch.StartNew();
                    try
                _mesUploadHelper.FireAndForget(
                    palletCode,
                    MesUploadStatusEnum.进站上传成功,
                    "InboundInContainer",
                    requestJson,
                    () =>
                    {
                        var result = string.IsNullOrWhiteSpace(token)
                            ? _mesService.InboundInContainer(mesRequest)
                            : _mesService.InboundInContainer(mesRequest, token);
                        localStopwatch.Stop();
                        bool isSuccess = result?.IsSuccess ?? false;
                        int status = isSuccess
                            ? (int)MesUploadStatusEnum.进站上传成功
                            : (int)MesUploadStatusEnum.进站上传失败;
                        await _stockInfoService.UpdateMesUploadStatusAsync(palletCode, status);
                        await _mesLogService.LogAsync(new MesApiLogDto
                        {
                            PalletCode = palletCode,
                            ApiType = "InboundInContainer",
                            RequestJson = requestJson,
                            ResponseJson = System.Text.Json.JsonSerializer.Serialize(result),
                            IsSuccess = isSuccess,
                            ErrorMessage = result?.ErrorMessage ?? "未知错误",
                            ElapsedMs = (int)localStopwatch.ElapsedMilliseconds,
                            Creator = App.User.UserName
                        });
                    }
                    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 = App.User.UserName
                        });
                    }
                });
                        return (
                            result?.IsSuccess ?? false,
                            System.Text.Json.JsonSerializer.Serialize(result),
                            result?.ErrorMessage ?? "未知错误"
                        );
                    },
                    App.User.UserName);
                // 6. 立即返回成功
                return response.OK("托盘进站成功");
@@ -223,50 +192,23 @@
                string palletCode = stockInfo.PalletCode;
                // 5. 异步执行MES调用(fire-and-forget)
                _ = Task.Run(async () =>
                {
                    var localStopwatch = Stopwatch.StartNew();
                    try
                _mesUploadHelper.FireAndForget(
                    palletCode,
                    MesUploadStatusEnum.出站上传成功,
                    "OutboundInContainer",
                    requestJson,
                    () =>
                    {
                        var result = string.IsNullOrWhiteSpace(token)
                            ? _mesService.OutboundInContainer(mesRequest)
                            : _mesService.OutboundInContainer(mesRequest, token);
                        localStopwatch.Stop();
                        bool isSuccess = result?.IsSuccess ?? false;
                        int status = isSuccess
                            ? (int)MesUploadStatusEnum.出站上传成功
                            : (int)MesUploadStatusEnum.出站上传失败;
                        await _stockInfoService.UpdateMesUploadStatusAsync(palletCode, status);
                        await _mesLogService.LogAsync(new MesApiLogDto
                        {
                            PalletCode = palletCode,
                            ApiType = "OutboundInContainer",
                            RequestJson = requestJson,
                            ResponseJson = System.Text.Json.JsonSerializer.Serialize(result),
                            IsSuccess = isSuccess,
                            ErrorMessage = result?.ErrorMessage ?? "未知错误",
                            ElapsedMs = (int)localStopwatch.ElapsedMilliseconds,
                            Creator = App.User.UserName
                        });
                    }
                    catch (Exception ex)
                    {
                        localStopwatch.Stop();
                        await _stockInfoService.UpdateMesUploadStatusAsync(palletCode, (int)MesUploadStatusEnum.出站上传失败);
                        await _mesLogService.LogAsync(new MesApiLogDto
                        {
                            PalletCode = palletCode,
                            ApiType = "OutboundInContainer",
                            IsSuccess = false,
                            ErrorMessage = ex.Message,
                            ElapsedMs = (int)localStopwatch.ElapsedMilliseconds,
                            Creator = App.User.UserName
                        });
                    }
                });
                        return (
                            result?.IsSuccess ?? false,
                            System.Text.Json.JsonSerializer.Serialize(result),
                            result?.ErrorMessage ?? "未知错误"
                        );
                    },
                    App.User.UserName);
                // 6. 立即返回成功
                return response.OK("托盘出站成功");