| | |
| | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | using Newtonsoft.Json; |
| | | using System.Diagnostics; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.TaskEnum; |
| | | using WIDESEA_Common.WareHouseEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.MES; |
| | | using WIDESEA_DTO.Task; |
| | | using WIDESEA_IBasicService; |
| | |
| | | /// </summary> |
| | | public async Task<WebResponseContent> InboundFinishTaskAsync(CreateTaskDto taskDto) |
| | | { |
| | | var stopwatch = Stopwatch.StartNew(); |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode); |
| | |
| | | if (location == null) return WebResponseContent.Instance.Error("未找到对应的货位"); |
| | | |
| | | var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode); |
| | | if (stockInfo == null) return WebResponseContent.Instance.Error("未找到对应库存信息"); |
| | | |
| | | // 判断是不是极卷库任务 |
| | | if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1) |
| | | if (stockInfo == null) |
| | | { |
| | | return await CompleteAgvInboundTaskAsync(taskDto); |
| | | return await _unitOfWorkManage.BeginTranAsync(async () => |
| | | { |
| | | stockInfo = new Dt_StockInfo |
| | | { |
| | | PalletCode = taskDto.PalletCode, |
| | | WarehouseId = task.WarehouseId, |
| | | StockStatus = StockStatusEmun.空托盘库存.GetHashCode(), |
| | | Creater = StockConstants.SYSTEM_USER, |
| | | Details = null, |
| | | LocationCode = location.LocationCode, |
| | | LocationId = location.Id |
| | | }; |
| | | var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location); |
| | | var updateStockResult = await _stockInfoService.Repository.AddDataAsync(stockInfo); |
| | | return await CompleteTaskAsync(task, "入库完成"); |
| | | }); |
| | | } |
| | | |
| | | return await _unitOfWorkManage.BeginTranAsync(async () => |
| | | else |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | stockInfo.LocationCode = location.LocationCode; |
| | | stockInfo.LocationId = location.Id; |
| | | |
| | | SetOutboundDateByRoadway(task, stockInfo); |
| | | |
| | | stockInfo.StockStatus = StockStatusEmun.入库完成.GetHashCode(); |
| | | |
| | | location.LocationStatus = LocationStatusEnum.InStock.GetHashCode(); |
| | | |
| | | var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location); |
| | | var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo); |
| | | if (!updateLocationResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("任务完成失败"); |
| | | // 根据库存Remark选择静置设备,查MES动态凭证 |
| | | string deviceName = stockInfo.Remark == "GW_1" ? "高温静置1" |
| | | : stockInfo.Remark == "GW_2" ? "高温静置2" |
| | | : "常温静置1"; |
| | | var mesConfig = _mesDeviceConfigService.GetByDeviceName(deviceName); |
| | | string equipmentCode = mesConfig?.EquipmentCode ?? StockConstants.MES_EQUIPMENT_CODE; |
| | | string resourceCode = mesConfig?.ResourceCode ?? StockConstants.MES_RESOURCE_CODE; |
| | | string token = mesConfig?.Token; |
| | | |
| | | // 调用MES托盘进站 |
| | | var inboundRequest = new InboundInContainerRequest |
| | | // 判断是不是极卷库任务 |
| | | if (taskDto.WarehouseId == (int)WarehouseEnum.FJ1 || taskDto.WarehouseId == (int)WarehouseEnum.ZJ1) |
| | | { |
| | | EquipmentCode = equipmentCode, |
| | | ResourceCode = resourceCode, |
| | | LocalTime = DateTime.Now, |
| | | ContainerCode = taskDto.PalletCode |
| | | }; |
| | | var inboundResult = string.IsNullOrWhiteSpace(token) |
| | | ? _mesService.InboundInContainer(inboundRequest) |
| | | : _mesService.InboundInContainer(inboundRequest, token); |
| | | if (inboundResult == null || inboundResult.Data == null || !inboundResult.Data.IsSuccess) |
| | | { |
| | | return content.Error($"任务完成失败:MES进站失败: {inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "未知错误"}"); |
| | | return await CompleteAgvInboundTaskAsync(taskDto); |
| | | } |
| | | return await CompleteTaskAsync(task, "入库完成"); |
| | | }); |
| | | |
| | | return await _unitOfWorkManage.BeginTranAsync(async () => |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | stockInfo.LocationCode = location.LocationCode; |
| | | stockInfo.LocationId = location.Id; |
| | | |
| | | SetOutboundDateByRoadway(task, stockInfo); |
| | | |
| | | stockInfo.StockStatus = StockStatusEmun.入库完成.GetHashCode(); |
| | | |
| | | location.LocationStatus = LocationStatusEnum.InStock.GetHashCode(); |
| | | |
| | | var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location); |
| | | var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo); |
| | | if (!updateLocationResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("任务完成失败"); |
| | | |
| | | // 根据库存Remark选择静置设备,查MES动态凭证 |
| | | //string deviceName = stockInfo.Remark == "GW_1" ? "高温静置1" |
| | | // : stockInfo.Remark == "GW_2" ? "高温静置2" |
| | | // : "常温静置1"; |
| | | //var mesConfig = _mesDeviceConfigService.GetByDeviceName(deviceName); |
| | | //string equipmentCode = mesConfig?.EquipmentCode ?? StockConstants.MES_EQUIPMENT_CODE; |
| | | //string resourceCode = mesConfig?.ResourceCode ?? StockConstants.MES_RESOURCE_CODE; |
| | | //string token = mesConfig?.Token; |
| | | |
| | | // 调用MES托盘进站 |
| | | //var inboundRequest = new InboundInContainerRequest |
| | | //{ |
| | | // EquipmentCode = equipmentCode, |
| | | // ResourceCode = resourceCode, |
| | | // LocalTime = DateTime.Now, |
| | | // ContainerCode = taskDto.PalletCode |
| | | //}; |
| | | //string requestJson = inboundRequest.ToJson(); |
| | | //var inboundResult = string.IsNullOrWhiteSpace(token) |
| | | // ? _mesService.InboundInContainer(inboundRequest) |
| | | // : _mesService.InboundInContainer(inboundRequest, token); |
| | | //stopwatch.Stop(); |
| | | //await _mesLogService.LogAsync(new MesApiLogDto |
| | | //{ |
| | | // ApiType = "InboundInContainer", |
| | | // RequestJson = requestJson, |
| | | // ResponseJson = JsonConvert.SerializeObject(inboundResult), |
| | | // IsSuccess = inboundResult.IsSuccess, |
| | | // ErrorMessage = inboundResult.ErrorMessage, |
| | | // ElapsedMs = (int)stopwatch.ElapsedMilliseconds, |
| | | // Creator = "systeam" |
| | | //}); |
| | | //if (inboundResult == null || inboundResult.Data == null || !inboundResult.Data.IsSuccess) |
| | | //{ |
| | | // return content.Error($"任务完成失败:MES进站失败: {inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "未知错误"}"); |
| | | //} |
| | | return await CompleteTaskAsync(task, "入库完成"); |
| | | }); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | |
| | | #endregion 入库任务 |
| | | } |
| | | } |
| | | } |