diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 966cebd49a..c997fdaa02 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -248,20 +248,27 @@ public class ApiScenarioReportService { List scenarioResultList = result.getScenarios(); List testPlanReportIdList = new ArrayList<>(); - StringBuilder scenarioIds = new StringBuilder(); +// StringBuilder scenarioIds = new StringBuilder(); StringBuilder scenarioNames = new StringBuilder(); String projectId = null; String userId = null; - TestResult fullResult = createTestResult(result); + List reportIds = new ArrayList<>(); + List scenarioIdList = new ArrayList<>(); for (ScenarioResult scenarioResult : scenarioResultList) { + // 存储场景报告 long startTime = System.currentTimeMillis(); if (CollectionUtils.isNotEmpty(scenarioResult.getRequestResults())) { startTime = scenarioResult.getRequestResults().get(0).getStartTime(); } + ApiScenarioReport report = editReport(scenarioResult, startTime); + TestResult newResult = createTestResult(result.getTestId(), scenarioResult); + newResult.setConsole(result.getConsole()); + scenarioResult.setName(report.getScenarioName()); + newResult.addScenario(scenarioResult); /** * 测试计划的定时任务场景执行时,主键是提前生成的【测试报告ID】。也就是TestResult.id是【测试报告ID】。 * report.getScenarioId中存放的是 TestPlanApiScenario.id:TestPlanReport.id 由于参数限制,只得将两个ID拼接起来 @@ -292,11 +299,7 @@ public class ApiScenarioReportService { testPlanApiScenario.setPassRate(passRate); // 报告详情内容 ApiScenarioReportDetail detail = new ApiScenarioReportDetail(); - TestResult newResult = createTestResult(result.getTestId(), scenarioResult); - List scenarioResults = new ArrayList(); - scenarioResult.setName(report.getScenarioName()); - scenarioResults.add(scenarioResult); - newResult.setScenarios(scenarioResults); + detail.setContent(JSON.toJSONString(newResult).getBytes(StandardCharsets.UTF_8)); detail.setReportId(report.getId()); detail.setProjectId(report.getProjectId()); @@ -305,11 +308,10 @@ public class ApiScenarioReportService { testPlanApiScenario.setReportId(report.getId()); testPlanApiScenario.setUpdateTime(System.currentTimeMillis()); testPlanApiScenarioMapper.updateByPrimaryKeySelective(testPlanApiScenario); - - fullResult.addScenario(scenarioResult); projectId = report.getProjectId(); userId = report.getUserId(); - scenarioIds.append(scenarioResult.getName()).append(","); +// scenarioIds.append(scenarioResult.getName()).append(","); + scenarioIdList.add(testPlanApiScenario.getApiScenarioId()); scenarioNames.append(report.getName()).append(","); lastReport = report; @@ -319,7 +321,7 @@ public class ApiScenarioReportService { // margeReport(result, scenarioIds, scenarioNames, runMode, projectId, userId, reportIds); TestPlanReportService testPlanReportService = CommonBeanFactory.getBean(TestPlanReportService.class); - testPlanReportService.updateReport(testPlanReportIdList, runMode, lastReport.getTriggerMode()); + testPlanReportService.updateReport(testPlanReportIdList, runMode, lastReport.getTriggerMode(),scenarioIdList); return lastReport; } diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java index 3a3c8b5f53..c4b838f6ff 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanReportController.java @@ -71,7 +71,7 @@ public class TestPlanReportController { String reportId = UUID.randomUUID().toString(); TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(reportId,planId,userId,ReportTriggerMode.API.name()); TestPlanReport report = testPlanReportService.genTestPlanReport(saveRequest); - testPlanReportService.countReportByTestPlanReportId(report.getId(),null, ReportTriggerMode.API.name()); + testPlanReportService.countReportByTestPlanReportId(report.getId(),null, ReportTriggerMode.API.name(),null); } @GetMapping("/saveTestPlanReport/{planId}/{triggerMode}") @@ -80,7 +80,7 @@ public class TestPlanReportController { String reportId = UUID.randomUUID().toString(); TestPlanReportSaveRequest saveRequest = new TestPlanReportSaveRequest(reportId,planId,userId,triggerMode); TestPlanReport report = testPlanReportService.genTestPlanReport(saveRequest); - testPlanReportService.countReportByTestPlanReportId(report.getId(),null, triggerMode); + testPlanReportService.countReportByTestPlanReportId(report.getId(),null, triggerMode,null); return "success"; } } diff --git a/backend/src/main/java/io/metersphere/track/dto/TestCaseReportAdvanceStatusResultDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestCaseReportAdvanceStatusResultDTO.java index 3b79964746..21b0087f28 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestCaseReportAdvanceStatusResultDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestCaseReportAdvanceStatusResultDTO.java @@ -12,5 +12,6 @@ public class TestCaseReportAdvanceStatusResultDTO { private List apiResult; private List scenarioResult; private List loadResult; + private List executedScenarioIds; } 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 153ff47575..d8ddb74a1b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -79,14 +79,14 @@ public class TestPlanReportService { } /** - * @param reportId 报告ID(外部传入) - * @param planId 测试计划ID - * @param userId 用户ID - * @param triggerMode 执行方式 - * @param countResources 是否统计资源-false的话, 下面三个不同资源是否运行则由参数决定。 true的话则由统计后的结果决定 - * @param apiCaseIsExecuting 接口案例是否执行中 - * @param scenarioIsExecuting 场景案例是否执行中 - * @param performanceIsExecuting 性能案例是否执行中 + * saveRequest.reportId 报告ID(外部传入) + * saveRequest.planId 测试计划ID + * saveRequest.userId 用户ID + * saveRequest.triggerMode 执行方式 + * saveRequest.countResources 是否统计资源-false的话, 下面三个不同资源是否运行则由参数决定。 true的话则由统计后的结果决定 + * saveRequest.apiCaseIsExecuting 接口案例是否执行中 + * saveRequest.scenarioIsExecuting 场景案例是否执行中 + * saveRequest.performanceIsExecuting 性能案例是否执行中 * @return */ public TestPlanReport genTestPlanReport(TestPlanReportSaveRequest saveRequest) { @@ -215,7 +215,13 @@ public class TestPlanReportService { public synchronized void updateReport(List testPlanReportIdList, String runMode, String triggerMode) { for (String planReportId : testPlanReportIdList) { - this.countReportByTestPlanReportId(planReportId, runMode, triggerMode); + this.countReportByTestPlanReportId(planReportId, runMode, triggerMode,null); + } + } + + public synchronized void updateReport(List testPlanReportIdList, String runMode, String triggerMode,List scenarioIdList) { + for (String planReportId : testPlanReportIdList) { + this.countReportByTestPlanReportId(planReportId, runMode, triggerMode,scenarioIdList); } } @@ -233,7 +239,7 @@ public class TestPlanReportService { * @param resourceRunMode 资源的运行模式,triggerMode非Scedule可以为null * @param triggerMode 触发方式 ReportTriggerMode.enum */ - public void countReportByTestPlanReportId(String planReportId, String resourceRunMode, String triggerMode) { + public void countReportByTestPlanReportId(String planReportId, String resourceRunMode, String triggerMode,List scenarioIdList) { TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(planReportId); QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest(); @@ -316,6 +322,39 @@ public class TestPlanReportService { TestPlanReportDataWithBLOBs testPlanReportData = null; if (!testPlanReportDataList.isEmpty()) { testPlanReportData = testPlanReportDataList.get(0); + + if (CollectionUtils.isNotEmpty(scenarioIdList) + &&StringUtils.equalsAny(triggerMode, ReportTriggerMode.SCHEDULE.name(), ReportTriggerMode.API.name()) + && StringUtils.equalsAny(resourceRunMode, ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { + try{ + List scenarioListArr = JSONArray.parseArray(testPlanReportData.getScenarioInfo(),String.class); + TestCaseReportAdvanceStatusResultDTO savedDTO = JSONObject.parseObject(testPlanReportData.getExecuteResult(),TestCaseReportAdvanceStatusResultDTO.class); + List executeScenarioList = new ArrayList<>(); + if(savedDTO != null){ + if(savedDTO.getExecutedScenarioIds() != null){ + executeScenarioList = savedDTO.getExecutedScenarioIds(); + } + } + for (String scenarioId : scenarioIdList) { + if (!executeScenarioList.contains(scenarioId)) { + executeScenarioList.add(scenarioId); + } + } + if(testCaseReportMetricDTO.getExecuteResult() == null){ + TestCaseReportAdvanceStatusResultDTO executeResultDTO = new TestCaseReportAdvanceStatusResultDTO(); + testCaseReportMetricDTO.setExecuteResult(executeResultDTO); + } + testCaseReportMetricDTO.getExecuteResult().setExecutedScenarioIds(executeScenarioList); + + if(!CollectionUtils.isEqualCollection(scenarioListArr,executeScenarioList)){ + testPlanReport.setIsScenarioExecuting(true); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + //统计执行的场景ID + testPlanReportData.setExecuteResult(JSONObject.toJSONString(testCaseReportMetricDTO.getExecuteResult())); testPlanReportData.setFailurTestCases(JSONObject.toJSONString(testCaseReportMetricDTO.getFailureTestCases())); testPlanReportData.setModuleExecuteResult(JSONArray.toJSONString(testCaseReportMetricDTO.getModuleExecuteResult())); diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue index fa702e8806..8f35ee3879 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue @@ -15,6 +15,7 @@