feat: (feature/REQ-3057) 用户列表增加roleTypes查询

This commit is contained in:
lilong 2024-11-12 11:31:44 +08:00
parent 7ef955f06e
commit 965f421a4d
4 changed files with 82 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package cn.axzo.tyr.client.model.roleuser.req;
import cn.axzo.foundation.dao.support.wrapper.CriteriaField;
import cn.axzo.foundation.dao.support.wrapper.Operator;
import cn.axzo.tyr.client.common.enums.FeatureResourceType;
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
import cn.axzo.tyr.client.model.enums.IdentityType;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -137,6 +138,9 @@ public class ListRoleUserRelationParam {
@CriteriaField(ignore = true)
private List<BatchPerson> batchPersons;
@CriteriaField(ignore = true)
private Set<RoleTypeEnum> roleTypes;
@Data
@Builder
@NoArgsConstructor

View File

@ -129,7 +129,8 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
}
Set<Long> roleIds = resolveRoleIds(param);
if (!CollectionUtils.isEmpty(param.getRoleCodes()) && CollectionUtils.isEmpty(roleIds)) {
if ((!CollectionUtils.isEmpty(param.getRoleCodes()) || !CollectionUtils.isEmpty(param.getRoleTypes()))
&& CollectionUtils.isEmpty(roleIds)) {
return param.toEmpty();
}
wrapper.in(!CollectionUtils.isEmpty(roleIds), "role_id", roleIds);
@ -202,13 +203,16 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl<SaasRoleUserRel
}
private Set<Long> resolveRoleIds(PageRoleUserRelationParam param) {
if (CollectionUtils.isEmpty(param.getRoleCodes())) {
if (CollectionUtils.isEmpty(param.getRoleCodes()) && CollectionUtils.isEmpty(param.getRoleTypes())) {
return Optional.ofNullable(param.getRoleIds())
.map(Sets::newHashSet)
.orElseGet(Sets::newHashSet);
}
ListRoleReq listSaasRoleParam = ListRoleReq.builder()
.roleCodes(param.getRoleCodes())
.roleTypes(Optional.ofNullable(param.getRoleTypes())
.map(e -> e.stream().map(RoleTypeEnum::getValue).collect(Collectors.toList()))
.orElse(null))
.build();
Set<Long> roleIds = roleService.list(listSaasRoleParam).stream()
.map(SaasRoleRes::getId)

View File

@ -1,10 +1,13 @@
package cn.axzo.tyr.server.service.impl;
import cn.axzo.foundation.exception.BusinessException;
import cn.axzo.foundation.page.PageResp;
import cn.axzo.tyr.base.BaseTest;
import cn.axzo.tyr.base.MysqlDataLoader;
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
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.server.repository.entity.SaasRoleUserRelation;
import cn.axzo.tyr.server.service.SaasRoleUserRelationService;
import com.google.common.collect.Lists;
@ -56,4 +59,63 @@ class SaasRoleUserRelationServiceImplTest extends BaseTest {
.build());
Assertions.assertEquals(saasRoleUserRelationService.listV2(ListRoleUserRelationParam.builder().build()).size(), 2);
}
@Test
void list() {
ListRoleUserRelationParam list = ListRoleUserRelationParam.builder()
.roleCodes(Sets.newHashSet("cms:mafb_business_vice_officer"))
.build();
List<SaasRoleUserV2DTO> result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 1);
list = ListRoleUserRelationParam.builder()
.roleCodes(Sets.newHashSet("cms:mafb_business_vice_officer1"))
.build();
result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 0);
list = ListRoleUserRelationParam.builder()
.roleCodes(Sets.newHashSet("cms:mafb_business_vice_officer", "cms:mafb_productivity_vice_officer"))
.build();
result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 2);
list = ListRoleUserRelationParam.builder()
.roleTypes(Sets.newHashSet(RoleTypeEnum.ADMIN))
.build();
result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 1);
list = ListRoleUserRelationParam.builder()
.roleTypes(Sets.newHashSet(RoleTypeEnum.SUPER_ADMIN))
.build();
result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 1);
list = ListRoleUserRelationParam.builder()
.roleTypes(Sets.newHashSet(RoleTypeEnum.ADMIN, RoleTypeEnum.SUPER_ADMIN))
.build();
result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 2);
list = ListRoleUserRelationParam.builder()
.roleTypes(Sets.newHashSet(RoleTypeEnum.ADMIN, RoleTypeEnum.SUPER_ADMIN))
.roleCodes(Sets.newHashSet("sdfdsf"))
.build();
result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 0);
list = ListRoleUserRelationParam.builder()
.roleTypes(Sets.newHashSet(RoleTypeEnum.ADMIN, RoleTypeEnum.SUPER_ADMIN))
.roleCodes(Sets.newHashSet("oms:project_manager"))
.workspaceOuPairs(Lists.newArrayList(ListRoleUserRelationParam.WorkspaceOuPair.builder()
.workspaceId(8L)
.ouId(1L)
.build()))
.build();
result = saasRoleUserRelationService.listV2(list);
Assertions.assertEquals(result.size(), 1);
}
}

View File

@ -5,4 +5,14 @@ INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, na
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type) VALUES (16401, 98, 3417, 3, 2020, 6, 1, 0, 0, 0, '2021-09-16 22:09:29', '2021-09-16 22:09:29', 0, 0, 2);
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type) VALUES (16402, 106, 3418, 3, 3577, 12, 1, 0, 0, 0, '2021-09-16 22:09:29', '2021-09-16 22:09:29', 0, 0, 2);
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
VALUES (3415, '项目经理', '', 'super_admin', 'oms:project_manager', -1, -1, 6, 6, 0, '2023-09-19 15:22:55', '2024-08-13 10:25:25', 2003043, 2003028, 1, 65535, 0, null, 0, '', 1, 2, 1);
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
VALUES (3416, '项目负责人', '', 'admin', 'cms:mafb_project_commissioner', -1, -1, 5, 2, 0, '2023-10-23 17:49:59', '2024-08-13 10:25:40', -1, 9000399985, 1, 65535, 0, null, 0, '', 1, 1, 1);
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
VALUES (3417, '商务副经理', '', 'init', 'cms:mafb_business_vice_officer', -1, -1, 5, 2, 0, '2023-10-23 17:50:00', '2024-08-13 10:25:41', -1, 2006333, 1, 65535, 0, null, 0, '', 1, 2, 1);
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
VALUES (3418, '生产副经理', '', 'init', 'cms:mafb_productivity_vice_officer', -1, -1, 5, 2, 0, '2023-10-23 17:50:00', '2024-08-13 10:25:41', -1, 2006333, 1, 65535, 0, null, 0, '', 1, 3, 1);
#-->SaasRoleUserRelationServiceImplTest.sql