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/AspNetCoreSchedule.cs                                         |   30 ++++---
 CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs                                    |    1 
 CodeManagement/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/04d18d8c-b910-43c8-aa25-623d0e81cddc |    0 
 CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs                                        |   94 ++++++-----------------
 CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs                         |    1 
 CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_After/CommonConveyorLine_AfterJob.cs                     |    2 
 CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs                                |   64 +++++----------
 7 files changed, 65 insertions(+), 127 deletions(-)

diff --git a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_After/CommonConveyorLine_AfterJob.cs b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_After/CommonConveyorLine_AfterJob.cs
index 2d5990d..e57eec5 100644
--- a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_After/CommonConveyorLine_AfterJob.cs
+++ b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_After/CommonConveyorLine_AfterJob.cs
@@ -185,7 +185,7 @@
             var taskNew = _taskRepository.QueryData(x => x.TargetAddress == stationInfo.stationChildCode && x.TaskType == (int)TaskOutboundTypeEnum.OutTray);
             var need = _needBarcodeRepository.QueryFirst(x => x.toArea == stationInfo.stationChildCode && x.productLine == stationInfo.productLine);
             var cache = command.Reserved5;
-            if (taskNew.Count < need.cacheNum)   //涓嶅瓨鍦ㄧ┖妗嗗嚭搴撲换鍔� 鍒欒姹俉MS鍑虹┖搴�
+            if (taskNew.Count + 2 < cache)   //涓嶅瓨鍦ㄧ┖妗嗗嚭搴撲换鍔� 鍒欒姹俉MS鍑虹┖搴�
             {
                 //ConsoleHelper.WriteWarningLine("璇锋眰绌烘墭鐩�");
                 if (_taskService.RequestTask(command.ConveyorLineBarcode, stationInfo).Result.Status)
diff --git a/CodeManagement/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/04d18d8c-b910-43c8-aa25-623d0e81cddc b/CodeManagement/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/04d18d8c-b910-43c8-aa25-623d0e81cddc
new file mode 100644
index 0000000..f4d6e3a
--- /dev/null
+++ b/CodeManagement/WMS/WIDESEA_WMSServer/.vs/WIDESEA_WMSServer/copilot-chat/bef6627e/sessions/04d18d8c-b910-43c8-aa25-623d0e81cddc
Binary files differ
diff --git a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs
index a38f83b..76c9934 100644
--- a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs
+++ b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MCS/Partial/NotifyFinishTest.cs
@@ -108,7 +108,6 @@
                         location.LocationStatus = (int) LocationEnum.InStockDisable;
                         _locationRepository.UpdateData(location);
 
-                        _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { taskDTO.PalletCode });
                     }
 
                     else
diff --git a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
index 3f05072..99f7612 100644
--- a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
+++ b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageBasicServices/Stock/StockInfoService.cs
@@ -115,7 +115,6 @@
                 _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.ManualOperation, 0);
             }
 
-            _simpleCacheService.HashDel<DtStockInfo>(CacheConst.Cache_DtStockInfo, stocks.ToArray());
             var hty = BaseDal.Db.InsertNav(stockInfos)
                 .Include(x => x.StockInfoDetails)
                 .ExecuteCommand();
diff --git a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs
index a707ae0..346fcec 100644
--- a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs
+++ b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/AspNetCoreSchedule.cs
@@ -48,13 +48,12 @@
 
                 if (area == null) { return; }
 
-                IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
-                List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
-
-                var stockInfo = stockInfoList.Where(x => x.AreaCode == area.AreaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢
-                     .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID) // 杩囨护鏉′欢
-                     .OrderBy(x => x.OutboundTime) // 鎺掑簭
-                     .ToList(); // 鑾峰彇绗竴涓厓绱�
+                var stockInfo = _stockInfoRepository.Db.Queryable<DtStockInfo>()
+                    .IncludesAllFirstLayer()
+                    .Where(x => x.AreaCode == area.AreaCode && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢
+                    .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID) // 杩囨护鏉′欢
+                    .OrderBy(x => x.OutboundTime) // 鎺掑簭
+                    .ToList(); // 鑾峰彇绗竴涓厓绱�
 
                 if (stockInfo.Count <= 0) return;
                 foreach (var item in stockInfo)
@@ -67,10 +66,18 @@
                     }
 
                     string position = string.Empty;
-                    if (item.LocationInfo.RoadwayNo == "GWSC1")
-                        position = "1059";
-                    else
-                        position = "1065";
+                    switch (item.LocationInfo.RoadwayNo)
+                    {
+                        case "GWSC1":
+                            position = "3101";
+                            break;
+                        case "GWSC2":
+                            position = "3104";
+                            break;
+                        default:
+                            position = "3107";
+                            break;
+                    }
 
                     var task = CreateTask(item, position, (int)TaskOutboundTypeEnum.Outbound);
                     task.NextAddress = "002-000-002";
@@ -93,7 +100,6 @@
                         _taskRepository.AddData(task);
                         // 鏇存柊搴撳瓨浣嶇疆鐘舵�佷负涓嶅彲鐢�
                         item.LocationInfo.LocationStatus = (int)LocationEnum.InStockDisable;
-                        _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { taskDTO.PalletCode });
                         _locationRepository.UpdateData(item.LocationInfo);
                     }
                 }
diff --git a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
index 1fd2cbc..5112a19 100644
--- a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
+++ b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -135,20 +135,6 @@
                 await DeleteTaskAsync(task.TaskId);
                 await AddTaskHtyAsync(taskHty);
             });
-            try
-            {
-                //using (_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
-                //{
-                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { stock.PalletCode });
-                //}
-            }
-            catch (Exception ex)
-            {
-                LogFactory.GetLog("鍒犻櫎缂撳瓨澶辫触").Error(true, $"{stock.PalletCode}_鍒犻櫎缂撳瓨澶辫触锛屽紓甯镐俊鎭細{ex.Message}");
-                //using (_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
-                //{
-                //}
-            }
 
             return content.OK("浠诲姟瀹屾垚鎴愬姛", task.Remark);
         }
@@ -386,16 +372,6 @@
 
                 stock.StockInfoDetails = new List<DtStockInfoDetail>() { { stock.StockInfoDetails[0] } };
                 stock.LocationInfo = locationInf;
-                //using(_simpleCacheService.AcquireLock(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, 2000))
-                //{
-                try
-                {
-                    _simpleCacheService.HashAdd(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, stock.PalletCode, stock);
-                }
-                catch (Exception ex)
-                {
-                    LogFactory.GetLog("娣诲姞缂撳瓨澶辫触").Error(true, $"{stock.PalletCode}_娣诲姞缂撳瓨澶辫触锛屽紓甯镐俊鎭細{ex.Message}");
-                }
 
                 content.OK("鍏ュ簱浠诲姟瀹屾垚鎴愬姛");
             }
@@ -659,7 +635,6 @@
             var taskDTOs = CreateTaskDTO(taskNews);
             BaseDal.AddData(taskNews);
             return content.OK(data: taskDTOs);
-
 
             // 鏌ヨ浠诲姟
             var task = await QueryTaskByPalletCode(input.PalletCode);
@@ -989,34 +964,26 @@
                                   .ToList()
                 : null;
 
-            IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo);
-            List<DtStockInfo> stockInfoList = stockInfos.Values.ToList();
             var result = new DtStockInfo();
 
-            //if (stockInfoList.IsNullOrEmpty())
-            //{
-            //    stockInfoList = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
-            //        .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock).IncludesAllFirstLayer().ToListAsync();
-            //}
+            result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
+                            .IncludesAllFirstLayer()
+                            .Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull)
+                            .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine)
+                            .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable)
+                            .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo))
+                            .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
+                            .OrderBy(x => x.OutboundTime)
+                            .FirstAsync();
 
-            result = stockInfoList.Where(x => x.AreaCode == areaCode && x.OutboundTime < DateTime.Now && x.IsFull)
-                              .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine)
-                              .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable)
-                              .WhereIF(!devices.IsNullOrEmpty(), x => devices.Contains(x.LocationInfo.RoadwayNo))
-                              .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
-                              .OrderBy(x => x.OutboundTime)
-            .FirstOrDefault();
-
-            if (result != null)
-                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode });
-            else
-                ConsoleHelper.WriteErrorLine("QueryStockInfoForRealTrayAsync鏌ヨ瀹炵洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
+            if (result.IsNullOrEmpty())
+                ConsoleHelper.WriteErrorLine($"{area.AreaName}-{productionLine}鏌ヨ瀹炵洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
 
             return result;
         }
         catch (Exception ex)
         {
-            ConsoleHelper.WriteErrorLine("QueryStockInfoForRealTrayAsync鏌ヨ瀹炵洏搴撳瓨淇℃伅澶辫触:" + ex.Message + "\r\n" + ex.StackTrace);
+            ConsoleHelper.WriteErrorLine("鏌ヨ瀹炵洏搴撳瓨淇℃伅澶辫触:" + ex.Message + "\r\n" + ex.StackTrace);
             return null;
         }
     }
@@ -1053,27 +1020,19 @@
                 .Where(x => x.DeviceStatus == "1")
                 .Where(x => x.DeviceCode.Contains("CWSC"))
                 .ToList().Select(x => x.DeviceCode).ToList();
-            //var deviceCode = devices.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 = stockInfoList.Where(x => areaCodes.Contains(x.AreaCode) && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢
+            var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
+                .IncludesAllFirstLayer()
+                .Where(x => areaCodes.Contains(x.AreaCode) && x.OutboundTime < DateTime.Now && x.IsFull == true) // 杩囨护鏉′欢
                 .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine)
                 .Where(x => x.LocationInfo != null && x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && areaId.Contains(x.LocationInfo.AreaId) && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 杩囨护鏉′欢
                 .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo))
                 .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode)))
                 .OrderBy(x => x.OutboundTime) // 鎺掑簭
-                .FirstOrDefault(); // 鑾峰彇绗竴涓厓绱�
+                .FirstAsync(); // 鑾峰彇绗竴涓厓绱�
 
-            if (result != null)
-            {
-                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode });
-            }
-            else
-            {
-                ConsoleHelper.WriteErrorLine("QueryStockInfoForRealTrayCWAsync鏌ヨ甯告俯瀹炵洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
-            }
+            if (result.IsNullOrEmpty())
+                ConsoleHelper.WriteErrorLine($"{JsonConvert.SerializeObject(areaCodes)}-{productionLine}鏌ヨ甯告俯瀹炵洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
 
             return result;
         }
@@ -1104,27 +1063,24 @@
                 .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 = stockInfoList.Where(x => x.ProductionLine == station.productLine)
+            var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>()
+                .IncludesAllFirstLayer()
+                .Where(x => x.ProductionLine == station.productLine)
                 .Where(x => x.AreaCode == areaCode && x.IsFull == false)
                 .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) // 杩囨护鏉′欢
                 .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo))
                 .OrderBy(x => x.CreateDate) // 鎺掑簭
-                .FirstOrDefault(); // 杞崲涓哄垪琛�
+                .FirstAsync(); // 杞崲涓哄垪琛�
 
-            if (result != null)
-                _simpleCacheService.HashDel<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo, new string[] { result.PalletCode });
-            else
-                ConsoleHelper.WriteErrorLine("QueryStockInfoForEmptyTrayAsync鏌ヨ绌虹洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
+            if (result.IsNullOrEmpty())
+                ConsoleHelper.WriteErrorLine($"{area}-{station.productLine}鏌ヨ绌虹洏搴撳瓨淇℃伅澶辫触:鏈壘鍒扮鍚堟潯浠剁殑鏁版嵁");
 
             return result;
         }
         catch (Exception ex)
         {
-            ConsoleHelper.WriteErrorLine("QueryStockInfoForEmptyTrayAsync鏌ヨ瀹炵洏搴撳瓨淇℃伅澶辫触:" + ex.Message + "\r\n" + ex.StackTrace);
+            ConsoleHelper.WriteErrorLine($"QueryStockInfoForEmptyTrayAsync鏌ヨ瀹炵洏搴撳瓨淇℃伅澶辫触:" + ex.Message + "\r\n" + ex.StackTrace);
             return null;
         }
     }
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