| | |
| | | using IBigBreenService; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | |
| | | namespace BigGreenService |
| | | { |
| | |
| | | private readonly IRepository<Dt_Task_Hty> _taskHtyRepository; |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | private readonly IRepository<Dt_StockInfo> _stockInfoRepository; |
| | | private readonly 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) |
| | | 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) |
| | | { |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _outBoundOrderRepository = outBoundOrderRepository; |
| | |
| | | _taskRepository = taskRepository; |
| | | _taskHtyRepository = taskHtyRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _materialExpirationDateRepository = materialExpirationDateRepository; |
| | | } |
| | | public WebResponseContent GetBigGreenData() |
| | | { |
| | |
| | | (int)OutOrderStatusEnum.åºåºä¸, |
| | | (int)OutOrderStatusEnum.æªå¼å§ |
| | | }; |
| | | var unOutBound =_outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x =>targetStatus.Contains(x.OrderStatus)).Count(); |
| | | var unOutBound = _outBoundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => targetStatus.Contains(x.OrderStatus)).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(); |
| | | 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; |
| | | decimal locationUtilizationRate = totalLocation == 0 |
| | | ? 0 |
| | | : Math.Round((decimal)inStockLocation / totalLocation, 4)*100; |
| | | : Math.Round((decimal)inStockLocation / totalLocation, 4) * 100; |
| | | |
| | | //计ç®å
¥åºä»»å¡ååºåºä»»å¡å®ææ°é |
| | | var inboundCount =_taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 500 && x.TaskType < 900 && x.CreateDate.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).Count(); |
| | | var outboundCount =_taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 100 && x.TaskType < 500 && x.CreateDate.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).Count(); |
| | | var inboundCount = _taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 500 && x.TaskType < 900 && x.CreateDate.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).Count(); |
| | | var outboundCount = _taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 100 && x.TaskType < 500 && x.CreateDate.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")).Count(); |
| | | |
| | | //è®¡ç®æè´§æç®±æ°é |
| | | var inStockPallet = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType ==(int) PalletTypeEnum.None && !string.IsNullOrEmpty(x.LocationCode)).Count(); |
| | | var inStockPallet = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == (int)PalletTypeEnum.None && !string.IsNullOrEmpty(x.LocationCode)).Count(); |
| | | //计ç®ç©ºç®±æ°é |
| | | var freeStockPallet = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == (int)PalletTypeEnum.Empty && !string.IsNullOrEmpty(x.LocationCode)).Count(); |
| | | // 4. è·åè¿7æ¥æ¯æ¥åºå
¥åºæç»ï¼æ ¸å¿ä¿®æ¹ï¼è°ç¨ä¸é¢çæ¹æ³ï¼ |
| | | var dailyInOutBoundList = Get7DaysDailyInOutBound(); |
| | | |
| | | var nearExpirationList = GetMaterialsNearExpiration(); |
| | | //è·åä½ä¸ç»è®¡ |
| | | var completeTask = SimpleStatistics(); |
| | | //ä»»å¡ |
| | |
| | | |
| | | var bigGreenData = new BigGreenDataDto |
| | | { |
| | | TotalStockQuantity=totalStockQuantity, |
| | | TotalStockQuantity = totalStockQuantity, |
| | | UnOutBoundOrderCount = unOutBound, |
| | | LocationUtilizationRate = locationUtilizationRate, |
| | | DailyInOutBoundList = dailyInOutBoundList, |
| | |
| | | OutboundCount = outboundCount, |
| | | InStockPallet = inStockPallet, |
| | | FreeStockPallet = freeStockPallet, |
| | | CompleteTask = completeTask |
| | | CompleteTask = completeTask, |
| | | NearExpirationList = nearExpirationList |
| | | }; |
| | | return WebResponseContent.Instance.OK(data: bigGreenData); |
| | | } |
| | |
| | | }) |
| | | .ToList() |
| | | .GroupBy(x => x.Date) |
| | | .ToDictionary(k => k.Key , g => g.Sum(x => (decimal?)x.OverOutQuantity) ?? 0); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | .ToDictionary(k => k.Key, g => g.Sum(x => (decimal?)x.OverOutQuantity) ?? 0); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | |
| | | // 3. æ¥è¯¢æ¯æ¥å
¥åºæç»ï¼ææ¥æåç»ï¼ |
| | | var dailyInboundList = _inboundOrderDetailRepository.Db |
| | | .Queryable<Dt_InboundOrderDetail>() |
| | | .Where(x => x.CreateDate != null // è¿æ»¤ç©ºæ¥æ |
| | | && x.CreateDate >= startDate |
| | | .Where(x => x.CreateDate >= startDate |
| | | && x.CreateDate < endDate.AddDays(1)) |
| | | .Select(x => new |
| | | { |
| | |
| | | x.OverInQuantity |
| | | }) |
| | | .ToList() |
| | | .GroupBy(x=>x.Date) |
| | | .GroupBy(x => x.Date) |
| | | .ToDictionary(k => k.Key, g => g.Sum(x => (decimal?)x.OverInQuantity) ?? 0); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | |
| | | // 4. åå¹¶æ¯æ¥æ°æ®ï¼ç¡®ä¿7å¤©æ¥æå®æ´ï¼æ æ°æ®è¡¥0ï¼ |
| | |
| | | Date = date, |
| | | DailyOutboundQuantity = dailyOutboundList.ContainsKey(date) ? dailyOutboundList[date] : 0, |
| | | DailyInboundQuantity = dailyInboundList.ContainsKey(date) ? dailyInboundList[date] : 0, |
| | | |
| | | |
| | | }).ToList(); |
| | | |
| | | return dailyInOutBoundList; |
| | |
| | | (int)t.TaskType >= 100 && (int)t.TaskType <= 299 ? "åºåº" : |
| | | (int)t.TaskType >= 500 && (int)t.TaskType <= 699 ? "å
¥åº" : "å
¶ä»" |
| | | ) |
| | | .Where(g => g.Key == "åºåº" || g.Key == "å
¥åº") |
| | | .Where(g => g.Key == "åºåº" || g.Key == "å
¥åº") |
| | | .Select(g => new SimpleStatisticsDTO |
| | | { |
| | | TaskType = g.Key, |
| | |
| | | public int FreeStockPallet { get; set; } |
| | | |
| | | public List<SimpleStatisticsDTO> CompleteTask { get; set; } |
| | | |
| | | public NearExpirationDTO NearExpirationList { get; set; } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public int Count { get; set; } |
| | | } |
| | | |
| | | public class NearExpirationDTO |
| | | { |
| | | public int DaysToExpiration { get; set; } |
| | | |
| | | public List<Dt_StockInfoDetail> Details { get; set; } |
| | | |
| | | public string LocationCode { get; set; } |
| | | |
| | | public string PalletCode { get; set; } |
| | | } |
| | | |
| | | ///<summary> |
| | | ///è·åè¿30天è¦è¿æçç©æ |
| | | /// </summary> |
| | | public NearExpirationDTO GetMaterialsNearExpiration() |
| | | { |
| | | // åå§åè¿åDTO |
| | | var resultDTO = new NearExpirationDTO |
| | | { |
| | | Details = new List<Dt_StockInfoDetail>(), |
| | | LocationCode = string.Empty, |
| | | PalletCode = string.Empty, |
| | | DaysToExpiration = 0 // åå§åå¤©æ° |
| | | }; |
| | | |
| | | 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) |
| | | .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) |
| | | { |
| | | return resultDTO; |
| | | } |
| | | |
| | | |
| | | 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)); |
| | | |
| | | |
| | | if (daysToExpiration < minDaysToExpiration) |
| | | { |
| | | minDaysToExpiration = daysToExpiration; |
| | | } |
| | | |
| | | |
| | | resultDTO.Details.Add(detail); |
| | | } |
| | | |
| | | |
| | | resultDTO.DaysToExpiration = minDaysToExpiration; |
| | | |
| | | return resultDTO; |
| | | } |
| | | } |
| | | } |