refactor: 测试计划报告分享增加有效期24小时
This commit is contained in:
parent
ece0186eff
commit
823f735b98
|
@ -81,9 +81,9 @@ public class ShareInfoController {
|
||||||
return returnDTO;
|
return returnDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/generateShareInfo")
|
@PostMapping("/generateShareInfoWithExpired")
|
||||||
public ShareInfoDTO generateShareInfo(@RequestBody ShareInfo request) {
|
public ShareInfoDTO generateShareInfo(@RequestBody ShareInfo request) {
|
||||||
ShareInfo apiShare = shareInfoService.generateShareInfo(request);
|
ShareInfo apiShare = shareInfoService.createShareInfo(request);
|
||||||
ShareInfoDTO returnDTO = shareInfoService.conversionShareInfoToDTO(apiShare);
|
ShareInfoDTO returnDTO = shareInfoService.conversionShareInfoToDTO(apiShare);
|
||||||
return returnDTO;
|
return returnDTO;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,13 @@ import io.metersphere.base.mapper.ext.ExtShareInfoMapper;
|
||||||
import io.metersphere.commons.constants.ShareType;
|
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.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||||
import io.metersphere.track.service.TestPlanScenarioCaseService;
|
import io.metersphere.track.service.TestPlanScenarioCaseService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -403,25 +405,34 @@ public class ShareInfoService {
|
||||||
return new ShareInfo();
|
return new ShareInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成分享连接
|
||||||
|
* 如果该数据有连接则,返回已有的连接,不做有效期判断
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public ShareInfo generateShareInfo(ShareInfo request) {
|
public ShareInfo generateShareInfo(ShareInfo request) {
|
||||||
ShareInfo shareInfo = null;
|
|
||||||
List<ShareInfo> shareInfos = extShareInfoMapper.selectByShareTypeAndShareApiIdWithBLOBs(request.getShareType(), request.getCustomData());
|
List<ShareInfo> shareInfos = extShareInfoMapper.selectByShareTypeAndShareApiIdWithBLOBs(request.getShareType(), request.getCustomData());
|
||||||
if (shareInfos.isEmpty()) {
|
if (shareInfos.isEmpty()) {
|
||||||
long createTime = System.currentTimeMillis();
|
return createShareInfo(request);
|
||||||
shareInfo = new ShareInfo();
|
|
||||||
shareInfo.setId(UUID.randomUUID().toString());
|
|
||||||
shareInfo.setCustomData(request.getCustomData());
|
|
||||||
shareInfo.setCreateUserId(SessionUtils.getUserId());
|
|
||||||
shareInfo.setCreateTime(createTime);
|
|
||||||
shareInfo.setUpdateTime(createTime);
|
|
||||||
shareInfo.setShareType(request.getShareType());
|
|
||||||
shareInfoMapper.insert(shareInfo);
|
|
||||||
return shareInfo;
|
|
||||||
} else {
|
} else {
|
||||||
return shareInfos.get(0);
|
return shareInfos.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShareInfo createShareInfo(ShareInfo request) {
|
||||||
|
long createTime = System.currentTimeMillis();
|
||||||
|
ShareInfo shareInfo = new ShareInfo();
|
||||||
|
shareInfo.setId(UUID.randomUUID().toString());
|
||||||
|
shareInfo.setCustomData(request.getCustomData());
|
||||||
|
shareInfo.setCreateUserId(SessionUtils.getUserId());
|
||||||
|
shareInfo.setCreateTime(createTime);
|
||||||
|
shareInfo.setUpdateTime(createTime);
|
||||||
|
shareInfo.setShareType(request.getShareType());
|
||||||
|
shareInfoMapper.insert(shareInfo);
|
||||||
|
return shareInfo;
|
||||||
|
}
|
||||||
|
|
||||||
private List<ShareInfo> findByShareTypeAndShareApiIdWithBLOBs(String shareType, List<String> shareApiIdList) {
|
private List<ShareInfo> findByShareTypeAndShareApiIdWithBLOBs(String shareType, List<String> shareApiIdList) {
|
||||||
String shareApiIdString = this.genShareIdJsonString(shareApiIdList);
|
String shareApiIdString = this.genShareIdJsonString(shareApiIdList);
|
||||||
return extShareInfoMapper.selectByShareTypeAndShareApiIdWithBLOBs(shareType, shareApiIdString);
|
return extShareInfoMapper.selectByShareTypeAndShareApiIdWithBLOBs(shareType, shareApiIdString);
|
||||||
|
@ -454,6 +465,8 @@ public class ShareInfoService {
|
||||||
|
|
||||||
public void validate(String shareId, String customData) {
|
public void validate(String shareId, String customData) {
|
||||||
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
|
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
|
||||||
|
ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
|
||||||
|
shareInfoService.validateExpired(shareInfo);
|
||||||
if (shareInfo == null) {
|
if (shareInfo == null) {
|
||||||
MSException.throwException("shareInfo not exist!");
|
MSException.throwException("shareInfo not exist!");
|
||||||
} else {
|
} else {
|
||||||
|
@ -463,6 +476,28 @@ public class ShareInfoService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void validateExpired(String shareId) {
|
||||||
|
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
|
||||||
|
ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
|
||||||
|
shareInfoService.validateExpired(shareInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不加入事务,抛出异常不回滚
|
||||||
|
* 若在当前类中调用请使用如下方式调用,否则该方法的事务注解不生效
|
||||||
|
* ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
|
||||||
|
* shareInfoService.validateExpired(shareInfo);
|
||||||
|
* @param shareInfo
|
||||||
|
*/
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
|
public void validateExpired(ShareInfo shareInfo) {
|
||||||
|
// 有效期24小时
|
||||||
|
if (shareInfo == null || System.currentTimeMillis() - shareInfo.getUpdateTime() > 1000*60*60*24) {
|
||||||
|
shareInfoMapper.deleteByPrimaryKey(shareInfo.getId());
|
||||||
|
MSException.throwException("连接已失效,请重新获取!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void apiReportValidate(String shareId, String testId) {
|
public void apiReportValidate(String shareId, String testId) {
|
||||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId);
|
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId);
|
||||||
if (!StringUtils.equals(getPlanId(shareId), testPlanApiCase.getTestPlanId())) {
|
if (!StringUtils.equals(getPlanId(shareId), testPlanApiCase.getTestPlanId())) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class ShiroUtils {
|
||||||
filterChainDefinitionMap.put("/anonymous/**", "anon");
|
filterChainDefinitionMap.put("/anonymous/**", "anon");
|
||||||
|
|
||||||
//分享相关接口
|
//分享相关接口
|
||||||
filterChainDefinitionMap.put("/share/info/generateShareInfo", "anon");
|
filterChainDefinitionMap.put("/share/info/generateShareInfoWithExpired", "anon");
|
||||||
filterChainDefinitionMap.put("/share/info/selectApiInfoByParam", "anon");
|
filterChainDefinitionMap.put("/share/info/selectApiInfoByParam", "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"); // 需要认证
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
placement="right"
|
placement="right"
|
||||||
width="300">
|
width="300">
|
||||||
<p>{{shareUrl}}</p>
|
<p>{{shareUrl}}</p>
|
||||||
|
<span style="color: red;float: left;margin-left: 10px;">24小时有效</span>
|
||||||
<div style="text-align: right; margin: 0">
|
<div style="text-align: right; margin: 0">
|
||||||
<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>
|
||||||
|
@ -37,7 +38,7 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
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 {generateShareInfo} from "@/network/share";
|
import {generateShareInfoWithExpired} from "@/network/share";
|
||||||
import TestPlanReportEdit
|
import TestPlanReportEdit
|
||||||
from "@/business/components/track/plan/view/comonents/report/detail/component/TestPlanReportEdit";
|
from "@/business/components/track/plan/view/comonents/report/detail/component/TestPlanReportEdit";
|
||||||
export default {
|
export default {
|
||||||
|
@ -71,7 +72,7 @@ export default {
|
||||||
pram.customData = this.report.id;
|
pram.customData = this.report.id;
|
||||||
pram.shareType = 'PLAN_DB_REPORT';
|
pram.shareType = 'PLAN_DB_REPORT';
|
||||||
}
|
}
|
||||||
generateShareInfo(pram, (data) => {
|
generateShareInfoWithExpired(pram, (data) => {
|
||||||
let thisHost = window.location.host;
|
let thisHost = window.location.host;
|
||||||
this.shareUrl = thisHost + "/sharePlanReport" + data.shareUrl;
|
this.shareUrl = thisHost + "/sharePlanReport" + data.shareUrl;
|
||||||
});
|
});
|
||||||
|
|
|
@ -111,35 +111,38 @@ export default {
|
||||||
// this.report = data;
|
// this.report = data;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
this.report.config = this.getDefaultConfig(this.report.config);
|
this.report.config = this.getDefaultConfig(this.report);
|
||||||
} else if (this.isDb) {
|
} else if (this.isDb) {
|
||||||
if (this.isShare) {
|
if (this.isShare) {
|
||||||
//持久化的报告分享
|
//持久化的报告分享
|
||||||
this.result = getShareTestPlanReportContent(this.shareId, this.reportId, (data) => {
|
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);
|
||||||
});
|
});
|
||||||
} else {
|
} 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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (this.isShare) {
|
} else if (this.isShare) {
|
||||||
this.result = getShareTestPlanReport(this.shareId, this.planId, (data) => {
|
this.result = getShareTestPlanReport(this.shareId, this.planId, (data) => {
|
||||||
this.report = data;
|
this.report = data;
|
||||||
this.report.config = this.getDefaultConfig(this.report.config);
|
this.report.config = this.getDefaultConfig(this.report);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.result = getTestPlanReport(this.planId, (data) => {
|
this.result = getTestPlanReport(this.planId, (data) => {
|
||||||
this.report = data;
|
this.report = data;
|
||||||
this.report.config = this.getDefaultConfig(this.report.config);
|
this.report.config = this.getDefaultConfig(this.report);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getDefaultConfig(configStr) {
|
getDefaultConfig(report) {
|
||||||
if (configStr) {
|
if (report && report.config) {
|
||||||
return JSON.parse(configStr);
|
let configStr = report.config;
|
||||||
|
if (configStr) {
|
||||||
|
return JSON.parse(configStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
overview: {
|
overview: {
|
||||||
|
|
|
@ -10,8 +10,8 @@ export function generateApiDocumentShareInfo(param, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateShareInfo(param, callback) {
|
export function generateShareInfoWithExpired(param, callback) {
|
||||||
return post("/share/info/generateShareInfo", param, response => {
|
return post("/share/info/generateShareInfoWithExpired", param, response => {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(response.data);
|
callback(response.data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue