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.
47 lines
1.4 KiB
47 lines
1.4 KiB
3 months ago
|
using AutoMapper;
|
||
|
using Kean.Domain.Basic.Commands;
|
||
|
using Kean.Domain.Basic.Events;
|
||
|
using Kean.Domain.Basic.Models;
|
||
|
using Kean.Domain.Basic.Repositories;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Kean.Domain.Basic.CommandHandlers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 自动清除记录命令处理程序
|
||
|
/// </summary>
|
||
|
public sealed class ClearRecordCommandHandler : CommandHandler<ClearRecordCommand>
|
||
|
{
|
||
|
private readonly ICommandBus _commandBus; // 命令总线
|
||
|
private readonly IInterfaceRecordRepository _interfaceRecordRepository;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public ClearRecordCommandHandler(
|
||
|
ICommandBus commandBus,
|
||
|
IInterfaceRecordRepository interfaceRecordRepository)
|
||
|
{
|
||
|
_commandBus = commandBus;
|
||
|
_interfaceRecordRepository = interfaceRecordRepository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 处理程序
|
||
|
/// </summary>
|
||
|
public override async Task Handle(ClearRecordCommand command, CancellationToken cancellationToken)
|
||
|
{
|
||
|
if (command.ValidationResult.IsValid)
|
||
|
{
|
||
|
await _interfaceRecordRepository.Clear(command.AddMonth);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await _commandBus.Notify(command.ValidationResult,
|
||
|
cancellationToken: cancellationToken);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|