using Kean.Domain.Task.Commands; using Kean.Domain.Task.Enums; using Kean.Domain.Task.Repositories; using Kean.Domain.Task.SharedServices.Proxies; using System.Threading; namespace Kean.Domain.Task.CommandHandlers { /// /// 任务执行命令处理程序 /// public sealed class ExecuteCommandHandler : CommandHandler { private readonly ICommandBus _commandBus; // 命令总线 private readonly ITaskRepository _taskRepository; // 任务仓库 private readonly StockProxy _stockProxy; // 库房仓库 /// /// 依赖注入 /// public ExecuteCommandHandler( ICommandBus commandBus, StockProxy stockProxy, ITaskRepository taskRepository) { _commandBus = commandBus; _taskRepository = taskRepository; _stockProxy = stockProxy; } /// /// 处理程序 /// public override async System.Threading.Tasks.Task Handle(ExecuteCommand command, CancellationToken cancellationToken) { if (command.ValidationResult.IsValid) { await _taskRepository.UpdateStatus(command.Id, TaskState.Running); try { var task = await _taskRepository.GetTask(command.Id); if(task.Type == TaskType.Infeed) await _stockProxy.Reupload(task.Type.ToString(), task.Barcode, task.RequestNo, "1"); } catch { } } else { await _commandBus.Notify(command.ValidationResult, cancellationToken: cancellationToken); } } } }