fix(项目报告): 修复项目报告发送邮件时动态计算报表问题出现的bug

修复项目报告发送邮件时动态计算报表问题的bug
This commit is contained in:
song-tianyang 2022-10-25 15:59:52 +08:00 committed by wxg0103
parent 5abcdc941f
commit 00938b25f1
7 changed files with 242 additions and 2 deletions

View File

@ -0,0 +1,32 @@
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 javax.annotation.Resource;
@Controller
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")
public ReportStatisticsWithBLOBs selectById(@RequestBody ReportStatisticsSaveRequest request) {
return reportStatisticsService.selectById(request.getId());
}
}

View File

@ -278,12 +278,12 @@ public class ReportStatisticsService {
Map<String, String> urlMap = new HashMap<>();
for (ReportStatisticsWithBLOBs blob : reportRecordIdList) {
String url = platformUrl + "/echartPic?shareId=" + blob.getId();
String url = platformUrl + "/report/chart-pic?shareId=" + blob.getId();
urlMap.put(blob.getId(), url);
}
headlessRequest.setUrlMap(urlMap);
headlessRequest.setRemoteDriverUrl(remoteDriverUrl);
LogUtil.info("使用ChromeUtil来获取图片信息。 language" + language + "headlessRequest" + JSON.toJSONString(headlessRequest));
LogUtil.info("使用ChromeUtil来获取图片信息。url:" + JSON.toJSONString(urlMap) + "; language" + language + "headlessRequest" + JSON.toJSONString(headlessRequest));
Map<String, String> returnMap = chromeUtils.getImageInfo(headlessRequest, language);
return returnMap;
}

View File

@ -0,0 +1,32 @@
import {post} from "metersphere-frontend/src/plugins/request"
let basePath = '/share/info';
export function selectShareReportById(param) {
return post(basePath + '/selectHistoryReportById', param)
}
export function getShareId() {
let herfUrl = window.location.href;
if (herfUrl.indexOf('shareId=') > -1) {
let shareId = '';
new URL(herfUrl).searchParams.forEach((value, key) => {
if (key === 'shareId') {
shareId = value;
}
});
return shareId;
} else {
if (herfUrl.indexOf("?") > 0) {
let paramArr = herfUrl.split("?");
if (paramArr.length > 1) {
let shareId = paramArr[1];
if (shareId.indexOf("#") > 0) {
shareId = shareId.split("#")[0];
}
return shareId;
}
}
}
return "";
}

View File

@ -0,0 +1,109 @@
<template>
<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"/>
</template>
<script>
// import ReportChart from "@/template/enterprise/share/ReportChart";
import ReportChart from "@/business/enterprisereport/components/chart/ReportChart";
import {getShareId, selectShareReportById} from "@/api/share";
export default {
name: "ShareEnterpriseReportTemplate",
components: {ReportChart},
data() {
return {
needReloading: false,
shareId: '',
dataOption: {
chartType: '',
loadOption: {
legend: {},
xAxis: {},
yAxis: {},
label: {},
tooltip: {},
series: []
},
pieOption: {
legend: {},
label: {},
tooltip: {},
series: [],
title: [],
},
},
}
},
created() {
this.initEchartData();
},
methods: {
initEchartData() {
this.shareId = getShareId();
let paramObj = {
id: this.shareId
};
this.resetOptions();
selectShareReportById(paramObj).then(response => {
let reportData = response.data;
if (reportData) {
let selectOption = JSON.parse(reportData.selectOption);
let data = JSON.parse(reportData.dataOption);
data.selectOption = selectOption;
this.dataOption = data;
this.reloadChart();
}
}).catch((error) => {
this.$error(this.$t('查找报告失败!'));
return false;
});
},
initPic(loadOptionParam, tableData) {
this.loading = true;
if (loadOptionParam) {
this.loadOption.legend = loadOptionParam.legend;
this.loadOption.xAxis = loadOptionParam.xaxis;
this.loadOption.series = loadOptionParam.series;
this.loadOption.grid = {
bottom: '75px',//
}
this.loadOption.series.forEach(item => {
item.type = this.$refs.analysisChart.chartType;
})
}
if (tableData) {
this.tableData = tableData;
}
this.loading = false;
},
reloadChart() {
console.info("load data over, reload compnents.");
this.$refs.analysisChart.reload();
},
resetOptions() {
this.dataOption = {
chartType: '',
loadOption: {
legend: {},
xAxis: {},
yAxis: {},
label: {},
tooltip: {},
series: []
},
pieOption: {
legend: {},
label: {},
tooltip: {},
series: [],
title: [],
},
};
},
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="shortcut icon" href="<%= BASE_URL %>favicon.ico">
<title>Enterprise Report</title>
</head>
<body>
<div id="shareEnterpriseReport"></div>
</body>
</html>

View File

@ -0,0 +1,47 @@
import ShareEnterpriseReportTemplate from "./ShareEnterpriseReportTemplate";
import Vue from 'vue';
import ElementUI, {Button, Card, Col, Form, FormItem, Input, Main, Row, Table, TableColumn} from 'element-ui';
import 'metersphere-frontend/src/assets/theme/index.css';
import 'metersphere-frontend/src/styles/business/menu-header.css';
import 'metersphere-frontend/src/styles/business/main.css';
import directives from "metersphere-frontend/src/directive";
import i18n from "@/i18n";
import filters from "metersphere-frontend/src/filters";
import icons from "metersphere-frontend/src/icons";
import plugins from "metersphere-frontend/src/plugins";
import JSONPathPicker from 'vue-jsonpath-picker';
import VuePapaParse from 'vue-papa-parse'
import mavonEditor from 'mavon-editor'
import chart from "metersphere-frontend/src/chart";
Vue.use(ElementUI, {
i18n: (key, value) => i18n.t(key, value)
});
Vue.use(Row);
Vue.use(Col);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Input);
Vue.use(Button);
Vue.use(JSONPathPicker);
Vue.use(VuePapaParse);
Vue.use(mavonEditor);
Vue.use(filters);
Vue.use(directives);
Vue.use(icons);
Vue.use(plugins);
Vue.use(chart);
Vue.use(Main);
Vue.use(Card);
Vue.use(TableColumn);
Vue.use(Table);
Vue.use(filters);
new Vue({
el: '#shareEnterpriseReport',
i18n,
render: h => h(ShareEnterpriseReportTemplate)
});

View File

@ -29,6 +29,13 @@ module.exports = {
'Access-Control-Allow-Origin': '*',
},
},
pages: {
shareEnterpriseReport: {
entry: "src/template/enterprise/share/share-enterprise-report.js",
template: "src/template/enterprise/share/share-enterprise-report.html",
filename: "share-enterprise-report.html",
},
},
configureWebpack: {
devtool: 'cheap-module-source-map',
resolve: {