From a2e2b0018f35737882377dd1335c786397eab7ce Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 27 三月 2026 14:34:00 +0800
Subject: [PATCH] feat(RouterService): 新增 ExistsRouter 两个重载
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs | 65 +++++++++++++++++++++++++++++++-
1 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
index 8ebe3d7..e1249fc 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
@@ -56,6 +56,57 @@
}
/// <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>
/// <param name="startPosi">璧风偣/褰撳墠浣嶇疆銆�</param>
@@ -409,9 +460,9 @@
// 杩斿洖鍘婚噸鍚庣殑浣嶇疆鍒楄〃
return positions.GroupBy(x => x).Select(x => x.Key).ToList();
}
- catch
+ catch (Exception ex)
{
-
+ ConsoleHelper.WriteErrorLine($"RouterService.QueryAllPositions 鏌ヨ澶辫触: {ex.Message}");
}
finally
{
@@ -608,7 +659,15 @@
// 閲嶆柊鏌ヨ鍏ㄩ噺璺敱锛堟鏃舵墠鍖呭惈鏂板鐨勮矾鐢憋級锛屽啀鍐欏叆缂撳瓨
List<Dt_Router> updatedRouters = BaseDal.QueryData(x => x.InOutType == routerType);
string cacheKey = $"Router:AllRouters:{(routerType == RouterInOutType.In.ObjToInt() ? "In" : "Out")}";
- _cacheService.AddOrUpdate(cacheKey, updatedRouters);
+
+ try
+ {
+ _cacheService.AddOrUpdate(cacheKey, updatedRouters);
+ }
+ catch
+ {
+ // 缂撳瓨鏇存柊澶辫触鏃堕潤榛樺拷鐣ワ紝涓嬫鏌ヨ浼氫粠DB鑷姩閲嶅缓缂撳瓨
+ }
content = WebResponseContent.Instance.OK();
}
--
Gitblit v1.9.3