Commit 4dcda56f authored by song-tianyang's avatar song-tianyang Committed by fit2-zhao
Browse files

feat(接口定义、接口自动化): 删除案例、场景时判读有没有被场景引用

--bug=1005178 --user=宋天阳 【接口定义】删除被场景引用的接口用例只有删除确认提示
https://www.tapd.cn/55049933/s/1025923
parent 102b8959
Showing with 1364 additions and 6 deletions
+1364 -6
......@@ -131,6 +131,12 @@ public class ApiAutomationController {
apiAutomationService.removeToGcByBatch(request);
}
@PostMapping("/checkBeforeDelete")
public DeleteCheckResult checkBeforeDelete(@RequestBody ApiScenarioBatchRequest request) {
DeleteCheckResult checkResult = apiAutomationService.checkBeforeDelete(request);
return checkResult;
}
@PostMapping("/reduction")
@MsAuditLog(module = "api_automation", type = OperLogConstants.RESTORE, beforeEvent = "#msClass.getLogDetails(#ids)", msClass = ApiAutomationService.class)
public void reduction(@RequestBody List<String> ids) {
......
......@@ -3,6 +3,7 @@ package io.metersphere.api.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.ApiCaseBatchRequest;
import io.metersphere.api.dto.DeleteCheckResult;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.base.domain.ApiTestCase;
......@@ -146,6 +147,10 @@ public class ApiTestCaseController {
public void deleteToGcByParam(@RequestBody ApiTestBatchRequest request) {
apiTestCaseService.deleteToGcByParam(request);
}
@PostMapping("/checkDeleteDatas")
public DeleteCheckResult checkDeleteDatas(@RequestBody ApiTestBatchRequest request) {
return apiTestCaseService.checkDeleteDatas(request);
}
@PostMapping("/relevance")
public void testPlanRelevance(@RequestBody ApiCaseRelevanceRequest request) {
......
package io.metersphere.api.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author song.tianyang
* @Date 2021/7/19 10:52 上午
*/
@Getter
@Setter
public class DeleteCheckResult {
boolean deleteFlag;
List<String> checkMsg;
}
......@@ -126,6 +126,8 @@ public class ApiAutomationService {
private TestPlanMapper testPlanMapper;
@Resource
private TcpApiParamService tcpApiParamService;
@Resource
private ApiScenarioReferenceIdService apiScenarioReferenceIdService;
public ApiScenarioWithBLOBs getDto(String id) {
return apiScenarioMapper.selectByPrimaryKey(id);
......@@ -266,6 +268,7 @@ public class ApiAutomationService {
esbApiParamService.checkScenarioRequests(request);
apiScenarioMapper.insert(scenario);
apiScenarioReferenceIdService.saveByApiScenario(scenario);
uploadFiles(request, bodyFiles, scenarioFiles);
......@@ -361,6 +364,7 @@ public class ApiAutomationService {
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenario);
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
apiScenarioMapper.updateByPrimaryKeySelective(scenario);
apiScenarioReferenceIdService.saveByApiScenario(scenario);
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务
uploadFiles(request, bodyFiles, scenarioFiles);
}
......@@ -448,6 +452,9 @@ public class ApiAutomationService {
}
public void preDelete(String scenarioId) {
//删除引用
apiScenarioReferenceIdService.deleteByScenarioId(scenarioId);
List<String> ids = new ArrayList<>();
ids.add(scenarioId);
deleteApiScenarioReport(ids);
......@@ -1619,6 +1626,7 @@ public class ApiAutomationService {
apiScenarioMapper.updateByExampleSelective(
apiScenarioWithBLOBs,
apiScenarioExample);
apiScenarioReferenceIdService.saveByApiScenario(apiScenarioWithBLOBs);
}
public void bathEditEnv(ApiScenarioBatchRequest request) {
......@@ -1631,6 +1639,7 @@ public class ApiAutomationService {
item.setScenarioDefinition(JSONObject.toJSONString(object));
}
apiScenarioMapper.updateByPrimaryKeySelective(item);
apiScenarioReferenceIdService.saveByApiScenario(item);
});
}
}
......@@ -1647,6 +1656,7 @@ public class ApiAutomationService {
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl));
batchMapper.insert(scenarioWithBLOBs);
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
} else {
//如果存在则修改
scenarioWithBLOBs.setId(sameRequest.get(0).getId());
......@@ -1654,6 +1664,7 @@ public class ApiAutomationService {
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl));
batchMapper.updateByPrimaryKeyWithBLOBs(scenarioWithBLOBs);
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
}
}
......@@ -1712,6 +1723,7 @@ public class ApiAutomationService {
List<ApiMethodUrlDTO> useUrl = this.parseUrl(scenarioWithBLOBs);
scenarioWithBLOBs.setUseUrl(JSONArray.toJSONString(useUrl));
batchMapper.insert(scenarioWithBLOBs);
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
}
} else {
......@@ -1902,6 +1914,7 @@ public class ApiAutomationService {
String newDefinition = JSON.toJSONString(object);
scenario.setScenarioDefinition(newDefinition);
apiScenarioMapper.updateByPrimaryKeySelective(scenario);
apiScenarioReferenceIdService.saveByApiScenario(scenario);
}
}
});
......@@ -2217,6 +2230,7 @@ public class ApiAutomationService {
updateModel.setId(scenario.getId());
updateModel.setUseUrl(JSONArray.toJSONString(useUrl));
apiScenarioMapper.updateByPrimaryKeySelective(updateModel);
apiScenarioReferenceIdService.saveByApiScenario(updateModel);
updateModel = null;
}
}
......@@ -2224,6 +2238,13 @@ public class ApiAutomationService {
}
}
public void checkApiScenarioReferenceId(){
List<ApiScenarioWithBLOBs> scenarioNoRefs = extApiScenarioMapper.selectByNoReferenceId();
for (ApiScenarioWithBLOBs model :scenarioNoRefs) {
apiScenarioReferenceIdService.saveByApiScenario(model);
}
}
public List<JmxInfoDTO> batchGenPerformanceTestJmx(ApiScenarioBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query));
......@@ -2290,9 +2311,61 @@ public class ApiAutomationService {
if (insertFlag) {
apiScenarioMapper.insert(newModel);
apiScenarioReferenceIdService.saveByApiScenario(newModel);
}
}
}
// uploadFiles(request, bodyFiles, scenarioFiles);
}
public DeleteCheckResult checkBeforeDelete(ApiScenarioBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query));
List<String> deleteIds = request.getIds();
DeleteCheckResult result = new DeleteCheckResult();
List<String> checkMsgList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(deleteIds)){
List<ApiScenarioReferenceId> apiScenarioReferenceIdList = apiScenarioReferenceIdService.findByReferenceIdsAndRefType(deleteIds,MsTestElementConstants.REF.name());
if(CollectionUtils.isNotEmpty(apiScenarioReferenceIdList)){
Map<String,List<String>> scenarioDic = new HashMap<>();
apiScenarioReferenceIdList.forEach( item ->{
String refreceID = item.getReferenceId();
String scenarioId = item.getApiScenarioId();
if(scenarioDic.containsKey(refreceID)){
scenarioDic.get(refreceID).add(scenarioId);
}else {
List<String> list = new ArrayList<>();
list.add(scenarioId);
scenarioDic.put(refreceID,list);
}
});
for (Map.Entry<String,List<String>> entry : scenarioDic.entrySet()){
String refreceId = entry.getKey();
List<String> scenarioIdList = entry.getValue();
if(CollectionUtils.isNotEmpty(scenarioIdList)){
String deleteScenarioName= extApiScenarioMapper.selectNameById(refreceId);
List<String> scenarioNames = extApiScenarioMapper.selectNameByIdIn(scenarioIdList);
if(StringUtils.isNotEmpty(deleteScenarioName) && CollectionUtils.isNotEmpty(scenarioNames)){
String nameListStr = "【";
for (String name : scenarioNames) {
nameListStr+= name +",";
}
if(nameListStr.length() > 1){
nameListStr = nameListStr.substring(0,nameListStr.length()-1) + "】";
}
String msg = deleteScenarioName+" "+Translator.get("delete_check_reference_by")+": "+nameListStr+" ";
checkMsgList.add(msg);
}
}
}
}
}
result.setDeleteFlag(checkMsgList.isEmpty());
result.setCheckMsg(checkMsgList);
return result;
}
}
package io.metersphere.api.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.ApiScenarioReferenceId;
import io.metersphere.base.domain.ApiScenarioReferenceIdExample;
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
import io.metersphere.base.mapper.ApiScenarioReferenceIdMapper;
import io.metersphere.commons.utils.SessionUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
/**
* @author song.tianyang
* @Date 2021/7/19 11:33 上午
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ApiScenarioReferenceIdService {
@Resource
private ApiScenarioReferenceIdMapper apiScenarioReferenceIdMapper;
public List<ApiScenarioReferenceId> findByReferenceIds(List<String> deleteIds) {
if (CollectionUtils.isEmpty(deleteIds)) {
return new ArrayList<>(0);
} else {
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
example.createCriteria().andReferenceIdIn(deleteIds);
return apiScenarioReferenceIdMapper.selectByExample(example);
}
}
public void deleteByScenarioId(String scenarioId) {
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
example.createCriteria().andApiScenarioIdEqualTo(scenarioId);
apiScenarioReferenceIdMapper.deleteByExample(example);
}
public void saveByApiScenario(ApiScenarioWithBLOBs scenario) {
this.deleteByScenarioId(scenario.getId());
long createTime = System.currentTimeMillis();
String createUser = SessionUtils.getUserId();
Map<String, ApiScenarioReferenceId> refreceIdDic = new HashMap<>();
try {
if (scenario.getScenarioDefinition() != null) {
JSONObject jsonObject = JSONObject.parseObject(scenario.getScenarioDefinition());
if (jsonObject.containsKey("hashTree")) {
JSONArray testElementList = jsonObject.getJSONArray("hashTree");
for (int index = 0; index < testElementList.size(); index++) {
JSONObject item = testElementList.getJSONObject(index);
String refId = "";
String refrenced = "";
String dataType = "";
if(item.containsKey("id")){
refId = item.getString("id");
}
if(item.containsKey("referenced")){
refrenced = item.getString("referenced");
}
if(item.containsKey("refType")){
dataType = item.getString("refType");
}
if (StringUtils.isNotEmpty(refId) && StringUtils.isNotEmpty(refrenced)) {
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
saveItem.setId(UUID.randomUUID().toString());
saveItem.setApiScenarioId(scenario.getId());
saveItem.setCreateTime(createTime);
saveItem.setCreateUserId(createUser);
saveItem.setReferenceId(refId);
saveItem.setReferenceType(refrenced);
saveItem.setDataType(dataType);
refreceIdDic.put(refId,saveItem);
}
if(item.containsKey("hashTree")){
refreceIdDic.putAll(this.deepParseTestElement(createTime,createUser,scenario.getId(),item.getJSONArray("hashTree")));
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if(MapUtils.isNotEmpty(refreceIdDic)){
for (ApiScenarioReferenceId model:refreceIdDic.values()) {
apiScenarioReferenceIdMapper.insert(model);
}
}else {
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
saveItem.setId(UUID.randomUUID().toString());
saveItem.setApiScenarioId(scenario.getId());
saveItem.setCreateTime(createTime);
saveItem.setCreateUserId(createUser);
try{
apiScenarioReferenceIdMapper.insert(saveItem);
}catch (Exception e){
e.printStackTrace();
}
}
}
public Map<String,ApiScenarioReferenceId> deepParseTestElement(long createTime,String createUser,String scenarioId,JSONArray testElementList){
Map<String,ApiScenarioReferenceId> returnMap = new HashMap<>();
if(CollectionUtils.isNotEmpty(testElementList)){
for (int index = 0; index < testElementList.size(); index++) {
JSONObject item = testElementList.getJSONObject(index);
String refId = "";
String refrenced = "";
String dataType = "";
if(item.containsKey("id")){
refId = item.getString("id");
}
if(item.containsKey("referenced")){
refrenced = item.getString("referenced");
}
if(item.containsKey("refType")){
dataType = item.getString("refType");
}
if (StringUtils.isNotEmpty(refId) && StringUtils.isNotEmpty(refrenced)) {
ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId();
saveItem.setId(UUID.randomUUID().toString());
saveItem.setApiScenarioId(scenarioId);
saveItem.setCreateTime(createTime);
saveItem.setCreateUserId(createUser);
saveItem.setReferenceId(refId);
saveItem.setReferenceType(refrenced);
saveItem.setDataType(dataType);
returnMap.put(refId,saveItem);
}
if(item.containsKey("hashTree")){
returnMap.putAll(this.deepParseTestElement(createTime,createUser,scenarioId,item.getJSONArray("hashTree")));
}
}
}
return returnMap;
}
public List<ApiScenarioReferenceId> findByReferenceIdsAndRefType(List<String> deleteIds, String referenceType) {
if (CollectionUtils.isEmpty(deleteIds)) {
return new ArrayList<>(0);
} else {
ApiScenarioReferenceIdExample example = new ApiScenarioReferenceIdExample();
example.createCriteria().andReferenceIdIn(deleteIds).andReferenceTypeEqualTo(referenceType);
return apiScenarioReferenceIdMapper.selectByExample(example);
}
}
}
......@@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.metersphere.api.dto.ApiCaseBatchRequest;
import io.metersphere.api.dto.DeleteCheckResult;
import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.definition.request.MsTestElement;
......@@ -20,6 +21,7 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.constants.TestPlanStatus;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
......@@ -82,6 +84,10 @@ public class ApiTestCaseService {
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private EsbApiParamService esbApiParamService;
@Resource
private ApiScenarioReferenceIdService apiScenarioReferenceIdService;
@Resource
private ExtApiScenarioMapper extApiScenarioMapper;
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
......@@ -828,4 +834,56 @@ public class ApiTestCaseService {
return extApiTestCaseMapper.selectCaseIdsByApiIds(apiIds);
}
}
public DeleteCheckResult checkDeleteDatas(ApiTestBatchRequest request) {
List<String> deleteIds = request.getIds();
if (request.isSelectAll()) {
deleteIds = this.getAllApiCaseIdsByFontedSelect(request.getFilters(), request.getModuleIds(), request.getName(), request.getProjectId(), request.getProtocol(), request.getUnSelectIds(), request.getStatus(),request.getApiDefinitionId());
}
DeleteCheckResult result = new DeleteCheckResult();
List<String> checkMsgList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(deleteIds)){
List<ApiScenarioReferenceId> apiScenarioReferenceIdList = apiScenarioReferenceIdService.findByReferenceIdsAndRefType(deleteIds, MsTestElementConstants.REF.name());
if(CollectionUtils.isNotEmpty(apiScenarioReferenceIdList)){
Map<String,List<String>> scenarioDic = new HashMap<>();
apiScenarioReferenceIdList.forEach( item ->{
String refreceID = item.getReferenceId();
String scenarioId = item.getApiScenarioId();
if(scenarioDic.containsKey(refreceID)){
scenarioDic.get(refreceID).add(scenarioId);
}else {
List<String> list = new ArrayList<>();
list.add(scenarioId);
scenarioDic.put(refreceID,list);
}
});
for (Map.Entry<String,List<String>> entry : scenarioDic.entrySet()){
String refreceId = entry.getKey();
List<String> scenarioIdList = entry.getValue();
if(CollectionUtils.isNotEmpty(scenarioIdList)){
List<String> scenarioNameList = extApiScenarioMapper.selectNameByIdIn(scenarioIdList);
String deleteCaseName = extApiTestCaseMapper.selectNameById(refreceId);
if(StringUtils.isNotEmpty(deleteCaseName) && CollectionUtils.isNotEmpty(scenarioNameList)){
String nameListStr = "【";
for (String name : scenarioNameList) {
nameListStr+= name +",";
}
if(nameListStr.length() > 1){
nameListStr = nameListStr.substring(0,nameListStr.length()-1) + "】";
}
String msg = deleteCaseName+" "+Translator.get("delete_check_reference_by")+": "+nameListStr+" ";
checkMsgList.add(msg);
}
}
}
}
}
result.setDeleteFlag(checkMsgList.isEmpty());
result.setCheckMsg(checkMsgList);
return result;
}
}
......@@ -57,6 +57,8 @@ public class HistoricalDataUpgradeService {
@Resource
private ApiAutomationService apiAutomationService;
@Resource
private ApiScenarioReferenceIdService apiScenarioReferenceIdService;
@Resource
SqlSessionFactory sqlSessionFactory;
@Resource
ApiTestEnvironmentService apiTestEnvironmentService;
......@@ -367,6 +369,7 @@ public class HistoricalDataUpgradeService {
List<ApiMethodUrlDTO> useUrl = apiAutomationService.parseUrl(scenario);
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
mapper.updateByPrimaryKeySelective(scenario);
apiScenarioReferenceIdService.saveByApiScenario(scenario);
} else {
scenario = new ApiScenarioWithBLOBs();
scenario.setId(id);
......@@ -387,6 +390,7 @@ public class HistoricalDataUpgradeService {
List<ApiMethodUrlDTO> useUrl = apiAutomationService.parseUrl(scenario);
scenario.setUseUrl(JSONArray.toJSONString(useUrl));
mapper.insert(scenario);
apiScenarioReferenceIdService.saveByApiScenario(scenario);
}
}
......
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class ApiScenarioReferenceId implements Serializable {
private String id;
private String apiScenarioId;
private Long createTime;
private String createUserId;
private String referenceId;
private String referenceType;
private String dataType;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package io.metersphere.base.mapper;
import io.metersphere.base.domain.ApiScenarioReferenceId;
import io.metersphere.base.domain.ApiScenarioReferenceIdExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface ApiScenarioReferenceIdMapper {
long countByExample(ApiScenarioReferenceIdExample example);
int deleteByExample(ApiScenarioReferenceIdExample example);
int deleteByPrimaryKey(String id);
int insert(ApiScenarioReferenceId record);
int insertSelective(ApiScenarioReferenceId record);
List<ApiScenarioReferenceId> selectByExample(ApiScenarioReferenceIdExample example);
ApiScenarioReferenceId selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") ApiScenarioReferenceId record, @Param("example") ApiScenarioReferenceIdExample example);
int updateByExample(@Param("record") ApiScenarioReferenceId record, @Param("example") ApiScenarioReferenceIdExample example);
int updateByPrimaryKeySelective(ApiScenarioReferenceId record);
int updateByPrimaryKey(ApiScenarioReferenceId record);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ApiScenarioReferenceIdMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.ApiScenarioReferenceId">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="api_scenario_id" jdbcType="VARCHAR" property="apiScenarioId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
<result column="reference_id" jdbcType="VARCHAR" property="referenceId" />
<result column="reference_type" jdbcType="VARCHAR" property="referenceType" />
<result column="data_type" jdbcType="VARCHAR" property="dataType" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, api_scenario_id, create_time, create_user_id, reference_id, reference_type, data_type
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.ApiScenarioReferenceIdExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from api_scenario_reference_id
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from api_scenario_reference_id
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from api_scenario_reference_id
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.ApiScenarioReferenceIdExample">
delete from api_scenario_reference_id
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.ApiScenarioReferenceId">
insert into api_scenario_reference_id (id, api_scenario_id, create_time,
create_user_id, reference_id, reference_type,
data_type)
values (#{id,jdbcType=VARCHAR}, #{apiScenarioId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{createUserId,jdbcType=VARCHAR}, #{referenceId,jdbcType=VARCHAR}, #{referenceType,jdbcType=VARCHAR},
#{dataType,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiScenarioReferenceId">
insert into api_scenario_reference_id
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="apiScenarioId != null">
api_scenario_id,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="createUserId != null">
create_user_id,
</if>
<if test="referenceId != null">
reference_id,
</if>
<if test="referenceType != null">
reference_type,
</if>
<if test="dataType != null">
data_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="apiScenarioId != null">
#{apiScenarioId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
#{createUserId,jdbcType=VARCHAR},
</if>
<if test="referenceId != null">
#{referenceId,jdbcType=VARCHAR},
</if>
<if test="referenceType != null">
#{referenceType,jdbcType=VARCHAR},
</if>
<if test="dataType != null">
#{dataType,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.ApiScenarioReferenceIdExample" resultType="java.lang.Long">
select count(*) from api_scenario_reference_id
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update api_scenario_reference_id
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.apiScenarioId != null">
api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
<if test="record.createUserId != null">
create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if>
<if test="record.referenceId != null">
reference_id = #{record.referenceId,jdbcType=VARCHAR},
</if>
<if test="record.referenceType != null">
reference_type = #{record.referenceType,jdbcType=VARCHAR},
</if>
<if test="record.dataType != null">
data_type = #{record.dataType,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update api_scenario_reference_id
set id = #{record.id,jdbcType=VARCHAR},
api_scenario_id = #{record.apiScenarioId,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
create_user_id = #{record.createUserId,jdbcType=VARCHAR},
reference_id = #{record.referenceId,jdbcType=VARCHAR},
reference_type = #{record.referenceType,jdbcType=VARCHAR},
data_type = #{record.dataType,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.ApiScenarioReferenceId">
update api_scenario_reference_id
<set>
<if test="apiScenarioId != null">
api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
create_user_id = #{createUserId,jdbcType=VARCHAR},
</if>
<if test="referenceId != null">
reference_id = #{referenceId,jdbcType=VARCHAR},
</if>
<if test="referenceType != null">
reference_type = #{referenceType,jdbcType=VARCHAR},
</if>
<if test="dataType != null">
data_type = #{dataType,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.ApiScenarioReferenceId">
update api_scenario_reference_id
set api_scenario_id = #{apiScenarioId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR},
reference_id = #{referenceId,jdbcType=VARCHAR},
reference_type = #{referenceType,jdbcType=VARCHAR},
data_type = #{dataType,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
......@@ -60,4 +60,10 @@ public interface ExtApiScenarioMapper {
List<Map<String, Object>> listModuleByCollection(@Param("request") ApiScenarioRequest request);
List<String> selectIdsByUseUrlIsNull();
String selectNameById(String id);
List<String> selectNameByIdIn(@Param("ids") List<String> id);
List<ApiScenarioWithBLOBs> selectByNoReferenceId();
}
......@@ -292,6 +292,11 @@
</foreach>
</select>
<select id="selectByNoReferenceId" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select * from api_scenario where id not in
(SELECT api_scenario_id FROM api_scenario_reference_id)
</select>
<select id="selectByIds" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select * from api_scenario where id in (${ids}) ORDER BY FIND_IN_SET(id,${oderId})
</select>
......@@ -409,6 +414,21 @@
where project_id = #{projectId}
and status = 'Trash'
</select>
<select id="selectNameById" resultType="java.lang.String">
select name
from api_scenario
WHERE id = #{0}
</select>
<select id="selectNameByIdIn" resultType="java.lang.String">
select name
from api_scenario
WHERE id IN
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</select>
<sql id="queryWhereConditionReview">
<where>
<if test="request.combine != null">
......
......@@ -47,4 +47,7 @@ public interface ExtApiTestCaseMapper {
List<ApiTestCaseDTO> getCannotReductionApiCaseList(@Param("ids") List<String> ids);
List<String> selectCaseIdsByApiIds(@Param("ids")List<String> apiIds);
List<String> selectNameByIdIn(@Param("ids")List<String> ids);
String selectNameById(String id);
}
......@@ -523,6 +523,19 @@
</foreach>
</select>
<select id="selectNameByIdIn" resultType="java.lang.String">
SELECT testCase.name FROM api_test_case testCase
WHERE testCase.id IN
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</select>
<select id="selectNameById" resultType="java.lang.String">
SELECT testCase.name FROM api_test_case testCase
WHERE testCase.id = #{0}
</select>
<update id="deleteToGc" parameterType="io.metersphere.api.dto.definition.ApiTestCaseRequest">
update api_test_case
set original_status=status,
......
......@@ -51,6 +51,7 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
initPythonEnv();
initOperate(apiAutomationService::checkApiScenarioUseUrl, "init.scenario.url");
initOperate(apiAutomationService::checkApiScenarioReferenceId, "init.scenario.referenceId");
initOperate(issuesService::syncThirdPartyIssues, "init.issue");
initOperate(issuesService::issuesCount, "init.issueCount");
......
......@@ -48,4 +48,19 @@ UPDATE api_scenario SET delete_time = update_time,delete_user_id = create_user W
-- 更新接口状态为“Trash'但是案例状态不是Trash的数据
UPDATE api_test_case testCase INNER JOIN (SELECT t1.id FROM api_test_case t1 INNER JOIN api_definition t2 ON t1.api_definition_id = t2.id
WHERE (t1.`status` is null or t1.`status` != 'Trash') and t2.`status` = 'Trash') table1 ON testCase.id = table1.id SET `STATUS` = 'Trash';
-- 功能案例、接口、接口案例、场景增加字段以及旧数据管理结束
\ No newline at end of file
-- 功能案例、接口、接口案例、场景增加字段以及旧数据管理结束
-- 场景增加外键表:引用的ID
CREATE TABLE api_scenario_reference_id (
`id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`api_scenario_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`create_time` bigint(13) NULL DEFAULT NULL,
`create_user_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`reference_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`reference_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`data_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `reference_id`(`reference_id`) USING BTREE,
INDEX `api_scenario_id`(`api_scenario_id`) USING BTREE,
INDEX `data_type`(`data_type`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
......@@ -84,10 +84,10 @@
<!-- <table tableName="custom_field"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="test_case"></table>-->
<table tableName="api_scenario"></table>
<table tableName="test_case"></table>
<table tableName="api_test_case"></table>
<table tableName="api_definition"></table>
<table tableName="api_scenario_reference_id"></table>
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="api_test_case"></table>-->
<!-- <table tableName="api_definition"></table>-->
......
......@@ -216,6 +216,7 @@ message_task_already_exists=Task recipient already exists
#automation
automation_name_already_exists=the scenario already exists in the project
automation_exec_info=There are no test steps to execute
delete_check_reference_by=be referenced by Scenario
#authsource
authsource_name_already_exists=Authentication source name already exists
authsource_name_is_null=Authentication source name cannot be empty
......
......@@ -216,6 +216,7 @@ message_task_already_exists=任务接收人已经存在
#automation
automation_name_already_exists=同一个项目下,场景名称不能重复
automation_exec_info=没有测试步骤,无法执行
delete_check_reference_by=被场景引用
#authsource
authsource_name_already_exists=认证源名称已经存在
authsource_name_is_null=认证源名称不能为空
......@@ -263,4 +264,4 @@ api_case=接口用例
performance_case=性能用例
scenario_case=场景用例
id_not_rightful=ID 不合法
\ No newline at end of file
id_not_rightful=ID 不合法
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment