diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index bf40289df3..75a2c11955 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -675,7 +675,7 @@ public class TestPlanReportService { try { returnDTO = testPlanService.buildTestPlanReportStruct(testPlan, testPlanReport, reportContent); //查找运行环境 - this.initRunInfomation(returnDTO, testPlanReport); + this.initRunInformation(returnDTO, testPlanReport); } catch (Exception e) { LogUtil.error("计算测试计划报告信息出错!", e); } @@ -1117,25 +1117,12 @@ public class TestPlanReportService { TestResourcePoolExample example = new TestResourcePoolExample(); example.createCriteria().andIdIn(report.getResourcePools()); List resourcePoolList = testResourcePoolMapper.selectByExample(example); - if (CollectionUtils.isNotEmpty(resourcePoolList)) { - ArrayList resourcePoolName = new ArrayList<>(); - resourcePoolList.forEach(item -> { - if (!resourcePoolName.contains(item.getName())) { - resourcePoolName.add(item.getName()); - } - }); - String resourcePoolNames = StringUtils.join(resourcePoolName.toArray(), StringUtils.SPACE); - report.setResourcePool(resourcePoolNames); - } else { - report.setResourcePool("LOCAL"); - } - } else { - report.setResourcePool("LOCAL"); + report.setResourcePool(getResourcePoolName(resourcePoolList, report.getResourcePools().contains("LOCAL"))); } return report; } - public void initRunInfomation(TestPlanReportDataStruct testPlanReportDTO, TestPlanReport testPlanReport) { + public void initRunInformation(TestPlanReportDataStruct testPlanReportDTO, TestPlanReport testPlanReport) { if (StringUtils.isNotEmpty(testPlanReport.getRunInfo())) { try { TestPlanReportRunInfoDTO runInfoDTO = JSON.parseObject(testPlanReport.getRunInfo(), TestPlanReportRunInfoDTO.class); @@ -1146,6 +1133,23 @@ public class TestPlanReportService { } } + private String getResourcePoolName(List resourcePoolList, boolean hasLocal) { + ArrayList resourcePoolName = new ArrayList<>(); + if (hasLocal) { + resourcePoolName.add("LOCAL"); + } + if (CollectionUtils.isNotEmpty(resourcePoolList)) { + resourcePoolList.forEach(item -> { + if (!resourcePoolName.contains(item.getName())) { + resourcePoolName.add(item.getName()); + } + }); + } + + String resourcePoolNames = StringUtils.join(resourcePoolName.toArray(), StringUtils.SPACE); + return resourcePoolNames; + } + public void setEnvironmentToDTO(TestPlanReportDataStruct testPlanReportDTO, TestPlanReportRunInfoDTO runInfoDTO) { if (ObjectUtils.allNotNull(testPlanReportDTO, runInfoDTO)) { //查找资源池 @@ -1153,19 +1157,9 @@ public class TestPlanReportService { TestResourcePoolExample example = new TestResourcePoolExample(); example.createCriteria().andIdIn(runInfoDTO.getResourcePools()); List resourcePoolList = testResourcePoolMapper.selectByExample(example); - if (CollectionUtils.isNotEmpty(resourcePoolList)) { - ArrayList resourcePoolName = new ArrayList<>(); - resourcePoolList.forEach(item -> { - if (!resourcePoolName.contains(item.getName())) { - resourcePoolName.add(item.getName()); - } - }); - String resourcePoolNames = StringUtils.join(resourcePoolName.toArray(), StringUtils.SPACE); - testPlanReportDTO.setResourcePool(resourcePoolNames); - } else { - testPlanReportDTO.setResourcePool("LOCAL"); - } - } else { + testPlanReportDTO.setResourcePool(getResourcePoolName(resourcePoolList, runInfoDTO.getResourcePools().contains("LOCAL"))); + } else if (CollectionUtils.isNotEmpty(testPlanReportDTO.getApiAllCases()) || CollectionUtils.isNotEmpty(testPlanReportDTO.getScenarioAllCases())) { + //存在接口或者场景的用例,资源池默认是local testPlanReportDTO.setResourcePool("LOCAL"); } // 环境组/运行环境 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java b/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java index d0a001838e..3501c80fdd 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/utils/TestPlanReportUtil.java @@ -136,13 +136,23 @@ public class TestPlanReportUtil { return null; } - public static List mergeResourcePools(List resourcePools, List originResourcePools) { + public static List mergeResourcePools(List resourcePools, List reFormatOriginResourcePools) { if (resourcePools == null) { resourcePools = new ArrayList<>(); } - if (originResourcePools == null) { + if (reFormatOriginResourcePools == null) { return resourcePools; } + //检查originResourcePools是否含有null。 null代表local + List originResourcePools = new ArrayList<>(); + for (String resourcePool : reFormatOriginResourcePools) { + if (StringUtils.isEmpty(resourcePool)) { + resourcePool = "LOCAL"; + } + if (!originResourcePools.contains(resourcePool)) { + originResourcePools.add(resourcePool); + } + } List returnList = new ArrayList<>(); returnList.addAll(resourcePools); returnList.addAll(originResourcePools);