using Kean.Domain.Task.Commands; using Kean.Domain.Task.Models; using Kean.Domain.Task.Repositories; using Kean.Domain.Task.SharedServices.Proxies; using Kean.Infrastructure.Configuration; using System.Linq; using System.Threading.Tasks; namespace Kean.Domain.Task.Strategies { /// /// 简单避让策略 /// public sealed class AvertStrategy_Simple : AvertStrategy { private readonly IWarehouseRepository _warehouseRepository; // 库房仓库 private readonly BarcodeInterpreter _barcodeInterpreter; // 条码解释器 private readonly StockProxy _stockProxy; // 仓储域代理 /// /// 依赖注入 /// public AvertStrategy_Simple( IWarehouseRepository warehouseRepository, BarcodeInterpreter barcodeInterpreter, StockProxy stockProxy) { _warehouseRepository = warehouseRepository; _barcodeInterpreter = barcodeInterpreter; _stockProxy = stockProxy; } /* * 实现 Kean.Domain.Task.Strategies.AvertStrategy.AutoCommand 方法 */ public override async Task AutoCommand(Cell cell) { var barcode = await _stockProxy.GetBarcode(cell.Id); if (barcode == null) { return new(); } else { var spec = await _stockProxy.GetSpec(barcode) ?? cell.Spec; var pallet = await _barcodeInterpreter.Interpret(barcode); var goodsid = await _stockProxy.GetStorageMaterial(barcode); var destination = (await _warehouseRepository.GetFreeCell(cell.Laneway, spec, pallet, goodsid)) .OrderByDescending(c => c.Deep) .ThenBy(r=>r.Row) .ThenBy(r=>r.Column) .FirstOrDefault(); return new() { Barcode = barcode, Destination = destination, Warehouse = destination == null ? 0 : destination.Warehouse }; } } } }