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
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 DisableCommandHandler : CommandHandler<DisableCommand>
|
||
|
{
|
||
|
private readonly ICommandBus _commandBus; // 命令总线
|
||
|
private readonly IWarehouseRepository _warehouseRepository; // 库房仓库
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public DisableCommandHandler(
|
||
|
ICommandBus commandBus,
|
||
|
IWarehouseRepository warehouseRepository)
|
||
|
{
|
||
|
_commandBus = commandBus;
|
||
|
_warehouseRepository = warehouseRepository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 处理程序
|
||
|
/// </summary>
|
||
|
public override async System.Threading.Tasks.Task Handle(DisableCommand 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:
|
||
|
await _warehouseRepository.DisableCell(command.CellTag, cell.Id);
|
||
|
states.Enqueue(false);
|
||
|
break;
|
||
|
case CellState.Selected:
|
||
|
states.Enqueue(true);
|
||
|
break;
|
||
|
case CellState.Disabled:
|
||
|
states.Enqueue(false);
|
||
|
break;
|
||
|
default:
|
||
|
states.Enqueue(null);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
Output(nameof(command.States), states);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await _commandBus.Notify(command.ValidationResult,
|
||
|
cancellationToken: cancellationToken);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|