| | |
| | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | using Newtonsoft.Json; |
| | | using System.Diagnostics; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | |
| | | /// </summary> |
| | | public async Task<WebResponseContent> InboundFinishTaskAsync(CreateTaskDto taskDto) |
| | | { |
| | | var stopwatch = Stopwatch.StartNew(); |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode); |
| | |
| | | Creater = StockConstants.SYSTEM_USER, |
| | | Details = null, |
| | | LocationCode = location.LocationCode, |
| | | LocationId = location.Id |
| | | LocationId = location.Id, |
| | | OutboundDate = DateTime.Now |
| | | }; |
| | | location.LocationStatus = LocationStatusEnum.InStock.GetHashCode(); |
| | | var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location); |
| | | var updateStockResult = await _stockInfoService.Repository.AddDataAsync(stockInfo); |
| | | return await CompleteTaskAsync(task, "入库完成"); |
| | |
| | | } |
| | | else |
| | | { |
| | | |
| | | |
| | | // 判断是不是极卷库任务 |
| | | if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1) |
| | | { |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | stockInfo.LocationCode = location.LocationCode; |
| | | stockInfo.LocationId = location.Id; |
| | | stockInfo.WarehouseId = task.WarehouseId; |
| | | |
| | | SetOutboundDateByRoadway(task, stockInfo); |
| | | |
| | | stockInfo.StockStatus = StockStatusEmun.入库完成.GetHashCode(); |
| | | |
| | | stockInfo.CreateDate = DateTime.Now; |
| | | |
| | | location.LocationStatus = LocationStatusEnum.InStock.GetHashCode(); |
| | | |
| | |
| | | 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 ?? "未知错误", |
| | | _mesService.BuildConfig(token ?? string.Empty).ToJson() |
| | | ); |
| | | }); |
| | | |
| | | 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, "入库完成"); |
| | | }); |
| | | } |
| | |
| | | /// <param name="stockInfo">库存信息</param> |
| | | private void SetOutboundDateByRoadway(Dt_Task task, Dt_StockInfo stockInfo) |
| | | { |
| | | var config = _outboundTimeOptions.CurrentValue; |
| | | var now = DateTime.Now; |
| | | if (task.Roadway.Contains("GW")) |
| | | { |
| | | stockInfo.OutboundDate = string.IsNullOrEmpty(stockInfo.Remark) |
| | | ? now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_GW1_FIRST) |
| | | ? now.AddHours(config.Gw1FirstHours) |
| | | : stockInfo.Remark == StockRemarkConstants.GW1 |
| | | ? now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_GW1_SECOND) |
| | | : now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_GW1_FIRST); |
| | | ? now.AddHours(config.Gw1SecondHours) |
| | | : now.AddHours(config.Gw1FirstHours); |
| | | |
| | | stockInfo.Remark = string.IsNullOrEmpty(stockInfo.Remark) |
| | | ? StockRemarkConstants.GW1 |
| | |
| | | } |
| | | else if (task.Roadway.Contains("CW")) |
| | | { |
| | | stockInfo.OutboundDate = now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_CW1); |
| | | stockInfo.OutboundDate = now.AddHours(config.Cw1Hours); |
| | | if (stockInfo.Remark == StockRemarkConstants.GW2) |
| | | stockInfo.Remark = StockRemarkConstants.CW1; |
| | | } |