fix(测试计划): 修复测试规划脑图资源池删除还显示问题

--bug=1044133 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001044133
This commit is contained in:
guoyuqi 2024-07-17 18:37:16 +08:00 committed by Craftsman
parent 3dbde4f287
commit 87b4c9d901
3 changed files with 34 additions and 11 deletions

View File

@ -8,4 +8,6 @@ public class TestPlanCollectionConfigDTO extends TestPlanCollection {
private String poolName; private String poolName;
private String envName; private String envName;
private boolean noResourcePool = false;
} }

View File

@ -10,13 +10,11 @@
tpc.test_resource_pool_id, tpc.retry_on_fail, tpc.test_resource_pool_id, tpc.retry_on_fail,
tpc.retry_times, tpc.retry_interval, tpc.stop_on_fail, tpc.retry_times, tpc.retry_interval, tpc.stop_on_fail,
tpc.create_user, tpc.create_time, tpc.pos, tpc.create_user, tpc.create_time, tpc.pos,
trp.name as poolName,
IF(env.name is not null, env.name, envg.name) as envName IF(env.name is not null, env.name, envg.name) as envName
FROM FROM
test_plan_collection tpc test_plan_collection tpc
LEFT JOIN test_resource_pool trp ON tpc.test_resource_pool_id = trp.id
LEFT JOIN environment env ON tpc.environment_id = env.id LEFT JOIN environment env ON tpc.environment_id = env.id
LEFT JOIN environment_group envg ON tpc.test_resource_pool_id = envg.id LEFT JOIN environment_group envg ON tpc.environment_id = envg.id
WHERE tpc.test_plan_id = #{planId} WHERE tpc.test_plan_id = #{planId}
</select> </select>

View File

@ -5,6 +5,7 @@ import io.metersphere.plan.dto.*;
import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest; import io.metersphere.plan.dto.request.BaseCollectionAssociateRequest;
import io.metersphere.plan.dto.request.TestPlanCollectionMinderEditRequest; import io.metersphere.plan.dto.request.TestPlanCollectionMinderEditRequest;
import io.metersphere.plan.mapper.*; import io.metersphere.plan.mapper.*;
import io.metersphere.project.mapper.ExtProjectMapper;
import io.metersphere.sdk.constants.ApiBatchRunMode; import io.metersphere.sdk.constants.ApiBatchRunMode;
import io.metersphere.sdk.constants.CaseType; import io.metersphere.sdk.constants.CaseType;
import io.metersphere.sdk.constants.CommonConstants; import io.metersphere.sdk.constants.CommonConstants;
@ -12,6 +13,7 @@ import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.TestResourcePool;
import io.metersphere.system.dto.sdk.SessionUser; import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -61,6 +63,12 @@ public class TestPlanCollectionMinderService {
@Resource @Resource
private TestPlanConfigMapper testPlanConfigMapper; private TestPlanConfigMapper testPlanConfigMapper;
@Resource
private ExtProjectMapper extProjectMapper;
@Resource
private TestPlanMapper testPlanMapper;
/** /**
* 测试计划-脑图用例列表查询 * 测试计划-脑图用例列表查询
* *
@ -69,6 +77,18 @@ public class TestPlanCollectionMinderService {
public List<TestPlanCollectionMinderTreeDTO> getMindTestPlanCase(String planId) { public List<TestPlanCollectionMinderTreeDTO> getMindTestPlanCase(String planId) {
List<TestPlanCollectionMinderTreeDTO> list = new ArrayList<>(); List<TestPlanCollectionMinderTreeDTO> list = new ArrayList<>();
List<TestPlanCollectionConfigDTO> testPlanCollections = extTestPlanCollectionMapper.getList(planId); List<TestPlanCollectionConfigDTO> testPlanCollections = extTestPlanCollectionMapper.getList(planId);
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
List<TestResourcePool> apiTest = extProjectMapper.getResourcePoolOption(testPlan.getProjectId(), "api_test");
Map<String, String> resourcePoolMap = apiTest.stream().collect(Collectors.toMap(TestResourcePool::getId, TestResourcePool::getName));
testPlanCollections.forEach(t->{
if (StringUtils.isBlank(resourcePoolMap.get(t.getTestResourcePoolId()))) {
t.setPoolName(Translator.get("resource_pool_not_exist"));
t.setNoResourcePool(true);
} else {
t.setPoolName(t.getPoolName());
}
});
//构造根节点 //构造根节点
TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(planId); TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(planId);
TestPlanCollectionMinderTreeNodeDTO testPlanCollectionMinderTreeNodeDTO = buildRoot(); TestPlanCollectionMinderTreeNodeDTO testPlanCollectionMinderTreeNodeDTO = buildRoot();
@ -190,18 +210,21 @@ public class TestPlanCollectionMinderService {
if (CollectionUtils.isNotEmpty(testPlanApiScenarios)) { if (CollectionUtils.isNotEmpty(testPlanApiScenarios)) {
count = testPlanApiScenarios.size(); count = testPlanApiScenarios.size();
} }
buildChild(countTreeNodeDTO, count + Translator.get("test_plan.mind.strip"), "test_plan.mind.case_count", countTreeDTO, endList); buildChild(countTreeNodeDTO, count + Translator.get("test_plan.mind.strip"), "test_plan.mind.case_count", countTreeDTO, endList, false);
TestPlanCollectionMinderTreeDTO envTreeDTO = new TestPlanCollectionMinderTreeDTO(); TestPlanCollectionMinderTreeDTO envTreeDTO = new TestPlanCollectionMinderTreeDTO();
TestPlanCollectionMinderTreeNodeDTO envTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO(); TestPlanCollectionMinderTreeNodeDTO envTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO();
buildChild(envTreeNodeDTO, StringUtils.equalsIgnoreCase(planCollection.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID) ? Translator.get("api_report_default_env") : planCollection.getEnvName(), "test_plan.mind.environment", envTreeDTO, endList); buildChild(envTreeNodeDTO, StringUtils.equalsIgnoreCase(planCollection.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID) ? Translator.get("api_report_default_env") : planCollection.getEnvName(), "test_plan.mind.environment", envTreeDTO, endList, false);
TestPlanCollectionMinderTreeDTO poolTreeDTO = new TestPlanCollectionMinderTreeDTO(); TestPlanCollectionMinderTreeDTO poolTreeDTO = new TestPlanCollectionMinderTreeDTO();
TestPlanCollectionMinderTreeNodeDTO poolTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO(); TestPlanCollectionMinderTreeNodeDTO poolTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO();
buildChild(poolTreeNodeDTO, planCollection.getPoolName(), "test_plan.mind.test_resource_pool", poolTreeDTO, endList); buildChild(poolTreeNodeDTO, planCollection.getPoolName(), "test_plan.mind.test_resource_pool", poolTreeDTO, endList, planCollection.isNoResourcePool());
} }
private static void buildChild(TestPlanCollectionMinderTreeNodeDTO treeNodeDTO, String text, String key, TestPlanCollectionMinderTreeDTO treeDTO, List<TestPlanCollectionMinderTreeDTO> endList) { private static void buildChild(TestPlanCollectionMinderTreeNodeDTO treeNodeDTO, String text, String key, TestPlanCollectionMinderTreeDTO treeDTO, List<TestPlanCollectionMinderTreeDTO> endList, boolean noResourcePool) {
treeNodeDTO.setText(text); treeNodeDTO.setText(text);
treeNodeDTO.setResource(List.of(Translator.get(key))); treeNodeDTO.setResource(List.of(Translator.get(key)));
if (noResourcePool) {
treeNodeDTO.setPriority(0);
}
treeDTO.setData(treeNodeDTO); treeDTO.setData(treeNodeDTO);
treeDTO.setChildren(new ArrayList<>()); treeDTO.setChildren(new ArrayList<>());
if (StringUtils.isNotBlank(text)) { if (StringUtils.isNotBlank(text)) {
@ -217,13 +240,13 @@ public class TestPlanCollectionMinderService {
if (CollectionUtils.isNotEmpty(testPlanApiCases)) { if (CollectionUtils.isNotEmpty(testPlanApiCases)) {
count = testPlanApiCases.size(); count = testPlanApiCases.size();
} }
buildChild(countTreeNodeDTO, count + Translator.get("test_plan.mind.strip"), "test_plan.mind.case_count", countTreeDTO, endList); buildChild(countTreeNodeDTO, count + Translator.get("test_plan.mind.strip"), "test_plan.mind.case_count", countTreeDTO, endList, false);
TestPlanCollectionMinderTreeDTO envTreeDTO = new TestPlanCollectionMinderTreeDTO(); TestPlanCollectionMinderTreeDTO envTreeDTO = new TestPlanCollectionMinderTreeDTO();
TestPlanCollectionMinderTreeNodeDTO envTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO(); TestPlanCollectionMinderTreeNodeDTO envTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO();
buildChild(envTreeNodeDTO, StringUtils.equalsIgnoreCase(planCollection.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID) ? Translator.get("api_report_default_env") : planCollection.getEnvName(), "test_plan.mind.environment", envTreeDTO, endList); buildChild(envTreeNodeDTO, StringUtils.equalsIgnoreCase(planCollection.getEnvironmentId(), ModuleConstants.ROOT_NODE_PARENT_ID) ? Translator.get("api_report_default_env") : planCollection.getEnvName(), "test_plan.mind.environment", envTreeDTO, endList, false);
TestPlanCollectionMinderTreeDTO poolTreeDTO = new TestPlanCollectionMinderTreeDTO(); TestPlanCollectionMinderTreeDTO poolTreeDTO = new TestPlanCollectionMinderTreeDTO();
TestPlanCollectionMinderTreeNodeDTO poolTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO(); TestPlanCollectionMinderTreeNodeDTO poolTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO();
buildChild(poolTreeNodeDTO, planCollection.getPoolName(), "test_plan.mind.test_resource_pool", poolTreeDTO, endList); buildChild(poolTreeNodeDTO, planCollection.getPoolName(), "test_plan.mind.test_resource_pool", poolTreeDTO, endList, planCollection.isNoResourcePool());
} }
private static void buildFunctionalChild(Map<String, List<TestPlanFunctionalCase>> testPlanFunctionalCaseMap, TestPlanCollectionConfigDTO planCollection, List<TestPlanCollectionMinderTreeDTO> endList) { private static void buildFunctionalChild(Map<String, List<TestPlanFunctionalCase>> testPlanFunctionalCaseMap, TestPlanCollectionConfigDTO planCollection, List<TestPlanCollectionMinderTreeDTO> endList) {
@ -234,7 +257,7 @@ public class TestPlanCollectionMinderService {
} }
TestPlanCollectionMinderTreeDTO countTreeDTO = new TestPlanCollectionMinderTreeDTO(); TestPlanCollectionMinderTreeDTO countTreeDTO = new TestPlanCollectionMinderTreeDTO();
TestPlanCollectionMinderTreeNodeDTO countTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO(); TestPlanCollectionMinderTreeNodeDTO countTreeNodeDTO = new TestPlanCollectionMinderTreeNodeDTO();
buildChild(countTreeNodeDTO, count + Translator.get("test_plan.mind.strip"), "test_plan.mind.case_count", countTreeDTO, endList); buildChild(countTreeNodeDTO, count + Translator.get("test_plan.mind.strip"), "test_plan.mind.case_count", countTreeDTO, endList, false);
} }
@NotNull @NotNull