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

49 lines
1.5 KiB

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 SyncOutputCommandHandler : CommandHandler<SyncOutputCommand>
{
private readonly ICommandBus _commandBus; // 命令总线
private readonly IMapper _mapper; // 模型映射
private readonly IWcsRepository _wcsRepository; // 控制仓库
/// <summary>
/// 依赖注入
/// </summary>
public SyncOutputCommandHandler(
ICommandBus commandBus,
IMapper mapper,
IWcsRepository wcsRepository)
{
_commandBus = commandBus;
_mapper = mapper;
_wcsRepository = wcsRepository;
}
/// <summary>
/// 处理程序
/// </summary>
public override async Task Handle(SyncOutputCommand command, CancellationToken cancellationToken)
{
if (command.ValidationResult.IsValid)
{
await _wcsRepository.SyncOutput(command.Id, command.State);
await _commandBus.Trigger(_mapper.Map<SyncOutputSuccessEvent>(command), cancellationToken);
}
else
{
await _commandBus.Notify(command.ValidationResult,
cancellationToken: cancellationToken);
}
}
}
}