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.
45 lines
1.5 KiB
45 lines
1.5 KiB
using Kean.Domain.Task.Commands;
|
|
using Kean.Domain.Task.Enums;
|
|
using Kean.Domain.Task.Repositories;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
|
|
namespace Kean.Domain.Task.CommandHandlers
|
|
{
|
|
/// <summary>
|
|
/// 设置应急模式
|
|
/// </summary>
|
|
public sealed class EmergencyCommandHandler : CommandHandler<EmergencyCommand>
|
|
{
|
|
private readonly ICommandBus _commandBus; // 命令总线
|
|
private readonly IWarehouseRepository _warehouseRepository; // 库房仓库
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public EmergencyCommandHandler(
|
|
ICommandBus commandBus,
|
|
IWarehouseRepository warehouseRepository)
|
|
{
|
|
_commandBus = commandBus;
|
|
_warehouseRepository = warehouseRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
public override async System.Threading.Tasks.Task Handle(EmergencyCommand command, CancellationToken cancellationToken)
|
|
{
|
|
if (command.ValidationResult.IsValid)
|
|
{
|
|
await _warehouseRepository.SetEmergency(command.StationCode, command.StationModel, command.stationStatus);
|
|
Output(nameof(command.StationCode), command.StationCode);
|
|
}
|
|
else
|
|
{
|
|
await _commandBus.Notify(command.ValidationResult,
|
|
cancellationToken: cancellationToken);
|
|
}
|
|
}
|
|
}
|
|
}
|