| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | |
| | | cacheKey, |
| | | _ => BaseDal.QueryData(x => x.InOutType == routeType) |
| | | ); |
| | | } |
| | | |
| | | /// <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> |
| | | public bool ExistsRouter(string startPosi, string endPosi) |
| | | { |
| | | // 从缓存获取入口类型和出口类型的全量路由数据并合并 |
| | | 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() |
| | | { |
| | | // 分别获取入口类型和出口类型的路由数量并相加 |
| | | 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> |
| | |
| | | _cacheService.TryAdd($"{RedisPrefix.System}:{RedisName.DevicePositions}:{deviceCode}", positions); |
| | | } |
| | | } |
| | | else |
| | | else |
| | | positions = device; |
| | | // 返回位置列表 |
| | | return positions; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取路由表中所有完整的路由信息(前端调用展示数据)。 |
| | | /// </summary> |
| | |
| | | return content; |
| | | } |
| | | } |
| | | } |
| | | } |