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 { /// /// 发送输出命令处理程序 /// public sealed class SendOutputCommandHandler : CommandHandler { private readonly ICommandBus _commandBus; // 命令总线 private readonly IMapper _mapper; // 模型映射 private readonly IWcsRepository _wcsRepository; // 控制仓库 /// /// 依赖注入 /// public SendOutputCommandHandler( ICommandBus commandBus, IMapper mapper, IWcsRepository wcsRepository) { _commandBus = commandBus; _mapper = mapper; _wcsRepository = wcsRepository; } /// /// 处理程序 /// public override async Task Handle(SendOutputCommand command, CancellationToken cancellationToken) { if (command.ValidationResult.IsValid) { await _wcsRepository.CreateOutput(_mapper.Map(command)); } else { await _commandBus.Notify(command.ValidationResult, cancellationToken: cancellationToken); } } } }