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.
87 lines
3.2 KiB
87 lines
3.2 KiB
3 months ago
|
using AutoMapper;
|
||
|
using Kean.Domain.Task.Commands;
|
||
|
using Kean.Domain.Task.Enums;
|
||
|
using Kean.Domain.Task.Events;
|
||
|
using Kean.Domain.Task.Repositories;
|
||
|
using Kean.Domain.Task.SharedServices.Proxies;
|
||
|
using Newtonsoft.Json;
|
||
|
using System;
|
||
|
using System.Threading;
|
||
|
|
||
|
namespace Kean.Domain.Task.CommandHandlers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 任务取消命令处理程序
|
||
|
/// </summary>
|
||
|
public sealed class CancelAgvApplyOutCommandHandler : CommandHandler<CancelAgvApplyOutCommand>
|
||
|
{
|
||
|
private readonly ICommandBus _commandBus; // 命令总线
|
||
|
private readonly IMapper _mapper; // 模型映射
|
||
|
private readonly ITaskRepository _taskRepository; // 任务仓库
|
||
|
private readonly IWarehouseRepository _warehouseRepository; // 库房仓库
|
||
|
private readonly StockProxy _stockProxy; // 库房仓库
|
||
|
private readonly WcsProxy _wcsProxy;
|
||
|
private readonly Kean.Infrastructure.Soap.LED.LedService _ledService;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public CancelAgvApplyOutCommandHandler(
|
||
|
ICommandBus commandBus,
|
||
|
IMapper mapper,
|
||
|
ITaskRepository taskRepository,
|
||
|
StockProxy stockProxy,
|
||
|
WcsProxy wcsProxy,
|
||
|
Kean.Infrastructure.Soap.LED.LedService ledService,
|
||
|
IWarehouseRepository warehouseRepository)
|
||
|
{
|
||
|
_commandBus = commandBus;
|
||
|
_mapper = mapper;
|
||
|
_taskRepository = taskRepository;
|
||
|
_stockProxy = stockProxy;
|
||
|
_wcsProxy = wcsProxy;
|
||
|
_ledService = ledService;
|
||
|
_warehouseRepository = warehouseRepository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 处理程序
|
||
|
/// </summary>
|
||
|
public override async System.Threading.Tasks.Task Handle(CancelAgvApplyOutCommand command, CancellationToken cancellationToken)
|
||
|
{
|
||
|
if (command.ValidationResult.IsValid)
|
||
|
{
|
||
|
var tasks = await _taskRepository.GetTaskByRequestNo(command.RequestNo);
|
||
|
if (tasks == null)
|
||
|
{
|
||
|
await _commandBus.Notify("requestNo", $"申请编号({command.RequestNo})的任务未找到,请核查申请编号", cancellationToken: cancellationToken);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
foreach (Kean.Domain.Task.Models.Task t in tasks)
|
||
|
{
|
||
|
if (t.ManageStatus != TaskState.Waiting.ToString())
|
||
|
{
|
||
|
await _commandBus.Notify("requestNo", $"申请编号({command.RequestNo})的任务已经执行,不能取消", cancellationToken: cancellationToken);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach (Kean.Domain.Task.Models.Task t in tasks)
|
||
|
{
|
||
|
CallDeleteCommand callDeleteCommand = new CallDeleteCommand();
|
||
|
callDeleteCommand.Id = t.Id;
|
||
|
callDeleteCommand.Operator = -4;
|
||
|
|
||
|
await _commandBus.Execute(callDeleteCommand, cancellationToken);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await _commandBus.Notify(command.ValidationResult,
|
||
|
cancellationToken: cancellationToken);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|