wanshenmean
2026-03-27 0a6698d14daa665825b47f97c78642d33ebdda63
feat(RouterService): 新增 GetAllRoutersFromCache 私有方法

- 封装 _cacheService.GetOrAdd,按 InOutType 加载入口/出口路由到缓存
- 缓存键格式:Router:AllRouters:In / Router:AllRouters:Out
- 适配 ICacheService.GetOrAdd 的实际签名 (Func<string, T>)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
已修改1个文件
16 ■■■■■ 文件已修改
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
@@ -40,6 +40,22 @@
        }
        /// <summary>
        /// 从缓存获取指定类型的全量路由数据,缓存不存在时自动从数据库加载并写入缓存
        /// </summary>
        /// <param name="routeType">路由类型(入口/出口)</param>
        /// <returns>该类型的全部路由列表</returns>
        private List<Dt_Router> GetAllRoutersFromCache(int routeType)
        {
            // 根据路由类型构建缓存Key,In类型对应"In",Out类型对应"Out"
            string cacheKey = $"Router:AllRouters:{(routeType == RouterInOutType.In.ObjToInt() ? "In" : "Out")}";
            // 通过缓存服务获取数据,缓存未命中时调用工厂方法从数据库查询并写入缓存
            return _cacheService.GetOrAdd(
                cacheKey,
                _ => BaseDal.QueryData(x => x.InOutType == routeType)
            );
        }
        /// <summary>
        /// 根据起点/当前位置、终点获取下一个子节点。
        /// </summary>
        /// <param name="startPosi">起点/当前位置。</param>