refactor(系统管理): 去掉重复的dto

This commit is contained in:
guoyuqi 2023-09-15 11:26:16 +08:00 committed by 刘瑞斌
parent 65b1360b46
commit 9522889ece
13 changed files with 63 additions and 93 deletions

View File

@ -1,15 +0,0 @@
package io.metersphere.sdk.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class OrgIdNameDTO {
@Schema(description = "关联的组织id")
private String id;
@Schema(description = "关联的组织名称")
private String name;
}

View File

@ -82,5 +82,5 @@ public class TestResourceReturnDTO {
* 关联的组织id集合 * 关联的组织id集合
*/ */
@Schema(description = "关联的组织id和名称的集合") @Schema(description = "关联的组织id和名称的集合")
private List<OrgIdNameDTO> orgIdNameMap; private List<OptionDTO> orgIdNameMap;
} }

View File

@ -268,18 +268,18 @@ public class TestResourcePoolService {
TestResourceReturnDTO testResourceReturnDTO = new TestResourceReturnDTO(); TestResourceReturnDTO testResourceReturnDTO = new TestResourceReturnDTO();
BeanUtils.copyBean(testResourceReturnDTO, testResourceDTO); BeanUtils.copyBean(testResourceReturnDTO, testResourceDTO);
List<String> orgIds = testResourceDTO.getOrgIds(); List<String> orgIds = testResourceDTO.getOrgIds();
List<OrgIdNameDTO> orgIdNameMap = new ArrayList<>(); List<OptionDTO> orgIdNameMap = new ArrayList<>();
if (CollectionUtils.isNotEmpty(orgIds)) { if (CollectionUtils.isNotEmpty(orgIds)) {
for (String orgId : orgIds) { for (String orgId : orgIds) {
OrgIdNameDTO orgIdNameDTO = new OrgIdNameDTO(); OptionDTO optionDTO = new OptionDTO();
Organization organization = organizationMapper.selectByPrimaryKey(orgId); Organization organization = organizationMapper.selectByPrimaryKey(orgId);
orgIdNameDTO.setId(orgId); optionDTO.setId(orgId);
if (organization != null) { if (organization != null) {
orgIdNameDTO.setName(organization.getName()); optionDTO.setName(organization.getName());
} else { } else {
orgIdNameDTO.setName(Translator.get("organization_not_exists")); optionDTO.setName(Translator.get("organization_not_exists"));
} }
orgIdNameMap.add(orgIdNameDTO); orgIdNameMap.add(optionDTO);
} }
} }
testResourceReturnDTO.setOrgIdNameMap(orgIdNameMap); testResourceReturnDTO.setOrgIdNameMap(orgIdNameMap);

View File

@ -3,13 +3,13 @@ package io.metersphere.system.controller;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.log.annotation.Log; import io.metersphere.sdk.log.annotation.Log;
import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager; import io.metersphere.sdk.util.Pager;
import io.metersphere.sdk.util.SessionUtils; import io.metersphere.sdk.util.SessionUtils;
import io.metersphere.system.dto.IdNameDisabledDTO; import io.metersphere.system.dto.OptionDisabledDTO;
import io.metersphere.system.dto.IdNameStructureDTO;
import io.metersphere.system.dto.OrgUserExtend; import io.metersphere.system.dto.OrgUserExtend;
import io.metersphere.system.request.*; import io.metersphere.system.request.*;
import io.metersphere.system.service.OrganizationService; import io.metersphere.system.service.OrganizationService;
@ -90,21 +90,21 @@ public class OrganizationController {
@GetMapping("/project/list/{organizationId}") @GetMapping("/project/list/{organizationId}")
@Operation(summary = "系统设置-组织-成员-获取当前组织下的所有项目") @Operation(summary = "系统设置-组织-成员-获取当前组织下的所有项目")
@RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ) @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ)
public List<IdNameStructureDTO> getProjectList(@PathVariable(value = "organizationId") String organizationId, @Schema(description = "查询关键字,根据项目名查询", requiredMode = Schema.RequiredMode.REQUIRED) @RequestParam(value = "keyword", required = false) String keyword) { public List<OptionDTO> getProjectList(@PathVariable(value = "organizationId") String organizationId, @Schema(description = "查询关键字,根据项目名查询", requiredMode = Schema.RequiredMode.REQUIRED) @RequestParam(value = "keyword", required = false) String keyword) {
return organizationService.getProjectList(organizationId, keyword); return organizationService.getProjectList(organizationId, keyword);
} }
@GetMapping("/user/role/list/{organizationId}") @GetMapping("/user/role/list/{organizationId}")
@Operation(summary = "系统设置-组织-成员-获取当前组织下的所有自定义用户组以及组织级别的用户组") @Operation(summary = "系统设置-组织-成员-获取当前组织下的所有自定义用户组以及组织级别的用户组")
@RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_READ) @RequiresPermissions(PermissionConstants.ORGANIZATION_MEMBER_READ)
public List<IdNameStructureDTO> getUserRoleList(@PathVariable(value = "organizationId") String organizationId) { public List<OptionDTO> getUserRoleList(@PathVariable(value = "organizationId") String organizationId) {
return organizationService.getUserRoleList(organizationId); return organizationService.getUserRoleList(organizationId);
} }
@GetMapping("/not-exist/user/list/{organizationId}") @GetMapping("/not-exist/user/list/{organizationId}")
@Operation(summary = "系统设置-组织-成员-获取不在当前组织的所有用户") @Operation(summary = "系统设置-组织-成员-获取不在当前组织的所有用户")
@RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ) @RequiresPermissions(PermissionConstants.SYSTEM_USER_ROLE_READ)
public List<IdNameDisabledDTO> getUserList(@PathVariable(value = "organizationId") String organizationId, @Schema(description = "查询关键字,根据用户名查询", requiredMode = Schema.RequiredMode.REQUIRED) public List<OptionDisabledDTO> getUserList(@PathVariable(value = "organizationId") String organizationId, @Schema(description = "查询关键字,根据用户名查询", requiredMode = Schema.RequiredMode.REQUIRED)
@RequestParam(value = "keyword", required = false) String keyword) { @RequestParam(value = "keyword", required = false) String keyword) {
return organizationService.getUserList(organizationId, keyword); return organizationService.getUserList(organizationId, keyword);
} }

View File

@ -1,17 +0,0 @@
package io.metersphere.system.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IdNameStructureDTO {
@Schema(description = "选项ID")
private String id;
@Schema(description = "选项名称")
private String name;
}

View File

@ -1,5 +1,6 @@
package io.metersphere.system.dto; package io.metersphere.system.dto;
import io.metersphere.sdk.dto.OptionDTO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -8,7 +9,7 @@ import lombok.NoArgsConstructor;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class IdNameDisabledDTO extends IdNameStructureDTO{ public class OptionDisabledDTO extends OptionDTO {
@Schema(description = "是否已经关联过") @Schema(description = "是否已经关联过")
private Boolean disabled = false; private Boolean disabled = false;
} }

View File

@ -1,5 +1,6 @@
package io.metersphere.system.dto; package io.metersphere.system.dto;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -15,8 +16,8 @@ import java.util.List;
public class OrgUserExtend extends User { public class OrgUserExtend extends User {
@Schema(description = "项目ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "项目ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED)
private List<IdNameStructureDTO> projectIdNameMap;; private List<OptionDTO> projectIdNameMap;;
@Schema(description = "用户组ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "用户组ID名称集合", requiredMode = Schema.RequiredMode.REQUIRED)
private List<IdNameStructureDTO> userRoleIdNameMap; private List<OptionDTO> userRoleIdNameMap;
} }

View File

@ -83,7 +83,7 @@ public interface ExtOrganizationMapper {
* @param keyword 组织成员列表请求参数 * @param keyword 组织成员列表请求参数
* @return 组织成员列表数据 * @return 组织成员列表数据
*/ */
List<IdNameDisabledDTO> selectListMemberByOrg(@Param("keyword") String keyword); List<OptionDisabledDTO> selectListMemberByOrg(@Param("keyword") String keyword);
/** /**
* 获取组织管理员 * 获取组织管理员

View File

@ -98,7 +98,7 @@
group by temp.id group by temp.id
</select> </select>
<select id="selectListMemberByOrg" resultType="io.metersphere.system.dto.IdNameDisabledDTO"> <select id="selectListMemberByOrg" resultType="io.metersphere.system.dto.OptionDisabledDTO">
select id, name select id, name
from user from user
where deleted = 0 where deleted = 0

View File

@ -1,6 +1,6 @@
package io.metersphere.system.mapper; package io.metersphere.system.mapper;
import io.metersphere.system.dto.IdNameStructureDTO; import io.metersphere.sdk.dto.OptionDTO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -14,5 +14,5 @@ public interface ExtSystemOrgProjectMapper {
* @param keyword 组织项目列表请求参数 * @param keyword 组织项目列表请求参数
* @return 组织项目列表数据 * @return 组织项目列表数据
*/ */
List<IdNameStructureDTO> selectListProjectByOrg(@Param("organizationId") String organizationId, @Param("keyword") String keyword); List<OptionDTO> selectListProjectByOrg(@Param("organizationId") String organizationId, @Param("keyword") String keyword);
} }

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.system.mapper.ExtSystemOrgProjectMapper"> <mapper namespace="io.metersphere.system.mapper.ExtSystemOrgProjectMapper">
<select id="selectListProjectByOrg" resultType="io.metersphere.system.dto.IdNameStructureDTO"> <select id="selectListProjectByOrg" resultType="io.metersphere.sdk.dto.OptionDTO">
select id, name select id, name
from project from project
where deleted = 0 where deleted = 0

View File

@ -297,7 +297,7 @@ public class OrganizationService {
Set<String> projectIds = userIdProjectIdMap.get(orgUserExtend.getId()); Set<String> projectIds = userIdProjectIdMap.get(orgUserExtend.getId());
if (CollectionUtils.isNotEmpty(projectIds)) { if (CollectionUtils.isNotEmpty(projectIds)) {
List<Project> projectFilters = projects.stream().filter(t -> projectIds.contains(t.getId())).toList(); List<Project> projectFilters = projects.stream().filter(t -> projectIds.contains(t.getId())).toList();
List<IdNameStructureDTO> projectList = new ArrayList<>(); List<OptionDTO> projectList = new ArrayList<>();
setProjectList(projectList, projectFilters); setProjectList(projectList, projectFilters);
orgUserExtend.setProjectIdNameMap(projectList); orgUserExtend.setProjectIdNameMap(projectList);
} }
@ -305,7 +305,7 @@ public class OrganizationService {
Set<String> userRoleIds = userIdRoleIdMap.get(orgUserExtend.getId()); Set<String> userRoleIds = userIdRoleIdMap.get(orgUserExtend.getId());
List<UserRole> userRoleFilters = userRoles.stream().filter(t -> userRoleIds.contains(t.getId())).toList(); List<UserRole> userRoleFilters = userRoles.stream().filter(t -> userRoleIds.contains(t.getId())).toList();
List<IdNameStructureDTO> userRoleList = new ArrayList<>(); List<OptionDTO> userRoleList = new ArrayList<>();
setUserRoleList(userRoleList, userRoleFilters); setUserRoleList(userRoleList, userRoleFilters);
orgUserExtend.setUserRoleIdNameMap(userRoleList); orgUserExtend.setUserRoleIdNameMap(userRoleList);
@ -323,12 +323,12 @@ public class OrganizationService {
userIdTargetIdMap.put(userId, targetIds); userIdTargetIdMap.put(userId, targetIds);
} }
private void setProjectList(List<IdNameStructureDTO> projectList, List<Project> projectFilters) { private void setProjectList(List<OptionDTO> projectList, List<Project> projectFilters) {
for (Project project : projectFilters) { for (Project project : projectFilters) {
IdNameStructureDTO idNameStructureDTO = new IdNameStructureDTO(); OptionDTO optionDTO = new OptionDTO();
idNameStructureDTO.setId(project.getId()); optionDTO.setId(project.getId());
idNameStructureDTO.setName(project.getName()); optionDTO.setName(project.getName());
projectList.add(idNameStructureDTO); projectList.add(optionDTO);
} }
} }
@ -652,7 +652,7 @@ public class OrganizationService {
* @param organizationId 组织ID * @param organizationId 组织ID
* @return 项目列表 * @return 项目列表
*/ */
public List<IdNameStructureDTO> getProjectList(String organizationId, String keyword) { public List<OptionDTO> getProjectList(String organizationId, String keyword) {
//校验组织是否存在 //校验组织是否存在
checkOrgExistById(organizationId); checkOrgExistById(organizationId);
return extSystemOrgProjectMapper.selectListProjectByOrg(organizationId, keyword); return extSystemOrgProjectMapper.selectListProjectByOrg(organizationId, keyword);
@ -664,11 +664,11 @@ public class OrganizationService {
* @param organizationId 组织ID * @param organizationId 组织ID
* @return 用户组列表 * @return 用户组列表
*/ */
public List<IdNameStructureDTO> getUserRoleList(String organizationId) { public List<OptionDTO> getUserRoleList(String organizationId) {
//校验组织是否存在 //校验组织是否存在
checkOrgExistById(organizationId); checkOrgExistById(organizationId);
List<String> scopeIds = Arrays.asList(UserRoleEnum.GLOBAL.toString(), organizationId); List<String> scopeIds = Arrays.asList(UserRoleEnum.GLOBAL.toString(), organizationId);
List<IdNameStructureDTO> userRoleList = new ArrayList<>(); List<OptionDTO> userRoleList = new ArrayList<>();
UserRoleExample userRoleExample = new UserRoleExample(); UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andTypeEqualTo(UserRoleType.ORGANIZATION.toString()).andScopeIdIn(scopeIds); userRoleExample.createCriteria().andTypeEqualTo(UserRoleType.ORGANIZATION.toString()).andScopeIdIn(scopeIds);
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample); List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
@ -676,12 +676,12 @@ public class OrganizationService {
return userRoleList; return userRoleList;
} }
private static void setUserRoleList(List<IdNameStructureDTO> userRoleList, List<UserRole> userRoles) { private static void setUserRoleList(List<OptionDTO> userRoleList, List<UserRole> userRoles) {
for (UserRole userRole : userRoles) { for (UserRole userRole : userRoles) {
IdNameStructureDTO idNameStructureDTO = new IdNameStructureDTO(); OptionDTO optionDTO = new OptionDTO();
idNameStructureDTO.setId(userRole.getId()); optionDTO.setId(userRole.getId());
idNameStructureDTO.setName(userRole.getName()); optionDTO.setName(userRole.getName());
userRoleList.add(idNameStructureDTO); userRoleList.add(optionDTO);
} }
} }
@ -691,24 +691,24 @@ public class OrganizationService {
* @param organizationId 组织ID * @param organizationId 组织ID
* @return 用户列表 * @return 用户列表
*/ */
public List<IdNameDisabledDTO> getUserList(String organizationId, String keyword) { public List<OptionDisabledDTO> getUserList(String organizationId, String keyword) {
//校验组织是否存在 //校验组织是否存在
checkOrgExistById(organizationId); checkOrgExistById(organizationId);
List<IdNameDisabledDTO> idNameDisabledDTOS = extOrganizationMapper.selectListMemberByOrg(keyword); List<OptionDisabledDTO> optionDisabledDTOS = extOrganizationMapper.selectListMemberByOrg(keyword);
UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample();
userRoleRelationExample.createCriteria().andSourceIdEqualTo(organizationId); userRoleRelationExample.createCriteria().andSourceIdEqualTo(organizationId);
List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); List<UserRoleRelation> userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample);
List<String> userIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().toList(); List<String> userIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().toList();
for (IdNameDisabledDTO idNameDisabledDTO : idNameDisabledDTOS) { for (OptionDisabledDTO optionDisabledDTO : optionDisabledDTOS) {
if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(idNameDisabledDTO.getId())) { if (CollectionUtils.isNotEmpty(userIds) && userIds.contains(optionDisabledDTO.getId())) {
idNameDisabledDTO.setDisabled(true); optionDisabledDTO.setDisabled(true);
} }
} }
return idNameDisabledDTOS; return optionDisabledDTOS;
} }
/** /**

View File

@ -4,9 +4,9 @@ import io.metersphere.sdk.base.BaseTest;
import io.metersphere.sdk.constants.InternalUserRole; import io.metersphere.sdk.constants.InternalUserRole;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.controller.handler.ResultHolder; import io.metersphere.sdk.controller.handler.ResultHolder;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Pager; import io.metersphere.sdk.util.Pager;
import io.metersphere.system.dto.IdNameStructureDTO;
import io.metersphere.system.dto.OrgUserExtend; import io.metersphere.system.dto.OrgUserExtend;
import io.metersphere.system.request.OrgMemberExtendProjectRequest; import io.metersphere.system.request.OrgMemberExtendProjectRequest;
import io.metersphere.system.request.OrganizationMemberExtendRequest; import io.metersphere.system.request.OrganizationMemberExtendRequest;
@ -336,11 +336,11 @@ public class OrganizationControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(); String contentAsString = mvcResult.getResponse().getContentAsString();
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class); List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
List<String> ids = projectList.stream().map(IdNameStructureDTO::getId).toList(); List<String> ids = projectList.stream().map(OptionDTO::getId).toList();
Assertions.assertTrue(ids.contains("sys_org_projectId")); Assertions.assertTrue(ids.contains("sys_org_projectId"));
List<String> names = projectList.stream().map(IdNameStructureDTO::getName).toList(); List<String> names = projectList.stream().map(OptionDTO::getName).toList();
Assertions.assertTrue(names.contains("sys_org_projectId")); Assertions.assertTrue(names.contains("sys_org_projectId"));
} }
@ -355,7 +355,7 @@ public class OrganizationControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(); String contentAsString = mvcResult.getResponse().getContentAsString();
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class); List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(CollectionUtils.isEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isEmpty(projectList));
} }
@ -383,11 +383,11 @@ public class OrganizationControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(); String contentAsString = mvcResult.getResponse().getContentAsString();
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class); List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
List<String> ids = projectList.stream().map(IdNameStructureDTO::getId).toList(); List<String> ids = projectList.stream().map(OptionDTO::getId).toList();
Assertions.assertTrue(ids.contains("sys_default_org_role_id_3")); Assertions.assertTrue(ids.contains("sys_default_org_role_id_3"));
List<String> names = projectList.stream().map(IdNameStructureDTO::getName).toList(); List<String> names = projectList.stream().map(OptionDTO::getName).toList();
Assertions.assertTrue(names.contains("sys_default_org_role_id_3")); Assertions.assertTrue(names.contains("sys_default_org_role_id_3"));
} }
@ -402,12 +402,12 @@ public class OrganizationControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<IdNameStructureDTO> userRoleList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class); List<OptionDTO> userRoleList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(CollectionUtils.isNotEmpty(userRoleList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(userRoleList));
List<String> ids = userRoleList.stream().map(IdNameStructureDTO::getId).toList(); List<String> ids = userRoleList.stream().map(OptionDTO::getId).toList();
Assertions.assertTrue(ids.contains("org_admin")); Assertions.assertTrue(ids.contains("org_admin"));
Assertions.assertTrue(ids.contains("org_member")); Assertions.assertTrue(ids.contains("org_member"));
List<String> names = userRoleList.stream().map(IdNameStructureDTO::getName).toList(); List<String> names = userRoleList.stream().map(OptionDTO::getName).toList();
Assertions.assertTrue(names.contains("组织管理员")); Assertions.assertTrue(names.contains("组织管理员"));
Assertions.assertTrue(names.contains("组织成员")); Assertions.assertTrue(names.contains("组织成员"));
@ -437,11 +437,11 @@ public class OrganizationControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(); String contentAsString = mvcResult.getResponse().getContentAsString();
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class); List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
List<String> ids = projectList.stream().map(IdNameStructureDTO::getId).toList(); List<String> ids = projectList.stream().map(OptionDTO::getId).toList();
Assertions.assertTrue(ids.contains("sys_default_user5")); Assertions.assertTrue(ids.contains("sys_default_user5"));
List<String> names = projectList.stream().map(IdNameStructureDTO::getName).toList(); List<String> names = projectList.stream().map(OptionDTO::getName).toList();
Assertions.assertTrue(names.contains("testUserFive")); Assertions.assertTrue(names.contains("testUserFive"));
} }
@ -456,7 +456,7 @@ public class OrganizationControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(); String contentAsString = mvcResult.getResponse().getContentAsString();
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<IdNameStructureDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), IdNameStructureDTO.class); List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
} }
@ -502,25 +502,25 @@ public class OrganizationControllerTests extends BaseTest {
} }
if (compare) { if (compare) {
Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap()); Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap());
List<String> userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(IdNameStructureDTO::getId).toList(); List<String> userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(OptionDTO::getId).toList();
Assertions.assertTrue(userRoleIds.contains(userRoleId)); Assertions.assertTrue(userRoleIds.contains(userRoleId));
if (StringUtils.isNotBlank(projectId)) { if (StringUtils.isNotBlank(projectId)) {
Assertions.assertNotNull(orgUserExtend.getProjectIdNameMap()); Assertions.assertNotNull(orgUserExtend.getProjectIdNameMap());
List<String> projectIds = orgUserExtend.getProjectIdNameMap().stream().map(IdNameStructureDTO::getId).toList(); List<String> projectIds = orgUserExtend.getProjectIdNameMap().stream().map(OptionDTO::getId).toList();
Assertions.assertTrue(projectIds.contains(projectId)); Assertions.assertTrue(projectIds.contains(projectId));
List<String> projectNames = orgUserExtend.getProjectIdNameMap().stream().map(IdNameStructureDTO::getName).toList(); List<String> projectNames = orgUserExtend.getProjectIdNameMap().stream().map(OptionDTO::getName).toList();
Assertions.assertTrue(projectNames.contains(projectId)); Assertions.assertTrue(projectNames.contains(projectId));
} }
} }
if (checkPart) { if (checkPart) {
Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap()); Assertions.assertNotNull(orgUserExtend.getUserRoleIdNameMap());
List<String> userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(IdNameStructureDTO::getId).toList(); List<String> userRoleIds = orgUserExtend.getUserRoleIdNameMap().stream().map(OptionDTO::getId).toList();
Assertions.assertFalse(userRoleIds.contains(noUserRoleId)); Assertions.assertFalse(userRoleIds.contains(noUserRoleId));
if (StringUtils.isNotBlank(noProjectId)) { if (StringUtils.isNotBlank(noProjectId)) {
Assertions.assertNotNull(orgUserExtend.getProjectIdNameMap()); Assertions.assertNotNull(orgUserExtend.getProjectIdNameMap());
List<String> projectIds = orgUserExtend.getProjectIdNameMap().stream().map(IdNameStructureDTO::getId).toList(); List<String> projectIds = orgUserExtend.getProjectIdNameMap().stream().map(OptionDTO::getId).toList();
Assertions.assertFalse(projectIds.contains(noProjectId)); Assertions.assertFalse(projectIds.contains(noProjectId));
} }