| | |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System.Diagnostics; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | |
| | | public IMesService _mesService { get; } |
| | | |
| | | private readonly IMesLogService _mesLogService; |
| | | private readonly IMesUploadHelper _mesUploadHelper; |
| | | |
| | | /// <summary> |
| | | /// 构造函数 |
| | |
| | | /// <param name="stockInfoService">库存信息服务</param> |
| | | /// <param name="stockInfoDetail_HtyService">库存明细历史服务</param> |
| | | /// <param name="stockInfo_HtyService">库存历史服务</param> |
| | | /// <param name="mesUploadHelper">MES异步上传辅助服务</param> |
| | | public StockService( |
| | | IStockInfoDetailService stockInfoDetailService, |
| | | IStockInfoService stockInfoService, |
| | |
| | | IMesService mesService, |
| | | IWarehouseService warehouseService, |
| | | ISqlSugarClient sqlSugarClient, |
| | | IMesLogService mesLogService) |
| | | IMesLogService mesLogService, |
| | | IMesUploadHelper mesUploadHelper) |
| | | { |
| | | StockInfoDetailService = stockInfoDetailService; |
| | | StockInfoService = stockInfoService; |
| | |
| | | _warehouseService = warehouseService; |
| | | SqlSugarClient = sqlSugarClient; |
| | | _mesLogService = mesLogService; |
| | | _mesUploadHelper = mesUploadHelper; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | ContainCode = palletCode, |
| | | SfcList = sfcList |
| | | }; |
| | | _ = Task.Run(() => |
| | | { |
| | | var stopwatch = Stopwatch.StartNew(); |
| | | try |
| | | string requestJson = unbindRequest.ToJson(); |
| | | var localToken = token; |
| | | |
| | | _mesUploadHelper.FireAndForget( |
| | | palletCode, |
| | | MesUploadStatusEnum.拆盘上传成功, |
| | | "UnBindContainer", |
| | | requestJson, |
| | | () => |
| | | { |
| | | var unbindResult = string.IsNullOrWhiteSpace(token) |
| | | var result = string.IsNullOrWhiteSpace(localToken) |
| | | ? _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); |
| | | } |
| | | }); |
| | | : _mesService.UnBindContainer(unbindRequest, localToken); |
| | | return ( |
| | | result?.Data?.IsSuccess ?? false, |
| | | System.Text.Json.JsonSerializer.Serialize(result), |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误" |
| | | ); |
| | | }); |
| | | |
| | | // 4. 删除临时表记录 |
| | | await SqlSugarClient.Deleteable<Dt_SplitTemp>().Where(t => t.PalletCode == palletCode).ExecuteCommandAsync(); |
| | |
| | | public async Task<WebResponseContent> GroupPalletConfirmAsync(string palletCode, string deviceName) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | var stopwatch = Stopwatch.StartNew(); |
| | | try |
| | | { |
| | | if (string.IsNullOrWhiteSpace(palletCode)) |
| | |
| | | }).ToList() |
| | | }; |
| | | string requestJson = bindRequest.ToJson(); |
| | | var localToken = token; |
| | | |
| | | // 3. Fire-and-forget异步调用MES绑定 |
| | | _ = Task.Run(() => |
| | | { |
| | | var stopwatch = Stopwatch.StartNew(); |
| | | try |
| | | _mesUploadHelper.FireAndForget( |
| | | palletCode, |
| | | MesUploadStatusEnum.组盘上传成功, |
| | | "BindContainer", |
| | | requestJson, |
| | | () => |
| | | { |
| | | var bindResult = string.IsNullOrWhiteSpace(token) |
| | | var result = string.IsNullOrWhiteSpace(localToken) |
| | | ? _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); |
| | | } |
| | | }); |
| | | : _mesService.BindContainer(bindRequest, localToken); |
| | | return ( |
| | | result?.Data?.IsSuccess ?? false, |
| | | System.Text.Json.JsonSerializer.Serialize(result), |
| | | result?.Data?.Msg ?? result?.ErrorMessage ?? "未知错误" |
| | | ); |
| | | }); |
| | | |
| | | return content.OK("批量组盘确认成功"); |
| | | } |