refactor(测试计划): 优化规划视图下列表返回模块名称

This commit is contained in:
WangXu10 2024-06-18 16:51:16 +08:00 committed by Craftsman
parent a020a8e595
commit 3872d84dea
8 changed files with 60 additions and 9 deletions

View File

@ -1,5 +1,6 @@
package io.metersphere.functional.mapper; package io.metersphere.functional.mapper;
import io.metersphere.functional.domain.FunctionalCaseModule;
import io.metersphere.functional.dto.FunctionalCaseModuleDTO; import io.metersphere.functional.dto.FunctionalCaseModuleDTO;
import io.metersphere.functional.dto.ProjectOptionDTO; import io.metersphere.functional.dto.ProjectOptionDTO;
import io.metersphere.project.dto.NodeSortQueryParam; import io.metersphere.project.dto.NodeSortQueryParam;
@ -38,4 +39,6 @@ public interface ExtFunctionalCaseModuleMapper {
List<String> selectIdByProjectIdAndReviewId(@Param("projectId")String projectId, @Param("reviewId")String reviewId); List<String> selectIdByProjectIdAndReviewId(@Param("projectId")String projectId, @Param("reviewId")String reviewId);
void batchUpdateStringColumn(@Param("column") String column, @Param("ids") List<String> ids, @Param("value") String value); void batchUpdateStringColumn(@Param("column") String column, @Param("ids") List<String> ids, @Param("value") String value);
List<FunctionalCaseModule> getNameInfoByIds(@Param("ids") List<String> ids);
} }

View File

@ -136,4 +136,13 @@
#{id} #{id}
</foreach> </foreach>
</update> </update>
<select id="getNameInfoByIds" resultType="io.metersphere.functional.domain.FunctionalCaseModule">
SELECT id, name
FROM functional_case_module
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper> </mapper>

View File

@ -39,6 +39,9 @@ public class TestPlanApiCasePageResponse implements Serializable {
@Schema(description = "模块ID") @Schema(description = "模块ID")
private String moduleId; private String moduleId;
@Schema(description = "模块名称")
private String moduleName;
@Schema(description = "环境fk") @Schema(description = "环境fk")
private String environmentId; private String environmentId;

View File

@ -35,6 +35,9 @@ public class TestPlanApiScenarioPageResponse implements Serializable {
@Schema(description = "模块ID") @Schema(description = "模块ID")
private String moduleId; private String moduleId;
@Schema(description = "模块名称")
private String moduleName;
@Schema(description = "环境fk") @Schema(description = "环境fk")
private String environmentId; private String environmentId;

View File

@ -26,6 +26,9 @@ public class TestPlanCasePageResponse implements Serializable {
@Schema(description = "模块ID") @Schema(description = "模块ID")
private String moduleId; private String moduleId;
@Schema(description = "模块名称")
private String moduleName;
@Schema(description = "项目ID") @Schema(description = "项目ID")
private String projectId; private String projectId;

View File

@ -5,6 +5,7 @@ import io.metersphere.api.dto.definition.ApiDefinitionDTO;
import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.api.dto.definition.ApiTestCaseDTO;
import io.metersphere.api.mapper.ApiReportMapper; import io.metersphere.api.mapper.ApiReportMapper;
import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.api.mapper.ApiTestCaseMapper;
import io.metersphere.api.mapper.ExtApiDefinitionModuleMapper;
import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.ApiBatchRunBaseService;
import io.metersphere.api.service.ApiExecuteService; import io.metersphere.api.service.ApiExecuteService;
import io.metersphere.api.service.definition.ApiDefinitionModuleService; import io.metersphere.api.service.definition.ApiDefinitionModuleService;
@ -19,7 +20,6 @@ import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.*; import io.metersphere.plan.dto.*;
import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.request.*;
import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse; import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse;
import io.metersphere.plan.dto.response.TestPlanApiScenarioPageResponse;
import io.metersphere.plan.dto.response.TestPlanAssociationResponse; import io.metersphere.plan.dto.response.TestPlanAssociationResponse;
import io.metersphere.plan.dto.response.TestPlanOperationResponse; import io.metersphere.plan.dto.response.TestPlanOperationResponse;
import io.metersphere.plan.mapper.*; import io.metersphere.plan.mapper.*;
@ -116,6 +116,8 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
private ApiReportMapper apiReportMapper; private ApiReportMapper apiReportMapper;
@Resource @Resource
private OperationLogService operationLogService; private OperationLogService operationLogService;
@Resource
private ExtApiDefinitionModuleMapper extApiDefinitionModuleMapper;
@Override @Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) { public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -233,11 +235,20 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
if (CollectionUtils.isNotEmpty(apiCaseList)) { if (CollectionUtils.isNotEmpty(apiCaseList)) {
Map<String, String> projectMap = getProject(apiCaseList); Map<String, String> projectMap = getProject(apiCaseList);
Map<String, String> userMap = getUserMap(apiCaseList); Map<String, String> userMap = getUserMap(apiCaseList);
handleCaseAndEnv(apiCaseList, projectMap, userMap, testPlanId); Map<String, String> moduleNameMap = getModuleName(apiCaseList);
handleCaseAndEnv(apiCaseList, projectMap, userMap, testPlanId, moduleNameMap);
} }
} }
private void handleCaseAndEnv(List<TestPlanApiCasePageResponse> apiCaseList, Map<String, String> projectMap, Map<String, String> userMap, String testPlanId) { private Map<String, String> getModuleName(List<TestPlanApiCasePageResponse> apiCaseList) {
List<String> moduleIds = apiCaseList.stream().map(TestPlanApiCasePageResponse::getModuleId).toList();
List<ApiDefinitionModule> modules = extApiDefinitionModuleMapper.getNameInfoByIds(moduleIds);
Map<String, String> moduleNameMap = modules.stream()
.collect(Collectors.toMap(ApiDefinitionModule::getId, ApiDefinitionModule::getName));
return moduleNameMap;
}
private void handleCaseAndEnv(List<TestPlanApiCasePageResponse> apiCaseList, Map<String, String> projectMap, Map<String, String> userMap, String testPlanId, Map<String, String> moduleNameMap) {
//获取二级节点环境 //获取二级节点环境
List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.API_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId); List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.API_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId);
Map<String, TestPlanCollectionEnvDTO> secondEnvMap = secondEnv.stream().collect(Collectors.toMap(TestPlanCollectionEnvDTO::getId, item -> item)); Map<String, TestPlanCollectionEnvDTO> secondEnvMap = secondEnv.stream().collect(Collectors.toMap(TestPlanCollectionEnvDTO::getId, item -> item));
@ -253,6 +264,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
item.setProjectName(projectMap.get(item.getProjectId())); item.setProjectName(projectMap.get(item.getProjectId()));
item.setCreateUserName(userMap.get(item.getCreateUser())); item.setCreateUserName(userMap.get(item.getCreateUser()));
item.setExecuteUserName(userMap.get(item.getExecuteUser())); item.setExecuteUserName(userMap.get(item.getExecuteUser()));
item.setModuleName(moduleNameMap.get(item.getModuleId()));
if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) { if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) {
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId()); TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
if (collectEnv.getExtended()) { if (collectEnv.getExtended()) {

View File

@ -1,12 +1,10 @@
package io.metersphere.plan.service; package io.metersphere.plan.service;
import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.*;
import io.metersphere.api.domain.ApiScenarioExample;
import io.metersphere.api.domain.ApiScenarioReport;
import io.metersphere.api.domain.ApiScenarioReportExample;
import io.metersphere.api.dto.scenario.ApiScenarioDTO; import io.metersphere.api.dto.scenario.ApiScenarioDTO;
import io.metersphere.api.dto.scenario.ApiScenarioDetail; import io.metersphere.api.dto.scenario.ApiScenarioDetail;
import io.metersphere.api.mapper.ApiScenarioMapper; import io.metersphere.api.mapper.ApiScenarioMapper;
import io.metersphere.api.mapper.ApiScenarioModuleMapper;
import io.metersphere.api.mapper.ApiScenarioReportMapper; import io.metersphere.api.mapper.ApiScenarioReportMapper;
import io.metersphere.api.service.ApiBatchRunBaseService; import io.metersphere.api.service.ApiBatchRunBaseService;
import io.metersphere.api.service.ApiExecuteService; import io.metersphere.api.service.ApiExecuteService;
@ -109,6 +107,8 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
private ApiScenarioReportMapper apiScenarioReportMapper; private ApiScenarioReportMapper apiScenarioReportMapper;
@Resource @Resource
private ApiScenarioMapper apiScenarioMapper; private ApiScenarioMapper apiScenarioMapper;
@Resource
private ApiScenarioModuleMapper apiScenarioModuleMapper;
@Override @Override
public void deleteBatchByTestPlanId(List<String> testPlanIdList) { public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
@ -367,11 +367,21 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
if (CollectionUtils.isNotEmpty(apiScenarioList)) { if (CollectionUtils.isNotEmpty(apiScenarioList)) {
Map<String, String> projectMap = getProject(apiScenarioList); Map<String, String> projectMap = getProject(apiScenarioList);
Map<String, String> userMap = getUserMap(apiScenarioList); Map<String, String> userMap = getUserMap(apiScenarioList);
handleScenarioAndEnv(apiScenarioList, projectMap, userMap, testPlanId); Map<String, String> moduleNameMap = getModuleName(apiScenarioList);
handleScenarioAndEnv(apiScenarioList, projectMap, userMap, testPlanId, moduleNameMap);
} }
} }
private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScenarioList, Map<String, String> projectMap, Map<String, String> userMap, String testPlanId) { private Map<String, String> getModuleName(List<TestPlanApiScenarioPageResponse> apiScenarioList) {
List<String> moduleIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getModuleId).distinct().toList();
ApiScenarioModuleExample moduleExample = new ApiScenarioModuleExample();
moduleExample.createCriteria().andIdIn(moduleIds);
List<ApiScenarioModule> modules = apiScenarioModuleMapper.selectByExample(moduleExample);
Map<String, String> moduleNameMap = modules.stream().collect(Collectors.toMap(ApiScenarioModule::getId, ApiScenarioModule::getName));
return moduleNameMap;
}
private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScenarioList, Map<String, String> projectMap, Map<String, String> userMap, String testPlanId, Map<String, String> moduleNameMap) {
//获取二级节点环境 //获取二级节点环境
List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.SCENARIO_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId); List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.SCENARIO_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId);
Map<String, TestPlanCollectionEnvDTO> secondEnvMap = secondEnv.stream().collect(Collectors.toMap(TestPlanCollectionEnvDTO::getId, item -> item)); Map<String, TestPlanCollectionEnvDTO> secondEnvMap = secondEnv.stream().collect(Collectors.toMap(TestPlanCollectionEnvDTO::getId, item -> item));
@ -387,6 +397,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
item.setProjectName(projectMap.get(item.getProjectId())); item.setProjectName(projectMap.get(item.getProjectId()));
item.setCreateUserName(userMap.get(item.getCreateUser())); item.setCreateUserName(userMap.get(item.getCreateUser()));
item.setExecuteUserName(userMap.get(item.getExecuteUser())); item.setExecuteUserName(userMap.get(item.getExecuteUser()));
item.setModuleName(StringUtils.isNotBlank(moduleNameMap.get(item.getModuleId())) ? moduleNameMap.get(item.getModuleId()) : Translator.get("api_unplanned_scenario"));
if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) { if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) {
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId()); TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
if (collectEnv.getExtended()) { if (collectEnv.getExtended()) {

View File

@ -14,6 +14,7 @@ import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseExample; import io.metersphere.functional.domain.FunctionalCaseExample;
import io.metersphere.functional.domain.FunctionalCaseModule; import io.metersphere.functional.domain.FunctionalCaseModule;
import io.metersphere.functional.dto.*; import io.metersphere.functional.dto.*;
import io.metersphere.functional.mapper.ExtFunctionalCaseModuleMapper;
import io.metersphere.functional.mapper.FunctionalCaseMapper; import io.metersphere.functional.mapper.FunctionalCaseMapper;
import io.metersphere.functional.service.FunctionalCaseAttachmentService; import io.metersphere.functional.service.FunctionalCaseAttachmentService;
import io.metersphere.functional.service.FunctionalCaseModuleService; import io.metersphere.functional.service.FunctionalCaseModuleService;
@ -121,6 +122,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
private FunctionalCaseMapper functionalCaseMapper; private FunctionalCaseMapper functionalCaseMapper;
@Resource @Resource
private OperationLogService operationLogService; private OperationLogService operationLogService;
@Resource
private ExtFunctionalCaseModuleMapper extFunctionalCaseModuleMapper;
@Override @Override
public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) { public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) {
@ -242,10 +245,14 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
List<SelectOption> statusOption = bugStatusService.getHeaderStatusOption(projectId); List<SelectOption> statusOption = bugStatusService.getHeaderStatusOption(projectId);
Map<String, String> statusMap = statusOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); Map<String, String> statusMap = statusOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds)); Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
List<String> moduleIds = functionalCaseLists.stream().map(TestPlanCasePageResponse::getModuleId).toList();
List<FunctionalCaseModule> modules = extFunctionalCaseModuleMapper.getNameInfoByIds(moduleIds);
Map<String, String> moduleNameMap = modules.stream().collect(Collectors.toMap(FunctionalCaseModule::getId, FunctionalCaseModule::getName));
functionalCaseLists.forEach(testPlanCasePageResponse -> { functionalCaseLists.forEach(testPlanCasePageResponse -> {
testPlanCasePageResponse.setCustomFields(collect.get(testPlanCasePageResponse.getCaseId())); testPlanCasePageResponse.setCustomFields(collect.get(testPlanCasePageResponse.getCaseId()));
testPlanCasePageResponse.setCreateUserName(userMap.get(testPlanCasePageResponse.getCreateUser())); testPlanCasePageResponse.setCreateUserName(userMap.get(testPlanCasePageResponse.getCreateUser()));
testPlanCasePageResponse.setExecuteUserName(userMap.get(testPlanCasePageResponse.getExecuteUser())); testPlanCasePageResponse.setExecuteUserName(userMap.get(testPlanCasePageResponse.getExecuteUser()));
testPlanCasePageResponse.setModuleName(moduleNameMap.get(testPlanCasePageResponse.getModuleId()));
if (bugListMap.containsKey(testPlanCasePageResponse.getCaseId())) { if (bugListMap.containsKey(testPlanCasePageResponse.getCaseId())) {
List<CaseRelateBugDTO> bugDTOList = bugListMap.get(testPlanCasePageResponse.getCaseId()); List<CaseRelateBugDTO> bugDTOList = bugListMap.get(testPlanCasePageResponse.getCaseId());
testPlanCasePageResponse.setBugList(handleStatus(bugDTOList, statusMap)); testPlanCasePageResponse.setBugList(handleStatus(bugDTOList, statusMap));