山东雷驰
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

3 months ago
using Kean.Domain.Task.Commands;
using Kean.Domain.Task.Enums;
using Kean.Domain.Task.Repositories;
using System.Collections.Generic;
using System.Threading;
namespace Kean.Domain.Task.CommandHandlers
{
/// <summary>
/// 创建启用命令处理程序
/// </summary>
public sealed class EnableCommandHandler : CommandHandler<EnableCommand>
{
private readonly ICommandBus _commandBus; // 命令总线
private readonly IWarehouseRepository _warehouseRepository; // 库房仓库
/// <summary>
/// 依赖注入
/// </summary>
public EnableCommandHandler(
ICommandBus commandBus,
IWarehouseRepository warehouseRepository)
{
_commandBus = commandBus;
_warehouseRepository = warehouseRepository;
}
/// <summary>
/// 处理程序
/// </summary>
public override async System.Threading.Tasks.Task Handle(EnableCommand command, CancellationToken cancellationToken)
{
if (command.ValidationResult.IsValid)
{
var states = new Queue<bool?>();
foreach (var item in command.Cells)
{
var cell = await _warehouseRepository.GetCellByName(item, command.Warehouse);
switch (cell?.State)
{
case CellState.Enabled:
states.Enqueue(true);
break;
case CellState.Selected:
states.Enqueue(true);
break;
case CellState.Disabled:
await _warehouseRepository.ReleaseCell(cell.Id);
states.Enqueue(true);
break;
default:
states.Enqueue(null);
break;
}
}
Output(nameof(command.States), states);
}
else
{
await _commandBus.Notify(command.ValidationResult,
cancellationToken: cancellationToken);
}
}
}
}