feat: (接口定义、接口自动化) 删除模块时,模块下的所有接口或场景被放入回收站 (#1268)

This commit is contained in:
Coooder-X 2021-01-26 17:21:21 +08:00 committed by GitHub
parent 27f5264a88
commit 6f93e09f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 2 deletions

View File

@ -124,6 +124,12 @@ public class ApiAutomationService {
apiScenarioMapper.deleteByExample(example);
}
public void removeToGcByIds(List<String> nodeIds) {
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andApiScenarioModuleIdIn(nodeIds);
extApiScenarioMapper.removeToGcByExample(example);
}
public ApiScenario create(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles) {
request.setId(UUID.randomUUID().toString());
checkNameExist(request);

View File

@ -240,7 +240,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
public int deleteNode(List<String> nodeIds) {
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
apiDefinitionExample.createCriteria().andModuleIdIn(nodeIds);
apiDefinitionMapper.deleteByExample(apiDefinitionExample);
extApiDefinitionMapper.removeToGcByExample(apiDefinitionExample); // 删除模块则模块下的接口放入回收站
ApiModuleExample apiDefinitionNodeExample = new ApiModuleExample();
apiDefinitionNodeExample.createCriteria().andIdIn(nodeIds);

View File

@ -194,7 +194,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
}
public int deleteNode(List<String> nodeIds) {
apiAutomationService.deleteByIds(nodeIds);
apiAutomationService.removeToGcByIds(nodeIds);
ApiScenarioModuleExample apiScenarioModuleExample = new ApiScenarioModuleExample();
apiScenarioModuleExample.createCriteria().andIdIn(nodeIds);

View File

@ -6,6 +6,8 @@ import io.metersphere.api.dto.definition.ApiDefinitionRequest;
import io.metersphere.api.dto.definition.ApiDefinitionResult;
import io.metersphere.api.dto.definition.ApiSwaggerUrlDTO;
import io.metersphere.base.domain.ApiDefinition;
import io.metersphere.base.domain.ApiDefinitionExample;
import io.metersphere.base.domain.ApiModuleExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -19,6 +21,8 @@ public interface ExtApiDefinitionMapper {
int removeToGc(@Param("ids") List<String> ids);
int removeToGcByExample(ApiDefinitionExample example);
int reduction(@Param("ids") List<String> ids);
List<ApiDataCountResult> countProtocolByProjectID(String projectId);

View File

@ -311,6 +311,15 @@
</foreach>
</update>
<update id="removeToGcByExample" parameterType="io.metersphere.base.domain.ApiDefinitionExample">
update api_definition
set
status = 'Trash', module_path = null, module_id = null
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</update>
<update id="reduction">
update api_definition
set

View File

@ -4,6 +4,7 @@ import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.base.domain.ApiScenario;
import io.metersphere.base.domain.ApiScenarioExample;
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
import org.apache.ibatis.annotations.Param;
@ -20,6 +21,8 @@ public interface ExtApiScenarioMapper {
int removeToGc(@Param("ids") List<String> ids);
int removeToGcByExample(ApiScenarioExample example);
int reduction(@Param("ids") List<String> ids);
long countByProjectID(String projectId);

View File

@ -7,6 +7,35 @@
<result column="project_name" property="projectName"/>
<result column="user_name" property="userName"/>
</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="condition">
<choose>
<when test='${object}.operator == "like"'>
@ -243,6 +272,15 @@
</foreach>
</update>
<update id="removeToGcByExample" parameterType="io.metersphere.base.domain.ApiScenarioExample">
update api_scenario
set
status = 'Trash', module_path = null, api_scenario_module_id = null
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</update>
<update id="reduction">
update api_scenario
set