查询角色通用接口补充是否包含权限集的开关

This commit is contained in:
陈维伟 2023-09-13 17:53:06 +08:00
parent 3c8c6179c7
commit 87fb605eef
3 changed files with 29 additions and 17 deletions

View File

@ -34,6 +34,7 @@ public class QuerySaasRoleGroupReq {
* 单位类型字典code
*/
private List<String> ouTypeCode;
/**
* 被那些角色使用到的分组
*/

View File

@ -49,4 +49,9 @@ public class QuerySaasRoleReq {
private List<Long> sassRoleGroupIds;
private Integer isCommon;
/**
* 是否包含权限集如果不需要则不执行后续查询链路
*/
private Boolean includePermissionGroup;
}

View File

@ -71,7 +71,7 @@ public class RoleServiceImpl implements RoleService {
if (CollectionUtils.isEmpty(roleIds)) {
return new ArrayList<>();
}
return getByIds(roleIds, null, null,null);
return getByIds(roleIds, null, null,null, null);
}
/**
@ -79,29 +79,35 @@ public class RoleServiceImpl implements RoleService {
*
* @return
*/
public List<SaasRoleVO> getByIds(List<Long> roleIds, Integer isCommon, List<Long> workspaceId, List<Long> ouId) {
public List<SaasRoleVO> getByIds(List<Long> roleIds, Integer isCommon, List<Long> workspaceId, List<Long> ouId, Boolean includePermissionGroup) {
if (includePermissionGroup == null) {
includePermissionGroup = true;
}
if (CollectionUtils.isEmpty(roleIds)) {
return new ArrayList<>();
}
// 查询角色信息
List<SaasRole> roles = saasRoleDao.lambdaQuery().in(BaseEntity::getId, roleIds).list();
// 查询权限集关联关系
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = queryPermissionGroupRelation(roleIds);
// 查询权限集
Map<Long, List<SaasPgroupRoleRelation>> pgrouRelationMap = null;
Map<Long, List<SaasPermissionGroupVO>> pGroupMap = null;
if (CollectionUtils.isNotEmpty(saasPgroupRoleRelations)) {
// 转map<roleId,relation>
pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
// 查询权限集
pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder()
.isCommon(isCommon)
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
.workspaceId(workspaceId)
.ouId(ouId)
.build())
// 转map<pgroupId>
.stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId));
// 如果不包含则跳过
if(includePermissionGroup) {
// 查询权限集关联关系
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = queryPermissionGroupRelation(roleIds);
if (CollectionUtils.isNotEmpty(saasPgroupRoleRelations)) {
// 转map<roleId,relation>
pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
// 查询权限集
pGroupMap = permissionGroupService.query(QuerySaasPermissionGroupReq.builder()
.isCommon(isCommon)
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
.workspaceId(workspaceId)
.ouId(ouId)
.build())
// 转map<pgroupId>
.stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId));
}
}
Map<Long, List<SaasPgroupRoleRelation>> finalPgrouRelationMap = pgrouRelationMap;
Map<Long, List<SaasPermissionGroupVO>> finalPGroupMap = pGroupMap;
@ -173,7 +179,7 @@ public class RoleServiceImpl implements RoleService {
.in(CollectionUtils.isNotEmpty(req.getOuId()),SaasRole::getOwnerOuId,req.getOuId())
.orderByDesc(BaseEntity::getId)
.list();
return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList()), req.getIsCommon(),req.getWorkspaceId(),req.getOuId());
return getByIds(list.stream().map(BaseEntity::getId).collect(Collectors.toList()), req.getIsCommon(),req.getWorkspaceId(),req.getOuId(),req.getIncludePermissionGroup());
}
@Override