From fac71280bbbda8d7a3b068d1cfaa49ac540eb7ae Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 22 三月 2025 11:31:36 +0800
Subject: [PATCH] 移除 Redis缓存 添加 MyBackgroundService 以定期处理库存任务

---
 CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs |   64 ++++++++++---------------------
 1 files changed, 21 insertions(+), 43 deletions(-)

diff --git a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
index 721f077..22d1772 100644
--- a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
+++ b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -540,15 +540,6 @@
         {
             if (stationManager.stationType != 7) throw new Exception("閿欒鐨勮皟鍙�");
 
-            // 浠庣紦瀛樹腑鑾峰彇搴撳瓨淇℃伅
-            //IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
-            //List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
-
-            //var stockinfo1 = stockInfoList.OrderBy(x => x.CreateDate)
-            //    .ToList();
-            //var strings = stationManager.Roadway.Split(",");
-            //var stockinfo = stockinfo1.Where(x => x.LocationInfo != null && !x.IsFull && strings.Contains(x.LocationInfo.RoadwayNo))
-            //    .FirstOrDefault();
             var stockInfo = await QueryStockInfoForEmptyTrayFRAsync("CWSC1", "10086", input.ProductionLine);
 
             if (stockInfo == null) return null;
@@ -571,7 +562,6 @@
                 Creater = "System",
                 ProductionLine = stockInfo.ProductionLine,
             };
-            _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { task.PalletCode });
             return task;
         }
         catch (Exception ex)
@@ -981,24 +971,18 @@
             .Where(x => stackers.Contains(x.DeviceCode))
             .ToList().Select(x => x.DeviceCode).ToList();
 
-        // 浠庣紦瀛樹腑鑾峰彇搴撳瓨淇℃伅
-        IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
-        List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
+        var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
+                                .IncludesAllFirstLayer().Where(x => x.ProductionLine == productLine)
+                                .Where(x => x.AreaCode == areaCode && x.IsFull == false)
+                                .Where(x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => y.MaterielCode == "绌烘墭鐩�"))
+                                .WhereIF(!deviceCode.IsNullOrEmpty(), x => x.LocationInfo != null && deviceCode.Contains(x.LocationInfo.RoadwayNo))
+                                .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢
+                                .OrderBy(x => x.CreateDate) // 鎺掑簭
+                                .FirstAsync();
 
-        var result1 = stockInfoList.Where(x => x.ProductionLine == productLine)
-            .Where(x => x.AreaCode == areaCode && x.IsFull == false)
-            .WhereIF(!deviceCode.IsNullOrEmpty(), x => x.LocationInfo != null && deviceCode.Contains(x.LocationInfo.RoadwayNo))
-            .OrderBy(x => x.CreateDate) // 鎺掑簭
-            .ToList(); // 杞崲涓哄垪琛�
-
-        var result = result1.Where(x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => y.MaterielCode == "绌烘墭鐩�"))
-            .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢
-            .FirstOrDefault(); // 鑾峰彇绗竴涓厓绱�
-
-        if (result != null)
-            _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode });
-        else
+        if (result.IsNullOrEmpty())
             ConsoleHelper.WriteColorLine($"甯告俯{productLine}绌烘墭鐩樺簱瀛樹笉瓒�", ConsoleColor.Red);
+
 
         return result;
     }
@@ -1028,25 +1012,20 @@
                 .Where(x => x.DeviceCode.Contains("CWSC")) // 杩囨护鏉′欢
                 .ToList().Select(x => x.DeviceCode).ToList();
 
-            // 浠庣紦瀛樹腑鑾峰彇搴撳瓨淇℃伅
-            IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
-            List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
 
             // 淇敼鍚庣殑鏌ヨ浠g爜
-            var stockInfo1 = stockInfoList
-                .Where(x => x.ProductionLine == station.productLine)
-                .Where(x => x.AreaCode == "CWSC3" && x.IsFull == true)
-                .OrderBy(x => x.OutboundTime)
-                .ToList();
+            var stockInfo = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
+                                .IncludesAllFirstLayer()
+                                .Where(x => x.ProductionLine == station.productLine)
+                                .Where(x => x.AreaCode == "CWSC3" && x.IsFull == true)
+                                // 澧炲姞瀵� LocationInfo 鐨勭┖鍊兼鏌�
+                                .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock)
+                                // 澧炲姞瀵� LocationInfo 鐨勭┖鍊兼鏌�
+                                .WhereIF(!deviceCode.IsNullOrEmpty(), x => x.LocationInfo != null && deviceCode.Contains(x.LocationInfo.RoadwayNo))
+                                .OrderBy(x => x.OutboundTime)
+                                .FirstAsync();
 
-            var stockInfo = stockInfo1
-                // 澧炲姞瀵� LocationInfo 鐨勭┖鍊兼鏌�
-                .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock)
-                // 澧炲姞瀵� LocationInfo 鐨勭┖鍊兼鏌�
-                .WhereIF(!deviceCode.IsNullOrEmpty(), x => x.LocationInfo != null && deviceCode.Contains(x.LocationInfo.RoadwayNo))
-                .FirstOrDefault();
-
-            if (stockInfo == null) throw new Exception($"搴撳唴{station.productLine}鏃犳弧瓒虫潯浠剁殑搴撳瓨鍙嚭搴�");
+            if (stockInfo.IsNullOrEmpty()) throw new Exception($"搴撳唴{station.productLine}鏃犳弧瓒虫潯浠剁殑搴撳瓨鍙嚭搴�");
 
             DtLocationInfo locationInfo = _locationRepository.QueryFirst(x => x.AreaId == 5 && x.LocationCode == stockInfo.LocationCode);
 
@@ -1081,7 +1060,6 @@
             stockInfo.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable;
             _locationRepository.UpdateData(stockInfo.LocationInfo);
 
-            _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { taskDTO.PalletCode });
 
             _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(stockInfo.LocationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum);
 

--
Gitblit v1.9.3