You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.8 KiB
56 lines
1.8 KiB
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
|
|
{
|
|
/// <summary>
|
|
/// 任务执行命令处理程序
|
|
/// </summary>
|
|
public sealed class ExecuteCommandHandler : CommandHandler<ExecuteCommand>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly ITaskRepository _taskRepository; // 任务仓库
|
|
private readonly StockProxy _stockProxy; // 库房仓库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public ExecuteCommandHandler(
|
|
ICommandBus commandBus,
|
|
StockProxy stockProxy,
|
|
ITaskRepository taskRepository)
|
|
{
|
|
_commandBus = commandBus;
|
|
_taskRepository = taskRepository;
|
|
_stockProxy = stockProxy;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|