feat(2046) 添加通过角色分组Code查询标准角色接口

This commit is contained in:
TanJ 2024-01-13 18:39:09 +08:00
parent aef8a7778e
commit a897771bf3
9 changed files with 118 additions and 9 deletions

View File

@ -11,6 +11,7 @@ import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.QueryRoleByNameResp;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import org.springframework.cloud.openfeign.FeignClient;
@ -118,4 +119,11 @@ public interface TyrSaasRoleApi {
@GetMapping("/api/saasRole/queryByWorkspaceType")
ApiResult<List<SaasRoleAndGroupVO>> queryInitRoleByWorkspaceId(@RequestParam("workspaceType") String workspaceType);
/**
* 通过角色分组Code查询标准角色
*/
@GetMapping("/api/saasRole/queryByCategoryCode")
ApiResult<List<SaasRoleCategoryVO>> queryByCategoryCode(@RequestParam("categoryCodes") List<String> categoryCodes);
}

View File

@ -0,0 +1,28 @@
package cn.axzo.tyr.client.model.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import javax.validation.constraints.NotBlank;
import java.util.Date;
import java.util.List;
/**
* 标准角色与其分组数据
* @author tanjie@axzo.cn
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class SaasRoleCategoryVO {
private String categoryCode;
private List<SaasRoleVO> roleInfos;
}

View File

@ -13,6 +13,7 @@ import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.QueryRoleByNameResp;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import cn.axzo.tyr.server.model.PermissionCacheKey;
@ -111,4 +112,9 @@ public class SaasRoleController implements TyrSaasRoleApi {
return ApiResult.ok(roleService.queryInitRoleByWorkspaceId(workspaceType));
}
@Override
public ApiResult<List<SaasRoleCategoryVO>> queryByCategoryCode(List<String> categoryCodes) {
return ApiResult.ok(roleService.queryByCategoryCode(categoryCodes));
}
}

View File

@ -32,5 +32,13 @@ public class SaasPgroupRoleRelationDao extends ServiceImpl<SaasPgroupRoleRelatio
.set(BaseEntity::getIsDelete, TableIsDeleteEnum.DELETE.value)
.update();
}
public List<SaasPgroupRoleRelation> findByRoleIds(Collection<Long> roleIds) {
return lambdaQuery()
.select(SaasPgroupRoleRelation::getGroupId)
.in(SaasPgroupRoleRelation::getRoleId, roleIds).list();
}
}

View File

@ -28,7 +28,10 @@ public class SaasRoleGroupRelationDao extends ServiceImpl<SaasRoleGroupRelationM
.update();
}
public List<SaasRoleGroupRelation> getByGroupIds(List<Long> groupIds) {
public List<SaasRoleGroupRelation> getByGroupIds(Collection<Long> groupIds) {
if (CollectionUtils.isEmpty(groupIds)) {
return new ArrayList<>();
}
return lambdaQuery().in(SaasRoleGroupRelation::getSaasRoleGroupId, groupIds)
.eq(BaseEntity::getIsDelete, 0)
.list();
@ -44,13 +47,6 @@ public class SaasRoleGroupRelationDao extends ServiceImpl<SaasRoleGroupRelationM
.update();
}
public List<SaasRoleGroupRelation> findByGroupId(Set<Long> groupIds) {
if (CollectionUtils.isEmpty(groupIds)) {
return new ArrayList<>();
}
return lambdaQuery().eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL)
.in(SaasRoleGroupRelation::getSaasRoleGroupId, groupIds).list();
}
}

View File

@ -131,5 +131,6 @@ public class SaasRoleUserRelationDao extends ServiceImpl<SaasRoleUserRelationMap
.setSql(" is_delete = id");
}
}

View File

@ -8,6 +8,7 @@ import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.QueryRoleByNameResp;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import cn.axzo.tyr.server.repository.entity.SaasRole;
@ -88,4 +89,6 @@ public interface RoleService {
void deleteRole(List<Long> roleIds,Long workSpaceId,Long outId);
List<SaasRole> getByIds(Set<Long> ids);
List<SaasRoleCategoryVO> queryByCategoryCode(List<String> categoryCodes);
}

View File

@ -16,6 +16,7 @@ import cn.axzo.tyr.client.model.res.QueryRoleByNameResp;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleAndGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleCategoryVO;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
@ -83,6 +84,8 @@ public class RoleServiceImpl implements RoleService {
SaasRoleUserRelationDao saasRoleUserRelationDao;
@Autowired
RoleUserService roleUserService;
@Autowired
SaasRoleGroupRelationDao saasRoleGroupRelationDao;
@Override
public List<SaasRoleVO> queryByIdentityIdType(Long identityId, Integer identityType, Long workspaceId, Long ouId, Boolean includePermissionGroup) {
@ -714,4 +717,60 @@ public class RoleServiceImpl implements RoleService {
public List<SaasRole> getByIds(Set<Long> ids) {
return saasRoleDao.listByIds(ids);
}
@Override
public List<SaasRoleCategoryVO> queryByCategoryCode(List<String> categoryCodes) {
if (CollectionUtils.isEmpty(categoryCodes)) {
return new ArrayList<>();
}
List<SaasRoleCategoryVO> result = new ArrayList<>();
List<SaasRoleGroup> saasRoleGroups = saasRoleGroupDao.listByCategoryCode(categoryCodes);
Set<Long> roleGroupId = saasRoleGroups.stream().map(BaseEntity::getId).collect(Collectors.toSet());
List<SaasRoleGroupRelation> roleGroupRelations = saasRoleGroupRelationDao.getByGroupIds(roleGroupId);
Map<Long, List<SaasRoleGroupRelation>> groupByGroupId = roleGroupRelations.stream().collect(Collectors.groupingBy(SaasRoleGroupRelation::getSaasRoleGroupId));
Set<Long> roleIds = roleGroupRelations.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toSet());
List<SaasPgroupRoleRelation> saasPgroupRoleRelations = saasPgroupRoleRelationDao.findByRoleIds(roleIds);
Map<Long, List<SaasPgroupRoleRelation>> rolePermissionMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
List<Long> permissionIds = saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).distinct().collect(Collectors.toList());
if (CollectionUtils.isEmpty(roleIds) || CollectionUtils.isEmpty(permissionIds)) {
return new ArrayList<>();
}
//原数据
List<SaasRole> roleInfos = getByIds(roleIds);
List<SaasPermissionGroup> permissionGroups = saasPermissionGroupDao.listByIds(permissionIds);
Map<Long, SaasRole> roleMap = roleInfos.stream().collect(Collectors.toMap(BaseEntity::getId, Function.identity()));
Map<Long, SaasPermissionGroup> permissionGroupMap = permissionGroups.stream().collect(Collectors.toMap(BaseEntity::getId, Function.identity()));
saasRoleGroups.stream().collect(Collectors.groupingBy(SaasRoleGroup::getCategoryCode)).forEach((categoryCode,saasRoleGroupsInfo)->{
SaasRoleCategoryVO saasRoleCategoryVO = new SaasRoleCategoryVO();
saasRoleCategoryVO.setCategoryCode(categoryCode);
List<Long> roleId = saasRoleGroupsInfo.stream().map(e -> groupByGroupId.get(e.getId())).flatMap(List::stream).map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList());
List<SaasRoleVO> saasRoleVOS = BeanUtil.copyToList(roleId.stream().map(roleMap::get).collect(Collectors.toList()), SaasRoleVO.class);
saasRoleVOS.forEach(
e->{
List<SaasPgroupRoleRelation> pgroupRoleRelations = rolePermissionMap.get(e.getId());
List<SaasPermissionGroup> permissionGroupList = pgroupRoleRelations.stream().map(pgroupRoleRelation -> permissionGroupMap.get(pgroupRoleRelation.getGroupId())).collect(Collectors.toList());
e.setPermissionGroup(BeanUtil.copyToList(permissionGroupList,SaasPermissionGroupVO.class));
}
);
saasRoleCategoryVO.setRoleInfos(saasRoleVOS);
result.add(saasRoleCategoryVO);
});
return result;
}
}

View File

@ -414,7 +414,7 @@ public class RoleUserService implements SaasRoleUserService {
throw new ServiceException("不支持清除该人员所有角色,请指定分组");
}
List<SaasRoleGroupVO> saasRoleGroupVO = saasRoleGroupService.listByCategoryCode(Lists.newArrayList(categoryCode));
List<SaasRoleGroupRelation> roleGroupRelations = saasRoleGroupRelationDao.findByGroupId(saasRoleGroupVO.stream().map(SaasRoleGroupVO::getId).collect(Collectors.toSet()));
List<SaasRoleGroupRelation> roleGroupRelations = saasRoleGroupRelationDao.getByGroupIds(saasRoleGroupVO.stream().map(SaasRoleGroupVO::getId).distinct().collect(Collectors.toList()));
Set<Long> roleIds = roleGroupRelations.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toSet());
if (CollectionUtil.isEmpty(roleIds)) {
return;