| | |
| | | using IBigBreenService; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | using WIDESEA_Common.TaskEnum; |
| | | using WIDESEA_Core; |
| | | 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; |
| | | 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) |
| | | 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; |
| | |
| | | _taskRepository = taskRepository; |
| | | _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; |
| | | : Math.Round((decimal)inStockLocation / totalLocation, 4) * 100; |
| | | |
| | | //计ç®å
¥åºä»»å¡ååºåºä»»å¡å®ææ°é |
| | | var inboundCount =_taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 500 && x.TaskType < 900).Count(); |
| | | var outboundCount =_taskHtyRepository.Db.Queryable<Dt_Task_Hty>().Where(x => x.TaskType >= 100 && x.TaskType < 500).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).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).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(); |
| | | |
| | | List<StockInfoDetailExtDTO> nearExpirationList = GetMaterialsNearExpiration(); |
| | | //è·åä½ä¸ç»è®¡ |
| | | var completeTask = SimpleStatistics(); |
| | | //ä»»å¡ |
| | | List<Dt_Task> tasks = _taskRepository.QueryData(); |
| | | |
| | | var bigGreenData = new BigGreenDataDto |
| | | { |
| | | TotalStockQuantity=totalStockQuantity, |
| | | TotalStockQuantity = totalStockQuantity, |
| | | UnOutBoundOrderCount = unOutBound, |
| | | LocationUtilizationRate = locationUtilizationRate, |
| | | DailyInOutBoundList = dailyInOutBoundList, |
| | |
| | | InboundCount = inboundCount, |
| | | OutboundCount = outboundCount, |
| | | InStockPallet = inStockPallet, |
| | | FreeStockPallet = freeStockPallet |
| | | FreeStockPallet = freeStockPallet, |
| | | CompleteTask = completeTask, |
| | | 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)) |
| | | .GroupBy(x => x.CreateDate) // ææ¥ææ ¼å¼ååç» |
| | | .Select(x => new |
| | | { |
| | | Date = x.CreateDate.ToString( "MM-dd"), |
| | | DailyOutbound = SqlFunc.AggregateSum((decimal?)x.OverOutQuantity) ?? 0 |
| | | }) |
| | | .ToList() |
| | | .ToDictionary(k => k.Date, v => v.DailyOutbound); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | |
| | | // 3. æ¥è¯¢æ¯æ¥å
¥åºæç»ï¼ææ¥æåç»ï¼ |
| | | var dailyInboundList = _inboundOrderDetailRepository.Db |
| | | .Queryable<Dt_InboundOrderDetail>() |
| | | .Where(x => x.CreateDate != null // è¿æ»¤ç©ºæ¥æ |
| | | && x.CreateDate >= startDate |
| | | && x.CreateDate < endDate.AddDays(1)) |
| | | .GroupBy(x => x.CreateDate).Distinct() // ææ¥ææ ¼å¼ååç» |
| | | .Select(x => new |
| | | { |
| | | Date = x.CreateDate.ToString("MM-dd"), |
| | | DailyInbound = SqlFunc.AggregateSum((decimal?)x.OverInQuantity) ?? 0 |
| | | x.OrderStatus |
| | | }) |
| | | .ToList() |
| | | .ToDictionary(k => k.Date, v => v.DailyInbound); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | .GroupBy(x => x.Date) |
| | | .ToDictionary(k => k.Key, g => g.Count(x => x.OrderStatus == (int)OutOrderStatusEnum.åºåºå®æ)); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | |
| | | // 3. æ¥è¯¢æ¯æ¥å
¥åºæç»ï¼ææ¥æåç»ï¼ |
| | | 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.OrderStatus |
| | | }) |
| | | .ToList() |
| | | .GroupBy(x => x.Date) |
| | | .ToDictionary(k => k.Key, g => g.Count(x => x.OrderStatus == (int)InOrderStatusEnum.å
¥åºå®æ)); // 转为åå
¸æ¹ä¾¿å¹é
|
| | | |
| | | // 4. åå¹¶æ¯æ¥æ°æ®ï¼ç¡®ä¿7å¤©æ¥æå®æ´ï¼æ æ°æ®è¡¥0ï¼ |
| | | var dailyInOutBoundList = all7Days.Select(date => new DailyInOutBoundDto |
| | |
| | | Date = date, |
| | | DailyOutboundQuantity = dailyOutboundList.ContainsKey(date) ? dailyOutboundList[date] : 0, |
| | | DailyInboundQuantity = dailyInboundList.ContainsKey(date) ? dailyInboundList[date] : 0, |
| | | |
| | | |
| | | }).ToList(); |
| | | |
| | | return dailyInOutBoundList; |
| | | } |
| | | |
| | | |
| | | public List<SimpleStatisticsDTO> SimpleStatistics() |
| | | { |
| | | var today = DateTime.Now.Date; |
| | | var threeDaysAgo = today.AddDays(-3); |
| | | |
| | | var targetStatuses = new List<int> { (int)InOrderStatusEnum.å
¥åºä¸, (int)InOrderStatusEnum.æªå¼å§, |
| | | (int)OutOrderStatusEnum.æªå¼å§, (int)OutOrderStatusEnum.åºåºä¸ }; |
| | | var failReturnStatuses = new List<int> {4,2}; |
| | | |
| | | 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> |
| | | /// 大å±/æ±æ»æ°æ®è¿åDTOï¼å¤§ç»¿æ°æ®æ±æ»ï¼ |
| | |
| | | /// å¾
åºåºè®¢åæ°éï¼åºåºä¸+æªå¼å§ï¼ |
| | | /// </summary> |
| | | public int UnOutBoundOrderCount { get; set; } |
| | | |
| | | public int UnInBoundOrderCount { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 空é²åºä½æ°é |
| | |
| | | /// <summary> |
| | | /// è¿7æ¥åå
¥åºéï¼å
¥åº-åºåºï¼ |
| | | /// </summary> |
| | | public decimal totalStockChangeRate { get; set; } |
| | | public decimal TotalStockChangeRate { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡å表 |
| | |
| | | public int InStockPallet { get; set; } |
| | | |
| | | public int FreeStockPallet { get; set; } |
| | | |
| | | public List<SimpleStatisticsDTO> CompleteTask { get; set; } |
| | | |
| | | public List<StockInfoDetailExtDTO> NearExpirationList { get; set; } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | } |
| | | |
| | | public class SimpleStatisticsDTO |
| | | { |
| | | 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 StockInfoDetailExtDTO : Dt_StockInfoDetail |
| | | { |
| | | public string LocationCode { get; set; } |
| | | public string PalletCode { get; set; } |
| | | public int DaysToExpiration { get; set; } |
| | | } |
| | | |
| | | ///<summary> |
| | | ///è·åè¿30天è¦è¿æçç©æ |
| | | /// </summary> |
| | | public List<StockInfoDetailExtDTO> GetMaterialsNearExpiration() |
| | | { |
| | | List<StockInfoDetailExtDTO> resultDTO = new List<StockInfoDetailExtDTO>(); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | foreach (var item in nearExpirationList) |
| | | { |
| | | int daysToExpire = item.Detail.ValidDate.HasValue |
| | | ? Math.Max(0, (item.Detail.ValidDate.Value - item.Detail.CreateDate).Days) |
| | | : 0; |
| | | |
| | | 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 |
| | | }; |
| | | |
| | | |
| | | resultDTO.Add(extDetail); |
| | | } |
| | | |
| | | resultDTO = resultDTO.OrderBy(d => d.DaysToExpiration).ToList(); |
| | | |
| | | return resultDTO; |
| | | } |
| | | } |
| | | } |