feature(role-query): 角色分页查询接口

This commit is contained in:
zhansihu 2023-10-18 16:22:53 +08:00
parent edba38383b
commit d14cb28066
7 changed files with 191 additions and 49 deletions

View File

@ -1,10 +1,13 @@
package cn.axzo.tyr.client.feign;
import cn.axzo.framework.domain.web.result.ApiPageResult;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
import cn.axzo.tyr.client.model.req.RoleWithUserQueryReq;
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import org.springframework.cloud.openfeign.FeignClient;
@ -72,4 +75,9 @@ public interface TyrSaasRoleApi {
@PostMapping("/api/saasRole/isSuperAdmin")
ApiResult<List<IsSuperAdminRes>> isSuperAdmin(@RequestBody List<QueryByIdentityIdTypeReq> req);
/** 分页查询角色含用户 **/
@PostMapping("/api/saasRole/queryWithUser")
ApiPageResult<RoleWithUserRes> queryRoleWithUser(@RequestBody RoleWithUserQueryReq req);
}

View File

@ -0,0 +1,24 @@
package cn.axzo.tyr.client.model.req;
import cn.axzo.basics.common.page.PageRequest;
import lombok.Data;
/**
* 角色-含用户查询参数
*
* @version V1.0
* @author: ZhanSiHu
* @date: 2023/10/16 17:58
*/
@Data
public class RoleWithUserQueryReq extends PageRequest {
/** 查询关键字 **/
private String keyword;
/** 企业组织ID **/
private Long ouId;
/** 工作台ID **/
private Long workspaceId;
}

View File

@ -0,0 +1,44 @@
package cn.axzo.tyr.client.model.res;
import lombok.Data;
import java.util.List;
/**
* 角色用户响应
*
* @version V1.0
* @author: ZhanSiHu
* @date: 2023/10/16 17:50
*/
@Data
public class RoleWithUserRes {
/** 角色ID **/
private Long roleId;
/** 角色名称 **/
private String roleName;
/** 角色类型 **/
private String roleType;
/** 角色下用户 **/
private List<UserVO> users;
@Data
public static class UserVO {
/** 身份ID **/
private Long identityId;
/** 身份类型 **/
private Integer identityType;
/** 名称 **/
private String name;
/** 组织节点ID **/
private Long nodeId;
}
}

View File

@ -30,6 +30,9 @@ public class FeignConfig implements RequestInterceptor, EnvironmentAware {
@Value("${sennaEnvUrl:http://dev-app.axzo.cn/workflow-engine}")
private String workflowEnvUrl;
@Value("${thronesEnvUrl:http://dev-app.axzo.cn/thrones}")
private String thronesEnvUrl;
private static String POD_NAMESPACE;
static {
@ -49,6 +52,7 @@ public class FeignConfig implements RequestInterceptor, EnvironmentAware {
// 如需修改微服务地址,建议通过外部化参数来调整
url = url.replace("http://msg-center:8080", msgCenterEnvUrl);
url = url.replace("http://workflow-engine:8080", workflowEnvUrl);
url = url.replace("http://thrones", thronesEnvUrl);
String profile = environment.getProperty("spring.profiles.active");
if(Objects.equals(profile, "test") && url.contains("dev-app.axzo.cn")) {
url = url.replace("dev-app", "test-api");

View File

@ -1,12 +1,15 @@
package cn.axzo.tyr.server.controller.role;
import cn.axzo.basics.common.exception.ServiceException;
import cn.axzo.framework.domain.web.result.ApiPageResult;
import cn.axzo.framework.domain.web.result.ApiResult;
import cn.axzo.tyr.client.feign.TyrSaasRoleApi;
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
import cn.axzo.tyr.client.model.req.RoleWithUserQueryReq;
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import cn.axzo.tyr.server.service.RoleService;
@ -74,4 +77,9 @@ public class SaasRoleController implements TyrSaasRoleApi {
return ApiResult.ok(roleService.isSuperAdmin(req));
}
@Override
public ApiPageResult<RoleWithUserRes> queryRoleWithUser(RoleWithUserQueryReq req) {
return ApiPageResult.ok(roleService.queryRoleWithUser(req));
}
}

View File

@ -1,11 +1,13 @@
package cn.axzo.tyr.server.service;
import cn.axzo.tyr.client.common.enums.WorkspaceJoinType;
import cn.axzo.framework.domain.page.PageResp;
import cn.axzo.tyr.client.model.enums.IdentityType;
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
import cn.axzo.tyr.client.model.req.RoleWithUserQueryReq;
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
import cn.axzo.tyr.client.model.vo.SaveOrUpdateRoleVO;
import cn.axzo.tyr.server.repository.entity.SaasRoleWithUser;
@ -51,4 +53,6 @@ public interface RoleService {
*/
Set<Long> filterPermissionPoint(Set<SaasRoleVO> role, TyrSaasAuthServiceImpl.UserRoleInfoMap userRoleInfoMap);
/** 分页查询角色含用户 **/
PageResp<RoleWithUserRes> queryRoleWithUser(RoleWithUserQueryReq req);
}

View File

@ -2,6 +2,7 @@ package cn.axzo.tyr.server.service.impl;
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.basics.common.exception.ServiceException;
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.common.enums.WorkspaceJoinType;
@ -13,8 +14,10 @@ import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
import cn.axzo.tyr.client.model.req.QuerySaasPermissionGroupReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleGroupReq;
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
import cn.axzo.tyr.client.model.req.RoleWithUserQueryReq;
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
import cn.axzo.tyr.client.model.res.QueryBatchByIdentityIdTypeRes;
import cn.axzo.tyr.client.model.res.RoleWithUserRes;
import cn.axzo.tyr.client.model.vo.SaasPermissionGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleGroupVO;
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
@ -28,6 +31,8 @@ import cn.axzo.tyr.server.service.SaasRoleGroupRelationService;
import cn.axzo.tyr.server.service.SaasRoleGroupService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -76,6 +81,9 @@ public class RoleServiceImpl implements RoleService {
@Autowired
SaasRoleGroupService saasRoleGroupService;
@Autowired
SaasRoleUserRelationDao saasRoleUserRelationDao;
@Override
public List<SaasRoleVO> queryByIdentityIdType(Long identityId, Integer identityType, Long workspaceId, Long ouId) {
// 查询人关联的角色id
@ -112,15 +120,15 @@ public class RoleServiceImpl implements RoleService {
pgrouRelationMap = saasPgroupRoleRelations.stream().collect(Collectors.groupingBy(SaasPgroupRoleRelation::getRoleId));
// 查询权限集
pGroupMap = permissionGroupService.page(QuerySaasPermissionGroupReq.builder()
.isCommon(isCommon)
.roleIds(roleIds)
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
.workspaceId(workspaceId)
.ouId(ouId)
.fetchPage(Boolean.FALSE)
.build()).getList()
// 转map<pgroupId>
.stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId));
.isCommon(isCommon)
.roleIds(roleIds)
.ids(saasPgroupRoleRelations.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList()))
.workspaceId(workspaceId)
.ouId(ouId)
.fetchPage(Boolean.FALSE)
.build()).getList()
// 转map<pgroupId>
.stream().collect(Collectors.groupingBy(SaasPermissionGroupVO::getId));
}
}
Map<Long, List<SaasPgroupRoleRelation>> finalPgrouRelationMap = pgrouRelationMap;
@ -130,12 +138,12 @@ public class RoleServiceImpl implements RoleService {
List<SaasPermissionGroupVO> pGroup = new ArrayList<>();
if (finalPgrouRelationMap != null && finalPgrouRelationMap.containsKey(role.getId())) {
pGroup = finalPgrouRelationMap.get(role.getId())
.stream()
.map(SaasPgroupRoleRelation::getGroupId)
.map(finalPGroupMap::get)
.filter(Objects::nonNull)
.flatMap(List::stream)
.collect(Collectors.toList());
.stream()
.map(SaasPgroupRoleRelation::getGroupId)
.map(finalPGroupMap::get)
.filter(Objects::nonNull)
.flatMap(List::stream)
.collect(Collectors.toList());
}
SaasRoleVO saasRoleVO = BeanUtil.copyProperties(role, SaasRoleVO.class);
saasRoleVO.setPermissionGroup(pGroup);
@ -166,10 +174,10 @@ public class RoleServiceImpl implements RoleService {
List<SaasRoleGroup> roleGroup = new ArrayList<>();
if (CollectionUtils.isNotEmpty(req.getWorkspaceTypeCode()) || CollectionUtils.isNotEmpty(req.getOuTypeCode())) {
roleGroup = saasRoleGroupDao.query(QuerySaasRoleGroupReq.builder()
.ids(req.getSassRoleGroupIds())
.workspaceTypeCode(req.getWorkspaceTypeCode())
.ouTypeCode(req.getOuTypeCode())
.build());
.ids(req.getSassRoleGroupIds())
.workspaceTypeCode(req.getWorkspaceTypeCode())
.ouTypeCode(req.getOuTypeCode())
.build());
if (CollectionUtils.isEmpty(roleGroup)) {
return new ArrayList<>();
}
@ -178,21 +186,21 @@ public class RoleServiceImpl implements RoleService {
List<SaasRoleGroupRelation> groupRelation = new ArrayList<>();
if (CollectionUtils.isNotEmpty(roleGroup)) {
groupRelation = roleGroupRelationDao.lambdaQuery()
.in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList()))
.list();
.in(SaasRoleGroupRelation::getSaasRoleGroupId, roleGroup.stream().map(BaseEntity::getId).collect(Collectors.toList()))
.list();
if (CollectionUtils.isEmpty(groupRelation)) {
return new ArrayList<>();
}
}
// 查询角色
List<SaasRole> list = saasRoleDao.lambdaQuery()
.in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId, req.getIds())
.in(CollectionUtils.isNotEmpty(groupRelation), BaseEntity::getId, groupRelation.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList()))
.in(CollectionUtils.isNotEmpty(req.getRoleType()), SaasRole::getRoleType, req.getRoleType())
.in(CollectionUtils.isNotEmpty(req.getWorkspaceId()),SaasRole::getWorkspaceId,req.getWorkspaceId())
.in(CollectionUtils.isNotEmpty(req.getOuId()),SaasRole::getOwnerOuId,req.getOuId())
.orderByDesc(BaseEntity::getId)
.list();
.in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId, req.getIds())
.in(CollectionUtils.isNotEmpty(groupRelation), BaseEntity::getId, groupRelation.stream().map(SaasRoleGroupRelation::getRoleId).collect(Collectors.toList()))
.in(CollectionUtils.isNotEmpty(req.getRoleType()), SaasRole::getRoleType, req.getRoleType())
.in(CollectionUtils.isNotEmpty(req.getWorkspaceId()),SaasRole::getWorkspaceId,req.getWorkspaceId())
.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(),req.getIncludePermissionGroup());
}
@ -201,12 +209,12 @@ public class RoleServiceImpl implements RoleService {
List<QueryBatchByIdentityIdTypeRes> result = new ArrayList<>();
req.forEach(e -> {
result.add(QueryBatchByIdentityIdTypeRes.builder()
.identityId(e.getIdentityId())
.identityType(e.getIdentityType())
.workspaceId(e.getWorkspaceId())
.ouId(e.getOuId())
.role(queryByIdentityIdType(e.getIdentityId(),e.getIdentityType(),e.getWorkspaceId(),e.getOuId()))
.build());
.identityId(e.getIdentityId())
.identityType(e.getIdentityType())
.workspaceId(e.getWorkspaceId())
.ouId(e.getOuId())
.role(queryByIdentityIdType(e.getIdentityId(),e.getIdentityType(),e.getWorkspaceId(),e.getOuId()))
.build());
});
return result;
}
@ -268,17 +276,17 @@ public class RoleServiceImpl implements RoleService {
List<SaasRole> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(roleIds)) {
list = saasRoleDao.lambdaQuery()
.in(BaseEntity::getId, roleIds)
.eq(SaasRole::getRoleType, RoleTypeEnum.SUPER_ADMIN.getValue())
.list();
.in(BaseEntity::getId, roleIds)
.eq(SaasRole::getRoleType, RoleTypeEnum.SUPER_ADMIN.getValue())
.list();
}
result.add(IsSuperAdminRes.builder()
.identityId(e.getIdentityId())
.identityType(e.getIdentityType())
.workspaceId(e.getWorkspaceId())
.ouId(e.getOuId())
.isSuperAdmin(CollectionUtils.isNotEmpty(list)?true:false)
.build());
.identityId(e.getIdentityId())
.identityType(e.getIdentityType())
.workspaceId(e.getWorkspaceId())
.ouId(e.getOuId())
.isSuperAdmin(CollectionUtils.isNotEmpty(list)?true:false)
.build());
});
return result;
}
@ -411,9 +419,9 @@ public class RoleServiceImpl implements RoleService {
*/
public List<SaasPgroupRoleRelation> queryPermissionGroupRelation(List<Long> roleIds) {
return saasPgroupRoleRelationDao.lambdaQuery()
.in(SaasPgroupRoleRelation::getRoleId, roleIds)
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list();
.in(SaasPgroupRoleRelation::getRoleId, roleIds)
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
.list();
}
@Override
@ -426,7 +434,7 @@ public class RoleServiceImpl implements RoleService {
Set<Long> initRoleId = new HashSet<>();
//有标准角查询角色分组
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()))
.ouTypeCode(Collections.singletonList(userRoleInfoMap.getWorkspaceJoinType().getValue().toString()))
.build());
@ -440,9 +448,51 @@ public class RoleServiceImpl implements RoleService {
.collect(Collectors.toList());
return resultRole.stream().map(
e -> e.getMatchFeature(userRoleInfoMap.workspaceId, userRoleInfoMap.getOuId()))
e -> e.getMatchFeature(userRoleInfoMap.workspaceId, userRoleInfoMap.getOuId()))
.flatMap(List::stream)
.map(PermissionPointTreeNode::getPermissionPointId)
.collect(Collectors.toSet());
}
@Override
public PageResp<RoleWithUserRes> queryRoleWithUser(RoleWithUserQueryReq req) {
//按role进行分页查询
Page<SaasRole> rolePage = saasRoleDao
.page(new Page<>(req.getPage(), req.getPageSize()),
new LambdaQueryWrapper<SaasRole>()
.eq(SaasRole::getOwnerOuId, req.getOuId())
.eq(SaasRole::getWorkspaceId, req.getWorkspaceId()));
if (CollectionUtil.isEmpty(rolePage.getRecords())) {
return PageResp.list(req.getPage(), req.getPageSize(), 0L, Collections.emptyList());
}
//反查relation
List<Long> roleIds = rolePage.getRecords().stream().map(SaasRole::getId).collect(Collectors.toList());
List<SaasRoleUserRelation> relationList = saasRoleUserRelationDao.list(new LambdaQueryWrapper<SaasRoleUserRelation>().
in(SaasRoleUserRelation::getRoleId, roleIds));
Map<Long, List<SaasRoleUserRelation>> relationMap = relationList.stream().collect(Collectors.groupingBy(SaasRoleUserRelation::getRoleId));
// 结果组装 - 用户信息到yoke组装
List<RoleWithUserRes> resultData = new ArrayList<>();
for (SaasRole role : rolePage.getRecords()) {
RoleWithUserRes roleWithUser = new RoleWithUserRes();
roleWithUser.setRoleId(role.getId());
roleWithUser.setRoleName(role.getName());
roleWithUser.setRoleType(role.getRoleType());
List<SaasRoleUserRelation> relations = relationMap.get(role.getId());
if (CollectionUtil.isNotEmpty(relations)) {
List<RoleWithUserRes.UserVO> users = relations.stream().map(e -> {
RoleWithUserRes.UserVO user = new RoleWithUserRes.UserVO();
user.setIdentityId(e.getIdentityId());
user.setIdentityType(e.getIdentityType());
return user;
}).collect(Collectors.toList());
roleWithUser.setUsers(users);
}
resultData.add(roleWithUser);
}
return PageResp.list(req.getPage(), req.getPageSize(), rolePage.getTotal(), resultData);
}
}