| | |
| | | } |
| | | public IRepository<Dt_InventoryInfo> Repository => BaseDal; |
| | | |
| | | public WebResponseContent GetExpiredAndlow() |
| | | { |
| | | try |
| | | { |
| | | // è·åå½åæ¶é´ï¼åªåæ¥æé¨åï¼å¿½ç¥æ¶é´ï¼ |
| | | DateTime currentDate = DateTime.Today; |
| | | // 计ç®30天åçæ¥æ |
| | | DateTime thresholdDate = currentDate.AddDays(30); |
| | | |
| | | // æ¥æ¾åºå䏿æåå |
| | | var inventoryList = BaseDal.QueryData(); |
| | | var expiredSoonList = new List<object>(); |
| | | |
| | | foreach (var item in inventoryList) |
| | | { |
| | | // æ£æ¥ValidityPeriodæ¯å¦ä¸ºç©º |
| | | if (string.IsNullOrEmpty(item.ValidityPeriod)) |
| | | continue; |
| | | |
| | | // 使ç¨ç²¾ç¡®æ ¼å¼è§£æ "2037-10-02" |
| | | if (DateTime.TryParseExact(item.ValidityPeriod.Trim(), "yyyy-MM-dd", |
| | | System.Globalization.CultureInfo.InvariantCulture, |
| | | System.Globalization.DateTimeStyles.None, out DateTime expiryDate)) |
| | | { |
| | | // 计ç®å©ä½å¤©æ°ï¼åªæ¯è¾æ¥æé¨åï¼ |
| | | double daysRemaining = (expiryDate - currentDate).TotalDays; |
| | | |
| | | // æ£æ¥æ¯å¦å¨30天å
ï¼å
æ¬å·²è¿æçï¼ |
| | | if (daysRemaining <= 30) |
| | | { |
| | | expiredSoonList.Add(new |
| | | { |
| | | MaterielCode = item.MaterielCode ?? "", |
| | | BatchNo = item.BatchNo ?? "", |
| | | ValidityPeriod = item.ValidityPeriod, |
| | | ExpiryDate = expiryDate.ToString("yyyy-MM-dd"), |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // è®°å½è§£æå¤±è´¥çè®°å½ï¼ç¨äºè°è¯ï¼ |
| | | Console.WriteLine($"æ æ³è§£æææ: {item.ValidityPeriod}"); |
| | | } |
| | | } |
| | | |
| | | // æå©ä½å¤©æ°ååºæåï¼å³å°è¿æçæåé¢ï¼ |
| | | var sortedList = expiredSoonList.OrderBy(x => |
| | | { |
| | | var days = (int)((dynamic)x).DaysRemaining; |
| | | return days; |
| | | }).ToList(); |
| | | |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Message = $"åç° {sortedList.Count} 个ååå°å¨30天å
è¿æ", |
| | | Data = new |
| | | { |
| | | TotalCount = sortedList.Count, |
| | | ExpiredCount = sortedList.Count(x => ((dynamic)x).DaysRemaining < 0), |
| | | WarningCount = sortedList.Count(x => ((dynamic)x).DaysRemaining >= 0), |
| | | CheckDate = currentDate.ToString("yyyy-MM-dd"), |
| | | Items = sortedList |
| | | } |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return new WebResponseContent |
| | | { |
| | | Status = false, |
| | | Message = $"è·åæææ°æ®å¤±è´¥: {ex.Message}" |
| | | }; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·ååºå |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |