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.
100 lines
3.9 KiB
100 lines
3.9 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.Models;
|
||
|
using Kean.Domain.Task.Repositories;
|
||
|
using Kean.Domain.Task.SharedServices.Proxies;
|
||
|
using Kean.Infrastructure.Configuration;
|
||
|
using Newtonsoft.Json;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading;
|
||
|
|
||
|
namespace Kean.Domain.Task.CommandHandlers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 创建下架命令处理程序
|
||
|
/// </summary>
|
||
|
public sealed class AutoPalletOutCommandHandler : CommandHandler<AutoPalletOutCommand>
|
||
|
{
|
||
|
private readonly ICommandBus _commandBus; // 命令总线
|
||
|
private readonly INotification _notifications; // 总线通知
|
||
|
private readonly IMapper _mapper; // 模型映射
|
||
|
private readonly ITaskRepository _taskRepository; // 任务仓库
|
||
|
private readonly IWarehouseRepository _warehouseRepository; // 库房仓库
|
||
|
private readonly BarcodeInterpreter _barcodeInterpreter; // 条码解释器
|
||
|
private readonly BarcodeValidator _barcodeValidator; // 条码验证器
|
||
|
private readonly StockProxy _stockProxy; // 仓储域代理
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public AutoPalletOutCommandHandler(
|
||
|
ICommandBus commandBus,
|
||
|
INotification notifications,
|
||
|
IMapper mapper,
|
||
|
ITaskRepository taskRepository,
|
||
|
IWarehouseRepository warehouseRepository,
|
||
|
BarcodeInterpreter barcodeInterpreter,
|
||
|
BarcodeValidator barcodeValidator,
|
||
|
StockProxy stockProxy)
|
||
|
{
|
||
|
_commandBus = commandBus;
|
||
|
_notifications = notifications;
|
||
|
_mapper = mapper;
|
||
|
_taskRepository = taskRepository;
|
||
|
_warehouseRepository = warehouseRepository;
|
||
|
_barcodeInterpreter = barcodeInterpreter;
|
||
|
_barcodeValidator = barcodeValidator;
|
||
|
_stockProxy = stockProxy;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 处理程序
|
||
|
/// </summary>
|
||
|
public override async System.Threading.Tasks.Task Handle(AutoPalletOutCommand command, CancellationToken cancellationToken)
|
||
|
{
|
||
|
if (await _taskRepository.GetPalletOutManageCount(command.Device) < 3)
|
||
|
{
|
||
|
//判断是否有后序空托盘回库移库任务,直接输送
|
||
|
if (await _taskRepository.HasMovePalletFromLaXian(command.InfeedDevice, command.GoodsId))
|
||
|
{
|
||
|
await _commandBus.Notify(nameof(command.Message), $"{command.Device}自动空托盘出库:存在空托盘回库,直接输送", null,
|
||
|
cancellationToken: cancellationToken);
|
||
|
return;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
List<int> lsGoods = new List<int>();
|
||
|
lsGoods.Add(command.GoodsId);
|
||
|
await _commandBus.Execute(new ApplyOutCommand
|
||
|
{
|
||
|
Warehouse = command.Device.Substring(0, 1) == "1" ? 1 : 2,
|
||
|
//RequestNo = requestNo,
|
||
|
Operator = -1,
|
||
|
//Tag = JsonConvert.SerializeObject(new{ postUser = "ASRS" }),
|
||
|
Destination = $"device:{command.Device}",
|
||
|
Priority = 0,
|
||
|
Manual = false,
|
||
|
Transaction = "PalletOut",
|
||
|
Materials = lsGoods,
|
||
|
Qty = 1,
|
||
|
Qc = "ok",
|
||
|
enable = true,
|
||
|
IsLocal = "1"
|
||
|
|
||
|
});
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await _commandBus.Notify(nameof(command.Message), $"{command.Device}空托盘出库任务 >= 4不需处理", null, cancellationToken: cancellationToken);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|