using JSMachine.WMS.App.Dto; using JSMachine.WMS.App.Dto.Enum; using JSMachine.WMS.App.IService; using JSMachine.WMS.Domain.Entity; using JSMachine.WMS.Infrastructure; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JSMachine.WMS.Business.StockIn.ServiceImpl.ResponsibilityChain { /// /// 责任链模式。入库处理基类 。责任流动方向:StockInByExist=》StockInByNew=》StockInByMixing /// public abstract class StockInHandler { protected StockInHandler _nextHandler; protected static IStorageRackService _storageRackService = GlobalServericeProvidor.GetService(); protected static IAGVTaskService _agvTaskService = GlobalServericeProvidor.GetService(); protected static IERPTaskService _erpTaskService = GlobalServericeProvidor.GetService(); protected static IStorageRackService StorageRackService = GlobalServericeProvidor.GetService(); protected static readonly SemaphoreSlim _SemaphoreSlim = new(1,1); public void SetNextHandler(StockInHandler nextHandler) { _nextHandler = nextHandler; } /// /// 计算目标库位 /// /// 起点 /// 批次 /// 所有未禁用的库位 /// public abstract Task CalculateWarehouse( TransportEnum startArea, FloorEnum floor, string materialBatch, List storageRacks); /// /// 有下一个处理者,则继续执行下一个处理者的逻辑 /// /// 起点 /// 批次 /// 所有未禁用的库位 /// public async Task HandleByNext( TransportEnum startArea, FloorEnum floor, string materialBatch, List storageRacks) { if (_nextHandler != null) { return await _nextHandler.CalculateWarehouse(startArea, floor, materialBatch, storageRacks); } else { return null; } } public async Task> GetStorageRackExceptStockout(FloorEnum floor) { List storageRacks = await StorageRackService.GetListByExpression(p => p.Floor == floor && p.Transport == TransportEnum.NormalArea); if(storageRacks.IsNullOrEmpty()) { return null; } List erpTaskStockOuts = await _erpTaskService .GetListByExpression(p => p.CreationTime > DateTime.Now.AddDays(-1) && p.TaskStatus == TaskStatusEnum.InExecution && (p.TaskType == TaskTypeEnum.SaleOut || p.TaskType == TaskTypeEnum.ProductionOut) ); if (!erpTaskStockOuts.IsNullOrEmpty()) { List agvTaks = await _agvTaskService.GetListByExpression(p => p.CreationTime > DateTime.Now.AddDays(-1) && erpTaskStockOuts.Select(x => x.Id).Contains(p.ErpTaskId) ); if (!agvTaks.IsNullOrEmpty()) { List startStorageRacks = await StorageRackService.GetListByExpression(p => agvTaks.Select(x => x.StartPositionCode).Contains(p.StorageRackNo)); List exceptCols = startStorageRacks.Select(p => p.ReservoirAreaColumnId).Distinct().ToList(); storageRacks.RemoveAll(p => exceptCols.Contains(p.ReservoirAreaColumnId)); } } return storageRacks; } } }