feat: 保存的报告支持分享功能
This commit is contained in:
parent
3cac84c2a2
commit
aeac439114
|
@ -3,12 +3,11 @@ package io.metersphere.api.service;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.api.dto.share.*;
|
import io.metersphere.api.dto.share.*;
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.domain.ShareInfo;
|
|
||||||
import io.metersphere.base.domain.TestPlanApiCase;
|
|
||||||
import io.metersphere.base.domain.TestPlanApiScenario;
|
|
||||||
import io.metersphere.base.mapper.ShareInfoMapper;
|
import io.metersphere.base.mapper.ShareInfoMapper;
|
||||||
|
import io.metersphere.base.mapper.TestPlanReportMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtShareInfoMapper;
|
import io.metersphere.base.mapper.ext.ExtShareInfoMapper;
|
||||||
|
import io.metersphere.commons.constants.ShareType;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.BeanUtils;
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
|
@ -38,6 +37,8 @@ public class ShareInfoService {
|
||||||
TestPlanApiCaseService testPlanApiCaseService;
|
TestPlanApiCaseService testPlanApiCaseService;
|
||||||
@Resource
|
@Resource
|
||||||
TestPlanScenarioCaseService testPlanScenarioCaseService;
|
TestPlanScenarioCaseService testPlanScenarioCaseService;
|
||||||
|
@Resource
|
||||||
|
TestPlanReportMapper testPlanReportMapper;
|
||||||
|
|
||||||
public List<ApiDocumentInfoDTO> findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) {
|
public List<ApiDocumentInfoDTO> findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) {
|
||||||
if (this.isParamLegitimacy(request)) {
|
if (this.isParamLegitimacy(request)) {
|
||||||
|
@ -440,7 +441,7 @@ public class ShareInfoService {
|
||||||
public ShareInfoDTO conversionShareInfoToDTO(ShareInfo apiShare) {
|
public ShareInfoDTO conversionShareInfoToDTO(ShareInfo apiShare) {
|
||||||
ShareInfoDTO returnDTO = new ShareInfoDTO();
|
ShareInfoDTO returnDTO = new ShareInfoDTO();
|
||||||
if (!StringUtils.isEmpty(apiShare.getCustomData())) {
|
if (!StringUtils.isEmpty(apiShare.getCustomData())) {
|
||||||
String url = "?" + apiShare.getId();
|
String url = "?shareId=" + apiShare.getId();
|
||||||
returnDTO.setId(apiShare.getId());
|
returnDTO.setId(apiShare.getId());
|
||||||
returnDTO.setShareUrl(url);
|
returnDTO.setShareUrl(url);
|
||||||
}
|
}
|
||||||
|
@ -463,19 +464,26 @@ public class ShareInfoService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apiReportValidate(String shareId, String testId) {
|
public void apiReportValidate(String shareId, String testId) {
|
||||||
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
|
|
||||||
String planId = shareInfo.getCustomData();
|
|
||||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId);
|
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId);
|
||||||
if (!StringUtils.equals(planId, testPlanApiCase.getTestPlanId())) {
|
if (!StringUtils.equals(getPlanId(shareId), testPlanApiCase.getTestPlanId())) {
|
||||||
MSException.throwException("validate failure!");
|
MSException.throwException("validate failure!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scenarioReportValidate(String shareId, String reportId) {
|
public String getPlanId(String shareId) {
|
||||||
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
|
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
|
||||||
String planId = shareInfo.getCustomData();
|
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);
|
TestPlanApiScenario testPlanApiScenario = testPlanScenarioCaseService.selectByReportId(reportId);
|
||||||
if (!StringUtils.equals(planId, testPlanApiScenario.getTestPlanId())) {
|
if (!StringUtils.equals(getPlanId(shareId), testPlanApiScenario.getTestPlanId())) {
|
||||||
MSException.throwException("validate failure!");
|
MSException.throwException("validate failure!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package io.metersphere.commons.constants;
|
||||||
|
|
||||||
|
public enum ShareType {
|
||||||
|
Single, Batch, PLAN_REPORT, PLAN_DB_REPORT
|
||||||
|
}
|
|
@ -51,6 +51,8 @@ public class ShareController {
|
||||||
PerformanceReportService performanceReportService;
|
PerformanceReportService performanceReportService;
|
||||||
@Resource
|
@Resource
|
||||||
PerformanceTestService performanceTestService;
|
PerformanceTestService performanceTestService;
|
||||||
|
@Resource
|
||||||
|
TestPlanReportService testPlanReportService;
|
||||||
|
|
||||||
@GetMapping("/issues/plan/get/{shareId}/{planId}")
|
@GetMapping("/issues/plan/get/{shareId}/{planId}")
|
||||||
public List<IssuesDao> getIssuesByPlanoId(@PathVariable String shareId, @PathVariable String planId) {
|
public List<IssuesDao> getIssuesByPlanoId(@PathVariable String shareId, @PathVariable String planId) {
|
||||||
|
@ -159,4 +161,10 @@ public class ShareController {
|
||||||
return performanceTestService.getJmxContent(testId);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<el-button type="primary" size="mini" :disabled="!shareUrl"
|
<el-button type="primary" size="mini" :disabled="!shareUrl"
|
||||||
v-clipboard:copy="shareUrl">{{ $t("commons.copy") }}</el-button>
|
v-clipboard:copy="shareUrl">{{ $t("commons.copy") }}</el-button>
|
||||||
</div>
|
</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()">
|
plain size="mini" @click="handleShare()">
|
||||||
{{'分享'}}
|
{{'分享'}}
|
||||||
</el-button>
|
</el-button>
|
||||||
|
@ -67,6 +67,10 @@ export default {
|
||||||
let pram = {};
|
let pram = {};
|
||||||
pram.customData = this.planId;
|
pram.customData = this.planId;
|
||||||
pram.shareType = 'PLAN_REPORT';
|
pram.shareType = 'PLAN_REPORT';
|
||||||
|
if (this.isDb) {
|
||||||
|
pram.customData = this.report.id;
|
||||||
|
pram.shareType = 'PLAN_DB_REPORT';
|
||||||
|
}
|
||||||
generateShareInfo(pram, (data) => {
|
generateShareInfo(pram, (data) => {
|
||||||
let thisHost = window.location.host;
|
let thisHost = window.location.host;
|
||||||
this.shareUrl = thisHost + "/sharePlanReport" + data.shareUrl;
|
this.shareUrl = thisHost + "/sharePlanReport" + data.shareUrl;
|
||||||
|
|
|
@ -18,7 +18,12 @@
|
||||||
<script>
|
<script>
|
||||||
import TestPlanFunctionalReport
|
import TestPlanFunctionalReport
|
||||||
from "@/business/components/track/plan/view/comonents/report/detail/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 TestPlanApiReport from "@/business/components/track/plan/view/comonents/report/detail/TestPlanApiReport";
|
||||||
import TestPlanLoadReport from "@/business/components/track/plan/view/comonents/report/detail/TestPlanLoadReport";
|
import TestPlanLoadReport from "@/business/components/track/plan/view/comonents/report/detail/TestPlanLoadReport";
|
||||||
import TestPlanReportContainer
|
import TestPlanReportContainer
|
||||||
|
@ -59,6 +64,9 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
planId() {
|
planId() {
|
||||||
this.getReport();
|
this.getReport();
|
||||||
|
},
|
||||||
|
reportId() {
|
||||||
|
this.getReport();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -91,16 +99,24 @@ export default {
|
||||||
if (this.isTemplate) {
|
if (this.isTemplate) {
|
||||||
this.report = "#report";
|
this.report = "#report";
|
||||||
this.report.config = this.getDefaultConfig(this.report.config);
|
this.report.config = this.getDefaultConfig(this.report.config);
|
||||||
} else if (this.isShare) {
|
} else if (this.isDb) {
|
||||||
this.result = getShareTestPlanReport(this.shareId, this.planId, (data) => {
|
if (this.isShare) {
|
||||||
|
//持久化的报告分享
|
||||||
|
this.result = getShareTestPlanReportContent(this.shareId, this.reportId, (data) => {
|
||||||
this.report = data;
|
this.report = data;
|
||||||
this.report.config = this.getDefaultConfig(this.report.config);
|
this.report.config = this.getDefaultConfig(this.report.config);
|
||||||
});
|
});
|
||||||
} if (this.isDb) {
|
} else {
|
||||||
this.result = getTestPlanReportContent(this.reportId, (data) => {
|
this.result = getTestPlanReportContent(this.reportId, (data) => {
|
||||||
this.report = data;
|
this.report = data;
|
||||||
this.report.config = this.getDefaultConfig(this.report.config);
|
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);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.result = getTestPlanReport(this.planId, (data) => {
|
this.result = getTestPlanReport(this.planId, (data) => {
|
||||||
this.report = data;
|
this.report = data;
|
||||||
|
|
|
@ -527,7 +527,17 @@ export function stopFullScreenLoading(loading, timeout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getShareId() {
|
export function getShareId() {
|
||||||
|
// let herfUrl = 'http://localhost:8080/sharePlanReport?shareId=ba80f96a-184f-4607-b78e-324129153d9e';
|
||||||
let herfUrl = window.location.href;
|
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){
|
if(herfUrl.indexOf("?") > 0){
|
||||||
let paramArr = herfUrl.split("?");
|
let paramArr = herfUrl.split("?");
|
||||||
if(paramArr.length > 1){
|
if(paramArr.length > 1){
|
||||||
|
@ -538,5 +548,6 @@ export function getShareId() {
|
||||||
return shareId;
|
return shareId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,10 @@ export function getTestPlanReportContent(reportId, callback) {
|
||||||
return reportId ? baseGet('/test/plan/report/db/' + 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) {
|
export function getPlanFunctionFailureCase(planId, callback) {
|
||||||
return planId ? baseGet('/test/plan/case/list/failure/' + planId, callback) : {};
|
return planId ? baseGet('/test/plan/case/list/failure/' + planId, callback) : {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<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>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -12,14 +12,21 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
planId: '',
|
planId: '',
|
||||||
|
reportId: '',
|
||||||
visible: false,
|
visible: false,
|
||||||
shareId: ''
|
shareId: '',
|
||||||
|
isDb: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.shareId = getShareId();
|
this.shareId = getShareId();
|
||||||
getShareInfo(this.shareId, (data) => {
|
getShareInfo(this.shareId, (data) => {
|
||||||
|
if (data.shareType === 'PLAN_REPORT') {
|
||||||
this.planId = data.customData;
|
this.planId = data.customData;
|
||||||
|
} else if (data.shareType === 'PLAN_DB_REPORT') {
|
||||||
|
this.reportId = data.customData;
|
||||||
|
this.isDb = true;
|
||||||
|
}
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue