/// <summary>
        ///
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <DTOAPIRes_RoutePages> GetRoutePage(long Id)
        {
            RoutePages routePage = this.accesser.Get(Id);

            if (routePage != null)
            {
                var List = (from
                            x
                            in
                            this.accesser.db.RoutePages.AsNoTracking()
                            where
                            x.HierarchyPath.StartsWith(routePage.HierarchyPath)
                            select
                            this.mapper.Map <DTOAPI_RoutePages>(x)
                            ).ToList();

                var tree = List.GenerateTree(c => c.id, c => c.parentId, (DTOAPI_RoutePages c, IEnumerable <DTOAPI_RoutePages> val) =>
                {
                    c.children = val.ToArray();
                }, root_id: null).ToArray();

                return(new DTOAPIRes_RoutePages {
                    routes = tree
                });
            }
            else
            {
                throw new NullReferenceException($"页面路由 ID{Id} 不存在");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Consume(ConsumeContext <UpdatePageRouteCommand> context)
        {
            var msg = context.Message.data;

            RoutePages route = this.accesser.Get(msg.Id);

            if (route == null)
            {
                throw new NullReferenceException("Role is null");
            }

            route.RouteName  = msg.RouteName ?? "";
            route.Path       = msg.Path ?? "";
            route.Component  = msg.Component ?? "";
            route.NoCache    = msg.NoCache;
            route.Affix      = msg.Affix;
            route.GroupName  = msg.GroupName ?? "";
            route.Platform   = msg.Platform ?? "";
            route.ActiveMenu = msg.ActiveMenu ?? "";
            route.AlwaysShow = msg.AlwaysShow;
            route.Hidden     = msg.Hidden;
            route.Icon       = msg.Icon;
            route.Title      = msg.Title;

            int effectRow = this.accesser.Update(route);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="routepage"></param>
        /// <returns></returns>
        public async Task <dynamic> AddRoutePages(DTOAPI_RoutePages item)
        {
            IList <DTOIn_PageRoute> list = new List <DTOIn_PageRoute>();

            Int64 result = 0;

            TreeItem <long> data = new TreeItem <long>();

            item.Foreach(x => x.children, (parent, x) =>
            {
                long NewID = this.IDGenerator.GetNewID <RoutePages>();

                DTOIn_PageRoute obj = this.mapper.Map <DTOIn_PageRoute>(x);

                if (parent == null)
                {
                    if (item == x)
                    {
                        result = NewID;
                        // 确保 根节点 HierarchyPath 的正确性
                        if (item.parentId != null)
                        {
                            RoutePages routepage = this.accesser.Get(item.parentId.Value);
                            if (routepage != null)
                            {
                                item.hierarchyPath = TreeHelper.GenerateHierarchyPath(routepage.HierarchyPath, NewID);

                                obj.HierarchyPath = item.hierarchyPath;
                            }
                        }
                    }

                    if (item == x)
                    {
                        result = NewID;
                    }
                }
                else
                {
                    obj.HierarchyPath = TreeHelper.GenerateHierarchyPath(parent.hierarchyPath, NewID);
                }

                list.Add(obj);
            });
            await this.publishEndpoint.Publish(new AddPageRoutesCommand
            {
                routes = list
            });

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Consume(ConsumeContext <AddPageRouteCommand> context)
        {
            DTOIn_PageRoute data = context.Message.data;

            var pageRoute = new RoutePages
            {
                Id            = data.Id,
                ParentId      = data.ParentId,
                RouteName     = data.RouteName ?? "",
                HierarchyPath = data.HierarchyPath,
                Path          = data.Path ?? "",
                Component     = data.Component,
                NoCache       = data.NoCache,
                Affix         = data.Affix,
                ActiveMenu    = data.ActiveMenu,
                AlwaysShow    = data.AlwaysShow,
                Hidden        = data.Hidden,
                Icon          = data.Icon,
                Title         = data.Title
            };

            this.accesser.Add(pageRoute);
        }