using Kean.Domain.Task.Commands; using Kean.Domain.Task.Enums; using Kean.Domain.Task.Repositories; using Kean.Domain.Task.SharedServices.Proxies; using System; using System.Threading; namespace Kean.Domain.Task.CommandHandlers { /// /// 任务出库确认失败命令处理程序 /// public sealed class SetTaskStateCommandHandler : CommandHandler { private readonly ICommandBus _commandBus; // 命令总线 private readonly ITaskRepository _taskRepository; // 任务仓库 private readonly WcsProxy _wcsProxy; private readonly StockProxy _stockProxy; // 库房仓库 /// /// 依赖注入 /// public SetTaskStateCommandHandler( ICommandBus commandBus, WcsProxy wcsProxy, StockProxy stockProxy, ITaskRepository taskRepository) { _commandBus = commandBus; _taskRepository = taskRepository; _stockProxy = stockProxy; _wcsProxy = wcsProxy; } /// /// 处理程序 /// public override async System.Threading.Tasks.Task Handle(SetTaskStateCommand command, CancellationToken cancellationToken) { if (command.ValidationResult.IsValid) { TaskState taskState = (TaskState)Enum.Parse(typeof(TaskState), command.State); if (command.Type.Contains("Task")) { await _taskRepository.UpdateStatus(command.Id, taskState, command.Message); } if (command.Type.Contains("Wcs")) { await _wcsProxy.SetOutputStatus(command.Id, (int)taskState); } var task = await _taskRepository.GetTask(command.Id); if (taskState == TaskState.Wcsgot) { await _stockProxy.Reupload(task.Type.ToString(), task.Barcode, task.RequestNo, "1"); } } else { await _commandBus.Notify(command.ValidationResult, cancellationToken: cancellationToken); } } } }