fix(项目报告): 修复项目报告分享链接时报告内容解析失败的问题

修复项目报告分享链接时报告内容解析失败的问题
This commit is contained in:
song-tianyang 2022-10-26 18:36:11 +08:00 committed by 刘瑞斌
parent e9773d6dc1
commit 8dea30cf46
8 changed files with 37 additions and 23 deletions

View File

@ -59,7 +59,7 @@ public class ShiroUtils {
//分享相关接口 //分享相关接口
filterChainDefinitionMap.put("/share/info/generateShareInfoWithExpired", "anon"); filterChainDefinitionMap.put("/share/info/generateShareInfoWithExpired", "anon");
filterChainDefinitionMap.put("/share/list", "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/get/**", "anon");
filterChainDefinitionMap.put("/share/info", "apikey, csrf, authc"); // 需要认证 filterChainDefinitionMap.put("/share/info", "apikey, csrf, authc"); // 需要认证
filterChainDefinitionMap.put("/document/**", "anon"); filterChainDefinitionMap.put("/document/**", "anon");

View File

@ -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";
}
}

View File

@ -3,30 +3,21 @@ package io.metersphere.reportstatistics.controller;
import io.metersphere.base.domain.ReportStatisticsWithBLOBs; import io.metersphere.base.domain.ReportStatisticsWithBLOBs;
import io.metersphere.reportstatistics.dto.ReportStatisticsSaveRequest; import io.metersphere.reportstatistics.dto.ReportStatisticsSaveRequest;
import io.metersphere.reportstatistics.service.ReportStatisticsService; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
@Controller @RestController
@RequestMapping(value = "/report/stat/share")
public class ReportStatShareController { public class ReportStatShareController {
@GetMapping(value = "/chart-pic")
public String getChart() {
return "share-enterprise-report.html";
}
}
@RequestMapping(value = "/share/info")
class ShareInfoController {
@Resource @Resource
private ReportStatisticsService reportStatisticsService; private ReportStatisticsService reportStatisticsService;
@PostMapping("/selectHistoryReportById") @PostMapping("/select/report/by/id")
public ReportStatisticsWithBLOBs selectById(@RequestBody ReportStatisticsSaveRequest request) { public ReportStatisticsWithBLOBs selectById(@RequestBody ReportStatisticsSaveRequest request) {
return reportStatisticsService.selectById(request.getId()); return reportStatisticsService.selectById(request.getId());
} }
} }

View File

@ -84,7 +84,7 @@ public class ReportStatisticsService {
boolean isReportNeedUpdate = this.isReportNeedUpdate(blob); boolean isReportNeedUpdate = this.isReportNeedUpdate(blob);
if (isReportNeedUpdate) { if (isReportNeedUpdate) {
TestCaseCountRequest countRequest = JSON.parseObject(blob.getSelectOption(), TestCaseCountRequest.class); TestCaseCountRequest countRequest = JSON.parseObject(blob.getSelectOption(), TestCaseCountRequest.class);
Map<String, Object> returnDataOption = this.reloadData(countRequest, JSON.toJSONString(dataOption.get("chartType"))); Map<String, Object> returnDataOption = this.reloadData(countRequest, dataOption.get("chartType").toString());
if (returnDataOption != null) { if (returnDataOption != null) {
dataOption = returnDataOption; dataOption = returnDataOption;
} }
@ -94,8 +94,13 @@ public class ReportStatisticsService {
if (dataOption.get("tableData") != null) { if (dataOption.get("tableData") != null) {
String tableDataJsonStr = JSON.toJSONString(dataOption.get("tableData")); String tableDataJsonStr = JSON.toJSONString(dataOption.get("tableData"));
List<TestCaseCountTableDTO> dtos = JSON.parseArray(tableDataJsonStr, TestCaseCountTableDTO.class); List<TestCaseCountTableDTO> dtos = JSON.parseArray(tableDataJsonStr, TestCaseCountTableDTO.class);
List<String> yaxis = new ArrayList<>();
try {
yaxis = (List<String>) selectOption.get("yaxis");
} catch (Exception e) {
String yaxisStr = JSON.toJSONString(selectOption.get("yaxis")); String yaxisStr = JSON.toJSONString(selectOption.get("yaxis"));
List<String> yaxis = JSON.parseArray(yaxisStr, String.class); yaxis = JSON.parseArray(yaxisStr, String.class);
}
TestCaseCountTableDataDTO showTable = this.countShowTable(String.valueOf(selectOption.get("xaxis")), yaxis, dtos); TestCaseCountTableDataDTO showTable = this.countShowTable(String.valueOf(selectOption.get("xaxis")), yaxis, dtos);
dataOption.put("showTable", showTable); dataOption.put("showTable", showTable);
blob.setDataOption(JSON.toJSONString(dataOption)); blob.setDataOption(JSON.toJSONString(dataOption));

View File

@ -70,7 +70,7 @@ public class ChromeUtil {
driver.get(url); driver.get(url);
driver.manage().window().fullscreen(); driver.manage().window().fullscreen();
//预留echart动画的加载时间 //预留echart动画的加载时间
Thread.sleep(3 * 1000); Thread.sleep(10 * 1000);
String js = "var chartsCanvas = document.getElementById('picChart').getElementsByTagName('canvas')[0];" + String js = "var chartsCanvas = document.getElementById('picChart').getElementsByTagName('canvas')[0];" +
"var imageUrl = null;" + "var imageUrl = null;" +
"if (chartsCanvas!= null) {" + "if (chartsCanvas!= null) {" +

View File

@ -1,9 +1,9 @@
import {post} from "metersphere-frontend/src/plugins/request" import {post} from "metersphere-frontend/src/plugins/request"
let basePath = '/share/info'; let basePath = '/report/stat/share';
export function selectShareReportById(param) { export function selectShareReportById(param) {
return post(basePath + '/selectHistoryReportById', param) return post(basePath + '/select/report/by/id', param)
} }
export function getShareId() { export function getShareId() {

View File

@ -203,6 +203,12 @@ export default {
if (typeof (formatData.xaxis) === 'string') { if (typeof (formatData.xaxis) === 'string') {
formatData.xaxis = JSON.parse(formatData.xaxis); 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') { if (typeof (formatData.series) === 'string') {
formatData.series = JSON.parse(formatData.series); formatData.series = JSON.parse(formatData.series);
} }

View File

@ -1,10 +1,10 @@
<template> <template>
<report-chart v-if="!needReloading" :read-only="true" :need-full-screen="false" :chart-type="dataOption.chartType" <report-chart v-if="!needReloading" :read-only="true" :need-full-screen="false"
:chart-type="dataOption.chartType"
ref="analysisChart" :load-option="dataOption.loadOption" :pie-option="dataOption.pieOption"/> ref="analysisChart" :load-option="dataOption.loadOption" :pie-option="dataOption.pieOption"/>
</template> </template>
<script> <script>
// import ReportChart from "@/template/enterprise/share/ReportChart";
import ReportChart from "@/business/enterprisereport/components/chart/ReportChart"; import ReportChart from "@/business/enterprisereport/components/chart/ReportChart";
import {getShareId, selectShareReportById} from "@/api/share"; import {getShareId, selectShareReportById} from "@/api/share";