From 8dea30cf460691c7580143bd9f7adf9f6092ee0d Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 26 Oct 2022 18:36:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E6=8A=A5=E5=91=8A):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B9=E7=9B=AE=E6=8A=A5=E5=91=8A=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E9=93=BE=E6=8E=A5=E6=97=B6=E6=8A=A5=E5=91=8A=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复项目报告分享链接时报告内容解析失败的问题 --- .../metersphere/commons/utils/ShiroUtils.java | 2 +- .../controller/PageRedirectController.java | 12 ++++++++++++ .../controller/ReportStatShareController.java | 19 +++++-------------- .../service/ReportStatisticsService.java | 11 ++++++++--- .../reportstatistics/utils/ChromeUtil.java | 2 +- report-stat/frontend/src/api/share.js | 4 ++-- .../components/chart/ReportChart.vue | 6 ++++++ .../share/ShareEnterpriseReportTemplate.vue | 4 ++-- 8 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/PageRedirectController.java diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java index 41867b6806..c5ad6e3464 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/ShiroUtils.java @@ -59,7 +59,7 @@ public class ShiroUtils { //分享相关接口 filterChainDefinitionMap.put("/share/info/generateShareInfoWithExpired", "anon"); filterChainDefinitionMap.put("/share/list", "anon"); - filterChainDefinitionMap.put("/share/info/selectHistoryReportById", "anon"); + filterChainDefinitionMap.put("/report/stat/share/**", "anon"); filterChainDefinitionMap.put("/share/get/**", "anon"); filterChainDefinitionMap.put("/share/info", "apikey, csrf, authc"); // 需要认证 filterChainDefinitionMap.put("/document/**", "anon"); diff --git a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/PageRedirectController.java b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/PageRedirectController.java new file mode 100644 index 0000000000..f1fd574b89 --- /dev/null +++ b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/PageRedirectController.java @@ -0,0 +1,12 @@ +package io.metersphere.reportstatistics.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class PageRedirectController { + @GetMapping(value = "/chart-pic") + public String getChart() { + return "share-enterprise-report.html"; + } +} diff --git a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/ReportStatShareController.java b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/ReportStatShareController.java index 028c680ee2..876a4344ce 100644 --- a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/ReportStatShareController.java +++ b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/controller/ReportStatShareController.java @@ -3,30 +3,21 @@ package io.metersphere.reportstatistics.controller; import io.metersphere.base.domain.ReportStatisticsWithBLOBs; import io.metersphere.reportstatistics.dto.ReportStatisticsSaveRequest; import io.metersphere.reportstatistics.service.ReportStatisticsService; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -@Controller +@RestController +@RequestMapping(value = "/report/stat/share") public class ReportStatShareController { - @GetMapping(value = "/chart-pic") - public String getChart() { - return "share-enterprise-report.html"; - } -} - -@RequestMapping(value = "/share/info") -class ShareInfoController { @Resource private ReportStatisticsService reportStatisticsService; - @PostMapping("/selectHistoryReportById") + @PostMapping("/select/report/by/id") public ReportStatisticsWithBLOBs selectById(@RequestBody ReportStatisticsSaveRequest request) { return reportStatisticsService.selectById(request.getId()); } -} - +} \ No newline at end of file diff --git a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/ReportStatisticsService.java b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/ReportStatisticsService.java index 64b0c2abb2..885808dda0 100644 --- a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/ReportStatisticsService.java +++ b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/ReportStatisticsService.java @@ -84,7 +84,7 @@ public class ReportStatisticsService { boolean isReportNeedUpdate = this.isReportNeedUpdate(blob); if (isReportNeedUpdate) { TestCaseCountRequest countRequest = JSON.parseObject(blob.getSelectOption(), TestCaseCountRequest.class); - Map returnDataOption = this.reloadData(countRequest, JSON.toJSONString(dataOption.get("chartType"))); + Map returnDataOption = this.reloadData(countRequest, dataOption.get("chartType").toString()); if (returnDataOption != null) { dataOption = returnDataOption; } @@ -94,8 +94,13 @@ public class ReportStatisticsService { if (dataOption.get("tableData") != null) { String tableDataJsonStr = JSON.toJSONString(dataOption.get("tableData")); List dtos = JSON.parseArray(tableDataJsonStr, TestCaseCountTableDTO.class); - String yaxisStr = JSON.toJSONString(selectOption.get("yaxis")); - List yaxis = JSON.parseArray(yaxisStr, String.class); + List yaxis = new ArrayList<>(); + try { + yaxis = (List) selectOption.get("yaxis"); + } catch (Exception e) { + String yaxisStr = JSON.toJSONString(selectOption.get("yaxis")); + yaxis = JSON.parseArray(yaxisStr, String.class); + } TestCaseCountTableDataDTO showTable = this.countShowTable(String.valueOf(selectOption.get("xaxis")), yaxis, dtos); dataOption.put("showTable", showTable); blob.setDataOption(JSON.toJSONString(dataOption)); diff --git a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/ChromeUtil.java b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/ChromeUtil.java index d2a03fad7d..75f0bf6624 100644 --- a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/ChromeUtil.java +++ b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/ChromeUtil.java @@ -70,7 +70,7 @@ public class ChromeUtil { driver.get(url); driver.manage().window().fullscreen(); //预留echart动画的加载时间 - Thread.sleep(3 * 1000); + Thread.sleep(10 * 1000); String js = "var chartsCanvas = document.getElementById('picChart').getElementsByTagName('canvas')[0];" + "var imageUrl = null;" + "if (chartsCanvas!= null) {" + diff --git a/report-stat/frontend/src/api/share.js b/report-stat/frontend/src/api/share.js index 3178c5c6e1..7703cd861b 100644 --- a/report-stat/frontend/src/api/share.js +++ b/report-stat/frontend/src/api/share.js @@ -1,9 +1,9 @@ import {post} from "metersphere-frontend/src/plugins/request" -let basePath = '/share/info'; +let basePath = '/report/stat/share'; export function selectShareReportById(param) { - return post(basePath + '/selectHistoryReportById', param) + return post(basePath + '/select/report/by/id', param) } export function getShareId() { diff --git a/report-stat/frontend/src/business/enterprisereport/components/chart/ReportChart.vue b/report-stat/frontend/src/business/enterprisereport/components/chart/ReportChart.vue index 7ee2db4dfd..40df2d8cc0 100644 --- a/report-stat/frontend/src/business/enterprisereport/components/chart/ReportChart.vue +++ b/report-stat/frontend/src/business/enterprisereport/components/chart/ReportChart.vue @@ -203,6 +203,12 @@ export default { if (typeof (formatData.xaxis) === 'string') { formatData.xaxis = JSON.parse(formatData.xaxis); } + if (typeof (formatData.xAxis) === 'string') { + formatData.xAxis = JSON.parse(formatData.xAxis); + } + if (typeof (formatData.yAxis) === 'string') { + formatData.yAxis = JSON.parse(formatData.yAxis); + } if (typeof (formatData.series) === 'string') { formatData.series = JSON.parse(formatData.series); } diff --git a/report-stat/frontend/src/template/enterprise/share/ShareEnterpriseReportTemplate.vue b/report-stat/frontend/src/template/enterprise/share/ShareEnterpriseReportTemplate.vue index eb2af6f2b6..8c5f398714 100644 --- a/report-stat/frontend/src/template/enterprise/share/ShareEnterpriseReportTemplate.vue +++ b/report-stat/frontend/src/template/enterprise/share/ShareEnterpriseReportTemplate.vue @@ -1,10 +1,10 @@