using AutoMapper; using Kean.Domain.Basic.Commands; using Kean.Domain.Basic.Events; using Kean.Domain.Basic.Repositories; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace Kean.Domain.Basic.CommandHandlers { /// /// 删除物料命令处理程序 /// public sealed class DeleteItemCommandHandler : CommandHandler { private readonly ICommandBus _commandBus; // 命令总线 private readonly IMapper _mapper; // 模型映射 private readonly IInterfaceRecordRepository _interfaceRecordRepository; /// /// 依赖注入 /// public DeleteItemCommandHandler( ICommandBus commandBus, IInterfaceRecordRepository interfaceRecordRepository, IMapper mapper) { _commandBus = commandBus; _mapper = mapper; _interfaceRecordRepository = interfaceRecordRepository; } /// /// 处理程序 /// public override async Task Handle(DeleteItemCommand command, CancellationToken cancellationToken) { if (command.ValidationResult.IsValid) { List result = new(); foreach (var item in command.Code) { int id = await _interfaceRecordRepository.DeleteItem(item); result.Add(id); } command.Id = result; } else { await _commandBus.Notify(command.ValidationResult, cancellationToken: cancellationToken); } } } }