diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml index 3480dfd2c7..790179635b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanReportMapper.xml @@ -92,7 +92,7 @@ SELECT tpr.id AS id, tpr.`name` AS `name`, tp.`name` AS testPlanName, IF(u.name is null,tpr.creator,u.name)AS creator, tpr.is_new, tpr.test_plan_id, tpr.create_time AS createTime,tpr.trigger_mode AS triggerMode,tpr.status AS status, - tpr.end_time AS endTime, (tpr.end_time - tpr.create_time) AS runTime, tprc.pass_rate AS passRate + tprc.end_time AS endTime, (tprc.end_time - tprc.start_time) AS runTime, tprc.pass_rate AS passRate FROM test_plan tp INNER JOIN test_plan_report tpr on tp.id = tpr.test_plan_id LEFT JOIN user u on tpr.creator = u.id 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 3dd50e1a24..d1df9d7f92 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -81,6 +81,14 @@ public class TestPlanReportService { private UserService userService; @Resource private ProjectService projectService; + @Resource + ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; + @Resource + private ExtLoadTestReportMapper extLoadTestReportMapper; + @Resource + private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; + @Resource + private ExtApiScenarioReportMapper extApiScenarioReportMapper; public List list(QueryTestPlanReportRequest request) { List list = new ArrayList<>(); @@ -109,9 +117,88 @@ public class TestPlanReportService { } } list = extTestPlanReportMapper.list(request); + + // 设置测试计划报告成功率 + setTestPlanReportPassRate(list); return list; } + public void setTestPlanReportPassRate(List list){ + for(TestPlanReportDTO testPlanReportDTO : list){ + TestPlanReportContentExample example = new TestPlanReportContentExample(); + example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportDTO.getId()); + List testPlanReportContents = testPlanReportContentMapper.selectByExampleWithBLOBs(example); + + if (CollectionUtils.isNotEmpty(testPlanReportContents)) { + TestPlanReportContentWithBLOBs testPlanReportContent = testPlanReportContents.get(0); + if (testPlanReportContent != null) { + if (this.isDynamicallyGenerateReports(testPlanReportContent)) { + String planId = testPlanReportDTO.getTestPlanId(); + TestPlanSimpleReportDTO report = new TestPlanSimpleReportDTO(); + Map statusResultMap = new HashMap<>(); + + TestPlanExecuteReportDTO testPlanExecuteReportDTO = genTestPlanExecuteReportDTOByTestPlanReportContent(testPlanReportContent); + // 功能用例 + TestPlanUtils.buildStatusResultMap(extTestPlanTestCaseMapper.selectForPlanReport(planId), statusResultMap, report, TestPlanTestCaseStatus.Pass.name()); + + if (testPlanExecuteReportDTO == null) { + // 接口用例 + List planReportApiCaseDTOS = extTestPlanApiCaseMapper.selectForPlanReport(planId); + TestPlanUtils.buildStatusResultMap(planReportApiCaseDTOS, statusResultMap, report, "success"); + // 场景用例 + List planReportScenarioCaseDTOS = extTestPlanScenarioCaseMapper.selectForPlanReport(planId); + TestPlanUtils.buildStatusResultMap(planReportScenarioCaseDTOS, statusResultMap, report, "Success"); + // 性能用例 + List planReportLoadCaseDTOS = extTestPlanLoadCaseMapper.selectForPlanReport(planId); + TestPlanUtils.buildStatusResultMap(planReportLoadCaseDTOS, statusResultMap, report, TestPlanLoadCaseStatus.success.name()); + }else{ + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap())) { + // 接口用例 + List apiReportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanApiCaseIdAndReportIdMap().values()); + List planReportCaseDTOS = extApiDefinitionExecResultMapper.selectForPlanReport(apiReportIds); + TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, "success"); + } + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap())) { + // 场景用例 + List reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanScenarioIdAndReportIdMap().values()); + List planReportCaseDTOS = extApiScenarioReportMapper.selectForPlanReport(reportIds); + TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, "Success"); + } + if (MapUtils.isNotEmpty(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap())) { + // 性能用例 + List reportIds = new ArrayList<>(testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap().values()); + List planReportCaseDTOS = extLoadTestReportMapper.selectForPlanReport(reportIds); + // 性能测试的报告状态跟用例的执行状态不一样 + planReportCaseDTOS.forEach(item -> { + if (item.getStatus().equals(PerformanceTestStatus.Completed.name())) { + item.setStatus(TestPlanLoadCaseStatus.success.name()); + } else if (item.getStatus().equals(PerformanceTestStatus.Error.name())) { + item.setStatus(TestPlanLoadCaseStatus.error.name()); + } else { + item.setStatus(TestPlanLoadCaseStatus.run.name()); + } + }); + TestPlanUtils.buildStatusResultMap(planReportCaseDTOS, statusResultMap, report, TestPlanLoadCaseStatus.success.name()); + } + } + // 设置成功率 + if (report.getCaseCount() != null && report.getExecuteCount() != 0) { + report.setExecuteRate(report.getExecuteCount() * 0.1 * 10 / report.getCaseCount()); + } else { + report.setExecuteRate(0.0); + } + if (report.getPassCount() != 0 && report.getCaseCount() != null) { + report.setPassRate(report.getPassCount() * 0.1 * 10 / report.getExecuteCount()); + } else { + report.setPassRate(0.0); + } + testPlanReportDTO.setPassRate(report.getPassRate()); + } + } + } + } + } + public TestPlanScheduleReportInfoDTO genTestPlanReportBySchedule(String projectID, String planId, String userId, String triggerMode) { Map planScenarioIdMap = new LinkedHashMap<>(); Map planTestCaseIdMap = new LinkedHashMap<>(); diff --git a/frontend/src/business/components/track/report/components/TestPlanReportList.vue b/frontend/src/business/components/track/report/components/TestPlanReportList.vue index 684c85b685..08eacc9ab9 100644 --- a/frontend/src/business/components/track/report/components/TestPlanReportList.vue +++ b/frontend/src/business/components/track/report/components/TestPlanReportList.vue @@ -101,7 +101,6 @@ prop="passRate" :field="item" :fields-width="fieldsWidth" - sortable="custom" :label="$t('test_track.report.list.pass_rate')">