| | |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | private readonly IRepository<Dt_StockInfo> _stockInfoRepository; |
| | | private readonly IRepository<Dt_MaterialExpirationDate> _materialExpirationDateRepository; |
| | | private readonly IRepository<Dt_InboundOrder> _inboundRepository; |
| | | |
| | | public BigGreenService(IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_OutboundOrder> outBoundOrderRepository, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_OutboundOrderDetail> outBoundOrderDetailRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IRepository<Dt_Task_Hty> taskHtyRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_MaterialExpirationDate> materialExpirationDateRepository) |
| | | public BigGreenService(IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_OutboundOrder> outBoundOrderRepository, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_OutboundOrderDetail> outBoundOrderDetailRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IRepository<Dt_Task_Hty> taskHtyRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_MaterialExpirationDate> materialExpirationDateRepository,IRepository<Dt_InboundOrder> inboundRepository) |
| | | { |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _outBoundOrderRepository = outBoundOrderRepository; |
| | |
| | | _taskHtyRepository = taskHtyRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _materialExpirationDateRepository = materialExpirationDateRepository; |
| | | _inboundRepository = inboundRepository; |
| | | } |
| | | public WebResponseContent GetBigGreenData() |
| | | { |
| | |
| | | (int)OutOrderStatusEnum.åºåºä¸, |
| | | (int)OutOrderStatusEnum.æªå¼å§ |
| | | }; |
| | | var unOutBound = _outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => targetStatus.Contains(x.OrderStatus)).Count(); |
| | | var targetInStatus = new List<int> |
| | | { |
| | | (int)InOrderStatusEnum.å
¥åºä¸, |
| | | (int)InOrderStatusEnum.æªå¼å§ |
| | | }; |
| | | var unOutBound = _outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => targetStatus.Contains(x.OrderStatus) && x.CreateDate.ToString("MM-dd") == DateTime.Now.ToString("MM-dd")).Count(); |
| | | var unInBound = _inboundRepository.Db.Queryable<Dt_InboundOrder>().Where(x => targetInStatus.Contains(x.OrderStatus) && x.CreateDate.ToString("MM-dd") == DateTime.Now.ToString("MM-dd")).Count(); |
| | | |
| | | //计ç®åºä½å©ç¨ç |
| | | var freeLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus == (int)LocationStatusEnum.Free).Count(); |
| | | var inStockLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus == (int)LocationStatusEnum.InStock || x.LocationStatus == (int)LocationStatusEnum.Pallet).Count(); |
| | | int totalLocation = freeLocation + inStockLocation; |
| | | var totalLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Select(x=>x.Id).Count(); |
| | | var inStockLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus == (int)LocationStatusEnum.InStock).Count(); |
| | | decimal locationUtilizationRate = totalLocation == 0 |
| | | ? 0 |
| | | : Math.Round((decimal)inStockLocation / totalLocation, 4) * 100; |
| | |
| | | // 4. è·åè¿7æ¥æ¯æ¥åºå
¥åºæç»ï¼æ ¸å¿ä¿®æ¹ï¼è°ç¨ä¸é¢çæ¹æ³ï¼ |
| | | var dailyInOutBoundList = Get7DaysDailyInOutBound(); |
| | | |
| | | var nearExpirationList = GetMaterialsNearExpiration(); |
| | | List<StockInfoDetailExtDTO> nearExpirationList = GetMaterialsNearExpiration(); |
| | | //è·åä½ä¸ç»è®¡ |
| | | var completeTask = SimpleStatistics(); |
| | | //ä»»å¡ |
| | |
| | | InStockPallet = inStockPallet, |
| | | FreeStockPallet = freeStockPallet, |
| | | CompleteTask = completeTask, |
| | | NearExpirationList = nearExpirationList |
| | | NearExpirationList = nearExpirationList, |
| | | UnInBoundOrderCount = unInBound |
| | | }; |
| | | return WebResponseContent.Instance.OK(data: bigGreenData); |
| | | } |
| | |
| | | .ToList(); |
| | | |
| | | // 2. æ¥è¯¢æ¯æ¥åºåºæç»ï¼ææ¥æåç»ï¼ |
| | | var dailyOutboundList = _outBoundOrderDetailRepository.Db |
| | | .Queryable<Dt_OutboundOrderDetail>() |
| | | var dailyOutboundList = _outBoundOrderRepository.Db |
| | | .Queryable<Dt_OutboundOrder>() |
| | | .Where(x => x.CreateDate >= startDate |
| | | && x.CreateDate < endDate.AddDays(1)) |
| | | |
| | | .Select(x => new |
| | | { |
| | | Date = x.CreateDate.ToString("MM-dd"), |
| | | x.OverOutQuantity |
| | | x.OrderStatus |
| | | }) |
| | | .ToList() |
| | | .GroupBy(x => x.Date) |
| | | .ToDictionary(k => k.Key, g => g.Sum(x => (decimal?)x.OverOutQuantity) ?? 0); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | .ToDictionary(k => k.Key, g => g.Count(x => x.OrderStatus == (int)OutOrderStatusEnum.åºåºå®æ)); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | |
| | | // 3. æ¥è¯¢æ¯æ¥å
¥åºæç»ï¼ææ¥æåç»ï¼ |
| | | var dailyInboundList = _inboundOrderDetailRepository.Db |
| | | .Queryable<Dt_InboundOrderDetail>() |
| | | var dailyInboundList = _inboundRepository.Db |
| | | .Queryable<Dt_InboundOrder>() |
| | | .Where(x => x.CreateDate >= startDate |
| | | && x.CreateDate < endDate.AddDays(1)) |
| | | .Select(x => new |
| | | { |
| | | Date = x.CreateDate.ToString("MM-dd"), |
| | | x.OverInQuantity |
| | | x.OrderStatus |
| | | }) |
| | | .ToList() |
| | | .GroupBy(x => x.Date) |
| | | .ToDictionary(k => k.Key, g => g.Sum(x => (decimal?)x.OverInQuantity) ?? 0); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | .ToDictionary(k => k.Key, g => g.Count(x => x.OrderStatus == (int)InOrderStatusEnum.å
¥åºå®æ)); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | |
| | | // 4. åå¹¶æ¯æ¥æ°æ®ï¼ç¡®ä¿7å¤©æ¥æå®æ´ï¼æ æ°æ®è¡¥0ï¼ |
| | | var dailyInOutBoundList = all7Days.Select(date => new DailyInOutBoundDto |
| | |
| | | |
| | | public List<SimpleStatisticsDTO> SimpleStatistics() |
| | | { |
| | | DateTime sevenDaysAgo = DateTime.Now.AddDays(-7); |
| | | var today = DateTime.Now.Date; |
| | | var threeDaysAgo = today.AddDays(-3); |
| | | |
| | | var stats = _taskHtyRepository |
| | | .QueryData(x => x.TaskStatus == (int)TaskStatusEnum.Finish && x.CreateDate >= sevenDaysAgo) |
| | | .GroupBy(t => |
| | | (int)t.TaskType >= 100 && (int)t.TaskType <= 299 ? "åºåº" : |
| | | (int)t.TaskType >= 500 && (int)t.TaskType <= 699 ? "å
¥åº" : "å
¶ä»" |
| | | ) |
| | | .Where(g => g.Key == "åºåº" || g.Key == "å
¥åº") |
| | | .Select(g => new SimpleStatisticsDTO |
| | | { |
| | | TaskType = g.Key, |
| | | Count = g.Count() |
| | | }) |
| | | .ToList(); |
| | | var targetStatuses = new List<int> { (int)InOrderStatusEnum.å
¥åºä¸, (int)InOrderStatusEnum.æªå¼å§, |
| | | (int)OutOrderStatusEnum.æªå¼å§, (int)OutOrderStatusEnum.åºåºä¸ }; |
| | | var failReturnStatuses = new List<int> {4,2}; |
| | | |
| | | return stats; |
| | | var inboundToday = QueryInboundOrders(today, today, targetStatuses); |
| | | var outboundToday = QueryOutboundOrders(today, today, targetStatuses); |
| | | var inboundFail3Days = QueryInboundOrders(threeDaysAgo, today, failReturnStatuses, isReturnStatus: true); |
| | | var outboundFail3Days = QueryOutboundOrders(threeDaysAgo, today, failReturnStatuses, isReturnStatus: true); |
| | | |
| | | |
| | | return new List<SimpleStatisticsDTO> { new() |
| | | { |
| | | inboundOrders = inboundToday, |
| | | outboundOrders = outboundToday, |
| | | inboundReturnFailOrders = inboundFail3Days, |
| | | outboundReturnFailOrders = outboundFail3Days |
| | | }}; |
| | | } |
| | | |
| | | |
| | | private List<Dt_InboundOrder> QueryInboundOrders(DateTime startDate, DateTime endDate, |
| | | List<int> statusList, bool isReturnStatus = false) |
| | | { |
| | | return _inboundRepository.QueryData(x => |
| | | x.CreateDate.Date >= startDate && |
| | | x.CreateDate.Date <= endDate && |
| | | (isReturnStatus ? statusList.Contains(x.ReturnToMESStatus) : statusList.Contains(x.OrderStatus))).ToList(); |
| | | } |
| | | |
| | | |
| | | private List<Dt_OutboundOrder> QueryOutboundOrders(DateTime startDate, DateTime endDate, |
| | | List<int> statusList, bool isReturnStatus = false) |
| | | { |
| | | return _outBoundOrderRepository.QueryData(x => |
| | | x.CreateDate.Date >= startDate && |
| | | x.CreateDate.Date <= endDate && |
| | | (isReturnStatus ? statusList.Contains(x.ReturnToMESStatus) : statusList.Contains(x.OrderStatus))).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// å¾
åºåºè®¢åæ°éï¼åºåºä¸+æªå¼å§ï¼ |
| | | /// </summary> |
| | | public int UnOutBoundOrderCount { get; set; } |
| | | |
| | | public int UnInBoundOrderCount { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 空é²åºä½æ°é |
| | |
| | | |
| | | public List<SimpleStatisticsDTO> CompleteTask { get; set; } |
| | | |
| | | public NearExpirationDTO NearExpirationList { get; set; } |
| | | public List<StockInfoDetailExtDTO> NearExpirationList { get; set; } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | public class SimpleStatisticsDTO |
| | | { |
| | | public string TaskType { get; set; } |
| | | public int Count { get; set; } |
| | | public List<Dt_InboundOrder> inboundOrders { get; set; } |
| | | public List<Dt_OutboundOrder> outboundOrders { get; set; } |
| | | public List<Dt_InboundOrder> inboundReturnFailOrders { get; set; } |
| | | public List<Dt_OutboundOrder> outboundReturnFailOrders { get; set; } |
| | | } |
| | | |
| | | public class NearExpirationDTO |
| | | |
| | | public class StockInfoDetailExtDTO : Dt_StockInfoDetail |
| | | { |
| | | public int DaysToExpiration { get; set; } |
| | | |
| | | public List<Dt_StockInfoDetail> Details { get; set; } |
| | | |
| | | public string LocationCode { get; set; } |
| | | |
| | | public string PalletCode { get; set; } |
| | | public int DaysToExpiration { get; set; } |
| | | } |
| | | |
| | | ///<summary> |
| | | ///è·åè¿30天è¦è¿æçç©æ |
| | | /// </summary> |
| | | public NearExpirationDTO GetMaterialsNearExpiration() |
| | | public List<StockInfoDetailExtDTO> GetMaterialsNearExpiration() |
| | | { |
| | | // åå§åè¿åDTO |
| | | var resultDTO = new NearExpirationDTO |
| | | { |
| | | Details = new List<Dt_StockInfoDetail>(), |
| | | LocationCode = string.Empty, |
| | | PalletCode = string.Empty, |
| | | DaysToExpiration = 0 // åå§åå¤©æ° |
| | | }; |
| | | List<StockInfoDetailExtDTO> resultDTO = new List<StockInfoDetailExtDTO>(); |
| | | |
| | | DateTime currentTime = DateTime.Now; |
| | | DateTime thirtyDaysLater = currentTime.AddDays(30); |
| | | |
| | | // çé30天å
è¿æçåºåæç» |
| | | var nearExpirationList = _stockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>() |
| | | .Where(x => (x.ValidDate.Value - x.CreateDate).TotalDays <= 30) |
| | | var nearExpirationList = _stockInfoDetailRepository.QueryData() |
| | | .Join( |
| | | _stockInfoRepository.QueryData(), |
| | | detail => detail.StockId, |
| | | stock => stock.Id, |
| | | (detail, stock) => new |
| | | { |
| | | Detail = detail, |
| | | LocationCode = stock.LocationCode, |
| | | PalletCode = stock.PalletCode |
| | | } |
| | | ) |
| | | .Where(x => x.Detail.ValidDate.HasValue |
| | | && (x.Detail.ValidDate.Value - x.Detail.CreateDate).TotalDays <= 30) |
| | | .ToList(); |
| | | |
| | | // æ ç¬¦åæ¡ä»¶çæç»ï¼ç´æ¥è¿å |
| | | |
| | | if (!nearExpirationList.Any()) |
| | | { |
| | | return resultDTO; |
| | | } |
| | | |
| | | |
| | | var firstStockId = nearExpirationList.First().StockId; |
| | | |
| | | var stock = _stockInfoRepository.Db.Queryable<Dt_StockInfo>() |
| | | .First(x => x.Id == firstStockId); |
| | | |
| | | |
| | | if (stock == null) |
| | | foreach (var item in nearExpirationList) |
| | | { |
| | | return resultDTO; |
| | | } |
| | | int daysToExpire = item.Detail.ValidDate.HasValue |
| | | ? Math.Max(0, (item.Detail.ValidDate.Value - item.Detail.CreateDate).Days) |
| | | : 0; |
| | | |
| | | |
| | | resultDTO.LocationCode = stock.LocationCode; |
| | | resultDTO.PalletCode = stock.PalletCode; |
| | | |
| | | |
| | | int minDaysToExpiration = int.MaxValue; |
| | | foreach (var detail in nearExpirationList) |
| | | { |
| | | |
| | | TimeSpan totalDaysToExpiration = detail.ValidDate.Value - detail.CreateDate; |
| | | double remainingDays = totalDaysToExpiration.TotalDays; |
| | | int daysToExpiration = (int)Math.Ceiling(Math.Max(0, remainingDays)); |
| | | var extDetail = new StockInfoDetailExtDTO |
| | | { |
| | | MaterielCode = item.Detail.MaterielCode, |
| | | MaterielName = item.Detail.MaterielName, |
| | | BatchNo = item.Detail.BatchNo, |
| | | SupplyCode = item.Detail.SupplyCode, |
| | | StockQuantity = item.Detail.StockQuantity, |
| | | CreateDate = item.Detail.CreateDate, |
| | | ValidDate = item.Detail.ValidDate, |
| | | LocationCode = item.LocationCode, |
| | | PalletCode = item.PalletCode, |
| | | Barcode = item.Detail.Barcode, |
| | | DaysToExpiration = daysToExpire |
| | | }; |
| | | |
| | | |
| | | if (daysToExpiration < minDaysToExpiration) |
| | | { |
| | | minDaysToExpiration = daysToExpiration; |
| | | } |
| | | |
| | | |
| | | resultDTO.Details.Add(detail); |
| | | resultDTO.Add(extDetail); |
| | | } |
| | | |
| | | |
| | | resultDTO.DaysToExpiration = minDaysToExpiration; |
| | | resultDTO = resultDTO.OrderBy(d => d.DaysToExpiration).ToList(); |
| | | |
| | | return resultDTO; |
| | | } |