feat:(REQ-2750) 去掉saasRoleUserRelation的重复查询代码,切换到新的统一查询接口

This commit is contained in:
lilong 2024-09-05 15:37:24 +08:00
parent 2c90e32499
commit 4082c9d8ce
8 changed files with 188 additions and 166 deletions

View File

@ -1,13 +1,12 @@
package cn.axzo.tyr.client.model.roleuser.dto;
import cn.axzo.tyr.client.model.res.SaasPermissionRelationRes;
import cn.axzo.tyr.client.model.res.SaasPermissionRes;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Date;
@Data
@Builder
@ -17,6 +16,30 @@ public class SaasRoleUserV2DTO {
private Long id;
protected Date createAt;
protected Date updateAt;
/**
* 创建者
*/
private Long createBy;
/**
* 更新者
*/
private Long updateBy;
/**
* 资源类型
*/
private Integer resourceType;
/**
* 资源Id
*/
private Long resourceId;
/**
* 角色Id
*/
@ -24,7 +47,7 @@ public class SaasRoleUserV2DTO {
private SaasRoleUser saasRoleUser;
private SaasRole saasRole;
private SaasRoleRes saasRole;
@Data
@Builder
@ -66,45 +89,4 @@ public class SaasRoleUserV2DTO {
return this.getOuId() + "_" + this.getWorkspaceId();
}
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class SaasRole {
private Long id;
/**
* 角色名称
*/
private String name;
/**
* 角色类型
* cn.axzo.tyr.client.common.enums.RoleTypeEnum
*/
private String roleType;
private String roleCode;
private Long workspaceId;
private Long ownerOuId;
/**
* 产品单位类型
* 1:总包 2:建设单位 3:监理单位 4:劳务分包 5:专业分包 6:OMS通用 7:企业通用 8:企业内班组 9:项目内班组
*/
private Integer productUnitType;
/**
* 角色权限
*/
private List<SaasPermissionRes> saasPermissions;
/**
* 角色关联的权限点id信息没有featureCode直接查询的pgPermissionRelation
*/
private List<SaasPermissionRelationRes> permissionRelations;
}
}

View File

@ -28,6 +28,15 @@ public class ListRoleUserRelationParam {
@CriteriaField(field = "ouId", operator = Operator.EQ)
private Long ouId;
@CriteriaField(field = "workspaceId", operator = Operator.EQ)
private Long workspaceId;
@CriteriaField(field = "ouId", operator = Operator.IN)
private Set<Long> ouIds;
@CriteriaField(field = "workspaceId", operator = Operator.IN)
private Set<Long> workspaceIds;
/**
* 是否显示
*/
@ -61,6 +70,9 @@ public class ListRoleUserRelationParam {
@CriteriaField(field = "identityId", operator = Operator.EQ)
private Long identityId;
@CriteriaField(field = "identityId", operator = Operator.IN)
private Set<Long> identityIds;
/**
* workspaceId和ouId配对查询
* 例如((workspaceId = ## and ouId = ##) or (workspaceId = ## and ouId = ##))

View File

@ -1,9 +1,11 @@
package cn.axzo.tyr.server.controller.roleuser;
import cn.axzo.basics.common.util.AssertUtil;
import cn.axzo.foundation.page.PageResp;
import cn.axzo.framework.domain.web.result.ApiPageResult;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
import cn.axzo.tyr.client.feign.TyrSaasRoleUserApi;
import cn.axzo.tyr.client.model.enums.IdentityType;
import cn.axzo.tyr.client.model.roleuser.RoleUserUpdateReq;
@ -12,13 +14,26 @@ import cn.axzo.tyr.client.model.roleuser.dto.GetUserFeatureResourceIdsResp;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.dto.SuperAminInfoResp;
import cn.axzo.tyr.client.model.roleuser.req.*;
import cn.axzo.tyr.client.model.roleuser.req.AutoOwnRoleUserReq;
import cn.axzo.tyr.client.model.roleuser.req.CreateSuperAdminRoleParam;
import cn.axzo.tyr.client.model.roleuser.req.GantOrUnGantaWorkerLeaderRoleReq;
import cn.axzo.tyr.client.model.roleuser.req.GetUserAutoOwnRoleReq;
import cn.axzo.tyr.client.model.roleuser.req.GetUserFeatureResourceIdsReq;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserReq;
import cn.axzo.tyr.client.model.roleuser.req.SuperAdminParam;
import cn.axzo.tyr.client.model.roleuser.req.WorkerManagerRoleUserReq;
import cn.axzo.tyr.server.model.PermissionCacheKey;
import cn.axzo.tyr.server.repository.dao.SaasRoleUserRelationDao;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import cn.axzo.tyr.server.service.PermissionCacheService;
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
import cn.axzo.tyr.server.service.SaasRoleUserService;
import cn.hutool.core.bean.BeanUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
@ -28,6 +43,9 @@ import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author tanjie@axzo.cn
@ -87,7 +105,54 @@ public class RoleUserController implements TyrSaasRoleUserApi {
@Override
public ApiResult<List<SaasRoleUserDTO>> roleUserList(@RequestBody @Valid RoleUserParam param) {
return ApiResult.ok(saasRoleUserRelationService.list(param));
// 去掉原saasRoleUserRelationService.list的重复查询接口原接口只查询1000条所以保持一致
List<SaasRoleUserV2DTO> saasRoleUsers = saasRoleUserRelationService.page(PageRoleUserRelationParam.builder()
.personId(param.getPersonId())
.identityId(param.getIdentityId())
.identityType(param.getIdentityType())
.roleIds(Optional.ofNullable(param.getRoleIds())
.map(Lists::newArrayList)
.orElse(null))
.identityIds(param.getIdentityIds())
.ouId(param.getOuId())
.workspaceId(param.getWorkspaceId())
.ouIds(Optional.ofNullable(param.getOuIds())
.map(Sets::newHashSet)
.orElse(null))
.workspaceIds(Optional.ofNullable(param.getWorkspaceIds())
.map(Sets::newHashSet)
.orElse(null))
.page(1)
.pageSize(1000)
.needRole(true)
.build())
.getData()
.stream()
.filter(e -> Objects.nonNull(e.getSaasRole()))
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(saasRoleUsers)) {
return ApiResult.ok(Collections.emptyList());
}
List<SaasRoleUserDTO> saasRoleUserDTOS = saasRoleUsers.stream()
.map(e -> {
SaasRoleUserDTO userRole = BeanUtil.copyProperties(e, SaasRoleUserDTO.class);
userRole.setNaturalPersonId(e.getSaasRoleUser().getPersonId());
userRole.setRoleName(e.getSaasRole().getName());
userRole.setDescription(e.getSaasRole().getDescription());
userRole.setRoleType(RoleTypeEnum.getRoleType(e.getSaasRole().getRoleType()));
userRole.setDisplayRole(e.getSaasRole().getIsDisplay());
userRole.setEnabled(e.getSaasRole().getEnabled());
userRole.setIdentityId(e.getSaasRoleUser().getIdentityId());
userRole.setIdentityType(e.getSaasRoleUser().getIdentityType());
userRole.setOuId(e.getSaasRoleUser().getOuId());
userRole.setWorkspaceId(e.getSaasRoleUser().getWorkspaceId());
return userRole;
})
.collect(Collectors.toList());
return ApiResult.ok(saasRoleUserDTOS);
}
@Override
@ -157,7 +222,50 @@ public class RoleUserController implements TyrSaasRoleUserApi {
@Override
public ApiPageResult<SaasRoleUserDTO> pageQuery(RoleUserParam param) {
return ApiPageResult.ok(saasRoleUserRelationService.pageQuery(param));
// 兼容以前接口切换到统一查询接口原接口废弃
PageResp<SaasRoleUserV2DTO> saasRoleUsers = saasRoleUserRelationService.page(PageRoleUserRelationParam.builder()
.personId(param.getPersonId())
.identityId(param.getIdentityId())
.identityType(param.getIdentityType())
.roleIds(Optional.ofNullable(param.getRoleIds())
.map(Lists::newArrayList)
.orElse(null))
.identityIds(param.getIdentityIds())
.ouId(param.getOuId())
.workspaceId(param.getWorkspaceId())
.ouIds(Optional.ofNullable(param.getOuIds())
.map(Sets::newHashSet)
.orElse(null))
.workspaceIds(Optional.ofNullable(param.getWorkspaceIds())
.map(Sets::newHashSet)
.orElse(null))
.page(Optional.ofNullable(param.getPage())
.map(Long::intValue)
.orElse(null))
.pageSize(Optional.ofNullable(param.getPageSize())
.map(Long::intValue)
.orElse(null))
.build());
if (CollectionUtils.isEmpty(saasRoleUsers.getData())) {
return ApiPageResult.ok(cn.axzo.framework.domain.page.PageResp.zero(param.getPage(), param.getPageSize()));
}
List<SaasRoleUserDTO> saasRoleUserDTOS = saasRoleUsers.getData().stream()
.map(e -> {
SaasRoleUserDTO userRole = BeanUtil.copyProperties(e, SaasRoleUserDTO.class);
userRole.setNaturalPersonId(e.getSaasRoleUser().getPersonId());
userRole.setIdentityId(e.getSaasRoleUser().getIdentityId());
userRole.setIdentityType(e.getSaasRoleUser().getIdentityType());
userRole.setOuId(e.getSaasRoleUser().getOuId());
userRole.setWorkspaceId(e.getSaasRoleUser().getWorkspaceId());
return userRole;
})
.collect(Collectors.toList());
return ApiPageResult.ok(cn.axzo.framework.domain.page.PageResp.list(saasRoleUsers.getCurrent(),
saasRoleUsers.getSize(),
saasRoleUsers.getTotal(),
saasRoleUserDTOS));
}
@Override

View File

@ -1,14 +1,9 @@
package cn.axzo.tyr.server.service;
import cn.axzo.framework.domain.page.PageResp;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.server.repository.entity.SaasRole;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -18,11 +13,10 @@ import java.util.List;
* @date 2023/9/14
*/
public interface SaasRoleUserRelationService extends IService<SaasRoleUserRelation> {
List<SaasRoleUserDTO> list(RoleUserParam param);
PageResp<SaasRoleUserDTO> pageQuery(RoleUserParam param);
List<SaasRoleUserV2DTO> listV2(ListRoleUserRelationParam param);
cn.axzo.foundation.page.PageResp<SaasRoleUserV2DTO> page(PageRoleUserRelationParam param);
void upsert(List<SaasRoleUserRelation> saasRoleUserRelations);
}

View File

@ -37,6 +37,7 @@ import cn.axzo.tyr.client.model.res.NavTreeResp;
import cn.axzo.tyr.client.model.res.ProductFeatureResourceResp;
import cn.axzo.tyr.client.model.res.SaasFeatureResourceResp;
import cn.axzo.tyr.client.model.res.SaasPermissionRelationRes;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import cn.axzo.tyr.client.model.res.TreePermissionResp;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
@ -412,7 +413,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
.map(roleUser -> {
WorkspaceProductService.WorkspaceProduct workspaceProduct = workspaceProductMap.get(roleUser.getSaasRoleUser().getWorkspaceId());
SaasRoleUserV2DTO.SaasRole saasRole = roleUser.getSaasRole();
SaasRoleRes saasRole = roleUser.getSaasRole();
if (RoleTypeEnum.isAdmin(saasRole.getRoleType())) {
return resolveAdminRole(workspaceProduct, saasRole);
}
@ -997,7 +998,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
return null;
}
SaasRoleUserV2DTO.SaasRole saasRole = roleUser.getSaasRole();
SaasRoleRes saasRole = roleUser.getSaasRole();
Set<Long> adminFeatureIds = resolveAdminRole(productFeatureSources, saasRole);
Set<Long> notAuthFeatureIds = resolveNotAuthFeatureIds(productFeatureSources, authFreeFeatureIds);
@ -1023,7 +1024,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
}
private Set<Long> resolveAdminRole(List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> productFeatureSources,
SaasRoleUserV2DTO.SaasRole saasRole) {
SaasRoleRes saasRole) {
if (!RoleTypeEnum.isAdmin(saasRole.getRoleType())) {
return Collections.emptySet();
@ -1038,7 +1039,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
}
private Set<Long> resolveNormalRole(List<ProductSaasFeatureResourceCacheService.FeatureResourceDTO> workspaceProduct,
SaasRoleUserV2DTO.SaasRole saasRole,
SaasRoleRes saasRole,
List<RoleSaasFeatureResourceCacheService.SaasFeatureResourceDTO> roleFeatureResources) {
if (CollectionUtils.isEmpty(roleFeatureResources)) {
@ -1071,7 +1072,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
}
private List<Long> resolveAdminRole(WorkspaceProductService.WorkspaceProduct workspaceProduct,
SaasRoleUserV2DTO.SaasRole saasRole) {
SaasRoleRes saasRole) {
//超管和管理员 直接取和角色类型匹配的租户产品权限
return workspaceProduct.getSaasProductModuleFeatureRelations().stream()
@ -1082,7 +1083,7 @@ public class PermissionQueryServiceImpl implements PermissionQueryService {
}
private List<Long> resolveNormalRole(WorkspaceProductService.WorkspaceProduct workspaceProduct,
SaasRoleUserV2DTO.SaasRole saasRole,
SaasRoleRes saasRole,
Set<Long> authFreeFeatureIds) {
//普通角色角色同类型的租户产品权限已分配 且角色上已分配 + 免授权
Set<Long> roleFeatureIds = Optional.ofNullable(saasRole.getPermissionRelations())

View File

@ -12,6 +12,7 @@ import cn.axzo.tyr.client.model.BaseWorkspaceModel;
import cn.axzo.tyr.client.model.enums.DictWorkSpaceTypeEnum;
import cn.axzo.tyr.client.model.enums.IdentityType;
import cn.axzo.tyr.client.model.enums.WorkerLeaderRoleEnum;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import cn.axzo.tyr.client.model.roleuser.RoleUserUpdateReq;
import cn.axzo.tyr.client.model.roleuser.dto.GetUserAutoOwnRoleResp;
import cn.axzo.tyr.client.model.roleuser.dto.GetUserFeatureResourceIdsResp;
@ -38,6 +39,7 @@ import cn.axzo.tyr.server.repository.entity.SaasPgroupRoleRelation;
import cn.axzo.tyr.server.repository.entity.SaasRole;
import cn.axzo.tyr.server.repository.entity.SaasRoleGroupRelation;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import cn.axzo.tyr.server.service.RoleService;
import cn.axzo.tyr.server.service.SaasRoleGroupService;
import cn.axzo.tyr.server.service.SaasRoleUserService;
import cn.hutool.core.collection.CollectionUtil;
@ -84,6 +86,7 @@ public class RoleUserService implements SaasRoleUserService {
private final SaasRoleGroupService saasRoleGroupService;
private final SaasRoleGroupRelationDao saasRoleGroupRelationDao;
private final SaasPgroupPermissionRelationDao saasPgroupPermissionRelationDao;
private final RoleService roleService;
// 单位类型默认角色关系,后面可以座位管理员的逻辑进行迭代
@Value("#{${participateUnitDefaultRoleId:{}}}")

View File

@ -1,33 +1,20 @@
package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.BeanMapper;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
import cn.axzo.basics.profiles.dto.basic.PersonProfileDto;
import cn.axzo.foundation.dao.support.converter.PageConverter;
import cn.axzo.foundation.dao.support.mysql.QueryWrapperHelper;
import cn.axzo.framework.domain.page.PageResp;
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserDTO;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.RoleUserParam;
import cn.axzo.tyr.server.repository.dao.SaasRoleDao;
import cn.axzo.tyr.server.repository.dao.SaasRoleUserRelationDao;
import cn.axzo.tyr.server.repository.entity.SaasRole;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import cn.axzo.tyr.server.repository.mapper.SaasRoleUserRelationMapper;
import cn.axzo.tyr.server.service.RoleService;
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
import cn.axzo.tyr.server.util.RpcInternalUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@ -36,9 +23,9 @@ import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -58,76 +45,11 @@ import java.util.stream.Collectors;
public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRelationMapper, SaasRoleUserRelation>
implements SaasRoleUserRelationService {
@Resource
private SaasRoleUserRelationDao saasRoleUserRelationDao;
@Resource
private SaasRoleDao saasRoleDao;
@Autowired
private UserProfileServiceApi userProfileServiceApi;
@Autowired
private RoleService roleService;
@Override
public List<SaasRoleUserDTO> list(RoleUserParam param) {
// TODO jhy 角色查询 需要验证标准角色和自定义角色的查询逻辑
LambdaQueryChainWrapper<SaasRoleUserRelation> wrapper = buildWrapper(param);
List<SaasRoleUserRelation> saasRoleUserRelations = wrapper.last("LIMIT 1000").list();
if (CollectionUtil.isEmpty(saasRoleUserRelations)) {
return Collections.emptyList();
}
Map<Long, SaasRole> roleMap = saasRoleDao.lambdaQuery()
.in(SaasRole::getId, saasRoleUserRelations.stream().map(SaasRoleUserRelation::getRoleId).collect(Collectors.toSet()))
.list().stream().collect(Collectors.toMap(SaasRole::getId, Function.identity()));
return saasRoleUserRelations.stream()
.filter(e -> roleMap.containsKey(e.getRoleId()))
.map(e -> {
SaasRoleUserDTO userRole = BeanUtil.copyProperties(e, SaasRoleUserDTO.class);
SaasRole role = roleMap.get(userRole.getRoleId());
userRole.setRoleName(role.getName());
userRole.setDescription(role.getDescription());
userRole.setRoleType(RoleTypeEnum.getRoleType(role.getRoleType()));
userRole.setDisplayRole(role.getIsDisplay());
userRole.setEnabled(role.getEnabled());
return userRole;
}).collect(Collectors.toList());
}
private LambdaQueryChainWrapper<SaasRoleUserRelation> buildWrapper(RoleUserParam param) {
return saasRoleUserRelationDao.lambdaQuery()
.eq(Objects.nonNull(param.getPersonId()), SaasRoleUserRelation::getNaturalPersonId, param.getPersonId())
.eq(Objects.nonNull(param.getIdentityId()), SaasRoleUserRelation::getIdentityId, param.getIdentityId())
.eq(Objects.nonNull(param.getIdentityType()), SaasRoleUserRelation::getIdentityType, param.getIdentityType())
.eq(Objects.nonNull(param.getWorkspaceId()), SaasRoleUserRelation::getWorkspaceId, param.getWorkspaceId())
.eq(Objects.nonNull(param.getOuId()), SaasRoleUserRelation::getOuId, param.getOuId())
.in(CollectionUtil.isNotEmpty(param.getOuIds()), SaasRoleUserRelation::getOuId, param.getOuIds())
.in(CollectionUtil.isNotEmpty(param.getWorkspaceIds()), SaasRoleUserRelation::getWorkspaceId, param.getWorkspaceIds())
.in(CollectionUtil.isNotEmpty(param.getRoleIds()), SaasRoleUserRelation::getRoleId, param.getRoleIds())
.in(CollectionUtil.isNotEmpty(param.getIdentityIds()), SaasRoleUserRelation::getIdentityId, param.getIdentityIds())
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value);
}
@Override
public PageResp<SaasRoleUserDTO> pageQuery(RoleUserParam param) {
//限制分页100
if (param.getPageSize() != null && param.getPageSize().compareTo(200L) > 0) {
param.setPageSize(100L);
}
//查询条件构造 - ID升序
LambdaQueryChainWrapper<SaasRoleUserRelation> wrapper = buildWrapper(param)
.orderByAsc(SaasRoleUserRelation::getId);
IPage<SaasRoleUserRelation> page = wrapper.page(param.toPage());
if (CollectionUtil.isEmpty(page.getRecords())) {
return PageResp.zero(param.getPage(), param.getPageSize());
}
List<SaasRoleUserDTO> list = page.getRecords().stream()
.map(r -> BeanMapper.copyBean(r, SaasRoleUserDTO.class))
.collect(Collectors.toList());
return PageResp.list(param.getPage(), param.getPageSize(), page.getTotal(), list);
}
@Override
public List<SaasRoleUserV2DTO> listV2(ListRoleUserRelationParam param) {
return PageConverter.drainAll(pageNumber -> {
@ -165,11 +87,17 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
Map<Long, SaasRoleUserV2DTO.SaasRoleUser> saasRoleUsers = listSaasRoleUser(param, page.getRecords());
Map<Long, SaasRoleUserV2DTO.SaasRole> saasRoles = listSaasRole(param, page.getRecords());
Map<Long, SaasRoleRes> saasRoles = listSaasRole(param, page.getRecords());
return PageConverter.toResp(page, (record) -> from(record, saasRoleUsers, saasRoles));
}
@Override
@Transactional
public void upsert(List<SaasRoleUserRelation> saasRoleUserRelations) {
}
private Set<Long> resolveRoleIds(PageRoleUserRelationParam param) {
if (CollectionUtils.isEmpty(param.getRoleCodes())) {
return Optional.ofNullable(param.getRoleIds())
@ -231,7 +159,7 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
private SaasRoleUserV2DTO from(SaasRoleUserRelation saasRoleUserRelation,
Map<Long, SaasRoleUserV2DTO.SaasRoleUser> saasRoleUsers,
Map<Long, SaasRoleUserV2DTO.SaasRole> saasRoles) {
Map<Long, SaasRoleRes> saasRoles) {
SaasRoleUserV2DTO.SaasRoleUser saasRoleUser = SaasRoleUserV2DTO.SaasRoleUser.builder()
.ouId(saasRoleUserRelation.getOuId())
@ -244,15 +172,16 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
.identityId(saasRoleUserRelation.getIdentityId())
.build();
return SaasRoleUserV2DTO.builder()
.id(saasRoleUserRelation.getId())
.roleId(saasRoleUserRelation.getRoleId())
SaasRoleUserV2DTO saasRoleUserDTO = SaasRoleUserV2DTO.builder()
.saasRoleUser(saasRoleUser)
.saasRole(saasRoles.get(saasRoleUserRelation.getRoleId()))
.build();
BeanUtils.copyProperties(saasRoleUserRelation, saasRoleUserDTO);
return saasRoleUserDTO;
}
private Map<Long, SaasRoleUserV2DTO.SaasRole> listSaasRole(PageRoleUserRelationParam param,
private Map<Long, SaasRoleRes> listSaasRole(PageRoleUserRelationParam param,
List<SaasRoleUserRelation> saasRoleUserRelations) {
if (CollectionUtils.isEmpty(saasRoleUserRelations) || BooleanUtils.isNotTrue(param.getNeedRole())) {
return Collections.emptyMap();
@ -276,11 +205,6 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
.needPermission(param.getNeedPermission())
.build();
return roleService.list(listSaasRoleParam).stream()
.map(e -> {
SaasRoleUserV2DTO.SaasRole saasRole = SaasRoleUserV2DTO.SaasRole.builder().build();
BeanUtils.copyProperties(e, saasRole);
return saasRole;
})
.collect(Collectors.toMap(SaasRoleUserV2DTO.SaasRole::getId, Function.identity()));
.collect(Collectors.toMap(SaasRoleRes::getId, Function.identity()));
}
}

View File

@ -1425,16 +1425,14 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
RoleService.ListSaasRoleParam listSaasRoleParam = RoleService.ListSaasRoleParam.builder()
.roleIds(Lists.newArrayList(identityAuthReq.getSpecifyRoleIds()))
.build();
Map<Long, SaasRoleUserV2DTO.SaasRole> saasRoles = roleService.list(listSaasRoleParam).stream()
.map(role -> SaasRoleUserV2DTO.SaasRole.builder()
.build())
.collect(Collectors.toMap(SaasRoleUserV2DTO.SaasRole::getId, Function.identity()));
Map<Long, SaasRoleRes> saasRoles = roleService.list(listSaasRoleParam).stream()
.collect(Collectors.toMap(SaasRoleRes::getId, Function.identity()));
return identityAuthReq.getWorkspaceOusPairs().stream()
.map(workspaceOuPair ->
identityAuthReq.getSpecifyRoleIds().stream()
.map(roleId -> {
SaasRoleUserV2DTO.SaasRole saasRole = saasRoles.get(roleId);
SaasRoleRes saasRole = saasRoles.get(roleId);
if (Objects.isNull(saasRole)) {
return null;
}
@ -1496,7 +1494,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
Map<Long, List<RolePermissionCacheService.PermissionDTO>> rolePermissions = listRolePermission(identityAuthReq, saasRoleUsers);
Map<String, List<SaasRoleUserV2DTO.SaasRole>> workspaceRoles = saasRoleUsers.stream()
Map<String, List<SaasRoleRes>> workspaceRoles = saasRoleUsers.stream()
.collect(Collectors.groupingBy(e -> e.getSaasRoleUser().buildOuWorkspaceKey(),
Collectors.mapping(SaasRoleUserV2DTO::getSaasRole, Collectors.toList())));
@ -1532,7 +1530,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
.build();
}
List<SaasRoleUserV2DTO.SaasRole> saasRoles = workspaceRoles.get(workspaceOuPair.buildOuWorkspaceKey());
List<SaasRoleRes> saasRoles = workspaceRoles.get(workspaceOuPair.buildOuWorkspaceKey());
if (CollectionUtils.isEmpty(saasRoles)) {
return IdentityAuthRes.WorkspacePermission.builder()
@ -1557,7 +1555,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
private IdentityAuthRes.WorkspacePermission buildPermissionsV2(IdentityAuthReq.WorkspaceOuPair workspaceOuPair,
List<ProductPermissionCacheService.PermissionDTO> productPermissions,
List<SaasRoleUserV2DTO.SaasRole> saasRoles,
List<SaasRoleRes> saasRoles,
Map<Long, List<RolePermissionCacheService.PermissionDTO>> rolePermissions,
List<SaasFeatureResourceService.SaasFeatureResourceCache> allFeatures) {
@ -1611,9 +1609,9 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
}
private Set<IdentityAuthRes.PermissionPoint> buildAdminPermissionV2(List<ProductPermissionCacheService.PermissionDTO> productPermissions,
List<SaasRoleUserV2DTO.SaasRole> saasRoles) {
List<SaasRoleRes> saasRoles) {
//超管和管理员角色
List<SaasRoleUserV2DTO.SaasRole> adminRoles = Optional.ofNullable(saasRoles)
List<SaasRoleRes> adminRoles = Optional.ofNullable(saasRoles)
.map(e -> e.stream()
.filter(r -> RoleTypeEnum.isAdmin(r.getRoleType()))
.collect(Collectors.toList()))
@ -1625,7 +1623,7 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
//聚合超管和管理员的权限点 直接取角色标签和产品标签相匹配的权限点
Set<String> productUnitTypes = adminRoles.stream()
.map(SaasRoleUserV2DTO.SaasRole::getProductUnitType)
.map(SaasRoleRes::getProductUnitType)
.map(String::valueOf)
.collect(Collectors.toSet());
@ -1673,10 +1671,10 @@ public class TyrSaasAuthServiceImpl implements TyrSaasAuthService {
}
private Set<IdentityAuthRes.PermissionPoint> buildNormalPermissionV2(List<ProductPermissionCacheService.PermissionDTO> productPermissions,
List<SaasRoleUserV2DTO.SaasRole> saasRoles,
List<SaasRoleRes> saasRoles,
Map<Long, List<RolePermissionCacheService.PermissionDTO>> rolePermissionMap) {
List<SaasRoleUserV2DTO.SaasRole> normalRoles =Optional.ofNullable(saasRoles)
List<SaasRoleRes> normalRoles =Optional.ofNullable(saasRoles)
.map(e -> e.stream()
.filter(r -> !RoleTypeEnum.isAdmin(r.getRoleType()))
.collect(Collectors.toList()))