using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEAWCS_Core.BaseServices; using WIDESEAWCS_IBasicInfoRepository; using WIDESEAWCS_IBasicInfoService; using WIDESEAWCS_Model.Models; namespace WIDESEAWCS_BasicInfoService { public class RouterService : ServiceBase, IRouterService { public RouterService(IRouterRepository BaseDal) : base(BaseDal) { } public List QueryNextRoutes(string startPosi, string endPosi) { List routers = new List(); try { List dt_Routers = BaseDal.QueryData(x => x.NextPosi == endPosi || x.ChildPosi == endPosi, new Dictionary { { nameof(Dt_Router.IsEnd), OrderByType.Desc } }); if (dt_Routers.Count > 0) { foreach (var item in dt_Routers) { if (item.StartPosi == startPosi && !routers.Any(x => x.Id == item.Id)) { routers.Add(item); } else { List tempRouters = QueryNextRoutes(startPosi, item.StartPosi); foreach (var router in tempRouters) { if (router.StartPosi == startPosi && !routers.Any(x => x.Id == router.Id)) { routers.Add(router); } } } } } else { throw new Exception($"该路径未配置或配置错误,请检查设备路由信息,起点:【{startPosi}】,终点:【{endPosi}】"); } } catch (Exception ex) { //throw new Exception(ex.Message); //记录错误信息 } return routers; } } }