diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java index 17ec6c5dff..62f555d156 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/RunScenarioRequest.java @@ -46,7 +46,5 @@ public class RunScenarioRequest { //生成测试报告:当isTestPlanScheduleJob为ture时使用 private String testPlanReportId; - private String testPlanReportContentId; - private String requestOriginator; } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/SchedulePlanScenarioExecuteRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/SchedulePlanScenarioExecuteRequest.java index 44c8d72ee7..a297003d23 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/SchedulePlanScenarioExecuteRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/SchedulePlanScenarioExecuteRequest.java @@ -37,7 +37,5 @@ public class SchedulePlanScenarioExecuteRequest { private String testPlanReportId; - private String planReportContentId; - private RunModeConfigDTO config; } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java index 63ebccbf93..769f29aecc 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/BatchRunDefinitionRequest.java @@ -22,6 +22,4 @@ public class BatchRunDefinitionRequest { //测试计划报告ID。 测试计划执行时使用 private String planReportId; - private String planReportContentId; - } diff --git a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java index 496ee3987d..092260850a 100644 --- a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java @@ -89,12 +89,10 @@ public class ApiCaseExecuteService { List responseDTOS = new LinkedList<>(); Map executeQueue = new HashMap<>(); - Map testPlanCaseIdAndReportIdMap = new HashMap<>(); String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name(); planApiCases.forEach(testPlanApiCase -> { ApiDefinitionExecResult report = ApiDefinitionExecResultUtil.addResult(request, testPlanApiCase, status, batchMapper); executeQueue.put(testPlanApiCase.getId(), report); - testPlanCaseIdAndReportIdMap.put(testPlanApiCase.getId(), report.getId()); responseDTOS.add(new MsExecResponseDTO(testPlanApiCase.getId(), report.getId(), request.getTriggerMode())); }); sqlSession.flushStatements(); @@ -108,11 +106,6 @@ public class ApiCaseExecuteService { String runMode = StringUtils.equals(request.getTriggerMode(), TriggerMode.MANUAL.name()) ? ApiRunMode.API_PLAN.name() : ApiRunMode.SCHEDULE_API_PLAN.name(); DBTestQueue deQueue = apiExecutionQueueService.add(executeQueue, poolId, ApiRunMode.API_PLAN.name(), request.getPlanReportId(), reportType, runMode, request.getConfig().getEnvMap()); - //如果是测试计划生成报告的执行,则更新执行信息、执行线程信息。 - if (StringUtils.isNotEmpty(request.getPlanReportContentId())) { - TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class); - testPlanReportService.updateTestPlanReportContentReportIds(request.getPlanReportContentId(),testPlanCaseIdAndReportIdMap,null,null); - } // 开始选择执行模式 if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) { LoggerUtil.debug("开始串行执行"); diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 2641464c3a..57ca19229f 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -224,7 +224,6 @@ public class ApiScenarioExecuteService { } String projectId = request.getProjectId(); Map scenarioMap = apiScenarios.stream().collect(Collectors.toMap(ApiScenarioWithBLOBs::getId, Function.identity(), (t1, t2) -> t1)); - Map scenarioReportIdMap = new HashMap<>(); for (Map.Entry entry : planScenarioIdMap.entrySet()) { String testPlanScenarioId = entry.getKey(); String scenarioId = entry.getValue(); @@ -256,9 +255,6 @@ public class ApiScenarioExecuteService { report = apiScenarioReportService.init(reportId, testPlanScenarioId, scenario.getName(), request.getTriggerMode(), request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(), scenario.getId()); - if (report != null && StringUtils.isNotEmpty(request.getTestPlanReportContentId())) { - scenarioReportIdMap.put(testPlanScenarioId, report.getId()); - } scenarioIds.add(scenario.getId()); if (request.getConfig() != null && StringUtils.isNotBlank(request.getConfig().getResourcePoolId())) { RunModeDataDTO runModeDataDTO = new RunModeDataDTO(); @@ -294,10 +290,6 @@ public class ApiScenarioExecuteService { // 重置报告ID reportId = UUID.randomUUID().toString(); } - if(StringUtils.isNotEmpty(request.getTestPlanReportContentId())){ - TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class); - testPlanReportService.updateTestPlanReportContentReportIds(request.getTestPlanReportContentId(),null,scenarioReportIdMap,null); - } } /** diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java index 30dae2367d..f368c76348 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanScheduleReportInfoDTO.java @@ -16,7 +16,6 @@ import java.util.Map; @Setter public class TestPlanScheduleReportInfoDTO { private TestPlanReport testPlanReport; - private TestPlanReportContent testPlanReportContent; private Map planScenarioIdMap = new LinkedHashMap<>(); private Map apiTestCaseDataMap = new LinkedHashMap<>(); private Map performanceIdMap = new LinkedHashMap<>(); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index 2766d3abc8..4e98ee2031 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -184,16 +184,6 @@ public class TestPlanReportService { testPlanReport.setEndTime(System.currentTimeMillis()); testPlanReport.setIsNew(true); - TestPlanReportContentWithBLOBs testPlanReportContent = new TestPlanReportContentWithBLOBs(); - testPlanReportContent.setId(UUID.randomUUID().toString()); - testPlanReportContent.setTestPlanReportId(testPlanReportID); - if (testPlanReportContent.getStartTime() == null) { - testPlanReportContent.setStartTime(System.currentTimeMillis()); - } - if (testPlanReportContent.getEndTime() == null) { - testPlanReportContent.setEndTime(System.currentTimeMillis()); - } - if (saveRequest.isCountResources()) { List testPlanApiCaseList = extTestPlanApiCaseMapper.selectLegalDataByTestPlanId(saveRequest.getPlanId()); List apiCaseIdList = testPlanApiCaseList.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList()); @@ -222,7 +212,6 @@ public class TestPlanReportService { } testPlanReportMapper.insert(testPlanReport); - testPlanReportContentMapper.insert(testPlanReportContent); //更新TestPlan状态,改为进行中 testPlan.setStatus(TestPlanStatus.Underway.name()); @@ -230,7 +219,6 @@ public class TestPlanReportService { TestPlanScheduleReportInfoDTO returnDTO = new TestPlanScheduleReportInfoDTO(); returnDTO.setTestPlanReport(testPlanReport); - returnDTO.setTestPlanReportContent(testPlanReportContent); return returnDTO; } @@ -337,6 +325,16 @@ public class TestPlanReportService { testPlanReport.setUpdateTime(endTime); } + //更新content表对结束日期 + TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); + contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); + + TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs(); + content.setStartTime(testPlanReport.getStartTime()); + content.setEndTime(endTime); + testPlanReportContentMapper.updateByExampleSelective(content,contentExample); + + //更新测试计划并发送通知 testPlanReport.setIsApiCaseExecuting(false); testPlanReport.setIsScenarioExecuting(false); @@ -732,10 +730,14 @@ public class TestPlanReportService { return testPlanReportContent; } - public synchronized void updateTestPlanReportContentReportIds(String testPlanReportContentId, Map apiCaseReportMap, Map scenarioReportIdMap, Map loadCaseReportIdMap) { - if (StringUtils.isNotEmpty(testPlanReportContentId)) { + public void createTestPlanReportContentReportIds(String testPlanReportID, Map apiCaseReportMap, Map scenarioReportIdMap, Map loadCaseReportIdMap) { + TestPlanReportContentExample example = new TestPlanReportContentExample(); + example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportID); + long dataCount = testPlanReportContentMapper.countByExample(example); + if(dataCount == 0){ TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs(); - content.setId(testPlanReportContentId); + content.setId(UUID.randomUUID().toString()); + content.setTestPlanReportId(testPlanReportID); if (MapUtils.isNotEmpty(apiCaseReportMap)) { content.setPlanApiCaseReportStruct(JSONObject.toJSONString(apiCaseReportMap)); @@ -746,10 +748,7 @@ public class TestPlanReportService { if (MapUtils.isNotEmpty(loadCaseReportIdMap)) { content.setPlanLoadCaseReportStruct(JSONObject.toJSONString(loadCaseReportIdMap)); } - - if (StringUtils.isNotEmpty(content.getPlanApiCaseReportStruct()) || StringUtils.isNotEmpty(content.getPlanScenarioReportStruct()) || StringUtils.isNotEmpty(content.getPlanLoadCaseReportStruct())) { - testPlanReportContentMapper.updateByPrimaryKeySelective(content); - } + testPlanReportContentMapper.insert(content); } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 2d5b9c0fbf..451afd4ae5 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -960,7 +960,6 @@ public class TestPlanService { request.setConfig(planScenarioExecuteRequest.getConfig()); request.setTestPlanScheduleJob(true); request.setTestPlanReportId(planScenarioExecuteRequest.getTestPlanReportId()); - request.setTestPlanReportContentId(planScenarioExecuteRequest.getPlanReportContentId()); request.setId(UUID.randomUUID().toString()); request.setProjectId(planScenarioExecuteRequest.getProjectId()); request.setRequestOriginator("TEST_PLAN"); @@ -1070,26 +1069,27 @@ public class TestPlanService { //执行接口案例任务 - this.executeApiTestCase(triggerMode, planReportId, reportInfoDTO.getTestPlanReportContent().getId(), userId, new ArrayList<>(reportInfoDTO.getApiTestCaseDataMap().keySet()), runModeConfig); + Map apiCaseReportMap = this.executeApiTestCase(triggerMode, planReportId,userId, new ArrayList<>(reportInfoDTO.getApiTestCaseDataMap().keySet()), runModeConfig); //执行场景执行任务 - this.executeScenarioCase(planReportId, reportInfoDTO.getTestPlanReportContent().getId(), testPlanID, projectID, runModeConfig, triggerMode, userId, reportInfoDTO.getPlanScenarioIdMap()); + Map scenarioReportMap = this.executeScenarioCase(planReportId, testPlanID, projectID, runModeConfig, triggerMode, userId, reportInfoDTO.getPlanScenarioIdMap()); //执行性能测试任务 - this.executeLoadCaseTask(runModeConfig, triggerMode, reportInfoDTO.getPerformanceIdMap(), reportInfoDTO.getTestPlanReportContent().getId()); + Map loadCaseReportMap = this.executeLoadCaseTask(runModeConfig, triggerMode, reportInfoDTO.getPerformanceIdMap()); + testPlanReportService.createTestPlanReportContentReportIds(planReportId, apiCaseReportMap,scenarioReportMap,loadCaseReportMap); return planReportId; } - private void executeApiTestCase(String triggerMode, String planReportId, String reportContentId, String userId, List planCaseIds, RunModeConfigDTO runModeConfig) { + private Map executeApiTestCase(String triggerMode, String planReportId, String userId, List planCaseIds, RunModeConfigDTO runModeConfig) { BatchRunDefinitionRequest request = new BatchRunDefinitionRequest(); request.setTriggerMode(triggerMode); request.setPlanIds(planCaseIds); request.setPlanReportId(planReportId); request.setConfig(runModeConfig); request.setUserId(userId); - request.setPlanReportContentId(reportContentId); - testPlanApiCaseService.run(request); + List dtoList = testPlanApiCaseService.run(request); + return this.parseMsExecREsponseDTOToTestIdReportMap(dtoList); } - private void executeScenarioCase(String planReportId, String reportContentId, String testPlanID, String projectID, RunModeConfigDTO runModeConfig, String triggerMode, String userId, Map planScenarioIdMap) { + private Map executeScenarioCase(String planReportId, String testPlanID, String projectID, RunModeConfigDTO runModeConfig, String triggerMode, String userId, Map planScenarioIdMap) { if (!planScenarioIdMap.isEmpty()) { SchedulePlanScenarioExecuteRequest scenarioRequest = new SchedulePlanScenarioExecuteRequest(); String senarionReportID = UUID.randomUUID().toString(); @@ -1113,15 +1113,28 @@ public class TestPlanService { scenarioRequest.setReportUserID(userId); scenarioRequest.setTestPlanID(testPlanID); scenarioRequest.setTestPlanReportId(planReportId); - scenarioRequest.setPlanReportContentId(reportContentId); scenarioRequest.setConfig(runModeConfig); - this.scenarioRunModeConfig(scenarioRequest); + List dtoList = this.scenarioRunModeConfig(scenarioRequest); + return this.parseMsExecREsponseDTOToTestIdReportMap(dtoList); + }else { + return new HashMap<>(); } } - private void executeLoadCaseTask(RunModeConfigDTO runModeConfig, String triggerMode, Map performanceIdMap, String reportContentId) { - Map loadCaseReportMap = new HashMap<>(); + private Map parseMsExecREsponseDTOToTestIdReportMap(List dtoList) { + Map returnMap = new HashMap<>(); + if(CollectionUtils.isNotEmpty(dtoList)){ + dtoList.forEach( item -> { + if(StringUtils.isNotEmpty(item.getTestId()) && StringUtils.isNotEmpty(item.getReportId())){ + returnMap.put(item.getTestId(),item.getReportId()); + } + }); + } + return returnMap; + } + private Map executeLoadCaseTask(RunModeConfigDTO runModeConfig, String triggerMode, Map performanceIdMap) { + Map loadCaseReportMap = new HashMap<>(); for (Map.Entry entry : performanceIdMap.entrySet()) { String id = entry.getKey(); String caseID = entry.getValue(); @@ -1160,7 +1173,7 @@ public class TestPlanService { } } - testPlanReportService.updateTestPlanReportContentReportIds(reportContentId, null, null, loadCaseReportMap); + return loadCaseReportMap; } public String getLogDetails(String id) {