using Kean.Domain.Task.Commands; using Kean.Domain.Task.Repositories; using Kean.Domain.Task.SharedServices.Proxies; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace Kean.Domain.Task.SharedServices { /// /// 申请空托盘出库 /// public sealed class ApplyOut { private readonly ICommandBus _commandBus; private readonly IWarehouseRepository _warehouseRepository; // 库房仓库 private readonly MaterialProxy _materialProxy; // 物料服务 /// /// 依赖注入 /// public ApplyOut(ICommandBus commandBus, MaterialProxy materialProxy, IWarehouseRepository warehouseRepository) { _commandBus = commandBus; _materialProxy = materialProxy; _warehouseRepository = warehouseRepository; } /// /// 处理程序 /// public async System.Threading.Tasks.Task Handler( string warehouseCode, string deviceCode, string barcode, string tag, CancellationToken cancellationToken) { Models.Station strion = await _warehouseRepository.GetStationByDevice(deviceCode, Convert.ToInt32(warehouseCode)); List lsGoods = new List(); var sGoods = await _materialProxy.GetMaterial(null, strion.Pallet.First(), false); Models.Material goods = JsonConvert.DeserializeObject(sGoods); if (goods == null) { await _commandBus.Notify(nameof(deviceCode), $"未找到站台({deviceCode})对应的托盘类型信息,请联系管理员", deviceCode, cancellationToken: cancellationToken); return; } lsGoods.Add(goods.Id); await _commandBus.Execute(new ApplyOutCommand { Warehouse = strion.Warehouse, //RequestNo = requestNo, Operator = -1, Tag = tag, Destination = $"device:{deviceCode}", Priority = 0, Manual = false, Transaction = "PalletOut", Materials = lsGoods, Qty = 1, Qc ="ok", enable = true, IsLocal="1" }); } } }