feat: 保存的报告支持分享功能

This commit is contained in:
chenjianxing 2021-08-25 15:38:09 +08:00 committed by jianxing
parent 3cac84c2a2
commit aeac439114
8 changed files with 90 additions and 27 deletions

View File

@ -3,12 +3,11 @@ package io.metersphere.api.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.dto.share.*;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ShareInfo;
import io.metersphere.base.domain.TestPlanApiCase;
import io.metersphere.base.domain.TestPlanApiScenario;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ShareInfoMapper;
import io.metersphere.base.mapper.TestPlanReportMapper;
import io.metersphere.base.mapper.ext.ExtShareInfoMapper;
import io.metersphere.commons.constants.ShareType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.SessionUtils;
@ -38,6 +37,8 @@ public class ShareInfoService {
TestPlanApiCaseService testPlanApiCaseService;
@Resource
TestPlanScenarioCaseService testPlanScenarioCaseService;
@Resource
TestPlanReportMapper testPlanReportMapper;
public List<ApiDocumentInfoDTO> findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) {
if (this.isParamLegitimacy(request)) {
@ -440,7 +441,7 @@ public class ShareInfoService {
public ShareInfoDTO conversionShareInfoToDTO(ShareInfo apiShare) {
ShareInfoDTO returnDTO = new ShareInfoDTO();
if (!StringUtils.isEmpty(apiShare.getCustomData())) {
String url = "?" + apiShare.getId();
String url = "?shareId=" + apiShare.getId();
returnDTO.setId(apiShare.getId());
returnDTO.setShareUrl(url);
}
@ -463,19 +464,26 @@ public class ShareInfoService {
}
public void apiReportValidate(String shareId, String testId) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
String planId = shareInfo.getCustomData();
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId);
if (!StringUtils.equals(planId, testPlanApiCase.getTestPlanId())) {
if (!StringUtils.equals(getPlanId(shareId), testPlanApiCase.getTestPlanId())) {
MSException.throwException("validate failure!");
}
}
public void scenarioReportValidate(String shareId, String reportId) {
public String getPlanId(String shareId) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
String planId = shareInfo.getCustomData();
if (ShareType.PLAN_DB_REPORT.name().equals(shareInfo.getShareType())) {
String reportId = shareInfo.getCustomData();
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId);
planId = testPlanReport.getTestPlanId();
}
return planId;
}
public void scenarioReportValidate(String shareId, String reportId) {
TestPlanApiScenario testPlanApiScenario = testPlanScenarioCaseService.selectByReportId(reportId);
if (!StringUtils.equals(planId, testPlanApiScenario.getTestPlanId())) {
if (!StringUtils.equals(getPlanId(shareId), testPlanApiScenario.getTestPlanId())) {
MSException.throwException("validate failure!");
}
}

View File

@ -0,0 +1,5 @@
package io.metersphere.commons.constants;
public enum ShareType {
Single, Batch, PLAN_REPORT, PLAN_DB_REPORT
}

View File

@ -51,6 +51,8 @@ public class ShareController {
PerformanceReportService performanceReportService;
@Resource
PerformanceTestService performanceTestService;
@Resource
TestPlanReportService testPlanReportService;
@GetMapping("/issues/plan/get/{shareId}/{planId}")
public List<IssuesDao> getIssuesByPlanoId(@PathVariable String shareId, @PathVariable String planId) {
@ -159,4 +161,10 @@ public class ShareController {
return performanceTestService.getJmxContent(testId);
}
@GetMapping("/test/plan/report/db/{shareId}/{reportId}")
public TestPlanSimpleReportDTO getTestPlanDbReport(@PathVariable String shareId, @PathVariable String reportId) {
shareInfoService.validate(shareId, reportId);
return testPlanReportService.getReport(reportId);
}
}

View File

@ -9,7 +9,7 @@
<el-button type="primary" size="mini" :disabled="!shareUrl"
v-clipboard:copy="shareUrl">{{ $t("commons.copy") }}</el-button>
</div>
<el-button icon="el-icon-share" v-if="!isDb" slot="reference" :disabled="!isTestManagerOrTestUser"
<el-button icon="el-icon-share" slot="reference" :disabled="!isTestManagerOrTestUser"
plain size="mini" @click="handleShare()">
{{'分享'}}
</el-button>
@ -67,6 +67,10 @@ export default {
let pram = {};
pram.customData = this.planId;
pram.shareType = 'PLAN_REPORT';
if (this.isDb) {
pram.customData = this.report.id;
pram.shareType = 'PLAN_DB_REPORT';
}
generateShareInfo(pram, (data) => {
let thisHost = window.location.host;
this.shareUrl = thisHost + "/sharePlanReport" + data.shareUrl;

View File

@ -18,7 +18,12 @@
<script>
import TestPlanFunctionalReport
from "@/business/components/track/plan/view/comonents/report/detail/TestPlanFunctionalReport";
import {getShareTestPlanReport, getTestPlanReport, getTestPlanReportContent} from "@/network/test-plan";
import {
getShareTestPlanReport,
getShareTestPlanReportContent,
getTestPlanReport,
getTestPlanReportContent
} from "@/network/test-plan";
import TestPlanApiReport from "@/business/components/track/plan/view/comonents/report/detail/TestPlanApiReport";
import TestPlanLoadReport from "@/business/components/track/plan/view/comonents/report/detail/TestPlanLoadReport";
import TestPlanReportContainer
@ -59,6 +64,9 @@ export default {
watch: {
planId() {
this.getReport();
},
reportId() {
this.getReport();
}
},
created() {
@ -91,16 +99,24 @@ export default {
if (this.isTemplate) {
this.report = "#report";
this.report.config = this.getDefaultConfig(this.report.config);
} else if (this.isDb) {
if (this.isShare) {
//
this.result = getShareTestPlanReportContent(this.shareId, this.reportId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report.config);
});
} else {
this.result = getTestPlanReportContent(this.reportId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report.config);
});
}
} else if (this.isShare) {
this.result = getShareTestPlanReport(this.shareId, this.planId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report.config);
});
} if (this.isDb) {
this.result = getTestPlanReportContent(this.reportId, (data) => {
this.report = data;
this.report.config = this.getDefaultConfig(this.report.config);
});
} else {
this.result = getTestPlanReport(this.planId, (data) => {
this.report = data;

View File

@ -527,15 +527,26 @@ export function stopFullScreenLoading(loading, timeout) {
}
export function getShareId() {
// let herfUrl = 'http://localhost:8080/sharePlanReport?shareId=ba80f96a-184f-4607-b78e-324129153d9e';
let herfUrl = window.location.href;
if(herfUrl.indexOf("?") > 0){
let paramArr = herfUrl.split("?");
if(paramArr.length > 1){
let shareId = paramArr[1];
if(shareId.indexOf("#") > 0){
shareId = shareId.split("#")[0];
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 shareId;
}
}
return "";

View File

@ -42,6 +42,10 @@ export function getTestPlanReportContent(reportId, callback) {
return reportId ? baseGet('/test/plan/report/db/' + reportId, callback) : {};
}
export function getShareTestPlanReportContent(shareId, reportId, callback) {
return reportId ? baseGet('/share/test/plan/report/db/' + shareId + '/' + reportId, callback) : {};
}
export function getPlanFunctionFailureCase(planId, callback) {
return planId ? baseGet('/test/plan/case/list/failure/' + planId, callback) : {};
}

View File

@ -1,5 +1,5 @@
<template>
<test-plan-report-content :share-id="shareId" :is-share="true" :plan-id="planId"/>
<test-plan-report-content :share-id="shareId" :report-id="reportId" :is-share="true" :is-db="isDb" :plan-id="planId"/>
</template>
<script>
@ -12,14 +12,21 @@ export default {
data() {
return {
planId: '',
reportId: '',
visible: false,
shareId: ''
shareId: '',
isDb: false
}
},
created() {
this.shareId = getShareId();
getShareInfo(this.shareId, (data) => {
this.planId = data.customData;
if (data.shareType === 'PLAN_REPORT') {
this.planId = data.customData;
} else if (data.shareType === 'PLAN_DB_REPORT') {
this.reportId = data.customData;
this.isDb = true;
}
this.visible = true;
});
},