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.
66 lines
2.2 KiB
66 lines
2.2 KiB
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
|
|
{
|
|
/// <summary>
|
|
/// 任务出库确认失败命令处理程序
|
|
/// </summary>
|
|
public sealed class SetTaskStateCommandHandler : CommandHandler<SetTaskStateCommand>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly ITaskRepository _taskRepository; // 任务仓库
|
|
private readonly WcsProxy _wcsProxy;
|
|
private readonly StockProxy _stockProxy; // 库房仓库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public SetTaskStateCommandHandler(
|
|
ICommandBus commandBus,
|
|
WcsProxy wcsProxy,
|
|
StockProxy stockProxy,
|
|
ITaskRepository taskRepository)
|
|
{
|
|
_commandBus = commandBus;
|
|
_taskRepository = taskRepository;
|
|
_stockProxy = stockProxy;
|
|
_wcsProxy = wcsProxy;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|