山东雷驰
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.
 
 
 
 

74 lines
2.7 KiB

using AutoMapper;
using Kean.Domain.Task.Commands;
using Kean.Domain.Task.Enums;
using Kean.Domain.Task.Events;
using Kean.Domain.Task.Repositories;
using System;
using System.Threading;
using Kean.Domain.Task.SharedServices.Proxies;
namespace Kean.Domain.Task.CommandHandlers
{
/// <summary>
/// 任务中转命令处理程序
/// </summary>
public sealed class TransferRelocateCommandHandler : CommandHandler<TransferRelocateCommand>
{
private readonly ICommandBus _commandBus; // 命令总线
private readonly ITaskRepository _taskRepository; // 任务仓库
private readonly IWarehouseRepository _warehouseRepository; // 库房仓库
private readonly StockProxy _stockProxy; // 仓储域
/// <summary>
/// 依赖注入
/// </summary>
public TransferRelocateCommandHandler(
ICommandBus commandBus,
IMapper mapper,
ITaskRepository taskRepository,
IWarehouseRepository warehouseRepository,
StockProxy stockProxy)
{
_commandBus = commandBus;
_taskRepository = taskRepository;
_warehouseRepository = warehouseRepository;
_stockProxy = stockProxy;
}
/// <summary>
/// 处理程序
/// </summary>
public override async System.Threading.Tasks.Task Handle(TransferRelocateCommand command, CancellationToken cancellationToken)
{
if (command.ValidationResult.IsValid)
{
var task = await _taskRepository.GetTask(command.Id);
await _taskRepository.UpdateStatus(command.Id, TaskState.Running);
if (task != null && (task.Type == TaskType.PalletOut || task.Type == TaskType.ApplyOut || task.Type == TaskType.Outfeed))
{
var outStation = await _warehouseRepository.GetStationById(task.Destination);
await _stockProxy.Relocate(
"Transfer",
task.Barcode,
null,
task.Original,
Convert.ToInt32(outStation.Group),
//task.Operator,
-1,
task.Tag,
(task.Timestamp,DateTime.Now));
await _taskRepository.UpdateTransitPlace(command.Id, Convert.ToInt32(outStation.Group));
await _warehouseRepository.ReleaseCell(task.Original, task.Destination);
}
}
else
{
await _commandBus.Notify(command.ValidationResult,
cancellationToken: cancellationToken);
}
}
}
}