mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-11-30 11:08:38 +08:00
refactor(测试计划): 优化列表运行环境显示
This commit is contained in:
parent
4c4fed22d7
commit
d4ee62f705
@ -23,4 +23,10 @@ public class TestPlanCollectionEnvDTO implements Serializable {
|
||||
|
||||
@Schema(description = "环境名称")
|
||||
private String environmentName;
|
||||
|
||||
@Schema(description = "是否继承")
|
||||
private Boolean extended;
|
||||
|
||||
@Schema(description = "父ID")
|
||||
private String parentId;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ public interface ExtTestPlanCollectionMapper {
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -24,12 +24,32 @@
|
||||
SELECT
|
||||
tpc.id,
|
||||
tpc.environment_id,
|
||||
e.`name` as environmentName
|
||||
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 <![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>
|
||||
</mapper>
|
@ -19,6 +19,7 @@ import io.metersphere.plan.domain.*;
|
||||
import io.metersphere.plan.dto.*;
|
||||
import io.metersphere.plan.dto.request.*;
|
||||
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.TestPlanOperationResponse;
|
||||
import io.metersphere.plan.mapper.*;
|
||||
@ -224,22 +225,24 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<TestPlanApiCasePageResponse> list = extTestPlanApiCaseMapper.relateApiCaseList(request, deleted);
|
||||
buildApiCaseResponse(list);
|
||||
buildApiCaseResponse(list, request.getTestPlanId());
|
||||
return list;
|
||||
}
|
||||
|
||||
private void buildApiCaseResponse(List<TestPlanApiCasePageResponse> apiCaseList) {
|
||||
private void buildApiCaseResponse(List<TestPlanApiCasePageResponse> apiCaseList, String testPlanId) {
|
||||
if (CollectionUtils.isNotEmpty(apiCaseList)) {
|
||||
Map<String, String> projectMap = getProject(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));
|
||||
//获取一级节点环境
|
||||
TestPlanCollectionEnvDTO firstEnv = extTestPlanCollectionMapper.selectFirstCollectionEnv(CaseType.API_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId);
|
||||
//当前用例环境
|
||||
List<String> caseEnvIds = apiCaseList.stream().map(TestPlanApiCasePageResponse::getEnvironmentId).toList();
|
||||
EnvironmentExample environmentExample = new EnvironmentExample();
|
||||
@ -250,17 +253,28 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||
item.setProjectName(projectMap.get(item.getProjectId()));
|
||||
item.setCreateUserName(userMap.get(item.getCreateUser()));
|
||||
item.setExecuteUserName(userMap.get(item.getExecuteUser()));
|
||||
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
|
||||
if (StringUtils.equalsIgnoreCase(collectEnv.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
|
||||
//计划集 == 默认环境 处理默认环境
|
||||
doHandleDefaultEnv(item, caseEnvMap);
|
||||
} else {
|
||||
//计划集 != 默认环境
|
||||
doHandleEnv(item, collectEnv);
|
||||
if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) {
|
||||
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
|
||||
if (collectEnv.getExtended()) {
|
||||
//继承
|
||||
getRunEnv(firstEnv, caseEnvMap, item);
|
||||
} else {
|
||||
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) {
|
||||
if (StringUtils.isNotBlank(collectEnv.getEnvironmentName())) {
|
||||
item.setEnvironmentId(collectEnv.getEnvironmentId());
|
||||
|
@ -359,22 +359,24 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
||||
*/
|
||||
public List<TestPlanApiScenarioPageResponse> hasRelateApiScenarioList(TestPlanApiScenarioRequest request, boolean deleted) {
|
||||
List<TestPlanApiScenarioPageResponse> list = extTestPlanApiScenarioMapper.relateApiScenarioList(request, deleted);
|
||||
buildApiScenarioResponse(list);
|
||||
buildApiScenarioResponse(list, request.getTestPlanId());
|
||||
return list;
|
||||
}
|
||||
|
||||
private void buildApiScenarioResponse(List<TestPlanApiScenarioPageResponse> apiScenarioList) {
|
||||
private void buildApiScenarioResponse(List<TestPlanApiScenarioPageResponse> apiScenarioList, String testPlanId) {
|
||||
if (CollectionUtils.isNotEmpty(apiScenarioList)) {
|
||||
Map<String, String> projectMap = getProject(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));
|
||||
//获取一级节点环境
|
||||
TestPlanCollectionEnvDTO firstEnv = extTestPlanCollectionMapper.selectFirstCollectionEnv(CaseType.SCENARIO_CASE.getKey(), ModuleConstants.ROOT_NODE_PARENT_ID, testPlanId);
|
||||
//当前用例环境
|
||||
List<String> caseEnvIds = apiScenarioList.stream().map(TestPlanApiScenarioPageResponse::getEnvironmentId).toList();
|
||||
EnvironmentExample environmentExample = new EnvironmentExample();
|
||||
@ -385,17 +387,28 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
||||
item.setProjectName(projectMap.get(item.getProjectId()));
|
||||
item.setCreateUserName(userMap.get(item.getCreateUser()));
|
||||
item.setExecuteUserName(userMap.get(item.getExecuteUser()));
|
||||
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
|
||||
if (StringUtils.equalsIgnoreCase(collectEnv.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) {
|
||||
//计划集 == 默认环境 处理默认环境
|
||||
doHandleDefaultEnv(item, caseEnvMap);
|
||||
} else {
|
||||
//计划集 != 默认环境
|
||||
doHandleEnv(item, collectEnv);
|
||||
if (secondEnvMap.containsKey(item.getTestPlanCollectionId())) {
|
||||
TestPlanCollectionEnvDTO collectEnv = secondEnvMap.get(item.getTestPlanCollectionId());
|
||||
if (collectEnv.getExtended()) {
|
||||
//继承
|
||||
getRunEnv(firstEnv, caseEnvMap, item);
|
||||
} else {
|
||||
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) {
|
||||
if (StringUtils.isNotBlank(collectEnv.getEnvironmentName())) {
|
||||
item.setEnvironmentId(collectEnv.getEnvironmentId());
|
||||
|
@ -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`)
|
||||
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_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_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_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', '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', '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)
|
||||
VALUES
|
||||
|
Loading…
Reference in New Issue
Block a user