refactor(role-query): 用户增加返回ouid

This commit is contained in:
zhansihu 2023-10-20 10:50:01 +08:00
parent 611490ec33
commit 1e03e4c0df
2 changed files with 41 additions and 37 deletions

View File

@ -29,6 +29,9 @@ public class RoleWithUserRes {
@Data @Data
public static class UserVO { public static class UserVO {
/** 企业组织ID **/
private Long ouId;
/** 身份ID **/ /** 身份ID **/
private Long identityId; private Long identityId;

View File

@ -111,15 +111,15 @@ public class RoleServiceImpl implements RoleService {
pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId)); pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
// 查询权限集 // 查询权限集
pGroupMap = permissionGroupService.page(QuerySaasPermissionGroupReq.builder() pGroupMap = permissionGroupService.page(QuerySaasPermissionGroupReq.builder()
.isCommon(isCommon) .isCommon(isCommon)
.roleIds(roleIds) .roleIds(roleIds)
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList())) .ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
.workspaceId(workspaceId) .workspaceId(workspaceId)
.ouId(ouId) .ouId(ouId)
.fetchPage(Boolean.FALSE) .fetchPage(Boolean.FALSE)
.build()).getList() .build()).getList()
// 转map<pgroupId> // 转map<pgroupId>
.stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId)); .stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId));
} }
} }
Map<Long, List<SaasPgroupRoleRelation>> finalPgrouRelationMap = pgrouRelationMap; Map<Long, List<SaasPgroupRoleRelation>> finalPgrouRelationMap = pgrouRelationMap;
@ -129,12 +129,12 @@ public class RoleServiceImpl implements RoleService {
List<SaasPermissionGroupVO> pGroup = new ArrayList<>(); List<SaasPermissionGroupVO> pGroup = new ArrayList<>();
if (finalPgrouRelationMap != null && finalPgrouRelationMap.containsKey(role.getId())) { if (finalPgrouRelationMap != null && finalPgrouRelationMap.containsKey(role.getId())) {
pGroup = finalPgrouRelationMap.get(role.getId()) pGroup = finalPgrouRelationMap.get(role.getId())
.stream() .stream()
.map(SaasPgroupRoleRelation::getGroupId) .map(SaasPgroupRoleRelation::getGroupId)
.map(finalPGroupMap::get) .map(finalPGroupMap::get)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.flatMap(List::stream) .flatMap(List::stream)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
SaasRoleVO saasRoleVO = BeanUtil.copyProperties(role, SaasRoleVO.class); SaasRoleVO saasRoleVO = BeanUtil.copyProperties(role, SaasRoleVO.class);
saasRoleVO.setPermissionGroup(pGroup); saasRoleVO.setPermissionGroup(pGroup);
@ -173,8 +173,8 @@ public class RoleServiceImpl implements RoleService {
List<SaasRoleGroupRelation> groupRelation = new ArrayList<>(); List<SaasRoleGroupRelation> groupRelation = new ArrayList<>();
if (CollectionUtils.isNotEmpty(roleGroup)) { if (CollectionUtils.isNotEmpty(roleGroup)) {
groupRelation = roleGroupRelationDao.lambdaQuery() groupRelation = roleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList())) .in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList()))
.list(); .list();
if (CollectionUtils.isEmpty(groupRelation)) { if (CollectionUtils.isEmpty(groupRelation)) {
return new ArrayList<>(); return new ArrayList<>();
} }
@ -197,12 +197,12 @@ public class RoleServiceImpl implements RoleService {
req.forEach(e -> { req.forEach(e -> {
result.add(QueryBatchByIdentityIdTypeRes.builder() result.add(QueryBatchByIdentityIdTypeRes.builder()
.identityId(e.getIdentityId()) .identityId(e.getIdentityId())
.identityType(e.getIdentityType()) .identityType(e.getIdentityType())
.workspaceId(e.getWorkspaceId()) .workspaceId(e.getWorkspaceId())
.ouId(e.getOuId()) .ouId(e.getOuId())
.role(queryByIdentityIdType(e.getIdentityId(),e.getIdentityType(),e.getWorkspaceId(),e.getOuId())) .role(queryByIdentityIdType(e.getIdentityId(),e.getIdentityType(),e.getWorkspaceId(),e.getOuId()))
.build()); .build());
}); });
return result; return result;
} }
@ -264,17 +264,17 @@ public class RoleServiceImpl implements RoleService {
List<SaasRole> list = new ArrayList<>(); List<SaasRole> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(roleIds)) { if (CollectionUtils.isNotEmpty(roleIds)) {
list = saasRoleDao.lambdaQuery() list = saasRoleDao.lambdaQuery()
.in(BaseEntity::getId, roleIds) .in(BaseEntity::getId, roleIds)
.eq(SaasRole::getRoleType, RoleTypeEnum.SUPER_ADMIN.getValue()) .eq(SaasRole::getRoleType, RoleTypeEnum.SUPER_ADMIN.getValue())
.list(); .list();
} }
result.add(IsSuperAdminRes.builder() result.add(IsSuperAdminRes.builder()
.identityId(e.getIdentityId()) .identityId(e.getIdentityId())
.identityType(e.getIdentityType()) .identityType(e.getIdentityType())
.workspaceId(e.getWorkspaceId()) .workspaceId(e.getWorkspaceId())
.ouId(e.getOuId()) .ouId(e.getOuId())
.isSuperAdmin(CollectionUtils.isNotEmpty(list)?true:false) .isSuperAdmin(CollectionUtils.isNotEmpty(list)?true:false)
.build()); .build());
}); });
return result; return result;
} }
@ -407,9 +407,9 @@ public class RoleServiceImpl implements RoleService {
*/ */
public List<SaasPgroupRoleRelation> queryPermissionGroupRelation(List<Long> roleIds) { public List<SaasPgroupRoleRelation> queryPermissionGroupRelation(List<Long> roleIds) {
return saasPgroupRoleRelationDao.lambdaQuery() return saasPgroupRoleRelationDao.lambdaQuery()
.in(SaasPgroupRoleRelation::getRoleId, roleIds) .in(SaasPgroupRoleRelation::getRoleId, roleIds)
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value) .eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list(); .list();
} }
@Override @Override
@ -422,7 +422,7 @@ public class RoleServiceImpl implements RoleService {
Set<Long> initRoleId = new HashSet<>(); Set<Long> initRoleId = new HashSet<>();
//有标准角查询角色分组 //有标准角查询角色分组
if (role.stream().anyMatch(r -> Objects.equals(RoleTypeEnum.INIT.getValue(), r.getRoleType()))) { if (role.stream().anyMatch(r -> Objects.equals(RoleTypeEnum.INIT.getValue(), r.getRoleType()))) {
List<SaasRoleGroupVO> roleGroupList = saasRoleGroupService.getList(QuerySaasRoleGroupReq.builder() List<SaasRoleGroupVO> roleGroupList = saasRoleGroupService.getList(QuerySaasRoleGroupReq.builder()
.workspaceTypeCode(Collections.singletonList(userRoleInfoMap.getWorkspaceType().toString())) .workspaceTypeCode(Collections.singletonList(userRoleInfoMap.getWorkspaceType().toString()))
.ouTypeCode(Collections.singletonList(userRoleInfoMap.getWorkspaceJoinType().getValue().toString())) .ouTypeCode(Collections.singletonList(userRoleInfoMap.getWorkspaceJoinType().getValue().toString()))
.build()); .build());
@ -436,7 +436,7 @@ public class RoleServiceImpl implements RoleService {
.collect(Collectors.toList()); .collect(Collectors.toList());
return resultRole.stream().map( return resultRole.stream().map(
e -> e.getMatchFeature(userRoleInfoMap.workspaceId, userRoleInfoMap.getOuId())) e -> e.getMatchFeature(userRoleInfoMap.workspaceId, userRoleInfoMap.getOuId()))
.flatMap(List::stream) .flatMap(List::stream)
.map(PermissionPointTreeNode::getPermissionPointId) .map(PermissionPointTreeNode::getPermissionPointId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
@ -471,6 +471,7 @@ public class RoleServiceImpl implements RoleService {
if (CollectionUtil.isNotEmpty(relations)) { if (CollectionUtil.isNotEmpty(relations)) {
List<RoleWithUserRes.UserVO> users = relations.stream().map(e -> { List<RoleWithUserRes.UserVO> users = relations.stream().map(e -> {
RoleWithUserRes.UserVO user = new RoleWithUserRes.UserVO(); RoleWithUserRes.UserVO user = new RoleWithUserRes.UserVO();
user.setOuId(req.getOuId());
user.setIdentityId(e.getIdentityId()); user.setIdentityId(e.getIdentityId());
user.setIdentityType(e.getIdentityType()); user.setIdentityType(e.getIdentityType());
return user; return user;