mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	update 优化用户ID查询角色列表
This commit is contained in:
		@@ -37,6 +37,7 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 角色 业务层处理
 | 
			
		||||
@@ -104,12 +105,11 @@ public class SysRoleServiceImpl implements ISysRoleService {
 | 
			
		||||
    public List<SysRoleVo> selectRolesAuthByUserId(Long userId) {
 | 
			
		||||
        List<SysRoleVo> userRoles = baseMapper.selectRolePermissionByUserId(userId);
 | 
			
		||||
        List<SysRoleVo> roles = selectRoleAll();
 | 
			
		||||
        // 使用HashSet提高查找效率
 | 
			
		||||
        Set<Long> userRoleIds = userRoles.stream().map(SysRoleVo::getRoleId).collect(Collectors.toSet());
 | 
			
		||||
        for (SysRoleVo role : roles) {
 | 
			
		||||
            for (SysRoleVo userRole : userRoles) {
 | 
			
		||||
                if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
 | 
			
		||||
                    role.setFlag(true);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            if (userRoleIds.contains(role.getRoleId())) {
 | 
			
		||||
                role.setFlag(true);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return roles;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user