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 MediatR; using Microsoft.Extensions.Logging; using System; using System.Linq; using System.Threading; namespace Kean.Domain.Task.EventHandlers { /// /// 任务完成命令成功时,处理后续 /// [EventHandlerIndex(8)] public sealed class CompleteSuccessEventHandler_Bypass : EventHandler { private readonly ICommandBus _commandBus; // 命令总线 private readonly INotification _notifications; // 总线通知 private readonly IMapper _mapper; // 模型映射 private readonly ITaskRepository _taskRepository; // 任务仓库 private readonly IWarehouseRepository _warehouseRepository; // 库房仓库 private readonly StockProxy _stockProxy; // 仓储域 private readonly ILogger _logger; // 日志 /// /// 依赖注入 /// public CompleteSuccessEventHandler_Bypass( ICommandBus commandBus, INotification notifications, IMapper mapper, ITaskRepository taskRepository, IWarehouseRepository warehouseRepository, ILogger logger, StockProxy stockProxy) { _commandBus = commandBus; _notifications = notifications; _mapper = mapper; _taskRepository = taskRepository; _warehouseRepository = warehouseRepository; _stockProxy = stockProxy; _logger = logger; } /// /// 处理程序 /// public override async System.Threading.Tasks.Task Handle(CompleteSuccessEvent @event, CancellationToken cancellationToken) { if (@event.Barcode.Substring(2,1) == "G" && @event.Type == TaskType.Outfeed) { if (await _taskRepository.HasAGVInput()) { //查找22009 是否有出库托盘 var stockBarcode = await _taskRepository.GetStockbarcode(22009); if (stockBarcode != null) { await _taskRepository.DeleteTask(@event.Id); BypassHithumCommand command = new BypassHithumCommand(); command.Barcode = stockBarcode; command.Original = "device:22009"; await _commandBus.Execute(command); } //删除AGV出库申请 if (_notifications.Any()) { } else { await _taskRepository.RemoveAGVInput(); } } } } } }