public object GetUserPermission()
        {
            List <RoleToPermissionCache> resData = new List <RoleToPermissionCache>();
            List <string> roleList = AbpSession.UserRoleList;

            foreach (var item in roleList)
            {
                //获取的是动作按钮授权
                var permissionList = _cacheManagerExtens.GetRoleToPermissionCache(Convert.ToInt64(item));
                //.Where(w => !string.IsNullOrEmpty(w.PermissionName));
                foreach (var pitem in permissionList.ToList())
                {
                    var data = resData.Where(w =>
                                             w.MenuId == pitem.MenuId &&
                                             w.HandleName == pitem.HandleName &&
                                             w.PermissionName == pitem.PermissionName
                                             );
                    if (!data.Any())
                    {
                        resData.Add(pitem);
                    }
                }
            }

            List <MenuActionPermissionCache> menuActionPermissionList = _cacheManagerExtens.GetMenuActionPermissionCache();
            var permissionData = menuActionPermissionList.Where(w => w.IsActive == true && w.RequiresAuthModel != "3");

            foreach (var item in permissionData)
            {
                var data = resData.Where(w =>
                                         (w.MenuId == item.MenuId && w.HandleName == item.MenuName && item.IsMenu && w.PermissionName == item.PermissionName) ||
                                         (w.MenuId == item.MenuId && w.HandleName == item.ActionName && !item.IsMenu && w.PermissionName == item.PermissionName)
                                         );
                if (!data.Any())
                {
                    resData.Add(new RoleToPermissionCache()
                    {
                        MenuName   = item.MenuName,
                        HandleName = item.IsMenu? item.MenuName: item.ActionName
                    });
                }
            }

            var userData = _cacheManagerExtens.GetUserInfoCache(AbpSession.UserId.Value);

            return(new
            {
                User = new
                {
                    UserNameCn = AbpSession.UserNameCn,
                    UserCode = AbpSession.UserCode,
                    IsAdmin = AbpSession.IsAdmin,
                    ImageUrl = userData.ImageUrl,
                    OrgCode = userData.OrgCode
                },
                Permission = resData
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="permissionName"></param>
        /// <returns></returns>
        //[UnitOfWork]
        public async Task <bool> IsValidationGrantedAsync(UserInfo userInfo, string permissionName)
        {
            permissionName = permissionName.ToLower();

            //
            if (userInfo.IsAdmin)
            {
                return(true);
            }

            //旧的方案:在Abp授权字典集合查询(启动状态下新增的授权将无法获取到)
            //Permission currentPermission = _permissionManager.GetPermissionOrNull(permissionName);
            //在所有授权对象里面查询(可以及时获取到新增的授权对象)
            Permission currentPermission = GetPermissionsOrNull(permissionName);

            if (currentPermission == null)
            {
                return(false);
            }

            //获取当前授权名称的请求对象
            List <MenuActionPermissionCache> menuActionPermissionList = _cacheManagerExtens.GetMenuActionPermissionCache();
            var resData = menuActionPermissionList
                          .Where(w => w.IsActive == true &&
                                 !string.IsNullOrEmpty(w.PermissionName) &&
                                 w.PermissionName.Equals(permissionName, StringComparison.CurrentCultureIgnoreCase));

            if (resData == null || !resData.Any())
            {
                return(false);
            }
            //
            string requiresAuthModel = resData.ToList()[0].RequiresAuthModel;

            //开放模式(所有用户可以访问)
            if (requiresAuthModel == "1")
            {
                return(true);
            }
            //登录模式(仅限登录验证通过的用户)
            else if (requiresAuthModel == "2" && AbpSessionExtens != null && AbpSessionExtens.UserId != null)
            {
                return(true);
            }
            //授权模式(不仅要登录还需要有授权的用户)
            else if (requiresAuthModel == "3")
            {
                //判断角色
                if (userInfo.SysRoleToUserList == null || !userInfo.SysRoleToUserList.Any())
                {
                    return(false);
                }

                foreach (var item in userInfo.SysRoleToUserList)
                {
                    var permissionList = _cacheManagerExtens.GetRoleToPermissionCache(Convert.ToInt64(item.RoleID))
                                         .Where(w => !string.IsNullOrEmpty(w.PermissionName) && w.PermissionName.ToLower() == permissionName);
                    if (permissionList.Any())
                    {
                        return(true);
                    }
                }
            }
            //
            return(await Task.FromResult(false));
        }
        public object GetUserPermission()
        {
            List <RoleToPermissionCache> resData = new List <RoleToPermissionCache>();
            //通过session获取当前登录用户角色集合
            List <string> roleList = AbpSession.UserRoleList;

            #region 获取菜单以及动作按钮授权
            foreach (var item in roleList)
            {
                var permissionList = _cacheManagerExtens.GetRoleToPermissionCache(Convert.ToInt64(item)); //.Where(w => !string.IsNullOrEmpty(w.PermissionName));
                foreach (var pitem in permissionList.ToList())
                {
                    //去重复
                    var data = resData.Where(w => w.MenuId == pitem.MenuId && w.HandleName == pitem.HandleName && w.PermissionName == pitem.PermissionName);
                    if (!data.Any())
                    {
                        resData.Add(pitem);
                    }
                }
            }
            #endregion

            /*
             * RequiresAuthModel
             *  开放模式 = 1 (不受权限控制)
             *  登陆模式 = 2 (所有登录用户)
             *  授权模式 = 3 (授权模式)
             */
            #region 加载不需要授权的菜单以及动作按钮授权
            List <MenuActionPermissionCache> menuActionPermissionList = _cacheManagerExtens.GetMenuActionPermissionCache();
            var permissionData = menuActionPermissionList.Where(w => w.IsActive == true && w.RequiresAuthModel != "3");
            foreach (var item in permissionData)
            {
                var data = resData.Where(w =>
                                         (w.MenuId == item.MenuId && w.HandleName == item.MenuName && item.IsMenu && w.PermissionName == item.PermissionName) ||
                                         (w.MenuId == item.MenuId && w.HandleName == item.ActionName && !item.IsMenu && w.PermissionName == item.PermissionName)
                                         );
                if (!data.Any())
                {
                    resData.Add(new RoleToPermissionCache()
                    {
                        MenuName   = item.MenuName,
                        HandleName = item.IsMenu ? item.MenuName : item.ActionName
                    });
                }
            }
            #endregion

            //登录用户信息
            var userData = _cacheManagerExtens.GetUserInfoCache(AbpSession.UserId.Value);

            return(new
            {
                User = new
                {
                    UserNameCn = AbpSession.UserNameCn,
                    UserCode = AbpSession.UserCode,
                    IsAdmin = AbpSession.IsAdmin,
                    ImageUrl = userData.ImageUrl,
                    OrgCode = userData.OrgCode
                },
                Permission = resData
            });
        }