| | |
| | | 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.Helper; |
| | | 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_ITaskInfoRepository; |
| | | 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 ITaskService _taskService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly IComponentContext _componentContext; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | /// <summary> |
| | | /// 初始化出库任务流程服务。 |
| | |
| | | /// <param name="routerService">路由服务。</param> |
| | | /// <param name="httpClientHelper">WMS接口调用帮助类。</param> |
| | | /// <param name="robotTaskService">机械手任务服务。</param> |
| | | /// <param name="taskService">任务服务(用于接收入库任务)。</param> |
| | | /// <param name="taskRepository">任务仓储(用于删除出库任务)。</param> |
| | | public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, ITaskService taskService, ITaskRepository taskRepository) |
| | | /// <param name="componentContext">Autofac组件上下文(用于延迟解析ITaskService以避免循环依赖)。</param> |
| | | public OutboundTaskFlowService(IRouterService routerService, HttpClientHelper httpClientHelper, IRobotTaskService robotTaskService, IComponentContext componentContext, IUnitOfWorkManage unitOfWorkManage) |
| | | { |
| | | _routerService = routerService; |
| | | _httpClientHelper = httpClientHelper; |
| | | _robotTaskService = robotTaskService; |
| | | _taskService = taskService; |
| | | _taskRepository = taskRepository; |
| | | _componentContext = componentContext; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 延迟解析ITaskService以避免循环依赖 |
| | | /// </summary> |
| | | private ITaskService TaskService => _componentContext.Resolve<ITaskService>(); |
| | | |
| | | /// <summary> |
| | | /// 接收WMS任务时初始化出库任务。 |
| | |
| | | |
| | | if (inboundTaskDto != null) |
| | | { |
| | | // 先删除本地出库任务,避免托盘号唯一键冲突 |
| | | _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成); |
| | | |
| | | // 调用ReceiveWMSTask创建本地入库任务 |
| | | var receiveResult = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { inboundTaskDto }); |
| | | if (!receiveResult.Status) |
| | | _unitOfWorkManage.BeginTran(() => |
| | | { |
| | | return content.Error($"创建本地入库任务失败: {receiveResult.Message}"); |
| | | } |
| | | // 先删除本地出库任务,避免托盘号唯一键冲突 |
| | | 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("创建本地入库任务成功"); |
| | | }); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |