wanshenmean
11 小时以前 91e3264be64c9417e3a28eabd81b2dc554cb863e
refactor(TaskService): MES出站调用改为Task.Run异步执行,不阻塞主逻辑

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
已修改1个文件
26 ■■■■■ 文件已修改
Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Outbound.cs 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_Outbound.cs
@@ -138,25 +138,15 @@
                        LocalTime = DateTime.Now,
                        ContainerCode = taskDto.PalletCode
                    };
                    string requestJson = outboundRequest.ToJson();
                    var outboundResult = string.IsNullOrWhiteSpace(token)
                        ? _mesService.OutboundInContainer(outboundRequest)
                        : _mesService.OutboundInContainer(outboundRequest, token);
                    stopwatch.Stop();
                    await _mesLogService.LogAsync(new MesApiLogDto
                    string palletCode = taskDto.PalletCode;
                    // Fire-and-forget: 异步执行MES出站,不阻塞主业务逻辑
                    _ = Task.Run(() => MesUploadAsync(palletCode, MesUploadStatusEnum.出站上传成功, async () =>
                    {
                        ApiType = "UnbindContainer",
                        RequestJson = requestJson,
                        ResponseJson = System.Text.Json.JsonSerializer.Serialize(outboundResult),
                        IsSuccess = outboundResult.IsSuccess,
                        ErrorMessage = outboundResult.ErrorMessage,
                        ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
                        Creator = "systeam"
                    });
                    if (outboundResult == null || outboundResult.Data == null || !outboundResult.Data.IsSuccess)
                    {
                        return content.Error($"出库完成失败:MES出站失败: {outboundResult?.Data?.Msg ?? outboundResult?.ErrorMessage ?? "未知错误"}");
                    }
                        return await Task.FromResult(string.IsNullOrWhiteSpace(token)
                            ? _mesService.OutboundInContainer(outboundRequest)
                            : _mesService.OutboundInContainer(outboundRequest, token));
                    }));
                    var completeResult = await CompleteTaskAsync(task, "出库完成");
                    if (!completeResult.Status)