Example #1
0
        /// <summary>
        /// 获取前台按钮权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public List <RoleButtonPermissionDto> GetButtonPermissionList(long roleId)
        {
            List <RoleButtonPermissionDto> permissionList = PermissionCache.GetFrontOperatesPermission(roleId);

            if (permissionList != null)
            {
                return(permissionList);
            }

            permissionList = new List <RoleButtonPermissionDto>();

            //菜单权限
            var menus = Sqldb.Select <sys_menu, sys_role_authorize>()
                        .InnerJoin((m, r) => m.id == r.menu_id)
                        .Where((m, r) => r.role_id == roleId && m.role_tag != "#")
                        .ToList((m, r) => m);

            List <string> roleTags = new List <string>();

            if (menus.Count > 0)
            {
                //按钮权限
                var buttonRoleTags = Sqldb.Select <sys_operate, sys_role_authorize>()
                                     .InnerJoin((o, r) => o.id == r.menu_id)
                                     .Where((o, r) => r.role_id == roleId)
                                     .ToList((o, r) => o);

                foreach (sys_menu menu in menus)
                {
                    //菜单权限标识
                    roleTags.Add(menu.role_tag.ToLower());

                    RoleButtonPermissionDto model = new RoleButtonPermissionDto();
                    model.menuId = CommHelper.GetMenuTabId(menu.menu_url.ToLower());
                    List <sys_operate> buttons = buttonRoleTags.Where(s => s.menu_id == menu.id).ToList();
                    foreach (sys_operate button in buttons)
                    {
                        model.add(button.role_tag.ToLower());
                        //操作权限标识
                        roleTags.Add(button.role_tag.ToLower());
                    }
                    permissionList.Add(model);
                }
            }

            //添加缓存
            if (permissionList.Count > 0)
            {
                PermissionCache.AddFrontOperatesPermission(roleId, permissionList);
            }
            if (roleTags.Count > 0)
            {
                PermissionCache.AddOperatePermission(roleId, roleTags);
            }
            return(permissionList);
        }
Example #2
0
        /// <summary>
        /// 首页导航菜单全部
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List <sys_menu> GetNaviMenu(LoginUserDto user)
        {
            //int total = 0;
            List <sys_menu> menus = new List <sys_menu>();

            if (user.IsSuper)
            {
                menus = Sqldb.Queryable <sys_menu>().OrderBy(s => s.menu_sort).ToList();
            }
            else
            {
                //获取权限缓存
                menus = PermissionCache.GetMenuPermission(user.RoleId);

                if (menus != null)
                {
                    return(menus);
                }
                menus = Sqldb.Select <sys_menu, sys_role_authorize>()
                        .InnerJoin((m, r) => m.id == r.menu_id)
                        .Where((m, r) => r.role_id == user.RoleId)
                        .OrderBy((m, r) => m.menu_sort)
                        .ToList((m, r) => m);
            }

            if (menus.Count > 0)
            {
                List <string>   roleTags = new List <string>();
                List <sys_menu> tops     = menus.Where(s => s.parent_id == 0).ToList();
                tops.ForEach(menu =>
                {
                    menu.tab_id = CommHelper.GetMenuTabId(menu.menu_url.ToLower());
                    var sons    = menus.Where(s => s.parent_id == menu.id).ToList();
                    sons.ForEach(son =>
                    {
                        son.tab_id = CommHelper.GetMenuTabId(son.menu_url.ToLower());
                        var sons2  = menus.Where(s => s.parent_id == son.id).ToList();
                        sons2.ForEach(s => {
                            s.tab_id = CommHelper.GetMenuTabId(s.menu_url.ToLower());
                        });
                        son.children = sons2;
                    });
                    menu.children = sons;
                });

                if (tops.Count > 0)
                {   // 设置权限缓存
                    PermissionCache.AddMenuPermission(user.RoleId, tops);
                }
                return(tops);
            }
            return(menus);
        }