using JSMachine.WMS.App.Dto.Enum; using JSMachine.WMS.App.IService; using JSMachine.WMS.RPC.ErpRPC.Dto.Out; using JSMachine.WMS.WebHost.Models; using Microsoft.AspNetCore.Mvc; namespace JSMachine.WMS.WebHost.Controllers { [Route("api/[controller]/[action]")] public class StatisticController: ControllerBase { private IStorageRackService _storageRackService; private IAGVTaskService _agvTaskService; private IERPTaskService _erptaskService; public StatisticController(IStorageRackService storageRackService, IAGVTaskService agvTaskService, IERPTaskService erptaskService) { _storageRackService = storageRackService; _agvTaskService = agvTaskService; _erptaskService = erptaskService; } [HttpPost] public async Task> GetStockInAndOutStatistic() { int stockInCount = await _erptaskService.Count(p => p.CreationTime > DateTime.Now.Date && (p.TaskType == TaskTypeEnum.PdaIn || p.TaskType == TaskTypeEnum.TailIn) ); int stockOutCount = await _agvTaskService.Count(p => p.CreationTime > DateTime.Now.Date && (p.TaskType == TaskTypeEnum.SaleOut || p.TaskType == TaskTypeEnum.ProductionOut) && p.Floor == FloorEnum.FirstFloor ); int allGoodsCount = await _storageRackService.Count(p => p.Floor == FloorEnum.SecondFloor && p.Transport == TransportEnum.NormalArea && !string.IsNullOrEmpty(p.BarCode) ); int emptyStorageCount = await _storageRackService.Count(p => p.Floor == FloorEnum.SecondFloor && p.Transport == TransportEnum.NormalArea && string.IsNullOrEmpty(p.BarCode) ); decimal storageRackeUsedRatio = (allGoodsCount) * 100m / (allGoodsCount+emptyStorageCount); return new ApiResult { ResultCode="200", Data = new StockInAndOutStatisticInfo { StockInCount = stockInCount, StockOutCount = stockOutCount, AllGoodsCount = allGoodsCount, EmptyStorageCount = emptyStorageCount, StorageRackeUsedRatio = Math.Floor(storageRackeUsedRatio) } }; } } }