using AutoMapper; using Kean.Domain.Wcs.Events; using Kean.Domain.Wcs.Models; using Kean.Domain.Wcs.Repositories; using Kean.Domain.Wcs.SharedServices.Proxies; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace Kean.Domain.Wcs.EventHandlers { /// /// 接受输入成功时,处理类型 1:上架申请 /// public sealed class AcceptInputSuccessEventHandler_1 : EventHandler { private readonly TaskProxy _taskProxy; // 任务代理 private readonly INotification _notification; // private readonly IWcsRepository _wcsRepository; // 控制仓库 private readonly Kean.Infrastructure.Soap.LED.LedService _ledService; private readonly ICommandBus _commandBus; // 命令总线 private readonly IMapper _mapper; // 模型映射 /// /// 依赖注入 /// public AcceptInputSuccessEventHandler_1( TaskProxy taskProxy, ICommandBus commandBus, IMapper mapper, IWcsRepository wcsRepository, Kean.Infrastructure.Soap.LED.LedService ledService, INotification notification) { _commandBus = commandBus; _mapper = mapper; _taskProxy = taskProxy; _wcsRepository = wcsRepository; _ledService = ledService; _notification = notification; _commandBus = commandBus; } /// /// 处理程序 /// public override async Task Handle(AcceptInputSuccessEvent @event, CancellationToken cancellationToken) { if (@event.Function == "1") { string line1 = $"{@event.Barcode}上架通过"; string line2 = " "; string para = @event.Parameters; if (string.IsNullOrEmpty(@event.Parameters)) { para = @event.Para01; } else if(@event.Parameters == "0") { para = @event.Para01; } await _taskProxy.Infeed( @event.Device == "12002" ? 1 : 2, @event.Barcode, int.TryParse(@event.Parameters, out var p) ? p : null, $"device:{@event.Device}", null, null, -1, @event.Function, null, para); if (_notification.Any()) { if (string.IsNullOrEmpty(@event.Parameters) || !@event.Parameters.StartsWith("errorMessage:")) { @event.Fallback(new Models.Input { Warehouse = @event.Device == "12002" ? "1" : "2", Function = "5", Device = @event.Device, Barcode = @event.Barcode, State = 0, Remark = _notification.FirstOrDefault().ErrorMessage }); } else //!@event.Parameters.StartsWith("errorMessage:") { //检尺异常 电气自己回退,但会申请,主要是为了显示错误信息 } line1 = $"{@event.Barcode}上架失败"; line2 = $"{_notification.FirstOrDefault().ErrorMessage}"; } //LED提示 await _ledService.Invoke(@event.Device, line1, line2); } } } }