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.
48 lines
1.4 KiB
48 lines
1.4 KiB
using AutoMapper;
|
|
using Kean.Domain.Wcs.Commands;
|
|
using Kean.Domain.Wcs.Models;
|
|
using Kean.Domain.Wcs.Repositories;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Domain.Wcs.CommandHandlers
|
|
{
|
|
/// <summary>
|
|
/// 发送输出命令处理程序
|
|
/// </summary>
|
|
public sealed class SendOutputCommandHandler : CommandHandler<SendOutputCommand>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly IMapper _mapper; // 模型映射
|
|
private readonly IWcsRepository _wcsRepository; // 控制仓库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public SendOutputCommandHandler(
|
|
ICommandBus commandBus,
|
|
IMapper mapper,
|
|
IWcsRepository wcsRepository)
|
|
{
|
|
_commandBus = commandBus;
|
|
_mapper = mapper;
|
|
_wcsRepository = wcsRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
public override async Task Handle(SendOutputCommand command, CancellationToken cancellationToken)
|
|
{
|
|
if (command.ValidationResult.IsValid)
|
|
{
|
|
await _wcsRepository.CreateOutput(_mapper.Map<Output>(command));
|
|
}
|
|
else
|
|
{
|
|
await _commandBus.Notify(command.ValidationResult,
|
|
cancellationToken: cancellationToken);
|
|
}
|
|
}
|
|
}
|
|
}
|