diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/plan/AutomationsRunInfoDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/plan/AutomationsRunInfoDTO.java new file mode 100644 index 0000000000..a4e10cbd3f --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/plan/AutomationsRunInfoDTO.java @@ -0,0 +1,14 @@ +package io.metersphere.api.dto.plan; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.Map; + +@Getter +@Setter +public class AutomationsRunInfoDTO { + List resourcePools; + Map> projectEnvMap; +} diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java index 9b85944499..cce9e4451f 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java @@ -12,4 +12,6 @@ public interface ExtApiScenarioModuleMapper { void updatePos(String id, Double pos); List selectByIds(@Param("ids") Collection ids); + + List selectResourcePoolIdByTestPlanScenarioIds(@Param("ids") List resourceIds); } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml index 2791905b26..2e7d283636 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml @@ -25,4 +25,14 @@ order by api_scenario_module.pos asc + + \ No newline at end of file diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java index 48fb0fa8cb..f08d897892 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.java @@ -62,5 +62,7 @@ public interface ExtTestPlanApiCaseMapper { String selectProjectId(String id); List selectByRefIds(@Param("ids") List ids); + + List selectResourcePoolIdByTestPlanApiIds(@Param("ids") List resourceIds); } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml index 39f9ada0ef..2ae91a5e32 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/plan/ext/ExtTestPlanApiCaseMapper.xml @@ -555,4 +555,16 @@ ORDER BY t.order DESC + + diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java index 8701fb51b3..0710dbaa3e 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanApiCaseController.java @@ -6,6 +6,7 @@ import io.metersphere.api.dto.QueryReferenceRequest; import io.metersphere.api.dto.automation.TestPlanApiDTO; import io.metersphere.api.dto.automation.TestPlanDTO; import io.metersphere.api.dto.definition.*; +import io.metersphere.api.dto.plan.AutomationsRunInfoDTO; import io.metersphere.api.dto.plan.TestPlanApiCaseBatchRequest; import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs; import io.metersphere.base.domain.ApiScenarioReportWithBLOBs; @@ -140,7 +141,7 @@ public class TestPlanApiCaseController { } @PostMapping("/get/plan/env/map") - public Map> getPlanProjectEnvMap(@RequestBody List resourceIds) { + public AutomationsRunInfoDTO getPlanProjectEnvMap(@RequestBody List resourceIds) { return testPlanApiCaseService.getPlanProjectEnvMap(resourceIds); } diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java index 463c5ca27f..80f3739414 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java @@ -226,7 +226,7 @@ public class TestPlanScenarioCaseController { } @PostMapping("/get/plan/env/map") - public Map> getPlanProjectEnvMap(@RequestBody List resourceIds) { + public AutomationsRunInfoDTO getPlanProjectEnvMap(@RequestBody List resourceIds) { return testPlanScenarioCaseService.getPlanProjectEnvMap(resourceIds); } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index ac7fb043d3..47f878fbbd 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -10,6 +10,7 @@ import io.metersphere.api.dto.QueryReferenceRequest; import io.metersphere.api.dto.automation.TestPlanApiDTO; import io.metersphere.api.dto.automation.TestPlanDTO; import io.metersphere.api.dto.definition.*; +import io.metersphere.api.dto.plan.AutomationsRunInfoDTO; import io.metersphere.api.dto.plan.TestPlanApiCaseBatchRequest; import io.metersphere.api.dto.plan.TestPlanApiCaseInfoDTO; import io.metersphere.api.exec.api.ApiCaseExecuteService; @@ -521,8 +522,9 @@ public class TestPlanApiCaseService { return extTestPlanApiCaseMapper.selectProjectId(id); } - public Map> getPlanProjectEnvMap(List resourceIds) { + public AutomationsRunInfoDTO getPlanProjectEnvMap(List resourceIds) { Map> result = new LinkedHashMap<>(); + List resourcePoolIds = new ArrayList<>(); if (!CollectionUtils.isEmpty(resourceIds)) { List execResults = apiDefinitionExecResultService.selectByResourceIdsAndMaxCreateTime(resourceIds); Map> projectConfigMap = new HashMap<>(); @@ -538,8 +540,12 @@ public class TestPlanApiCaseService { } }); result = apiDefinitionService.getProjectEnvNameByEnvConfig(projectConfigMap); + resourcePoolIds = extTestPlanApiCaseMapper.selectResourcePoolIdByTestPlanApiIds(resourceIds); } - return result; + AutomationsRunInfoDTO returnDTO = new AutomationsRunInfoDTO(); + returnDTO.setProjectEnvMap(result); + returnDTO.setResourcePools(resourcePoolIds); + return returnDTO; } public void setProjectEnvMap(Map> result, Map> projectEnvMap) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java index 1467372df0..e134710895 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java @@ -1093,13 +1093,18 @@ public class TestPlanScenarioCaseService { return extTestPlanScenarioCaseMapper.selectForPlanReport(planId); } - public Map> getPlanProjectEnvMap(List resourceIds) { + public AutomationsRunInfoDTO getPlanProjectEnvMap(List resourceIds) { + AutomationsRunInfoDTO returnRunInfoDTO = new AutomationsRunInfoDTO(); Map> result = new LinkedHashMap<>(); + List resourcePoolList = new ArrayList<>(); if (!com.alibaba.nacos.common.utils.CollectionUtils.isEmpty(resourceIds)) { Map> projectEnvMap = apiScenarioEnvService.selectProjectEnvMapByTestPlanScenarioIds(resourceIds); testPlanApiCaseService.setProjectEnvMap(result, projectEnvMap); + resourcePoolList = extApiScenarioModuleMapper.selectResourcePoolIdByTestPlanScenarioIds(resourceIds); } - return result; + returnRunInfoDTO.setResourcePools(resourcePoolList); + returnRunInfoDTO.setProjectEnvMap(result); + return returnRunInfoDTO; } public List getNodeByPlanId(List projectIds, String planId) { diff --git a/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.java b/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.java index 6478bd74f5..6694eb6e55 100644 --- a/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.java +++ b/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.java @@ -43,4 +43,9 @@ public interface ExtTestPlanLoadCaseMapper { void updateStatusNullById(String id); String selectPlanIdByTestPlanId(@Param("id") String id); + + List getResourcePoolByPlanId(String planId); + + List getCaseResourcePoolByPlanId(String planId); + } diff --git a/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml b/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml index b9e1ab90b9..4912bea4f0 100644 --- a/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml +++ b/performance-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanLoadCaseMapper.xml @@ -367,4 +367,20 @@ and ${versionTable}.ref_id = #{request.refId} + + + + diff --git a/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java b/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java index d40f290fdc..38d1fc4e0e 100644 --- a/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java +++ b/performance-test/backend/src/main/java/io/metersphere/plan/controller/TestPlanLoadCaseController.java @@ -22,9 +22,9 @@ import io.metersphere.plan.service.TestPlanLoadCaseService; import io.metersphere.request.PlanSubReportRequest; import io.metersphere.request.ResetOrderRequest; import io.metersphere.request.RunTestPlanRequest; +import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; import java.util.List; @RequestMapping("/test/plan/load/case") @@ -179,6 +179,16 @@ public class TestPlanLoadCaseController { return testPlanLoadCaseService.getStatus(planId); } + @GetMapping("/resource/pool/{planId}") + public List getResourcePoolByPlanId(@PathVariable String planId) { + return testPlanLoadCaseService.getResourcePoolByPlanId(planId); + } + + @GetMapping("/resource/pool/case/{planId}") + public List getCaseResourcePoolByPlanId(@PathVariable String planId) { + return testPlanLoadCaseService.getCaseResourcePoolByPlanId(planId); + } + @GetMapping("/get/report/status/{planId}") public List selectStatusForPlanReport(@PathVariable("planId") String planId) { return testPlanLoadCaseService.selectStatusForPlanReport(planId); diff --git a/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java b/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java index 86273196b2..8c99855b21 100644 --- a/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java +++ b/performance-test/backend/src/main/java/io/metersphere/plan/service/TestPlanLoadCaseService.java @@ -709,4 +709,12 @@ public class TestPlanLoadCaseService { .map(TestPlanLoadCaseDTO::getLoadCaseId) .collect(Collectors.toList()).isEmpty(); } + + public List getResourcePoolByPlanId(String planId) { + return extTestPlanLoadCaseMapper.getResourcePoolByPlanId(planId); + } + + public List getCaseResourcePoolByPlanId(String planId) { + return extTestPlanLoadCaseMapper.getCaseResourcePoolByPlanId(planId); + } } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/AutomationsRunInfoDTO.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/AutomationsRunInfoDTO.java new file mode 100644 index 0000000000..05a5edc9f1 --- /dev/null +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/AutomationsRunInfoDTO.java @@ -0,0 +1,14 @@ +package io.metersphere.plan.dto; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.Map; + +@Getter +@Setter +public class AutomationsRunInfoDTO { + List resourcePools; + Map> projectEnvMap; +} diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java index bd0066b108..3e682ef431 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java @@ -17,7 +17,7 @@ public class TestPlanReportRunInfoDTO { private String runMode; private Map> requestEnvMap; - private String resourcePool; + private List resourcePools; // <测试计划场景关联表ID, <项目ID,环境ID>> private Map>> scenarioRunInfo; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java index bd5587e21f..1d5b1e6e60 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java @@ -29,6 +29,8 @@ public class TestPlanSimpleReportDTO extends TestPlanReportContent { */ private String runMode; private String resourcePool; + + private List resourcePools; private String envGroupName; private Map> projectEnvMap; 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 e326f3e967..f571b97636 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 @@ -299,7 +299,7 @@ public class TestPlanReportService { returnDTO.setApiTestCaseDataMap(planApiCaseIdMap); } - + List loadResourcePools = new ArrayList<>(); if (serviceIdSet.contains(MicroServiceName.PERFORMANCE_TEST)) { Map performanceIdMap = new LinkedHashMap<>(); List testPlanLoadCaseDTOList = planTestPlanLoadCaseService.list(planId); @@ -308,10 +308,10 @@ public class TestPlanReportService { } saveRequest.setPerformanceIsExecuting(!performanceIdMap.isEmpty()); saveRequest.setPerformanceIdMap(performanceIdMap); - returnDTO.setPerformanceIdMap(performanceIdMap); - } + loadResourcePools = planTestPlanLoadCaseService.selectResourcePoolsByPlan(planId); + } if (serviceIdSet.contains(MicroServiceName.UI_TEST)) { Map uiScenarioIdMap = new LinkedHashMap<>(); @@ -333,9 +333,13 @@ public class TestPlanReportService { returnDTO.setUiScenarioIdMap(uiScenarioIdMap); } - if (testPlanReport == null) { - runInfoDTO.setResourcePool(runModeConfigDTO.getResourcePoolId()); + runInfoDTO.setResourcePools(loadResourcePools); + if (StringUtils.isNotEmpty(runModeConfigDTO.getResourcePoolId())) { + if (!runInfoDTO.getResourcePools().contains(runModeConfigDTO.getResourcePoolId())) { + runInfoDTO.getResourcePools().add(runModeConfigDTO.getResourcePoolId()); + } + } returnDTO = this.genTestPlanReport(saveRequest, runInfoDTO); } returnDTO.setPlanScenarioIdMap(saveRequest.getScenarioIdMap()); @@ -1103,6 +1107,23 @@ public class TestPlanReportService { } else { report.setIsThirdPartIssue(true); } + + //查找资源池 + if (CollectionUtils.isNotEmpty(report.getResourcePools())) { + 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); + } + } return report; } @@ -1120,10 +1141,19 @@ public class TestPlanReportService { public void setEnvironmentToDTO(TestPlanSimpleReportDTO testPlanReportDTO, TestPlanReportRunInfoDTO runInfoDTO) { if (ObjectUtils.allNotNull(testPlanReportDTO, runInfoDTO)) { //查找资源池 - if (StringUtils.isNotEmpty(runInfoDTO.getResourcePool())) { - TestResourcePool resourcePool = testResourcePoolMapper.selectByPrimaryKey(runInfoDTO.getResourcePool()); - if (resourcePool != null) { - testPlanReportDTO.setResourcePool(resourcePool.getName()); + if (CollectionUtils.isNotEmpty(runInfoDTO.getResourcePools())) { + 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); } } // 环境组/运行环境 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 28539a4268..c7bfafe91e 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -876,6 +876,7 @@ public class TestPlanService { if (haveExecCase(testPlanId, true)) { this.verifyPool(projectId, runModeConfig); } + //创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数 TestPlanScheduleReportInfoDTO reportInfoDTO = this.genTestPlanReport(planReportId, testPlanId, userId, triggerMode, runModeConfig); //定时任务执行重新设置实际开始时间 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java index d7453d3278..bd9202f89b 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanApiCaseService.java @@ -1,22 +1,18 @@ package io.metersphere.plan.service.remote.api; import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs; -import io.metersphere.base.domain.ApiScenarioReportWithBLOBs; import io.metersphere.commons.constants.MicroServiceName; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.*; -import io.metersphere.plan.dto.ApiModuleDTO; -import io.metersphere.plan.dto.BatchRunDefinitionRequest; -import io.metersphere.plan.dto.TestCaseReportStatusResultDTO; -import io.metersphere.plan.dto.TestPlanSimpleReportDTO; +import io.metersphere.plan.dto.*; import io.metersphere.plan.request.api.ApiTestCaseRequest; import io.metersphere.plan.service.TestPlanService; +import io.metersphere.plan.utils.TestPlanReportUtil; import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.utils.DiscoveryUtil; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -50,30 +46,10 @@ public class PlanTestPlanApiCaseService extends ApiTestService { calculatePlanReport(report, planReportCaseDTOS); //记录接口用例的运行环境信息 List idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); - try { - if (MapUtils.isEmpty(report.getProjectEnvMap())) { - report.setProjectEnvMap(getPlanProjectEnvMap(idList)); - } else { - Map> projectEnvMap = getPlanProjectEnvMap(idList); - if (MapUtils.isNotEmpty(projectEnvMap)) { - for (Map.Entry> entry : projectEnvMap.entrySet()) { - String project = entry.getKey(); - List envList = entry.getValue(); - if (report.getProjectEnvMap().containsKey(project)) { - for (String env : envList) { - if (!report.getProjectEnvMap().get(project).contains(env)) { - report.getProjectEnvMap().get(project).add(env); - } - } - } else { - report.getProjectEnvMap().put(project, envList); - } - - } - } - } - } catch (Exception e) { - LogUtil.error(e); + AutomationsRunInfoDTO automationsRunInfoDTO = getPlanProjectEnvMap(idList); + if (automationsRunInfoDTO != null) { + report.setProjectEnvMap(TestPlanReportUtil.mergeProjectEnvMap(report.getProjectEnvMap(), automationsRunInfoDTO.getProjectEnvMap())); + report.setResourcePools(TestPlanReportUtil.mergeResourcePools(report.getResourcePools(), automationsRunInfoDTO.getResourcePools())); } } } @@ -132,8 +108,8 @@ public class PlanTestPlanApiCaseService extends ApiTestService { return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/status/" + planId, PlanReportCaseDTO.class); } - public Map> getPlanProjectEnvMap(List resourceIds) { - return (Map>) microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map", resourceIds); + public AutomationsRunInfoDTO getPlanProjectEnvMap(List resourceIds) { + return microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map", resourceIds, AutomationsRunInfoDTO.class); } public List run(BatchRunDefinitionRequest request) { @@ -217,7 +193,4 @@ public class PlanTestPlanApiCaseService extends ApiTestService { return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/ext/" + planId, ApiDefinitionExecResultWithBLOBs.class); } - public List selectExtForPlanScenarioReport(String planId) { - return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/scenario/ext/" + planId, ApiScenarioReportWithBLOBs.class); - } } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java index 864d06f37d..92e8848ab2 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/api/PlanTestPlanScenarioCaseService.java @@ -10,11 +10,11 @@ import io.metersphere.plan.dto.*; import io.metersphere.plan.request.api.ApiPlanReportRequest; import io.metersphere.plan.request.api.ApiScenarioRequest; import io.metersphere.plan.service.TestPlanService; +import io.metersphere.plan.utils.TestPlanReportUtil; import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.utils.DiscoveryUtil; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; import org.jetbrains.annotations.NotNull; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -40,30 +40,10 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService { calculatePlanReport(report, planReportCaseDTOS); //记录接口用例的运行环境信息 List idList = planReportCaseDTOS.stream().map(PlanReportCaseDTO::getId).collect(Collectors.toList()); - try { - if (MapUtils.isEmpty(report.getProjectEnvMap())) { - report.setProjectEnvMap(getPlanProjectEnvMap(idList)); - } else { - Map> projectEnvMap = getPlanProjectEnvMap(idList); - if (MapUtils.isNotEmpty(projectEnvMap)) { - for (Map.Entry> entry : projectEnvMap.entrySet()) { - String project = entry.getKey(); - List envList = entry.getValue(); - if (report.getProjectEnvMap().containsKey(project)) { - for (String env : envList) { - if (!report.getProjectEnvMap().get(project).contains(env)) { - report.getProjectEnvMap().get(project).add(env); - } - } - } else { - report.getProjectEnvMap().put(project, envList); - } - - } - } - } - } catch (Exception e) { - LogUtil.error(e); + AutomationsRunInfoDTO automationsRunInfoDTO = getPlanProjectEnvMap(idList); + if (automationsRunInfoDTO != null) { + report.setProjectEnvMap(TestPlanReportUtil.mergeProjectEnvMap(report.getProjectEnvMap(), automationsRunInfoDTO.getProjectEnvMap())); + report.setResourcePools(TestPlanReportUtil.mergeResourcePools(report.getResourcePools(), automationsRunInfoDTO.getResourcePools())); } } } @@ -138,8 +118,8 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService { return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/status/" + planId, PlanReportCaseDTO.class); } - public Map> getPlanProjectEnvMap(List resourceIds) { - return (Map>) microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map", resourceIds); + public AutomationsRunInfoDTO getPlanProjectEnvMap(List resourceIds) { + return microService.postForData(serviceName, BASE_UEL + "/get/plan/env/map", resourceIds, AutomationsRunInfoDTO.class); } public List getExecResultByPlanId(String planId) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java index 42b08fcad9..99b0e0e44f 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/remote/performance/PlanTestPlanLoadCaseService.java @@ -13,6 +13,7 @@ import io.metersphere.plan.request.api.ApiPlanReportRequest; import io.metersphere.plan.request.performance.LoadCaseRequest; import io.metersphere.plan.request.performance.LoadPlanReportDTO; import io.metersphere.plan.service.TestPlanService; +import io.metersphere.plan.utils.TestPlanReportUtil; import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.utils.DiscoveryUtil; import jakarta.annotation.Resource; @@ -40,6 +41,8 @@ public class PlanTestPlanLoadCaseService extends LoadTestService { if (DiscoveryUtil.hasService(MicroServiceName.PERFORMANCE_TEST)) { List planReportCaseDTOS = selectStatusForPlanReport(planId); calculatePlanReport(report, planReportCaseDTOS); + List resourcePools = selectResourcePoolsByPlanReport(planId); + report.setResourcePools(TestPlanReportUtil.mergeResourcePools(report.getResourcePools(), resourcePools)); } } @@ -118,6 +121,11 @@ public class PlanTestPlanLoadCaseService extends LoadTestService { return microService.getForDataArray(serviceName, BASE_UEL + "/get/report/status/" + planId, PlanReportCaseDTO.class); } + public List selectResourcePoolsByPlanReport(String planId) { + return (List) microService.getForData(serviceName, BASE_UEL + "/resource/pool/" + planId); + } + + public Boolean hasFailCase(String planId, List performanceIds) { return (Boolean) microService.postForData(serviceName, BASE_UEL + "/has/fail/" + planId, performanceIds); } @@ -142,4 +150,7 @@ public class PlanTestPlanLoadCaseService extends LoadTestService { return (String) microService.getForData(serviceName, BASE_UEL + "/pool/" + loadReportId); } + public List selectResourcePoolsByPlan(String planId) { + return (List) microService.getForData(serviceName, BASE_UEL + "/resource/pool/case/" + planId); + } } 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 7431d5f83d..d0a001838e 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 @@ -135,4 +135,17 @@ public class TestPlanReportUtil { } return null; } + + public static List mergeResourcePools(List resourcePools, List originResourcePools) { + if (resourcePools == null) { + resourcePools = new ArrayList<>(); + } + if (originResourcePools == null) { + return resourcePools; + } + List returnList = new ArrayList<>(); + returnList.addAll(resourcePools); + returnList.addAll(originResourcePools); + return returnList.stream().distinct().collect(Collectors.toList()); + } }