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.
53 lines
1.7 KiB
53 lines
1.7 KiB
3 months ago
|
using AutoMapper;
|
||
|
using Kean.Domain.Wcs.Commands;
|
||
|
using Kean.Domain.Wcs.Events;
|
||
|
using Kean.Domain.Wcs.Repositories;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Kean.Domain.Wcs.CommandHandlers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 接受输入命令处理程序
|
||
|
/// </summary>
|
||
|
public sealed class AcceptInputCommandHandler : CommandHandler<AcceptInputCommand>
|
||
|
{
|
||
|
private readonly ICommandBus _commandBus; // 命令总线
|
||
|
private readonly IMapper _mapper; // 模型映射
|
||
|
private readonly IWcsRepository _wcsRepository; // 控制仓库
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public AcceptInputCommandHandler(
|
||
|
ICommandBus commandBus,
|
||
|
IWcsRepository wcsRepository,
|
||
|
IMapper mapper)
|
||
|
{
|
||
|
_commandBus = commandBus;
|
||
|
_wcsRepository = wcsRepository;
|
||
|
_mapper = mapper;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 处理程序
|
||
|
/// </summary>
|
||
|
public override async Task Handle(AcceptInputCommand command, CancellationToken cancellationToken)
|
||
|
{
|
||
|
if (command.ValidationResult.IsValid)
|
||
|
{
|
||
|
var @event = _mapper.Map<AcceptInputSuccessEvent>(command);
|
||
|
@event.Fallback = input => Output(nameof(command.Fallback), _mapper.Map<AcceptInputCommand>(input));
|
||
|
await _commandBus.Trigger(@event, cancellationToken);
|
||
|
|
||
|
await _wcsRepository.RemoveInput(command.Id);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await _commandBus.Notify(command.ValidationResult,
|
||
|
cancellationToken: cancellationToken);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|