refactor(测试计划): 优化列表运行环境显示

This commit is contained in:
WangXu10 2024-06-18 13:41:01 +08:00 committed by Craftsman
parent 4c4fed22d7
commit d4ee62f705
6 changed files with 83 additions and 29 deletions

View File

@ -23,4 +23,10 @@ public class TestPlanCollectionEnvDTO implements Serializable {
@Schema(description = "环境名称") @Schema(description = "环境名称")
private String environmentName; private String environmentName;
@Schema(description = "是否继承")
private Boolean extended;
@Schema(description = "父ID")
private String parentId;
} }

View File

@ -10,6 +10,7 @@ public interface ExtTestPlanCollectionMapper {
List<TestPlanCollectionConfigDTO> getList(@Param("planId") String planId); List<TestPlanCollectionConfigDTO> getList(@Param("planId") String planId);
List<TestPlanCollectionEnvDTO> selectSecondCollectionEnv(@Param("type") String type, @Param("parentId") String parentId); List<TestPlanCollectionEnvDTO> selectSecondCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId);
TestPlanCollectionEnvDTO selectFirstCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId);
} }

View File

@ -24,12 +24,32 @@
SELECT SELECT
tpc.id, tpc.id,
tpc.environment_id, tpc.environment_id,
e.`name` as environmentName e.`name` as environmentName,
tpc.parent_id,
tpc.extended
FROM FROM
test_plan_collection tpc test_plan_collection tpc
LEFT JOIN environment e ON tpc.environment_id = e.id LEFT JOIN environment e ON tpc.environment_id = e.id
WHERE WHERE
tpc.type = #{type} tpc.type = #{type}
and tpc.parent_id <![CDATA[<>]]> #{parentId} and tpc.parent_id <![CDATA[<>]]> #{parentId}
and tpc.test_plan_id = #{testPlanId}
</select>
<select id="selectFirstCollectionEnv" resultType="io.metersphere.plan.dto.TestPlanCollectionEnvDTO">
SELECT
tpc.id,
tpc.environment_id,
e.`name` as environmentName,
tpc.parent_id,
tpc.extended
FROM
test_plan_collection tpc
LEFT JOIN environment e ON tpc.environment_id = e.id
WHERE
tpc.type = #{type}
and tpc.parent_id = #{parentId}
and tpc.test_plan_id = #{testPlanId}
</select> </select>
</mapper> </mapper>

View File

@ -19,6 +19,7 @@ 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.*;
@ -224,22 +225,24 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
return new ArrayList<>(); return new ArrayList<>();
} }
List<TestPlanApiCasePageResponse> list = extTestPlanApiCaseMapper.relateApiCaseList(request, deleted); List<TestPlanApiCasePageResponse> list = extTestPlanApiCaseMapper.relateApiCaseList(request, deleted);
buildApiCaseResponse(list); buildApiCaseResponse(list, request.getTestPlanId());
return list; return list;
} }
private void buildApiCaseResponse(List<TestPlanApiCasePageResponse> apiCaseList) { private void buildApiCaseResponse(List<TestPlanApiCasePageResponse> apiCaseList, String testPlanId) {
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); handleCaseAndEnv(apiCaseList, projectMap, userMap, testPlanId);
} }
} }
private void handleCaseAndEnv(List<TestPlanApiCasePageResponse> apiCaseList, Map<String, String> projectMap, Map<String, String> userMap) { private void handleCaseAndEnv(List<TestPlanApiCasePageResponse> apiCaseList, Map<String, String> projectMap, Map<String, String> userMap, String testPlanId) {
//获取二级节点环境 //获取二级节点环境
List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.API_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID); 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));
//获取一级节点环境
TestPlanCollectionEnvDTO firstEnv = extTestPlanCollectionMapper.selectFirstCollectionEnv(CaseType.API_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId);
//当前用例环境 //当前用例环境
List<String> caseEnvIds = apiCaseList.stream().map(TestPlanApiCasePageResponse::getEnvironmentId).toList(); List<String> caseEnvIds = apiCaseList.stream().map(TestPlanApiCasePageResponse::getEnvironmentId).toList();
EnvironmentExample environmentExample = new EnvironmentExample(); EnvironmentExample environmentExample = new EnvironmentExample();
@ -250,17 +253,28 @@ 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()));
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId()); if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) {
if (StringUtils.equalsIgnoreCase(collectEnv.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) { TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
//计划集 == 默认环境 处理默认环境 if (collectEnv.getExtended()) {
doHandleDefaultEnv(item, caseEnvMap); //继承
} else { getRunEnv(firstEnv, caseEnvMap, item);
//计划集 != 默认环境 } else {
doHandleEnv(item, collectEnv); getRunEnv(collectEnv, caseEnvMap, item);
}
} }
}); });
} }
private void getRunEnv(TestPlanCollectionEnvDTO collectEnv, Map<String, String> caseEnvMap, TestPlanApiCasePageResponse item) {
if (StringUtils.equalsIgnoreCase(collectEnv.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
//计划集 == 默认环境 处理默认环境
doHandleDefaultEnv(item, caseEnvMap);
} else {
//计划集 != 默认环境
doHandleEnv(item, collectEnv);
}
}
private void doHandleEnv(TestPlanApiCasePageResponse item, TestPlanCollectionEnvDTO collectEnv) { private void doHandleEnv(TestPlanApiCasePageResponse item, TestPlanCollectionEnvDTO collectEnv) {
if (StringUtils.isNotBlank(collectEnv.getEnvironmentName())) { if (StringUtils.isNotBlank(collectEnv.getEnvironmentName())) {
item.setEnvironmentId(collectEnv.getEnvironmentId()); item.setEnvironmentId(collectEnv.getEnvironmentId());

View File

@ -359,22 +359,24 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
*/ */
public List<TestPlanApiScenarioPageResponse> hasRelateApiScenarioList(TestPlanApiScenarioRequest request, boolean deleted) { public List<TestPlanApiScenarioPageResponse> hasRelateApiScenarioList(TestPlanApiScenarioRequest request, boolean deleted) {
List<TestPlanApiScenarioPageResponse> list = extTestPlanApiScenarioMapper.relateApiScenarioList(request, deleted); List<TestPlanApiScenarioPageResponse> list = extTestPlanApiScenarioMapper.relateApiScenarioList(request, deleted);
buildApiScenarioResponse(list); buildApiScenarioResponse(list, request.getTestPlanId());
return list; return list;
} }
private void buildApiScenarioResponse(List<TestPlanApiScenarioPageResponse> apiScenarioList) { private void buildApiScenarioResponse(List<TestPlanApiScenarioPageResponse> apiScenarioList, String testPlanId) {
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); handleScenarioAndEnv(apiScenarioList, projectMap, userMap, testPlanId);
} }
} }
private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScenarioList, Map<String, String> projectMap, Map<String, String> userMap) { private void handleScenarioAndEnv(List<TestPlanApiScenarioPageResponse> apiScenarioList, Map<String, String> projectMap, Map<String, String> userMap, String testPlanId) {
//获取二级节点环境 //获取二级节点环境
List<TestPlanCollectionEnvDTO> secondEnv = extTestPlanCollectionMapper.selectSecondCollectionEnv(CaseType.SCENARIO_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID); 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));
//获取一级节点环境
TestPlanCollectionEnvDTO firstEnv = extTestPlanCollectionMapper.selectFirstCollectionEnv(CaseType.SCENARIO_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId);
//当前用例环境 //当前用例环境
List<String> caseEnvIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getEnvironmentId).toList(); List<String> caseEnvIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getEnvironmentId).toList();
EnvironmentExample environmentExample = new EnvironmentExample(); EnvironmentExample environmentExample = new EnvironmentExample();
@ -385,17 +387,28 @@ 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()));
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId()); if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) {
if (StringUtils.equalsIgnoreCase(collectEnv.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) { TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
//计划集 == 默认环境 处理默认环境 if (collectEnv.getExtended()) {
doHandleDefaultEnv(item, caseEnvMap); //继承
} else { getRunEnv(firstEnv, caseEnvMap, item);
//计划集 != 默认环境 } else {
doHandleEnv(item, collectEnv); getRunEnv(collectEnv, caseEnvMap, item);
}
} }
}); });
} }
private void getRunEnv(TestPlanCollectionEnvDTO collectEnv, Map<String, String> caseEnvMap, TestPlanApiScenarioPageResponse item) {
if (StringUtils.equalsIgnoreCase(collectEnv.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
//计划集 == 默认环境 处理默认环境
doHandleDefaultEnv(item, caseEnvMap);
} else {
//计划集 != 默认环境
doHandleEnv(item, collectEnv);
}
}
private void doHandleEnv(TestPlanApiScenarioPageResponse item, TestPlanCollectionEnvDTO collectEnv) { private void doHandleEnv(TestPlanApiScenarioPageResponse item, TestPlanCollectionEnvDTO collectEnv) {
if (StringUtils.isNotBlank(collectEnv.getEnvironmentName())) { if (StringUtils.isNotBlank(collectEnv.getEnvironmentName())) {
item.setEnvironmentId(collectEnv.getEnvironmentId()); item.setEnvironmentId(collectEnv.getEnvironmentId());

View File

@ -19,9 +19,9 @@ VALUES
INSERT INTO `api_test_case`(`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`) INSERT INTO `api_test_case`(`id`, `name`, `priority`, `num`, `tags`, `status`, `last_report_status`, `last_report_id`, `pos`, `project_id`, `api_definition_id`, `version_id`, `environment_id`, `create_time`, `create_user`, `update_time`, `update_user`, `delete_time`, `delete_user`, `deleted`)
VALUES VALUES
('wxxx_api_case_1', '231', 'P0', 100055001, '[]', 'PROCESSING', 'SUCCESS', '1130899263537153', 64, 'wxx_1234', 'wxxx_api_1', '899658209591296', '899606669983745', 1716199600948, 'admin', 1716199600948, 'admin', NULL, NULL, b'0'), ('wxxx_api_case_1', '231', 'P0', 100055001, '[]', 'PROCESSING', 'SUCCESS', '1130899263537153', 64, 'wxx_1234', 'wxxx_api_1', '899658209591296', '123', 1716199600948, 'admin', 1716199600948, 'admin', NULL, NULL, b'0'),
('wxxx_api_case_2', '232', 'P0', 100055001, '[]', 'PROCESSING', 'SUCCESS', '1130899263537153', 64, 'wxx_1234', 'wxxx_api_1', '899658209591296', '899606669983745', 1716199600948, 'admin', 1716199600948, 'admin', NULL, NULL, b'0'), ('wxxx_api_case_2', '232', 'P0', 100055001, '[]', 'PROCESSING', 'SUCCESS', '1130899263537153', 64, 'wxx_1234', 'wxxx_api_1', '899658209591296', '123', 1716199600948, 'admin', 1716199600948, 'admin', NULL, NULL, b'0'),
('wxxx_api_case_3', '233', 'P0', 100055001, '[]', 'PROCESSING', 'SUCCESS', '1130899263537153', 64, 'wxx_1234', 'wxxx_api_2', '899658209591296', '899606669983745', 1716199600948, 'admin', 1716199600948, 'admin', NULL, NULL, b'0'); ('wxxx_api_case_3', '233', 'P0', 100055001, '[]', 'PROCESSING', 'SUCCESS', '1130899263537153', 64, 'wxx_1234', 'wxxx_api_2', '899658209591296', '123', 1716199600948, 'admin', 1716199600948, 'admin', NULL, NULL, b'0');
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting) INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, module_setting)
VALUES VALUES