fix(测试跟踪): 修复测试计划环境列表与环境组切换显示的问题

--bug=1023697 --user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001023697
This commit is contained in:
guoyuqi 2023-02-24 15:50:16 +08:00 committed by fit2-zhao
parent 19ea15c61f
commit 0a517e96d1
2 changed files with 20 additions and 17 deletions

View File

@ -28,6 +28,7 @@ import io.metersphere.dto.MsExecResponseDTO;
import io.metersphere.dto.PlanReportCaseDTO;
import io.metersphere.dto.ProjectConfig;
import io.metersphere.dto.RunModeConfigDTO;
import io.metersphere.environment.service.BaseEnvGroupProjectService;
import io.metersphere.environment.service.BaseEnvironmentService;
import io.metersphere.i18n.Translator;
import io.metersphere.log.vo.OperatingLogDetails;
@ -92,6 +93,8 @@ public class TestPlanScenarioCaseService {
@Resource
private BaseEnvironmentService apiTestEnvironmentService;
@Resource
private BaseEnvGroupProjectService environmentGroupProjectService;
@Resource
private ExtApiScenarioModuleMapper extApiScenarioModuleMapper;
@Lazy
@Resource
@ -314,9 +317,6 @@ public class TestPlanScenarioCaseService {
testPlanApiScenarioExample.createCriteria().andIdIn(planScenarioIds);
testPlanApiScenarios = testPlanApiScenarioMapper.selectByExampleWithBLOBs(testPlanApiScenarioExample);
}
if (CollectionUtils.isEmpty(planScenarioIds)) {
return;
}
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
TestPlanApiScenarioMapper mapper = sqlSession.getMapper(TestPlanApiScenarioMapper.class);
@ -369,9 +369,14 @@ public class TestPlanScenarioCaseService {
}
if (StringUtils.equals(environmentType, EnvironmentType.GROUP.toString())) {
Map<String, String> envMap = new HashMap<>();
if (StringUtils.isNotBlank(environmentGroupId)) {
envMap = environmentGroupProjectService.getEnvMap(environmentGroupId);
}
for (TestPlanApiScenario testPlanApiScenario : testPlanApiScenarios) {
testPlanApiScenario.setEnvironmentType(EnvironmentType.GROUP.toString());
testPlanApiScenario.setEnvironmentGroupId(environmentGroupId);
testPlanApiScenario.setEnvironment(JSON.toJSONString(envMap));
mapper.updateByPrimaryKeyWithBLOBs(testPlanApiScenario);
}
sqlSession.flushStatements();

View File

@ -1613,20 +1613,18 @@ public class TestPlanService {
if (MapUtils.isEmpty(scenarioEnv)) {
return uiScenarioEnv;
}
if (MapUtils.isNotEmpty(uiScenarioEnv)) {
uiScenarioEnv.entrySet().forEach(entry -> {
if (scenarioEnv.containsKey(entry.getKey())) {
List<String> environmentIds = scenarioEnv.get(entry.getKey());
entry.getValue().forEach(eId -> {
if (!environmentIds.contains(eId)) {
environmentIds.add(eId);
}
});
} else {
scenarioEnv.put(entry.getKey(), entry.getValue());
}
});
}
uiScenarioEnv.forEach((key, value) -> {
if (scenarioEnv.containsKey(key)) {
List<String> environmentIds = scenarioEnv.get(key);
value.forEach(eId -> {
if (!environmentIds.contains(eId)) {
environmentIds.add(eId);
}
});
} else {
scenarioEnv.put(key, value);
}
});
return scenarioEnv;
}