From 64840e4e6d97d177b8a765ba8c53888abcf86d16 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 13 一月 2026 18:48:20 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs |   98 +++++++++++++++++++++---------------------------
 1 files changed, 43 insertions(+), 55 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs"
index 2c3797e..f533a7f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/BigGreenService/BigGreenService.cs"
@@ -58,7 +58,7 @@
 
             //璁$畻搴撲綅鍒╃敤鐜�
             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 inStockLocation = _locationInfoRepository.Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationStatus != (int)LocationStatusEnum.Free).Count();
             int totalLocation = freeLocation + inStockLocation;
             decimal locationUtilizationRate = totalLocation == 0
                 ? 0
@@ -75,7 +75,7 @@
             // 4. 鑾峰彇杩�7鏃ユ瘡鏃ュ嚭鍏ュ簱鏄庣粏锛堟牳蹇冧慨鏀癸細璋冪敤涓婇潰鐨勬柟娉曪級
             var dailyInOutBoundList = Get7DaysDailyInOutBound();
 
-            var nearExpirationList = GetMaterialsNearExpiration();
+            List<StockInfoDetailExtDTO> nearExpirationList = GetMaterialsNearExpiration();
             //鑾峰彇浣滀笟缁熻
             var completeTask = SimpleStatistics();
             //浠诲姟
@@ -239,7 +239,7 @@
 
             public List<SimpleStatisticsDTO> CompleteTask { get; set; }
 
-            public NearExpirationDTO NearExpirationList { get; set; }
+            public List<StockInfoDetailExtDTO> NearExpirationList { get; set; }
         }
 
         /// <summary>
@@ -270,82 +270,70 @@
             public int Count { 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()
         {
-            // 鍒濆鍖栬繑鍥濪TO
-            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;
         }

--
Gitblit v1.9.3