diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java index e4e100b933..6b57435ea8 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java @@ -213,6 +213,11 @@ public class TestPlanController { testPlanService.exportPlanReport(planId, response); } + @GetMapping("/report/db/export/{reportId}") + public void exportHtmlDbReport(@PathVariable String reportId, HttpServletResponse response) throws UnsupportedEncodingException { + testPlanService.exportPlanDbReport(reportId, response); + } + @GetMapping("/report/{planId}") public TestPlanSimpleReportDTO getReport(@PathVariable String planId) { return testPlanService.getReport(planId); 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 8834890313..2034105527 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -927,6 +927,9 @@ public class TestPlanReportService { TestPlanReportDataExample example = new TestPlanReportDataExample(); example.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); testPlanReportDataMapper.deleteByExample(example); + TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); + contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); + testPlanReportContentMapper.deleteByExample(contentExample); // TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); // resourceExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); // testPlanReportResourceService.deleteByExample(resourceExample); @@ -954,6 +957,10 @@ public class TestPlanReportService { example.createCriteria().andTestPlanReportIdIn(deleteReportIds); testPlanReportDataMapper.deleteByExample(example); + TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); + contentExample.createCriteria().andTestPlanReportIdIn(deleteReportIds); + testPlanReportContentMapper.deleteByExample(contentExample); + // TestPlanReportResourceExample resourceExample = new TestPlanReportResourceExample(); // resourceExample.createCriteria().andTestPlanReportIdIn(deleteReportIds); // testPlanReportResourceService.deleteByExample(resourceExample); @@ -1096,6 +1103,9 @@ public class TestPlanReportService { if (StringUtils.isNotBlank(testPlanReportContent.getLoadFailureCases())) { testPlanReportDTO.setLoadFailureCases(JSONObject.parseArray(testPlanReportContent.getLoadFailureCases(), TestPlanLoadCaseDTO.class)); } + testPlanReportDTO.setId(reportId); + TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportContent.getTestPlanReportId()); + testPlanReportDTO.setName(testPlanReport.getName()); return testPlanReportDTO; } } 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 0fc6b9e9ff..d7495bea4d 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -1397,19 +1397,12 @@ public class TestPlanService { apiAllCases = testPlanApiCaseService.getAllCases(planId); report.setApiAllCases(apiAllCases); if (saveResponse) { - apiAllCases.forEach(item -> { - APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId()); - if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) { - item.setResponse(dbResult.getContent()); - } - }); + buildApiResponse(apiAllCases); } //场景 scenarioAllCases = testPlanScenarioCaseService.getAllCases(planId); if (saveResponse) { - scenarioAllCases.forEach((item) -> { - item.setResponse(apiScenarioReportService.get(item.getReportId())); - }); + buildScenarioResponse(scenarioAllCases); } report.setScenarioAllCases(scenarioAllCases); } @@ -1425,12 +1418,7 @@ public class TestPlanService { apiFailureCases = testPlanApiCaseService.getFailureCases(planId); } if (saveResponse) { - apiFailureCases.forEach(item -> { - APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId()); - if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) { - item.setResponse(dbResult.getContent()); - } - }); + buildApiResponse(apiFailureCases); } report.setApiFailureCases(apiFailureCases); @@ -1445,43 +1433,66 @@ public class TestPlanService { scenarioFailureCases = testPlanScenarioCaseService.getFailureCases(planId); } if (saveResponse) { - scenarioFailureCases.forEach((item) -> { - item.setResponse(apiScenarioReportService.get(item.getReportId())); - }); + buildScenarioResponse(scenarioFailureCases); } report.setScenarioFailureCases(scenarioFailureCases); } } } + public void buildApiResponse(List cases) { + if (!CollectionUtils.isEmpty(cases)) { + cases.forEach(item -> { + APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId()); + if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) { + item.setResponse(dbResult.getContent()); + } + }); + } + } + + public void buildScenarioResponse(List cases) { + if (!CollectionUtils.isEmpty(cases)) { + cases.forEach((item) -> { + item.setResponse(apiScenarioReportService.get(item.getReportId())); + }); + } + } + + public void buildLoadResponse(List cases) { + if (!CollectionUtils.isEmpty(cases)) { + cases.forEach(item -> { + LoadCaseReportRequest request = new LoadCaseReportRequest(); + String reportId = item.getLoadReportId(); + if (StringUtils.isNotBlank(reportId)) { + request.setTestPlanLoadCaseId(item.getId()); + request.setReportId(reportId); + Boolean existReport = testPlanLoadCaseService.isExistReport(request); + if (existReport) { + LoadTestReportWithBLOBs loadTestReport = performanceReportService.getLoadTestReport(reportId); + ReportTimeInfo reportTimeInfo = performanceReportService.getReportTimeInfo(reportId); + TestPlanLoadCaseDTO.ReportDTO reportDTO = new TestPlanLoadCaseDTO.ReportDTO(); + if (loadTestReport != null) { + BeanUtils.copyBean(reportDTO, loadTestReport); + } + if (reportTimeInfo != null) { + BeanUtils.copyBean(reportDTO, reportTimeInfo); + } + item.setResponse(reportDTO); + // todo 报告详情 + } + } + }); + } + } + public void buildLoadReport(TestPlanSimpleReportDTO report, JSONObject config, String planId, boolean saveResponse) { if (checkReportConfig(config, "load")) { List allCases = null; if (checkReportConfig(config, "load", "all")) { allCases = testPlanLoadCaseService.getAllCases(planId); if (saveResponse) { - allCases.forEach(item -> { - LoadCaseReportRequest request = new LoadCaseReportRequest(); - String reportId = item.getLoadReportId(); - if (StringUtils.isNotBlank(reportId)) { - request.setTestPlanLoadCaseId(item.getId()); - request.setReportId(reportId); - Boolean existReport = testPlanLoadCaseService.isExistReport(request); - if (existReport) { - LoadTestReportWithBLOBs loadTestReport = performanceReportService.getLoadTestReport(reportId); - ReportTimeInfo reportTimeInfo = performanceReportService.getReportTimeInfo(reportId); - TestPlanLoadCaseDTO.ReportDTO reportDTO = new TestPlanLoadCaseDTO.ReportDTO(); - if (loadTestReport != null) { - BeanUtils.copyBean(reportDTO, loadTestReport); - } - if (reportTimeInfo != null) { - BeanUtils.copyBean(reportDTO, reportTimeInfo); - } - item.setResponse(reportDTO); - // todo 报告详情 - } - } - }); + buildLoadResponse(allCases); } report.setLoadAllCases(allCases); } @@ -1659,6 +1670,16 @@ public class TestPlanService { render(buildPlanReport(planId, true), response); } + public void exportPlanDbReport(String reportId, HttpServletResponse response) throws UnsupportedEncodingException { + TestPlanSimpleReportDTO report = testPlanReportService.getReport(reportId); + buildApiResponse(report.getApiAllCases()); + buildApiResponse(report.getApiFailureCases()); + buildScenarioResponse(report.getScenarioAllCases()); + buildScenarioResponse(report.getScenarioFailureCases()); + buildLoadResponse(report.getLoadAllCases()); + render(report, response); + } + public Boolean checkReportConfig(JSONObject config, String key) { if (config == null) { return true; @@ -1709,7 +1730,7 @@ public class TestPlanService { start += 1024; } } - } catch (Exception e) { + } catch (Throwable e) { LogUtil.error(e.getMessage(), e); MSException.throwException(e.getMessage()); } diff --git a/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportButtons.vue b/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportButtons.vue index ab06a3b4e5..3999067997 100644 --- a/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportButtons.vue +++ b/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportButtons.vue @@ -9,14 +9,14 @@ {{ $t("commons.copy") }} - {{'分享'}} - + {{'保存'}} @@ -26,7 +26,7 @@ - + {{'配置'}} @@ -49,7 +49,8 @@ export default { props: { planId:String, isShare: Boolean, - report: Object + report: Object, + isDb: Boolean }, data() { return { @@ -91,6 +92,9 @@ export default { method: 'get', responseType: 'blob' }; + if (this.isDb) { + config.url = '/test/plan/report/db/export/' + this.report.id; + } if (this.isShare) { config.url = '/share' + config.url; } diff --git a/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportContent.vue b/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportContent.vue index 62a6bdf023..9daddeedaa 100644 --- a/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportContent.vue +++ b/frontend/src/business/components/track/plan/view/comonents/report/detail/TestPlanReportContent.vue @@ -2,8 +2,8 @@
- +