| | |
| | | public class RoleService extends BaseServiceImpl<RoleMapper, Role> { |
| | | |
| | | private final AdminRoleRelationService adminRoleRelationService; |
| | | private final ClientRoleRelationService clientRoleRelationService; |
| | | private final RoleMenuRelationService roleMenuRelationService; |
| | | private final MenuService menuService; |
| | | private final MenuMapper menuMapper; |
| | |
| | | /** |
| | | * 获取指定管理员的spring security权限认证列表 |
| | | */ |
| | | public Collection<GrantedAuthority> mapToGrantedAuthorities(Long adminId) { |
| | | |
| | | // 获取管理员的角色id |
| | | List<Role> roles = listByAdminId(adminId); |
| | | public Collection<GrantedAuthority> mapToGrantedAuthorities(Long adminId, boolean flag) { |
| | | List<Role> roles; |
| | | if (flag) { |
| | | // 获取管理员的角色id |
| | | roles = listByAdminId(adminId); |
| | | } else { |
| | | roles = listByClientId(adminId); |
| | | } |
| | | |
| | | if (CollectionUtil.isEmpty(roles)) { |
| | | throw new BusinessException("当前用户没有角色"); |
| | |
| | | // 获取管理员的角色id |
| | | List<AdminRoleRelation> list = adminRoleRelationService.list(Wrappers.lambdaQuery(AdminRoleRelation.class).eq(AdminRoleRelation::getAdminId, adminId).select(AdminRoleRelation::getRoleId)); |
| | | List<Long> roleIdList = list.stream().map(AdminRoleRelation::getRoleId).collect(Collectors.toList()); |
| | | if (CollectionUtil.isEmpty(roleIdList)) { |
| | | return null; |
| | | } |
| | | return listByIds(roleIdList); |
| | | } |
| | | |
| | | /** |
| | | * 获取某个普通用户的角色列表 |
| | | */ |
| | | public List<Role> listByClientId(Long clientId) { |
| | | // 获取普通用户的角色id |
| | | List<ClientRoleRelation> list = clientRoleRelationService.list(Wrappers.lambdaQuery(ClientRoleRelation.class).eq(ClientRoleRelation::getClientId, clientId).select(ClientRoleRelation::getRoleId)); |
| | | List<Long> roleIdList = list.stream().map(ClientRoleRelation::getRoleId).collect(Collectors.toList()); |
| | | if (CollectionUtil.isEmpty(roleIdList)) { |
| | | return null; |
| | | } |
| | |
| | | if (role == null) { |
| | | throw new BusinessException("找不到角色"); |
| | | } |
| | | //超级管理员不能删除 |
| | | if (RoleLevelStatus.SUPER.getCode().equals(role.getLevel())) { |
| | | throw new BusinessException("当前角色为超级管理员,无法删除"); |
| | | } |
| | | |
| | | assertLevels(role.getLevel()); |
| | | List<AdminRoleRelation> list = adminRoleRelationService.list(Wrappers.lambdaQuery(AdminRoleRelation.class).eq(AdminRoleRelation::getRoleId, role)); |
| | | if (CollectionUtil.isNotEmpty(list)) { |