feat(接口测试): 接口定义页面高级搜索

--task=1016128 --user=陈建星 高级搜索-视图增删改查-后端 https://www.tapd.cn/55049933/s/1573254
This commit is contained in:
AgAngle 2024-09-06 19:48:03 +08:00 committed by Craftsman
parent 2fd3ce8c88
commit e3f971c17f
7 changed files with 175 additions and 199 deletions

View File

@ -23,13 +23,9 @@ public class BaseCondition {
@Valid
private CombineSearch combineSearch;
/**
* todo 删除
*/
@Deprecated
private String searchMode = "AND";
/**
* todo 删除
*/
@Deprecated
private Map<String, Object> combine;
// 转JSON时会调用 前台数据传过来时可以顺便处理掉转义字符

View File

@ -22,10 +22,6 @@ public class CombineSearch {
@Valid
private List<CombineCondition> conditions;
public List<CombineCondition> getConditions() {
return conditions;
}
public String getSearchMode() {
return StringUtils.isBlank(searchMode) ? SearchMode.AND.name() : searchMode;
}

View File

@ -13,23 +13,27 @@ import io.metersphere.project.dto.DropNode;
import io.metersphere.project.dto.NodeSortQueryParam;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.interceptor.BaseConditionFilter;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtApiDefinitionMapper {
void deleteApiToGc(@Param("ids") List<String> ids, @Param("userId") String userId, @Param("time") long time);
@BaseConditionFilter
List<ApiDefinitionDTO> list(@Param("request") ApiDefinitionPageRequest request);
@BaseConditionFilter
List<ApiDefinitionDTO> listDoc(@Param("request") ApiDefinitionDocRequest request);
List<ApiTestCase> selectNotInTrashCaseIdsByApiIds(@Param("apiIds") List<String> apiIds);
Long getPos(@Param("projectId") String projectId);
@BaseConditionFilter
List<String> getIds(@Param("request") TableBatchProcessDTO request, @Param("projectId") String projectId, @Param("protocols") List<String> protocols, @Param("deleted") boolean deleted);
@BaseConditionFilter
List<String> getIdsBySort(@Param("request") TableBatchProcessDTO request, @Param("projectId") String projectId, @Param("protocols") List<String> protocols, @Param("orderColumns") String orderColumns);
List<String> getRefIds(@Param("ids") List<String> ids, @Param("deleted") boolean deleted);
@ -40,6 +44,7 @@ public interface ExtApiDefinitionMapper {
List<ApiDefinitionVersionDTO> getApiDefinitionByRefId(@Param("refId") String refId);
@BaseConditionFilter
void batchMove(@Param("request") ApiDefinitionBatchMoveRequest request, @Param("ids") List<String> ids, @Param("userId") String userId);
void batchDeleteByRefId(@Param("refIds") List<String> refIds, @Param("userId") String userId, @Param("projectId") String projectId);
@ -52,6 +57,7 @@ public interface ExtApiDefinitionMapper {
void updateLatestVersion(@Param("id") String id, @Param("projectId") String projectId);
@BaseConditionFilter
List<ApiDefinitionDetail> importList(@Param("request") ApiDefinitionPageRequest request);
List<String> selectIdsByIdsAndDeleted(@Param("ids") List<String> ids, @Param("deleted") boolean deleted);

View File

@ -279,13 +279,9 @@
<property name="filter" value="request.filter"/>
</include>
<if test="request.combine != null and request.combine != ''">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="name" value="request.name"/>
<property name="ObjectTags" value="request.combine.tags"/>
<property name="combineSearch" value="request.combineSearch"/>
</include>
</if>
<include refid="queryVersionCondition">
<property name="versionTable" value="api_definition"/>
@ -367,108 +363,71 @@
</sql>
<sql id="combine">
-- todo 待修改
<!-- <if test='${condition}.name != null and (${name} == null or ${name} == "")'>-->
<!-- and api_definition.name-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.name"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test='${condition}.id != null'>-->
<!-- and api_definition.num-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.id"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test="${condition}.updateTime != null">-->
<!-- and api_definition.update_time-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.updateTime"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test="${condition}.createTime != null">-->
<!-- and api_definition.create_time-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.createTime"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test="${condition}.status != null">-->
<!-- and api_definition.status-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.status"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test="${condition}.path != null">-->
<!-- and api_definition.path-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.path"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test="${condition}.method != null">-->
<!-- and api_definition.method-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.method"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test='${condition}.tags != null and ${ObjectTags}.operator == "not like"'>-->
<!-- and (api_definition.tags is null or api_definition.tags-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.tags"/>-->
<!-- </include>-->
<!-- )-->
<!-- </if>-->
<!-- <if test='${condition}.tags != null and ${ObjectTags}.operator == "like"'>-->
<!-- and api_definition.tags-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="${condition}.tags"/>-->
<!-- </include>-->
<!-- </if>-->
<!-- <if test="${condition}.customs != null and ${condition}.customs.size() > 0">-->
<!-- <foreach collection="${condition}.customs" item="custom" separator="" open="" close="">-->
<!-- <if test="custom.value != ''">-->
<!-- <if test='custom.operator == "not like" or custom.operator == "not in"'>-->
<!-- and api_definition.id not in (-->
<!-- </if>-->
<!-- <if test='custom.operator != "not like" and custom.operator != "not in"'>-->
<!-- and api_definition.id in (-->
<!-- </if>-->
<!-- select api_id from api_definition_custom_field where field_id = #{custom.id}-->
<!-- <choose>-->
<!-- <when test="custom.type == 'TEXTAREA' or custom.operator == 'current user'">-->
<!-- and `value`-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="custom"/>-->
<!-- </include>-->
<!-- </when>-->
<!-- <when test="custom.type == 'MULTIPLE_MEMBER' or custom.type == 'CHECKBOX' or custom.type == 'MULTIPLE_SELECT'">-->
<!-- and ${custom.value}-->
<!-- </when>-->
<!-- <when test="custom.type == 'DATE' or custom.type == 'DATETIME'">-->
<!-- and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13)-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="custom"/>-->
<!-- </include>-->
<!-- </when>-->
<!-- <otherwise>-->
<!-- and trim(both '"' from `value`)-->
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">-->
<!-- <property name="object" value="custom"/>-->
<!-- </include>-->
<!-- </otherwise>-->
<!-- </choose>-->
<!-- )-->
<!-- </if>-->
<!-- </foreach>-->
<!-- </if>-->
<trim prefix="AND" suffixOverrides="AND|OR">
<if test="${combineSearch} != null">
<foreach collection="${combineSearch}.userViewConditions" item="condition">
<if test="condition.name == 'createUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="api_definition.create_user"/>
</include>
</if>
<if test="condition.name == 'follower'">
api_definition.id in (
select api_definition_id from api_definition_follower where
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="user_id"/>
</include>
)
</if>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include>
</foreach>
<foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions">
<property name="condition" value="condition"/>
<property name="tablePrefix" value="api_definition"/>
</include>
<if test="condition.name == 'protocol'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="api_definition.protocol"/>
</include>
</if>
<if test="condition.name == 'status'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="api_definition.status"/>
</include>
</if>
<if test="condition.name == 'method'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="api_definition.method"/>
</include>
</if>
<if test="condition.name == 'path'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="api_definition.path"/>
</include>
</if>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include>
</foreach>
<if test="${combineSearch}.customFiledConditions.size() > 0">
api_definition.id in (
select api_id from api_definition_custom_field where
<include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions">
<property name="conditions" value="${combineSearch}.customFiledConditions"/>
</include>
)
</if>
</if>
</trim>
</sql>
<sql id="queryVersionCondition">
@ -492,11 +451,9 @@
</sql>
<sql id="queryWhereConditionByBaseQueryRequest">
<if test="request.condition.combine != null">
<include refid="combine">
<property name="condition" value="request.condition.combine"/>
<property name="combineSearch" value="request.condition.combineSearch"/>
</include>
</if>
<if test="request.condition.keyword != null">
and (
api_definition.num like concat('%', #{request.condition.keyword},'%')

View File

@ -33,6 +33,8 @@ import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.project.service.FileAssociationService;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.dto.CombineCondition;
import io.metersphere.sdk.dto.CombineSearch;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.FileRequest;
@ -988,10 +990,17 @@ public class ApiDefinitionControllerTests extends BaseTest {
filters.put("version_id", List.of("1005704995741369851"));
request.setFilter(filters);
Map<String, Object> map = new HashMap<>();
map.put("name", Map.of("operator", "like", "value", "test-1"));
map.put("method", Map.of("operator", "in", "value", Arrays.asList("GET", "POST")));
request.setCombine(map);
CombineSearch combineSearch = new CombineSearch();
CombineCondition condition = new CombineCondition();
condition.setName("name");
condition.setOperator(CombineCondition.CombineConditionOperator.CONTAINS.name());
condition.setValue("test-1");
CombineCondition condition2 = new CombineCondition();
condition2.setName("method");
condition2.setOperator(CombineCondition.CombineConditionOperator.IN.name());
condition2.setValue(List.of("GET", "POST"));
combineSearch.setConditions(List.of(condition, condition2));
request.setCombineSearch(combineSearch);
}
private void configureKeywordSearch(ApiDefinitionPageRequest request) {
@ -1011,26 +1020,30 @@ public class ApiDefinitionControllerTests extends BaseTest {
}
private void configureCombineSearch(ApiDefinitionPageRequest request) {
Map<String, Object> map = new HashMap<>();
map.put("name", Map.of("operator", "like", "value", "test"));
map.put("method", Map.of("operator", "in", "value", Arrays.asList("GET", "POST")));
map.put("createUser", Map.of("operator", "current user", "value", StringUtils.EMPTY));
List<Map<String, Object>> customs = new ArrayList<>();
Map<String, Object> custom = new HashMap<>();
custom.put("id", "test_field");
custom.put("operator", "in");
custom.put("type", "MULTIPLE_SELECT");
custom.put("value", JSON.toJSONString(List.of("test", "default")));
customs.add(custom);
Map<String, Object> currentUserCustom = new HashMap<>();
currentUserCustom.put("id", "test_field");
currentUserCustom.put("operator", "current user");
currentUserCustom.put("type", "MULTIPLE_MEMBER");
currentUserCustom.put("value", "current user");
customs.add(currentUserCustom);
map.put("customs", customs);
CombineSearch combineSearch = new CombineSearch();
CombineCondition condition = new CombineCondition();
condition.setName("name");
condition.setOperator(CombineCondition.CombineConditionOperator.CONTAINS.name());
condition.setValue("test");
request.setCombine(map);
CombineCondition condition2 = new CombineCondition();
condition2.setName("method");
condition2.setOperator(CombineCondition.CombineConditionOperator.IN.name());
condition2.setValue(List.of("GET", "POST"));
CombineCondition condition3 = new CombineCondition();
condition3.setName("createUser");
condition3.setOperator(CombineCondition.CombineConditionOperator.IN.name());
condition3.setValue(List.of("currentUser"));
CombineCondition customCondition = new CombineCondition();
customCondition.setCustomField(true);
customCondition.setName("test_field");
customCondition.setOperator(CombineCondition.CombineConditionOperator.CONTAINS.name());
customCondition.setValue("test");
combineSearch.setConditions(List.of(condition, condition2, condition3, customCondition));
request.setCombineSearch(combineSearch);
}
private void configureDeleteSearch(ApiDefinitionPageRequest request) {

View File

@ -184,7 +184,7 @@
<include refid="filters">
<property name="filter" value="request.filter"/>
</include>
<include refid="queryCombine">
<include refid="combine">
<property name="combineSearch" value="request.combineSearch"/>
</include>
<include refid="queryVersionCondition">
@ -209,7 +209,7 @@
<include refid="filters">
<property name="filter" value="request.condition.filter"/>
</include>
<include refid="queryCombine">
<include refid="combine">
<property name="combineSearch" value="request.condition.combineSearch"/>
</include>
<include refid="queryVersionCondition">
@ -281,7 +281,7 @@
</if>
</sql>
<sql id="queryCombine">
<sql id="combine">
<trim prefix="AND" suffixOverrides="AND|OR">
<if test="${combineSearch} != null">
<foreach collection="${combineSearch}.userViewConditions" item="condition">
@ -305,54 +305,10 @@
</include>
</foreach>
<foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<if test="condition.name == 'name'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.name"/>
<property name="tablePrefix" value="functional_case"/>
</include>
</if>
<if test="condition.name == 'num'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.num"/>
</include>
</if>
<if test="condition.name == 'moduleId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.module_id"/>
</include>
</if>
<if test="condition.name == 'createUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.create_User"/>
</include>
</if>
<if test="condition.name == 'updateUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.update_user"/>
</include>
</if>
<if test="condition.name == 'updateTime'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.update_time"/>
</include>
</if>
<if test="condition.name == 'createTime'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.create_time"/>
</include>
</if>
<if test="condition.name == 'tags'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.tags"/>
</include>
</if>
<if test="condition.name == 'reviewStatus'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>

View File

@ -1,6 +1,58 @@
<?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.system.mapper.BaseMapper">
<sql id="commonSystemFieldConditions">
<if test="condition.name == 'name'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.name"/>
</include>
</if>
<if test="condition.name == 'num'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.num"/>
</include>
</if>
<if test="condition.name == 'moduleId'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.module_id"/>
</include>
</if>
<if test="condition.name == 'createUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.create_User"/>
</include>
</if>
<if test="condition.name == 'updateUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.update_user"/>
</include>
</if>
<if test="condition.name == 'updateTime'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.update_time"/>
</include>
</if>
<if test="condition.name == 'createTime'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.create_time"/>
</include>
</if>
<if test="condition.name == 'tags'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.tags"/>
</include>
</if>
</sql>
<sql id="customFiledConditions">
<trim suffixOverrides="AND|OR">
<foreach collection="${conditions}" item="condition">