| | |
| | | } |
| | | } |
| | | |
| | | // 3. 调用MES解绑 |
| | | // 3. Fire-and-forget异步调用MES解绑 |
| | | var unbindRequest = new UnBindContainerRequest |
| | | { |
| | | EquipmentCode = equipmentCode, |
| | |
| | | ContainCode = palletCode, |
| | | SfcList = sfcList |
| | | }; |
| | | var unbindResult = string.IsNullOrWhiteSpace(token) |
| | | ? _mesService.UnBindContainer(unbindRequest) |
| | | : _mesService.UnBindContainer(unbindRequest, token); |
| | | if (unbindResult == null || unbindResult.Data == null || !unbindResult.Data.IsSuccess) |
| | | _ = Task.Run(() => |
| | | { |
| | | return content.Error($"MES解绑失败: {unbindResult?.Data?.Msg ?? unbindResult?.ErrorMessage ?? "未知错误"}"); |
| | | } |
| | | var stopwatch = Stopwatch.StartNew(); |
| | | try |
| | | { |
| | | var unbindResult = string.IsNullOrWhiteSpace(token) |
| | | ? _mesService.UnBindContainer(unbindRequest) |
| | | : _mesService.UnBindContainer(unbindRequest, token); |
| | | stopwatch.Stop(); |
| | | |
| | | bool isSuccess = unbindResult?.Data?.IsSuccess ?? false; |
| | | int status = isSuccess |
| | | ? (int)MesUploadStatusEnum.拆盘上传成功 |
| | | : (int)MesUploadStatusEnum.拆盘上传失败; |
| | | |
| | | // 更新MES上传状态 |
| | | StockInfoService.UpdateMesUploadStatusAsync(palletCode, status).ConfigureAwait(false); |
| | | |
| | | // 记录MES日志 |
| | | _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = palletCode, |
| | | ApiType = "UnBindContainer", |
| | | RequestJson = unbindRequest.ToJson(), |
| | | ResponseJson = System.Text.Json.JsonSerializer.Serialize(unbindResult), |
| | | IsSuccess = isSuccess, |
| | | ErrorMessage = unbindResult?.Data?.Msg ?? unbindResult?.ErrorMessage ?? "未知错误", |
| | | ElapsedMs = (int)stopwatch.ElapsedMilliseconds, |
| | | Creator = "System" |
| | | }).ConfigureAwait(false); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 调用失败 |
| | | StockInfoService.UpdateMesUploadStatusAsync(palletCode, (int)MesUploadStatusEnum.拆盘上传失败).ConfigureAwait(false); |
| | | } |
| | | }); |
| | | |
| | | // 4. 删除临时表记录 |
| | | await SqlSugarClient.Deleteable<Dt_SplitTemp>().Where(t => t.PalletCode == palletCode).ExecuteCommandAsync(); |
| | |
| | | }).ToList() |
| | | }; |
| | | string requestJson = bindRequest.ToJson(); |
| | | var bindResult = string.IsNullOrWhiteSpace(token) |
| | | ? _mesService.BindContainer(bindRequest) |
| | | : _mesService.BindContainer(bindRequest, token); |
| | | stopwatch.Stop(); |
| | | await _mesLogService.LogAsync(new MesApiLogDto |
| | | // 3. Fire-and-forget异步调用MES绑定 |
| | | _ = Task.Run(() => |
| | | { |
| | | ApiType = "BindContainer", |
| | | RequestJson = requestJson, |
| | | ResponseJson = System.Text.Json.JsonSerializer.Serialize(bindResult), |
| | | IsSuccess = bindResult.IsSuccess, |
| | | ErrorMessage = bindResult.ErrorMessage, |
| | | ElapsedMs = (int)stopwatch.ElapsedMilliseconds, |
| | | Creator = "systeam" |
| | | var stopwatch = Stopwatch.StartNew(); |
| | | try |
| | | { |
| | | var bindResult = string.IsNullOrWhiteSpace(token) |
| | | ? _mesService.BindContainer(bindRequest) |
| | | : _mesService.BindContainer(bindRequest, token); |
| | | stopwatch.Stop(); |
| | | |
| | | bool isSuccess = bindResult?.Data?.IsSuccess ?? false; |
| | | int status = isSuccess |
| | | ? (int)MesUploadStatusEnum.组盘上传成功 |
| | | : (int)MesUploadStatusEnum.组盘上传失败; |
| | | |
| | | // 更新MES上传状态 |
| | | StockInfoService.UpdateMesUploadStatusAsync(palletCode, status).ConfigureAwait(false); |
| | | |
| | | // 记录MES日志 |
| | | _mesLogService.LogAsync(new MesApiLogDto |
| | | { |
| | | PalletCode = palletCode, |
| | | ApiType = "BindContainer", |
| | | RequestJson = requestJson, |
| | | ResponseJson = System.Text.Json.JsonSerializer.Serialize(bindResult), |
| | | IsSuccess = isSuccess, |
| | | ErrorMessage = bindResult?.ErrorMessage ?? "未知错误", |
| | | ElapsedMs = (int)stopwatch.ElapsedMilliseconds, |
| | | Creator = "System" |
| | | }).ConfigureAwait(false); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 调用失败 |
| | | StockInfoService.UpdateMesUploadStatusAsync(palletCode, (int)MesUploadStatusEnum.组盘上传失败).ConfigureAwait(false); |
| | | } |
| | | }); |
| | | if (bindResult == null || bindResult.Data == null || !bindResult.Data.IsSuccess) |
| | | { |
| | | return content.Error($"MES绑定失败: {bindResult?.Data?.Msg ?? bindResult?.ErrorMessage ?? "未知错误"}"); |
| | | } |
| | | |
| | | return content.OK("批量组盘确认成功"); |
| | | } |