Пример #1
0
        public List <string> selectMenuPermsByUserId(long userId)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append(@" select distinct m.perms
		     from sys_menu m
			 left join sys_role_menu rm on m.menu_id = rm.menu_id
			 left join sys_user_role ur on rm.role_id = ur.role_id
			 left join sys_role r on r.role_id = ur.role_id
		    where m.status = '0' and r.status = '0' and ur.user_id = @userId"        );

            MySqlParameter[] parametera = new MySqlParameter[1] {
                new MySqlParameter("userId", MySqlDbType.Int64)
            };
            parametera[0].Value = userId;

            var models = _dataContext.GetDatabase().SqlQuery <SysMenuPerms>(sql.ToString(), parametera);

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

            foreach (SysMenuPerms perm in models)
            {
                if (null != perm)
                {
                    permsSet.AddRange(perm.perms.Trim().Split(",").ToList());
                }
            }
            return(permsSet);
        }
Пример #2
0
        /// <summary>
        /// 根据用户ID查询权限
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns>权限列表</returns>
        public List <string> selectRolePermissionByUserId(long userId)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append(@" select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope,
                          r.status, r.del_flag, r.create_time, r.remark
                          from sys_role r
                          left join sys_user_role ur on ur.role_id = r.role_id
                          left join sys_user u on u.user_id = ur.user_id
                          left join sys_dept d on u.dept_id = d.dept_id");
            sql.Append("  WHERE r.del_flag = '0' and ur.user_id = @userId ");
            MySqlParameter[] parametera = new MySqlParameter[1] {
                new MySqlParameter("userId", MySqlDbType.Int64)
            };
            parametera[0].Value = userId;

            var models = _dataContext.GetDatabase().SqlQuery <SysRole>(sql.ToString(), parametera);

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

            foreach (SysRole perm in models)
            {
                if (null != perm)
                {
                    permsSet.AddRange(perm.RoleKey.Trim().Split(",").ToList());
                }
            }
            return(permsSet);
        }
Пример #3
0
        public List <int> selectDeptListByRoleId(long roleId)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append(@"select d.dept_id, d.parent_id
		from sys_dept d
            left join sys_role_dept rd on d.dept_id = rd.dept_id
        where rd.role_id = @roleId
            and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = @roleId)
		order by d.parent_id, d.order_num"        );

            MySqlParameter[] parameters = new MySqlParameter[1] {
                new MySqlParameter("userId", MySqlDbType.Int64)
            };
            parameters[0].Value = roleId;

            List <SysDept> models = _dataContext.GetDatabase().SqlQuery <SysDept>(sql.ToString(), parameters);

            return(models.Select(u => u.Id).ToList());
        }