From 5171d3f59b89389bf75293afd210cfa6de4ccff7 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 10 四月 2026 23:03:49 +0800
Subject: [PATCH] feat: 添加堆垛机相关常量类并重构代码使用常量
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs | 307 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 254 insertions(+), 53 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
index 3cdd283..b060189 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
@@ -1,9 +1,5 @@
锘縰sing SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using WIDESEAWCS_Common;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
@@ -11,6 +7,7 @@
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
+using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
namespace WIDESEAWCS_QuartzJob.Service
{
@@ -21,6 +18,7 @@
{
private readonly IDeviceProtocolRepository _deviceProtocolRepository;
private readonly IDeviceInfoRepository _deviceInfoRepository;
+ private readonly ICacheService _cacheService;
/// <summary>
/// 璺敱閰嶇疆涓氬姟灞�
@@ -28,10 +26,142 @@
/// <param name="BaseDal"></param>
/// <param name="deviceProtocolRepository"></param>
/// <param name="deviceInfoRepository"></param>
- public RouterService(IRouterRepository BaseDal, IDeviceProtocolRepository deviceProtocolRepository, IDeviceInfoRepository deviceInfoRepository) : base(BaseDal)
+ public RouterService(IRouterRepository BaseDal, IDeviceProtocolRepository deviceProtocolRepository, IDeviceInfoRepository deviceInfoRepository, ICacheService cacheService) : base(BaseDal)
{
_deviceProtocolRepository = deviceProtocolRepository;
_deviceInfoRepository = deviceInfoRepository;
+ _cacheService = cacheService;
+ }
+
+ /// <summary>
+ /// 浠庣紦瀛樿幏鍙栨寚瀹氱被鍨嬬殑鍏ㄩ噺璺敱鏁版嵁锛岀紦瀛樹笉瀛樺湪鏃惰嚜鍔ㄤ粠鏁版嵁搴撳姞杞藉苟鍐欏叆缂撳瓨
+ /// </summary>
+ /// <param name="routeType">璺敱绫诲瀷锛堝叆鍙�/鍑哄彛锛�</param>
+ /// <returns>璇ョ被鍨嬬殑鍏ㄩ儴璺敱鍒楄〃</returns>
+ private List<Dt_Router> GetAllRoutersFromCache(int routeType)
+ {
+ // 鏍规嵁璺敱绫诲瀷鏋勫缓缂撳瓨Key锛孖n绫诲瀷瀵瑰簲"In"锛孫ut绫诲瀷瀵瑰簲"Out"
+ string cacheKey = $"Router:AllRouters:{(routeType == RouterInOutType.In.ObjToInt() ? "In" : "Out")}";
+ // 閫氳繃缂撳瓨鏈嶅姟鑾峰彇鏁版嵁锛岀紦瀛樻湭鍛戒腑鏃惰皟鐢ㄥ伐鍘傛柟娉曚粠鏁版嵁搴撴煡璇㈠苟鍐欏叆缂撳瓨
+ return _cacheService.GetOrAdd(
+ cacheKey,
+ _ => BaseDal.QueryData(x => x.InOutType == routeType)
+ );
+ }
+
+ /// <summary>
+ /// 娓呴櫎鎵�鏈夎矾鐢辩紦瀛橈紙鍏ュ彛鍜屽嚭鍙g被鍨嬶級
+ /// </summary>
+ public void ClearRouterCache()
+ {
+ _cacheService.Remove("Router:AllRouters:In");
+ _cacheService.Remove("Router:AllRouters:Out");
+ }
+
+ /// <summary>
+ /// 鏍规嵁璁惧缂栧彿鏌ヨ缁忚繃璇ヨ澶囩殑鎵�鏈夎矾鐢憋紙鍚堝苟鍏ュ彛+鍑哄彛绫诲瀷锛�
+ /// </summary>
+ /// <param name="deviceCode">璁惧缂栧彿</param>
+ /// <returns>缁忚繃璇ヨ澶囩殑璺敱鍒楄〃</returns>
+ public List<Dt_Router> QueryRoutersByDeviceCode(string deviceCode)
+ {
+ // 浠庣紦瀛樿幏鍙栧叆鍙g被鍨嬪拰鍑哄彛绫诲瀷鐨勫叏閲忚矾鐢辨暟鎹�
+ List<Dt_Router> inRouters = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt());
+ List<Dt_Router> outRouters = GetAllRoutersFromCache(RouterInOutType.Out.ObjToInt());
+ // 鍚堝苟鍚庣瓫閫夊嚭缁忚繃鎸囧畾璁惧鐨勮矾鐢憋紙ChildPosiDeviceCode鍖归厤锛�
+ return inRouters.Concat(outRouters)
+ .Where(x => x.ChildPosiDeviceCode == deviceCode)
+ .ToList();
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇涓ょ偣涔嬮棿鏄惁瀛樺湪璺敱锛堝叏绫诲瀷锛�
+ /// </summary>
+ public bool ExistsRouter(string startPosi, string endPosi)
+ {
+ // 浠庣紦瀛樿幏鍙栧叆鍙g被鍨嬪拰鍑哄彛绫诲瀷鐨勫叏閲忚矾鐢辨暟鎹苟鍚堝苟
+ List<Dt_Router> inRouters = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt());
+ List<Dt_Router> outRouters = GetAllRoutersFromCache(RouterInOutType.Out.ObjToInt());
+ var allRouters = inRouters.Concat(outRouters).ToList();
+ // 鍦ㄥ唴瀛樹腑鏌ユ壘浠庤捣鐐瑰埌缁堢偣鐨勮矾鐢�
+ var routes = FindRoutesInMemory(startPosi, endPosi, allRouters, null);
+ return routes.Count > 0;
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇涓ょ偣涔嬮棿鏄惁瀛樺湪鎸囧畾绫诲瀷鐨勮矾鐢�
+ /// </summary>
+ public bool ExistsRouter(string startPosi, string endPosi, int routeType)
+ {
+ // 浠庣紦瀛樿幏鍙栨寚瀹氱被鍨嬬殑鍏ㄩ噺璺敱鏁版嵁
+ List<Dt_Router> allRouters = GetAllRoutersFromCache(routeType);
+ // 鍦ㄥ唴瀛樹腑鏌ユ壘浠庤捣鐐瑰埌缁堢偣鐨勮矾鐢�
+ var routes = FindRoutesInMemory(startPosi, endPosi, allRouters, routeType);
+ return routes.Count > 0;
+ }
+
+ /// <summary>
+ /// 鑾峰彇鍏ㄩ噺璺敱鏁伴噺锛堝叆鍙�+鍑哄彛鍚堣锛�
+ /// </summary>
+ public int GetRouterCount()
+ {
+ // 鍒嗗埆鑾峰彇鍏ュ彛绫诲瀷鍜屽嚭鍙g被鍨嬬殑璺敱鏁伴噺骞剁浉鍔�
+ int inCount = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt()).Count;
+ int outCount = GetAllRoutersFromCache(RouterInOutType.Out.ObjToInt()).Count;
+ return inCount + outCount;
+ }
+
+ /// <summary>
+ /// 鑾峰彇鎸囧畾绫诲瀷璺敱鏁伴噺
+ /// </summary>
+ public int GetRouterCount(int routeType)
+ {
+ // 鑾峰彇鎸囧畾绫诲瀷鐨勫叏閲忚矾鐢辨暟鎹苟杩斿洖鏁伴噺
+ return GetAllRoutersFromCache(routeType).Count;
+ }
+
+ /// <summary>
+ /// 鎵归噺鍒犻櫎鎸囧畾ID鐨勮矾鐢憋紝鍒犻櫎鍚庡悓姝ユ竻闄ゅ搴旂被鍨嬬殑缂撳瓨
+ /// </summary>
+ /// <param name="routerIds">寰呭垹闄ょ殑璺敱ID鍒楄〃</param>
+ /// <returns>杩斿洖澶勭悊缁撴灉</returns>
+ public WebResponseContent DeleteRouters(List<long> routerIds)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (routerIds == null || routerIds.Count == 0)
+ {
+ return content = WebResponseContent.Instance.Error("寰呭垹闄ょ殑璺敱ID鍒楄〃涓嶈兘涓虹┖");
+ }
+
+ // 鏌ヨ寰呭垹闄よ矾鐢辩殑绫诲瀷锛堢敤浜庡悗缁竻闄ょ紦瀛橈級
+ var routersToDelete = BaseDal.QueryData(x => routerIds.Contains(x.Id));
+ if (routersToDelete.Count == 0)
+ {
+ return content = WebResponseContent.Instance.Error("鏈壘鍒板緟鍒犻櫎鐨勮矾鐢�");
+ }
+
+ // 璁板綍娑夊強鐨勭被鍨嬶紙鍘婚噸锛�
+ var affectedTypes = routersToDelete.Select(x => x.InOutType).Distinct().ToList();
+
+ // 鎵ц鎵归噺鍒犻櫎
+ BaseDal.DeleteData(routersToDelete);
+
+ // 娓呴櫎鍙楀奖鍝嶇被鍨嬬殑缂撳瓨
+ foreach (var routeType in affectedTypes)
+ {
+ string cacheKey = $"Router:AllRouters:{(routeType == RouterInOutType.In.ObjToInt() ? "In" : "Out")}";
+ _cacheService.Remove(cacheKey);
+ }
+
+ content = WebResponseContent.Instance.OK();
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error(ex.Message);
+ }
+ return content;
}
/// <summary>
@@ -45,12 +175,14 @@
List<Dt_Router> routers = new List<Dt_Router>();
try
{
- // 涓�娆℃�ф煡璇㈡墍鏈夎矾鐢辨暟鎹埌鍐呭瓨
- List<Dt_Router> allRouters = BaseDal.QueryData(x => true);
-
+ // 浠庣紦瀛樺姞杞藉叆鍙g被鍨嬪拰鍑哄彛绫诲瀷鐨勮矾鐢辨暟鎹苟鍚堝苟锛堝垱寤烘柊鍒楄〃锛岄伩鍏嶄慨鏀圭紦瀛樺紩鐢級
+ List<Dt_Router> allRouters = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt())
+ .Concat(GetAllRoutersFromCache(RouterInOutType.Out.ObjToInt()))
+ .ToList();
+
// 鍦ㄥ唴瀛樹腑杩涜璺緞鎼滅储
routers = FindRoutesInMemory(startPosi, endPosi, allRouters, null);
-
+
if (routers.Count == 0)
{
throw new Exception($"璇ヨ矾寰勬湭閰嶇疆鎴栭厤缃敊璇�,璇锋鏌ヨ澶囪矾鐢变俊鎭�,璧风偣:銆恵startPosi}銆�,缁堢偣:銆恵endPosi}銆�");
@@ -75,12 +207,12 @@
List<Dt_Router> routers = new List<Dt_Router>();
try
{
- // 涓�娆℃�ф煡璇㈡寚瀹氱被鍨嬬殑鎵�鏈夎矾鐢辨暟鎹埌鍐呭瓨
- List<Dt_Router> allRouters = BaseDal.QueryData(x => x.InOutType == routeType);
-
+ // 浠庣紦瀛樺姞杞芥寚瀹氱被鍨嬬殑鎵�鏈夎矾鐢辨暟鎹�
+ List<Dt_Router> allRouters = GetAllRoutersFromCache(routeType);
+
// 鍦ㄥ唴瀛樹腑杩涜璺緞鎼滅储
routers = FindRoutesInMemory(startPosi, endPosi, allRouters, routeType);
-
+
if (routers.Count == 0)
{
throw new Exception($"璇ヨ矾寰勬湭閰嶇疆鎴栭厤缃敊璇�,璇锋鏌ヨ澶囪矾鐢变俊鎭�,璧风偣:銆恵startPosi}銆�,缁堢偣:銆恵endPosi}銆�");
@@ -110,7 +242,7 @@
var routersByNext = allRouters
.GroupBy(r => r.NextPosi)
.ToDictionary(g => g.Key, g => g.ToList());
-
+
var routersByChild = allRouters
.GroupBy(r => r.ChildPosi)
.ToDictionary(g => g.Key, g => g.ToList());
@@ -127,7 +259,7 @@
// 浣跨敤闃熷垪杩涜骞垮害浼樺厛鎼滅储
Queue<(Dt_Router router, List<Dt_Router> path)> queue = new Queue<(Dt_Router, List<Dt_Router>)>();
-
+
// 灏嗘墍鏈夌粓鐐硅矾鐢卞姞鍏ラ槦鍒�
foreach (var endRouter in endRouters)
{
@@ -185,10 +317,12 @@
{
try
{
- // 鏌ヨ浠庤捣鐐瑰嚭鍙戠殑鎵�鏈夎矾鐢�
- List<Dt_Router> routes = BaseDal.QueryData(x => x.StartPosi == startPosi,
- new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
-
+ // 浠庣紦瀛樿幏鍙栧叆鍙g被鍨嬬殑鎵�鏈夎矾鐢辨暟鎹紝鍩轰簬璧风偣绛涢�夊悗鎸塈sEnd闄嶅簭鎺掑簭
+ List<Dt_Router> routes = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt())
+ .Where(x => x.StartPosi == startPosi)
+ .ToList();
+ routes = routes.OrderByDescending(x => x.IsEnd).ToList();
+
// 杩斿洖绗竴涓矾鐢�
return routes.FirstOrDefault();
}
@@ -209,10 +343,12 @@
{
try
{
- // 鏌ヨ浠庤捣鐐瑰嚭鍙戠殑鎸囧畾绫诲瀷璺敱
- List<Dt_Router> routes = BaseDal.QueryData(x => x.StartPosi == startPosi && x.InOutType == routeType,
- new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
-
+ // 浠庣紦瀛樿幏鍙栨寚瀹氱被鍨嬬殑鎵�鏈夎矾鐢辨暟鎹紝绛涢�夎捣鐐瑰悗鎸塈sEnd闄嶅簭鎺掑垪
+ List<Dt_Router> routes = GetAllRoutersFromCache(routeType)
+ .Where(x => x.StartPosi == startPosi)
+ .ToList();
+ routes = routes.OrderByDescending(x => x.IsEnd).ToList();
+
// 杩斿洖绗竴涓矾鐢�
return routes.FirstOrDefault();
}
@@ -234,10 +370,12 @@
{
try
{
- // 鏌ヨ浠庤捣鐐瑰嚭鍙戠殑鎸囧畾绫诲瀷璺敱
- List<Dt_Router> routes = BaseDal.QueryData(x => x.StartPosi == startPosi && x.InOutType == routeType,
- new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
-
+ // 浠庣紦瀛樿幏鍙栨寚瀹氱被鍨嬬殑鎵�鏈夎矾鐢辨暟鎹紝绛涢�夎捣鐐瑰悗鎸塈sEnd闄嶅簭鎺掑垪
+ List<Dt_Router> routes = GetAllRoutersFromCache(routeType)
+ .Where(x => x.StartPosi == startPosi)
+ .ToList();
+ routes = routes.OrderByDescending(x => x.IsEnd).ToList();
+
if (routes.Count == 0)
return null;
@@ -246,8 +384,8 @@
if (directRoute != null)
return directRoute;
- // 濡傛灉娌℃湁鐩存帴璺敱锛屼娇鐢ㄦ煡鎵剧畻娉曟壘鍒版湞鍚戠粓鐐圭殑璺敱
- List<Dt_Router> allRouters = BaseDal.QueryData(x => x.InOutType == routeType);
+ // 濡傛灉娌℃湁鐩存帴璺敱锛屼娇鐢ㄧ紦瀛樹腑鐨勫叏閲忚矾鐢辨暟鎹煡鎵炬湞鍚戠粓鐐圭殑璺敱
+ List<Dt_Router> allRouters = GetAllRoutersFromCache(routeType);
foreach (var route in routes)
{
// 妫�鏌ヤ粠杩欎釜璺敱鐨勪笅涓�涓綅缃槸鍚﹁兘鍒拌揪缁堢偣
@@ -255,6 +393,42 @@
if (pathToEnd.Count > 0)
return route;
}
+
+ // 濡傛灉閮戒笉鑳藉埌杈剧粓鐐癸紝杩斿洖绗竴涓矾鐢�
+ return routes.FirstOrDefault();
+ }
+ catch (Exception ex)
+ {
+ // 璁板綍閿欒淇℃伅
+ return null;
+ }
+ }
+
+ /// <summary>
+ /// 鏍规嵁璧风偣銆佺粓鐐规柟鍚戝拰璺敱绫诲瀷鑾峰彇涓嬩竴涓崟涓瓙鑺傜偣璺敱锛堟櫤鑳介�夋嫨鏈濆悜缁堢偣鐨勮矾鐢憋級
+ /// </summary>
+ /// <param name="startPosi">璧风偣/褰撳墠浣嶇疆</param>
+ /// <param name="endPosi">缁堢偣浣嶇疆锛堢敤浜庢柟鍚戝垽鏂級</param>
+ /// <returns>杩斿洖涓嬩竴涓矾鐢辫妭鐐癸紝浼樺厛杩斿洖鏈濆悜缁堢偣鐨勮矾鐢憋紝濡傛灉娌℃湁鍒欒繑鍥瀗ull</returns>
+ public Dt_Router QueryNextRoute(string startPosi, string endPosi)
+ {
+ try
+ {
+ // 浠庣紦瀛樿幏鍙栧叆鍙e拰鍑哄彛绫诲瀷鐨勬墍鏈夎矾鐢辨暟鎹紝绛涢�夎捣鐐瑰悗鎸塈sEnd闄嶅簭鎺掑簭
+ List<Dt_Router> inRoutes = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt());
+ List<Dt_Router> outRoutes = GetAllRoutersFromCache(RouterInOutType.Out.ObjToInt());
+ List<Dt_Router> routes = inRoutes.Concat(outRoutes)
+ .Where(x => x.StartPosi == startPosi)
+ .ToList();
+ routes = routes.OrderByDescending(x => x.IsEnd).ToList();
+
+ if (routes.Count == 0)
+ return null;
+
+ // 浼樺厛閫夋嫨鐩存帴鎸囧悜缁堢偣鐨勮矾鐢�
+ Dt_Router directRoute = routes.FirstOrDefault(x => x.NextPosi == endPosi || x.ChildPosi == endPosi);
+ if (directRoute != null)
+ return directRoute;
// 濡傛灉閮戒笉鑳藉埌杈剧粓鐐癸紝杩斿洖绗竴涓矾鐢�
return routes.FirstOrDefault();
@@ -278,7 +452,7 @@
List<Dt_Router> path = new List<Dt_Router>();
string currentPosi = startPosi;
HashSet<string> visitedPositions = new HashSet<string>();
-
+
try
{
while (currentPosi != endPosi)
@@ -290,21 +464,21 @@
visitedPositions.Add(currentPosi);
Dt_Router nextRoute = QueryNextRoute(currentPosi, endPosi, routeType);
-
+
if (nextRoute == null)
{
break;
}
-
+
path.Add(nextRoute);
currentPosi = nextRoute.NextPosi;
-
+
if (path.Count > 1000)
{
break;
}
}
-
+
if (currentPosi != endPosi)
{
return new List<Dt_Router>();
@@ -314,7 +488,7 @@
{
return new List<Dt_Router>();
}
-
+
return path;
}
@@ -327,27 +501,38 @@
{
// 鍒涘缓涓�涓瓧绗︿覆鍒楄〃锛岀敤浜庡瓨鍌ㄦ墍鏈変綅缃�
List<string> positions = new List<string>();
- try
+ var device = _cacheService.Get<List<string>>($"{RedisPrefix.System}:{RedisName.DevicePositions}:{deviceCode}");
+ if (device.IsNullOrEmpty())
{
- // 鏌ヨ鎵�鏈夎繘鍏ヨ矾鐢卞櫒鐨勪綅缃�
- List<string> inRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.In.ObjToInt()).GroupBy(x => x.StartPosi).Select(x => x.Key).ToList();
+ try
+ {
+ // 鏌ヨ鎵�鏈夎繘鍏ヨ矾鐢卞櫒鐨勪綅缃�
+ List<string> inRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.In.ObjToInt()).GroupBy(x => x.StartPosi).Select(x => x.Key).ToList();
- // 鏌ヨ鎵�鏈夌寮�璺敱鍣ㄧ殑浣嶇疆
- List<string> outRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.Out.ObjToInt()).GroupBy(x => x.ChildPosi).Select(x => x.Key).ToList();
+ // 鏌ヨ鎵�鏈夌寮�璺敱鍣ㄧ殑浣嶇疆
+ List<string> outRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.Out.ObjToInt()).GroupBy(x => x.ChildPosi).Select(x => x.Key).ToList();
- // 灏嗚繘鍏ュ拰绂诲紑璺敱鍣ㄧ殑浣嶇疆娣诲姞鍒板垪琛ㄤ腑
- positions.AddRange(inRouterPositions);
- positions.AddRange(outRouterPositions);
- // 杩斿洖鍘婚噸鍚庣殑浣嶇疆鍒楄〃
- return positions.GroupBy(x => x).Select(x => x.Key).ToList();
+ // 灏嗚繘鍏ュ拰绂诲紑璺敱鍣ㄧ殑浣嶇疆娣诲姞鍒板垪琛ㄤ腑
+ positions.AddRange(inRouterPositions);
+ positions.AddRange(outRouterPositions);
+ // 杩斿洖鍘婚噸鍚庣殑浣嶇疆鍒楄〃
+ return positions.GroupBy(x => x).Select(x => x.Key).ToList();
+ }
+ catch (Exception ex)
+ {
+ ConsoleHelper.WriteErrorLine($"RouterService.QueryAllPositions 鏌ヨ澶辫触: {ex.Message}");
+ }
+ finally
+ {
+ _cacheService.TryAdd($"{RedisPrefix.System}:{RedisName.DevicePositions}:{deviceCode}", positions);
+ }
}
- catch
- {
-
- }
+ else
+ positions = device;
// 杩斿洖浣嶇疆鍒楄〃
return positions;
}
+
/// <summary>
/// 鑾峰彇璺敱琛ㄤ腑鎵�鏈夊畬鏁寸殑璺敱淇℃伅(鍓嶇璋冪敤灞曠ず鏁版嵁)銆�
/// </summary>
@@ -355,8 +540,10 @@
public List<object> GetAllWholeRouters()
{
List<object> data = new List<object>();
- // 鏌ヨ鎵�鏈夎矾鐢�
- List<Dt_Router> allRouters = BaseDal.QueryData(x => true);
+ // 浠庣紦瀛樺姞杞藉叆鍙g被鍨嬪拰鍑哄彛绫诲瀷鐨勫叏閲忚矾鐢辨暟鎹苟鍚堝苟
+ List<Dt_Router> inRouters = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt());
+ List<Dt_Router> outRouters = GetAllRoutersFromCache(RouterInOutType.Out.ObjToInt());
+ List<Dt_Router> allRouters = inRouters.Concat(outRouters).ToList();
// 鏌ヨ鎵�鏈夌粨鏉熺殑璺敱锛屽苟鎸塈d鎺掑簭
List<Dt_Router> dt_Routers = allRouters.Where(x => x.IsEnd).OrderBy(x => x.Id).ToList();
@@ -527,6 +714,20 @@
// 娣诲姞鏂扮殑璺敱淇℃伅
BaseDal.AddData(routers);
+
+ // 閲嶆柊鏌ヨ鍏ㄩ噺璺敱锛堟鏃舵墠鍖呭惈鏂板鐨勮矾鐢憋級锛屽啀鍐欏叆缂撳瓨
+ List<Dt_Router> updatedRouters = BaseDal.QueryData(x => x.InOutType == routerType);
+ string cacheKey = $"Router:AllRouters:{(routerType == RouterInOutType.In.ObjToInt() ? "In" : "Out")}";
+
+ try
+ {
+ _cacheService.AddOrUpdate(cacheKey, updatedRouters);
+ }
+ catch
+ {
+ // 缂撳瓨鏇存柊澶辫触鏃堕潤榛樺拷鐣ワ紝涓嬫鏌ヨ浼氫粠DB鑷姩閲嶅缓缂撳瓨
+ }
+
content = WebResponseContent.Instance.OK();
}
catch (Exception ex)
@@ -536,4 +737,4 @@
return content;
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3