예제 #1
0
        /// <summary>
        /// 获取某个角色所能操作的菜单列表,不递归包含子集
        /// </summary>
        /// <param name="loggingSession">当前登录用户的Session信息</param>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public IList <MenuModel> GetRoleMenusList(LoggingSessionInfo loggingSessionInfo, string roleId)
        {
            //分隔出角色ID和单位ID
            string[] arr_role = roleId.Split(new char[] { ',' });
            roleId = arr_role[0];

            //DataSet ds = appSysService.GetRoleMenus(roleId);//从Dal层获取数据

            //IList<MenuModel> menulist = new List<MenuModel>();

            //if (ds != null && ds.Tables[0].Rows.Count > 0)
            //{
            //menulist = DataTableToObject.ConvertToList<MenuModel>(ds.Tables[0]);//菜单列表转换成实体对象
            var menulist = default(List <MenuModel>);

            menulist = new RedisRoleBLL().GetRole(loggingSessionInfo.ClientID, roleId);
            if (menulist == null || menulist.Count <= 0)
            {
                menulist = appSysService.GetRoleMenus(loggingSessionInfo.ClientID, roleId);
                menulist = GetAllMenuList(menulist);
                new RedisRoleBLL().SetRole(loggingSessionInfo.ClientID, roleId, menulist);
                new RedisXML().RedisReadDBCount("RoleID", "角色权限相关", 2);
            }
            else
            {
                menulist = GetAllMenuList(menulist);
                new RedisXML().RedisReadDBCount("RoleID", "角色权限相关", 1);
            }
            //if (menulist != null && menulist.Count > 0)
            //{
            //    foreach (MenuModel menu in menulist)
            //    {
            //        menu.SubMenuList = new List<MenuModel>();
            //        foreach (MenuModel subMenu in menulist)//遍历所有的菜单项
            //        {
            //            if (subMenu.Parent_Menu_Id == menu.Menu_Id)
            //            {
            //                menu.SubMenuList.Add(subMenu);
            //            }
            //        }
            //    }
            //}
            //}
            return(menulist);
        }
예제 #2
0
        /// <summary>
        /// 获取某个角色所能操作的菜单列表
        /// </summary>
        /// <param name="loggingSession">当前登录用户的Session信息</param>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public MenuModel GetRoleMenusByPMenuCode(LoggingSessionInfo loggingSessionInfo, string roleId, string menu_code, out string errMsg)
        {
            //分隔出角色ID和单位ID
            string[] arr_role = roleId.Split(new char[] { ',' });
            roleId = arr_role[0];
            //DataSet ds = appSysService.GetRoleMenus(roleId);//从Dal层获取数据
            //IList<MenuModel> menulist = new List<MenuModel>();
            MenuModel currentMenu = new MenuModel();

            errMsg = "";
            //if (ds != null && ds.Tables[0].Rows.Count > 0)
            //{
            //menulist = DataTableToObject.ConvertToList<MenuModel>(ds.Tables[0]);//菜单列表转换成实体对象

            var menulist = default(List <MenuModel>);

            menulist = new RedisRoleBLL().GetRole(loggingSessionInfo.ClientID, roleId);
            if (menulist == null || menulist.Count <= 0)
            {
                menulist = appSysService.GetRoleMenus(loggingSessionInfo.ClientID, roleId);
                new RedisRoleBLL().SetRole(loggingSessionInfo.ClientID, roleId, menulist);
                new RedisXML().RedisReadDBCount("RoleID", "角色权限相关", 2);
            }
            else
            {
                new RedisXML().RedisReadDBCount("RoleID", "角色权限相关", 1);
            }

            var currentMenuList = menulist.Where(p => p.Menu_Code == menu_code).ToArray();

            if (currentMenuList == null || currentMenuList.Length == 0)
            {
                errMsg = "没有找到对应菜单编码的菜单";
            }
            else
            {
                currentMenu = currentMenuList[0];
                GetSubMenus(currentMenu, menulist);
            }
            //}
            return(currentMenu);
        }
예제 #3
0
        /// <summary>
        /// 获取某个角色所能操作的菜单列表
        /// </summary>
        /// <param name="loggingSession">当前登录用户的Session信息</param>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public IList <MenuModel> GetRoleMenus(LoggingSessionInfo loggingSessionInfo, string roleId, int getMode = 0)
        {
            //分隔出角色ID和单位ID
            string[] arr_role = roleId.Split(new char[] { ',' });
            roleId = arr_role[0];

            //DataSet ds = appSysService.GetRoleMenus(roleId);//从Dal层获取数据

            //IList<MenuModel> menulist = new List<MenuModel>();

            //if (ds != null && ds.Tables[0].Rows.Count > 0)
            //{
            //menulist = //DataTableToObject.ConvertToList<MenuModel>(ds.Tables[0]);//菜单列表转换成实体对象
            var menulist = default(List <MenuModel>);

            menulist = new RedisRoleBLL().GetRole(loggingSessionInfo.ClientID, roleId);
            if (menulist == null || menulist.Count <= 0)//从redis没有读取到,从数据库读取
            {
                menulist = appSysService.GetRoleMenus(loggingSessionInfo.ClientID, roleId);
                new RedisRoleBLL().SetRole(loggingSessionInfo.ClientID, roleId, menulist);
                new RedisXML().RedisReadDBCount("RoleID", "角色权限相关", 2);
            }
            else
            {
                new RedisXML().RedisReadDBCount("RoleID", "角色权限相关", 1);
            }

            #region 修改菜单权限Bug
            //修改菜单权限Bug
            //if (getMode != 0)
            //{
            //    var r = (from m in menulist
            //             where !menulist.Select(x => x.Menu_Id).Contains(m.Parent_Menu_Id) && m.Parent_Menu_Id != "--"
            //             select m.Parent_Menu_Id).Distinct().ToArray();
            //    var newMenuDbSet = appSysService.GetMenuByIds(r);
            //    if (newMenuDbSet != null)
            //    {
            //        List<MenuModel> newMenuList = DataTableToObject.ConvertToList<MenuModel>(newMenuDbSet.Tables[0]);
            //        menulist.AddRange(newMenuList);
            //    }
            //}
            if (getMode == 0)
            {
                //for (int i = 0; i < 10000; i++)
                //{
                //    var r = (from m in menulist
                //             where !menulist.Select(x => x.Menu_Id).Contains(m.Parent_Menu_Id) && m.Parent_Menu_Id != "--"
                //             select m.Parent_Menu_Id).Distinct().ToArray();
                //    var newMenuDbSet = appSysService.GetMenuByIds(r);
                //    if (newMenuDbSet != null && newMenuDbSet.Tables[0].Rows.Count > 0)
                //    {
                //        List<MenuModel> newMenuList = DataTableToObject.ConvertToList<MenuModel>(newMenuDbSet.Tables[0]);
                //        menulist.AddRange(newMenuList);
                //    }
                //    else
                //    {
                //        break;
                //    }
                //}
                menulist = GetAllMenuList(menulist);
            }

            #endregion
            //var newMenuList2 = new List<MenuModel>();
            //for (int i = 1; i <= 10; i++)
            //{
            //    var l = menulist.Where(x => x.Menu_Level == i).Select(x => x);
            //    if (i == 1)
            //    {
            //        newMenuList2.AddRange(l);
            //    }
            //    else
            //    {
            //        foreach (var m in l)
            //        {
            //            var parentMenu = newMenuList2.Where(x => x.Menu_Id == m.Parent_Menu_Id).ToList().FirstOrDefault();
            //            if (parentMenu != null)
            //            {
            //                if (parentMenu.SubMenuList == null)
            //                    parentMenu.SubMenuList = new List<MenuModel>();
            //                parentMenu.SubMenuList.Add(m);
            //            }
            //        }
            //    }
            //}
            //return newMenuList2;

            if (menulist != null && menulist.Count > 0)
            {
                foreach (MenuModel menu in menulist)
                {
                    menu.SubMenuList = new List <MenuModel>();
                    foreach (MenuModel subMenu in menulist)//遍历所有的菜单项
                    {
                        if (subMenu.Parent_Menu_Id == menu.Menu_Id)
                        {
                            menu.SubMenuList.Add(subMenu);
                        }
                    }
                }
            }
            return(menulist);
        }