| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清除所有路由缓存(入口和出口类型) |
| | | /// </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) |
| | | { |
| | | // 从缓存获取入口类型和出口类型的全量路由数据 |
| | | 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> |
| | | /// <param name="startPosi">起点/当前位置。</param> |
| | |
| | | // 返回去重后的位置列表 |
| | | return positions.GroupBy(x => x).Select(x => x.Key).ToList(); |
| | | } |
| | | catch |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | ConsoleHelper.WriteErrorLine($"RouterService.QueryAllPositions 查询失败: {ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | |
| | | public List<object> GetAllWholeRouters() |
| | | { |
| | | List<object> data = new List<object>(); |
| | | // 查询所有路由 |
| | | List<Dt_Router> allRouters = BaseDal.QueryData(x => true); |
| | | // 从缓存加载入口类型和出口类型的全量路由数据并合并 |
| | | List<Dt_Router> inRouters = GetAllRoutersFromCache(RouterInOutType.In.ObjToInt()); |
| | | List<Dt_Router> outRouters = GetAllRoutersFromCache(RouterInOutType.Out.ObjToInt()); |
| | | List<Dt_Router> allRouters = inRouters.Concat(outRouters).ToList(); |
| | | // 查询所有结束的路由,并按Id排序 |
| | | List<Dt_Router> dt_Routers = allRouters.Where(x => x.IsEnd).OrderBy(x => x.Id).ToList(); |
| | | |
| | |
| | | |
| | | // 添加新的路由信息 |
| | | 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) |