fix(测试计划): 修复测试计划执行查询环境时没有过滤回收站里用例的问题

--bug=1033796 --user=宋天阳 【测试跟踪】测试计划-操作执行-项目展示错误
https://www.tapd.cn/55049933/s/1446912
This commit is contained in:
song-tianyang 2023-12-21 16:21:52 +08:00 committed by 刘瑞斌
parent 8f617203b6
commit 0cc2336a3c
2 changed files with 24 additions and 16 deletions

View File

@ -1064,7 +1064,10 @@ public class ApiDefinitionService {
LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败", e); LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败", e);
} }
if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) { if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) {
String envId = runModeConfigDTO.getEnvMap().get(projectId); String envId = null;
for (String envItemId : runModeConfigDTO.getEnvMap().values()) {
envId = envItemId;
}
apiReportEnvConfig.setEnvName(apiTestEnvironmentService.selectNameById(envId)); apiReportEnvConfig.setEnvName(apiTestEnvironmentService.selectNameById(envId));
} }
if (runModeConfigDTO != null && StringUtils.isNotBlank(runModeConfigDTO.getResourcePoolId())) { if (runModeConfigDTO != null && StringUtils.isNotBlank(runModeConfigDTO.getResourcePoolId())) {
@ -2199,10 +2202,8 @@ public class ApiDefinitionService {
Map<String, List<String>> returnMap = new HashMap<>(); Map<String, List<String>> returnMap = new HashMap<>();
if (MapUtils.isNotEmpty(projectEnvConfigMap)) { if (MapUtils.isNotEmpty(projectEnvConfigMap)) {
for (Map.Entry<String, List<String>> entry : projectEnvConfigMap.entrySet()) { for (Map.Entry<String, List<String>> entry : projectEnvConfigMap.entrySet()) {
String projectId = entry.getKey();
List<String> configList = entry.getValue(); List<String> configList = entry.getValue();
Project project = baseProjectService.getProjectById(projectId);
List<String> envIdList = new ArrayList<>();
configList.forEach(envConfig -> { configList.forEach(envConfig -> {
RunModeConfigDTO runModeConfigDTO = null; RunModeConfigDTO runModeConfigDTO = null;
try { try {
@ -2210,19 +2211,24 @@ public class ApiDefinitionService {
} catch (Exception e) { } catch (Exception e) {
LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败", e); LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败", e);
} }
if (runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) {
if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) { runModeConfigDTO.getEnvMap().forEach((k, v) -> {
String envId = runModeConfigDTO.getEnvMap().get(projectId); Project project = baseProjectService.getProjectById(k);
if (!envIdList.contains(envId)) { String envName = apiTestEnvironmentService.selectNameById(v);
envIdList.add(envId); String projectName = project == null ? null : project.getName();
} if (StringUtils.isNoneBlank(projectName, projectName)) {
if (returnMap.containsKey(projectName) && !returnMap.get(projectName).contains(envName)) {
returnMap.get(projectName).add(envName);
} else if (!returnMap.containsKey(projectName)) {
returnMap.put(projectName, new ArrayList<>() {{
this.add(envName);
}});
}
}
});
} }
}); });
String projectName = project == null ? null : project.getName();
if (StringUtils.isNotEmpty(projectName) && CollectionUtils.isNotEmpty(envIdList)) {
List<String> envNameList = apiTestEnvironmentService.selectNameByIdList(envIdList);
returnMap.put(projectName, envNameList);
}
} }
} }
return returnMap; return returnMap;

View File

@ -910,6 +910,8 @@ public class TestPlanApiCaseService {
ApiTestCaseExample example = new ApiTestCaseExample(); ApiTestCaseExample example = new ApiTestCaseExample();
example.createCriteria().andIdIn(apiCaseIds); example.createCriteria().andIdIn(apiCaseIds);
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example); List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
return apiTestCases.stream().map(ApiTestCase::getProjectId).distinct().collect(Collectors.toList()); List<ApiTestCase> filtedList = apiTestCases.stream().filter(
apiTestCase -> apiTestCase.getStatus() == null || !CommonConstants.TRASH_STATUS.equals(apiTestCase.getStatus())).collect(Collectors.toList());
return filtedList.stream().map(ApiTestCase::getProjectId).distinct().collect(Collectors.toList());
} }
} }