refactor: 测试计划报告分享增加有效期24小时
This commit is contained in:
parent
ece0186eff
commit
823f735b98
|
@ -81,9 +81,9 @@ public class ShareInfoController {
|
|||
return returnDTO;
|
||||
}
|
||||
|
||||
@PostMapping("/generateShareInfo")
|
||||
@PostMapping("/generateShareInfoWithExpired")
|
||||
public ShareInfoDTO generateShareInfo(@RequestBody ShareInfo request) {
|
||||
ShareInfo apiShare = shareInfoService.generateShareInfo(request);
|
||||
ShareInfo apiShare = shareInfoService.createShareInfo(request);
|
||||
ShareInfoDTO returnDTO = shareInfoService.conversionShareInfoToDTO(apiShare);
|
||||
return returnDTO;
|
||||
}
|
||||
|
|
|
@ -10,11 +10,13 @@ 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.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||
import io.metersphere.track.service.TestPlanScenarioCaseService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -403,25 +405,34 @@ public class ShareInfoService {
|
|||
return new ShareInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成分享连接
|
||||
* 如果该数据有连接则,返回已有的连接,不做有效期判断
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public ShareInfo generateShareInfo(ShareInfo request) {
|
||||
ShareInfo shareInfo = null;
|
||||
List<ShareInfo> shareInfos = extShareInfoMapper.selectByShareTypeAndShareApiIdWithBLOBs(request.getShareType(), request.getCustomData());
|
||||
if (shareInfos.isEmpty()) {
|
||||
long createTime = System.currentTimeMillis();
|
||||
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;
|
||||
return createShareInfo(request);
|
||||
} else {
|
||||
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) {
|
||||
String shareApiIdString = this.genShareIdJsonString(shareApiIdList);
|
||||
return extShareInfoMapper.selectByShareTypeAndShareApiIdWithBLOBs(shareType, shareApiIdString);
|
||||
|
@ -454,6 +465,8 @@ public class ShareInfoService {
|
|||
|
||||
public void validate(String shareId, String customData) {
|
||||
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
|
||||
ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
|
||||
shareInfoService.validateExpired(shareInfo);
|
||||
if (shareInfo == null) {
|
||||
MSException.throwException("shareInfo not exist!");
|
||||
} 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) {
|
||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(testId);
|
||||
if (!StringUtils.equals(getPlanId(shareId), testPlanApiCase.getTestPlanId())) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ShiroUtils {
|
|||
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/get/**", "anon");
|
||||
filterChainDefinitionMap.put("/share/info", "apikey, csrf, authc"); // 需要认证
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
placement="right"
|
||||
width="300">
|
||||
<p>{{shareUrl}}</p>
|
||||
<span style="color: red;float: left;margin-left: 10px;">24小时有效</span>
|
||||
<div style="text-align: right; margin: 0">
|
||||
<el-button type="primary" size="mini" :disabled="!shareUrl"
|
||||
v-clipboard:copy="shareUrl">{{ $t("commons.copy") }}</el-button>
|
||||
|
@ -37,7 +38,7 @@
|
|||
<script>
|
||||
|
||||
import TestPlanApiReport from "@/business/components/track/plan/view/comonents/report/detail/TestPlanApiReport";
|
||||
import {generateShareInfo} from "@/network/share";
|
||||
import {generateShareInfoWithExpired} from "@/network/share";
|
||||
import TestPlanReportEdit
|
||||
from "@/business/components/track/plan/view/comonents/report/detail/component/TestPlanReportEdit";
|
||||
export default {
|
||||
|
@ -71,7 +72,7 @@ export default {
|
|||
pram.customData = this.report.id;
|
||||
pram.shareType = 'PLAN_DB_REPORT';
|
||||
}
|
||||
generateShareInfo(pram, (data) => {
|
||||
generateShareInfoWithExpired(pram, (data) => {
|
||||
let thisHost = window.location.host;
|
||||
this.shareUrl = thisHost + "/sharePlanReport" + data.shareUrl;
|
||||
});
|
||||
|
|
|
@ -111,35 +111,38 @@ export default {
|
|||
// this.report = data;
|
||||
// });
|
||||
|
||||
this.report.config = this.getDefaultConfig(this.report.config);
|
||||
this.report.config = this.getDefaultConfig(this.report);
|
||||
} 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);
|
||||
this.report.config = this.getDefaultConfig(this.report);
|
||||
});
|
||||
} else {
|
||||
this.result = getTestPlanReportContent(this.reportId, (data) => {
|
||||
this.report = data;
|
||||
this.report.config = this.getDefaultConfig(this.report.config);
|
||||
this.report.config = this.getDefaultConfig(this.report);
|
||||
});
|
||||
}
|
||||
} else if (this.isShare) {
|
||||
this.result = getShareTestPlanReport(this.shareId, this.planId, (data) => {
|
||||
this.report = data;
|
||||
this.report.config = this.getDefaultConfig(this.report.config);
|
||||
this.report.config = this.getDefaultConfig(this.report);
|
||||
});
|
||||
} else {
|
||||
this.result = getTestPlanReport(this.planId, (data) => {
|
||||
this.report = data;
|
||||
this.report.config = this.getDefaultConfig(this.report.config);
|
||||
this.report.config = this.getDefaultConfig(this.report);
|
||||
});
|
||||
}
|
||||
},
|
||||
getDefaultConfig(configStr) {
|
||||
if (configStr) {
|
||||
return JSON.parse(configStr);
|
||||
getDefaultConfig(report) {
|
||||
if (report && report.config) {
|
||||
let configStr = report.config;
|
||||
if (configStr) {
|
||||
return JSON.parse(configStr);
|
||||
}
|
||||
}
|
||||
return {
|
||||
overview: {
|
||||
|
|
|
@ -10,8 +10,8 @@ export function generateApiDocumentShareInfo(param, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
export function generateShareInfo(param, callback) {
|
||||
return post("/share/info/generateShareInfo", param, response => {
|
||||
export function generateShareInfoWithExpired(param, callback) {
|
||||
return post("/share/info/generateShareInfoWithExpired", param, response => {
|
||||
if (callback) {
|
||||
callback(response.data);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue