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.
56 lines
1.7 KiB
56 lines
1.7 KiB
3 months ago
|
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
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 删除物料命令处理程序
|
||
|
/// </summary>
|
||
|
public sealed class DeleteItemCommandHandler : CommandHandler<DeleteItemCommand>
|
||
|
{
|
||
|
private readonly ICommandBus _commandBus; // 命令总线
|
||
|
private readonly IMapper _mapper; // 模型映射
|
||
|
private readonly IInterfaceRecordRepository _interfaceRecordRepository;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public DeleteItemCommandHandler(
|
||
|
ICommandBus commandBus,
|
||
|
IInterfaceRecordRepository interfaceRecordRepository,
|
||
|
IMapper mapper)
|
||
|
{
|
||
|
_commandBus = commandBus;
|
||
|
_mapper = mapper;
|
||
|
_interfaceRecordRepository = interfaceRecordRepository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 处理程序
|
||
|
/// </summary>
|
||
|
public override async Task Handle(DeleteItemCommand command, CancellationToken cancellationToken)
|
||
|
{
|
||
|
if (command.ValidationResult.IsValid)
|
||
|
{
|
||
|
List<int> 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|