|
|
|
@ -23,6 +23,7 @@ import org.dromara.common.mybatis.core.page.PageQuery; |
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
|
import org.dromara.common.satoken.utils.LoginHelper; |
|
|
|
import org.dromara.system.domain.SysUser; |
|
|
|
import org.dromara.system.domain.SysRole; |
|
|
|
import org.dromara.system.domain.SysUserPost; |
|
|
|
import org.dromara.system.domain.SysUserRole; |
|
|
|
import org.dromara.system.domain.bo.QuerySysUserBo; |
|
|
|
@ -894,4 +895,76 @@ public class SysUserServiceImpl implements ISysUserService, UserService { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过角色Key查询用户ID列表 |
|
|
|
* |
|
|
|
* @param roleKey 角色权限字符串 |
|
|
|
* @return 用户ID列表 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<Long> selectUserIdsByRoleKey(String roleKey) { |
|
|
|
if (StringUtils.isBlank(roleKey)) { |
|
|
|
return List.of(); |
|
|
|
} |
|
|
|
// 通过 roleKey 查询角色ID列表
|
|
|
|
List<SysRole> roles = roleMapper.selectList( |
|
|
|
new LambdaQueryWrapper<SysRole>() |
|
|
|
.select(SysRole::getRoleId) |
|
|
|
.eq(SysRole::getRoleKey, roleKey) |
|
|
|
.eq(SysRole::getStatus, SystemConstants.NORMAL)); |
|
|
|
if (CollUtil.isEmpty(roles)) { |
|
|
|
return List.of(); |
|
|
|
} |
|
|
|
List<Long> roleIds = StreamUtils.toList(roles, SysRole::getRoleId); |
|
|
|
return this.selectUserIdsByRoleIds(roleIds); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过角色Key查询用户列表 |
|
|
|
* |
|
|
|
* @param roleKey 角色权限字符串 |
|
|
|
* @return 用户列表 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<UserDTO> selectUsersByRoleKey(String roleKey) { |
|
|
|
if (StringUtils.isBlank(roleKey)) { |
|
|
|
return List.of(); |
|
|
|
} |
|
|
|
// 通过 roleKey 查询角色ID列表
|
|
|
|
List<SysRole> roles = roleMapper.selectList( |
|
|
|
new LambdaQueryWrapper<SysRole>() |
|
|
|
.select(SysRole::getRoleId) |
|
|
|
.eq(SysRole::getRoleKey, roleKey) |
|
|
|
.eq(SysRole::getStatus, SystemConstants.NORMAL)); |
|
|
|
if (CollUtil.isEmpty(roles)) { |
|
|
|
return List.of(); |
|
|
|
} |
|
|
|
List<Long> roleIds = StreamUtils.toList(roles, SysRole::getRoleId); |
|
|
|
return this.selectUsersByRoleIds(roleIds); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过用户ID查询用户所有的角色Key |
|
|
|
* |
|
|
|
* @param userId 用户ID |
|
|
|
* @return 角色Key集合 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Set<String> selectRoleKeysByUserId(Long userId) { |
|
|
|
if (userId == null) { |
|
|
|
return Set.of(); |
|
|
|
} |
|
|
|
List<SysRoleVo> roles = roleMapper.selectRolesByUserId(userId); |
|
|
|
if (CollUtil.isEmpty(roles)) { |
|
|
|
return Set.of(); |
|
|
|
} |
|
|
|
Set<String> roleKeys = new HashSet<>(); |
|
|
|
for (SysRoleVo role : roles) { |
|
|
|
if (role != null && StringUtils.isNotBlank(role.getRoleKey())) { |
|
|
|
roleKeys.add(role.getRoleKey().trim()); |
|
|
|
} |
|
|
|
} |
|
|
|
return roleKeys; |
|
|
|
} |
|
|
|
} |
|
|
|
|