| | |
| | | using SqlSugar; |
| | | using System.DirectoryServices.Protocols; |
| | | using System.Text.Json; |
| | | using WIDESEA_Common.Constants; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.TaskEnum; |
| | |
| | | { |
| | | if (stockInfo.Remark.IsNullOrEmpty()) |
| | | { |
| | | stockInfo.OutboundDate = now.AddHours(16); |
| | | stockInfo.Remark = "GW_1"; |
| | | stockInfo.OutboundDate = now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_GW1_FIRST); |
| | | stockInfo.Remark = StockRemarkConstants.GW1; |
| | | } |
| | | else if (stockInfo.Remark == "GW_1") |
| | | else if (stockInfo.Remark == StockRemarkConstants.GW1) |
| | | { |
| | | stockInfo.OutboundDate = now.AddHours(24); |
| | | stockInfo.Remark = "GW_2"; |
| | | stockInfo.OutboundDate = now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_GW1_SECOND); |
| | | stockInfo.Remark = StockRemarkConstants.GW2; |
| | | } |
| | | else |
| | | { |
| | | stockInfo.OutboundDate = now.AddHours(16); |
| | | stockInfo.OutboundDate = now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_GW1_FIRST); |
| | | } |
| | | } |
| | | else if (task.Roadway.Contains("CW")) |
| | | { |
| | | if (stockInfo.Remark == "GW_2") |
| | | if (stockInfo.Remark == StockRemarkConstants.GW2) |
| | | { |
| | | stockInfo.OutboundDate = now.AddHours(12); |
| | | stockInfo.Remark = "CW_1"; |
| | | stockInfo.OutboundDate = now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_CW1); |
| | | stockInfo.Remark = StockRemarkConstants.CW1; |
| | | } |
| | | else |
| | | { |
| | | stockInfo.OutboundDate = now.AddHours(12); |
| | | stockInfo.OutboundDate = now.AddHours(OutboundTimeConstants.OUTBOUND_HOURS_CW1); |
| | | } |
| | | } |
| | | else |
| | |
| | | if (!updateLocationResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("任务完成失败"); |
| | | |
| | | // 调用MES托盘出站 |
| | | //var outboundRequest = new OutboundInContainerRequest |
| | | //{ |
| | | // EquipmentCode = "STK-GROUP-001", |
| | | // ResourceCode = "STK-GROUP-001", |
| | | // LocalTime = DateTime.Now, |
| | | // ContainerCode = taskDto.PalletCode, |
| | | // ParamList = new List<ParamItem>() |
| | | //}; |
| | | //var outboundResult = _mesService.OutboundInContainer(outboundRequest); |
| | | //if (outboundResult == null || outboundResult.Data == null || !outboundResult.Data.IsSuccess) |
| | | //{ |
| | | // return content.Error($"任务完成失败:MES出站失败: {outboundResult?.Data?.Msg ?? outboundResult?.ErrorMessage ?? "未知错误"}"); |
| | | //} |
| | | // 高温2号出库到CWSC1时,自动创建入库任务到常温1号巷道 |
| | | WMSTaskDTO? inboundTaskDto = null; |
| | | if (task.TargetAddress == TaskAddressConstants.GW2_ADDRESS) |
| | | { |
| | | var inboundTask = new Dt_Task |
| | | { |
| | | TaskNum = await BaseDal.GetTaskNo(), |
| | | PalletCode = task.PalletCode, |
| | | PalletType = task.PalletType, |
| | | Roadway = "CW1", |
| | | TaskType = TaskInboundTypeEnum.Inbound.GetHashCode(), |
| | | TaskStatus = TaskInStatusEnum.InNew.GetHashCode(), |
| | | SourceAddress = task.TargetAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | CurrentAddress = task.TargetAddress, |
| | | NextAddress = task.TargetAddress, |
| | | WarehouseId = (int)WarehouseEnum.CW1, |
| | | Grade = 1, |
| | | Creater = "system_auto" |
| | | }; |
| | | await Repository.AddDataAsync(inboundTask); |
| | | inboundTaskDto = _mapper.Map<WMSTaskDTO>(inboundTask); |
| | | } |
| | | |
| | | return await CompleteTaskAsync(task, "出库完成"); |
| | | var completeResult = await CompleteTaskAsync(task, "出库完成"); |
| | | if (!completeResult.Status) |
| | | return completeResult; |
| | | |
| | | // 返回入库任务信息(如果有) |
| | | if (inboundTaskDto != null) |
| | | { |
| | | return content.OK("出库完成,已创建入库任务", inboundTaskDto); |
| | | } |
| | | return content.OK("出库完成"); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 手动创建任务 |
| | | /// </summary> |
| | | /// <param name="dto">手动创建任务参数</param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> CreateManualTaskAsync(CreateManualTaskDto dto) |
| | | { |
| | | try |
| | | { |
| | | // 1. 根据任务类型字符串确定 TaskType 和 TaskStatus |
| | | int taskType; |
| | | int taskStatus; |
| | | switch (dto.TaskType) |
| | | { |
| | | case "入库": |
| | | taskType = TaskTypeEnum.Inbound.GetHashCode(); |
| | | taskStatus = TaskInStatusEnum.InNew.GetHashCode(); |
| | | break; |
| | | case "出库": |
| | | taskType = TaskTypeEnum.Outbound.GetHashCode(); |
| | | taskStatus = TaskOutStatusEnum.OutNew.GetHashCode(); |
| | | break; |
| | | case "移库": |
| | | taskType = TaskTypeEnum.Relocation.GetHashCode(); |
| | | taskStatus = TaskRelocationStatusEnum.RelocationNew.GetHashCode(); |
| | | break; |
| | | default: |
| | | return WebResponseContent.Instance.Error($"不支持的任务类型: {dto.TaskType}"); |
| | | } |
| | | |
| | | // 2. 生成任务号 |
| | | int taskNum = await BaseDal.GetTaskNo(); |
| | | |
| | | // 3. 构建任务实体 |
| | | var task = new Dt_Task |
| | | { |
| | | TaskNum = taskNum, |
| | | PalletCode = dto.Barcode, |
| | | SourceAddress = dto.SourceAddress, |
| | | TargetAddress = dto.TargetAddress, |
| | | TaskType = taskType, |
| | | TaskStatus = taskStatus, |
| | | Grade = dto.Grade, |
| | | WarehouseId = dto.WarehouseId, |
| | | CurrentAddress = dto.SourceAddress, |
| | | NextAddress = dto.TargetAddress, |
| | | Creater = "manual", |
| | | CreateDate = DateTime.Now, |
| | | ModifyDate = DateTime.Now |
| | | }; |
| | | |
| | | // 4. 保存到数据库 |
| | | var result = await BaseDal.AddDataAsync(task) > 0; |
| | | if (!result) |
| | | return WebResponseContent.Instance.Error("创建任务失败"); |
| | | |
| | | // 5. 发送到 WCS |
| | | var wmsTaskDto = new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum, |
| | | PalletCode = task.PalletCode, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskType = task.TaskType, |
| | | TaskStatus = task.TaskStatus, |
| | | WarehouseId = task.WarehouseId |
| | | }; |
| | | |
| | | var wcsResult = _httpClientHelper.Post<WebResponseContent>( |
| | | "http://localhost:9292/api/Task/ReceiveManualTask", |
| | | wmsTaskDto.ToJson()); |
| | | |
| | | if (!wcsResult.IsSuccess || !wcsResult.Data.Status) |
| | | return WebResponseContent.Instance.Error($"任务已创建但发送给WCS失败: {wcsResult.Data?.Message}"); |
| | | |
| | | return WebResponseContent.Instance.OK($"手动创建任务成功,任务号: {taskNum}"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"手动创建任务异常: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | #endregion WCS逻辑处理 |
| | | } |
| | | } |