| | |
| | | using Newtonsoft.Json; |
| | | using Autofac; |
| | | using Newtonsoft.Json; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Common.HttpEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO; |
| | | using WIDESEAWCS_DTO.Stock; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | |
| | | private readonly IRouterService _routerService; |
| | | private readonly HttpClientHelper _httpClientHelper; |
| | | private readonly IRobotTaskService _robotTaskService; |
| | | private readonly IComponentContext _componentContext; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | /// <summary> |
| | | /// 初始化出库任务流程服务。 |
| | |
| | | /// <param name="routerService">路由服务。</param> |
| | | /// <param name="httpClientHelper">WMS接口调用帮助类。</param> |
| | | /// <param name="robotTaskService">机械手任务服务。</param> |
| | | public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService) |
| | | /// <param name="componentContext">Autofac组件上下文(用于延迟解析ITaskService以避免循环依赖)。</param> |
| | | public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, IComponentContext componentContext, IUnitOfWorkManage unitOfWorkManage) |
| | | { |
| | | _routerService = routerService; |
| | | _httpClientHelper = httpClientHelper; |
| | | _robotTaskService = robotTaskService; |
| | | _componentContext = componentContext; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 延迟解析ITaskService以避免循环依赖 |
| | | /// </summary> |
| | | private ITaskService TaskService => _componentContext.Resolve<ITaskService>(); |
| | | |
| | | /// <summary> |
| | | /// 接收WMS任务时初始化出库任务。 |
| | |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | |
| | | content = NotifyWMSOutboundFinish(task); |
| | | if (!content.Status) |
| | | // 通知WMS出库完成并获取返回结果 |
| | | var result = _httpClientHelper.Post<WebResponseContent>( |
| | | nameof(ConfigKey.OutboundFinishTaskAsync), |
| | | new StockInfoDTO { PalletCode = task.PalletCode, TaskNum = task.TaskNum }.ToJson()); |
| | | |
| | | if (!result.IsSuccess || !result.Data.Status) |
| | | { |
| | | return content; |
| | | return content.Error($"通知WMS系统堆垛机出库完成失败,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】,错误信息:【{result.Data?.Message}】"); |
| | | } |
| | | |
| | | return content.Error($"通知WMS系统堆垛机出库完成成功,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】"); |
| | | // 处理WMS返回的入库任务(如果有) |
| | | if (result.Data?.Data != null) |
| | | { |
| | | var inboundTaskJson = result.Data.Data.ToString(); |
| | | var inboundTaskDto = JsonConvert.DeserializeObject<WMSTaskDTO>(inboundTaskJson); |
| | | |
| | | if (inboundTaskDto != null) |
| | | { |
| | | _unitOfWorkManage.BeginTran(() => |
| | | { |
| | | // 先删除本地出库任务,避免托盘号唯一键冲突 |
| | | bool isDeleted = TaskService.Repository.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成); |
| | | if (!isDeleted) |
| | | { |
| | | return content.Error($"删除本地出库任务失败,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】"); |
| | | } |
| | | |
| | | // 调用ReceiveWMSTask创建本地入库任务 |
| | | var receiveResult = TaskService.ReceiveWMSTask(new List<WMSTaskDTO> { inboundTaskDto }); |
| | | if (!receiveResult.Status) |
| | | { |
| | | return content.Error($"创建本地入库任务失败: {receiveResult.Message}"); |
| | | } |
| | | return content.OK("创建本地入库任务成功"); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | return content.OK($"通知WMS系统堆垛机出库完成成功,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】"); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | var result = _httpClientHelper.Post<WebResponseContent>( |
| | | nameof(ConfigKey.UpdateTaskByStatus), |
| | | new UpdateTaskDto { Id = task.TaskNum, NewStatus = task.TaskStatus }.ToJson()); |
| | | new UpdateTaskDto { Id = task.TaskNum, NewStatus = task.TaskStatus, NextAddress = task.NextAddress, CurrentAddress = task.CurrentAddress }.ToJson()); |
| | | |
| | | if (!result.IsSuccess || !result.Data.Status) |
| | | return WebResponseContent.Instance.Error($"调用WMS接口更新任务状态失败,任务号:【{task.TaskNum}】,错误信息:【{result.Data?.Message}】"); |
| | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | } |
| | | } |
| | | } |