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 @Valid
private CombineSearch combineSearch; private CombineSearch combineSearch;
/** @Deprecated
* todo 删除
*/
private String searchMode = "AND"; private String searchMode = "AND";
/** @Deprecated
* todo 删除
*/
private Map<String, Object> combine; private Map<String, Object> combine;
// 转JSON时会调用 前台数据传过来时可以顺便处理掉转义字符 // 转JSON时会调用 前台数据传过来时可以顺便处理掉转义字符

View File

@ -22,10 +22,6 @@ public class CombineSearch {
@Valid @Valid
private List<CombineCondition> conditions; private List<CombineCondition> conditions;
public List<CombineCondition> getConditions() {
return conditions;
}
public String getSearchMode() { public String getSearchMode() {
return StringUtils.isBlank(searchMode) ? SearchMode.AND.name() : searchMode; 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.project.dto.NodeSortQueryParam;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.interceptor.BaseConditionFilter;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
public interface ExtApiDefinitionMapper { public interface ExtApiDefinitionMapper {
void deleteApiToGc(@Param("ids") List<String> ids, @Param("userId") String userId, @Param("time") long time); void deleteApiToGc(@Param("ids") List<String> ids, @Param("userId") String userId, @Param("time") long time);
@BaseConditionFilter
List<ApiDefinitionDTO> list(@Param("request") ApiDefinitionPageRequest request); List<ApiDefinitionDTO> list(@Param("request") ApiDefinitionPageRequest request);
@BaseConditionFilter
List<ApiDefinitionDTO> listDoc(@Param("request") ApiDefinitionDocRequest request); List<ApiDefinitionDTO> listDoc(@Param("request") ApiDefinitionDocRequest request);
List<ApiTestCase> selectNotInTrashCaseIdsByApiIds(@Param("apiIds") List<String> apiIds); List<ApiTestCase> selectNotInTrashCaseIdsByApiIds(@Param("apiIds") List<String> apiIds);
Long getPos(@Param("projectId") String projectId); 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); 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> 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); 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); List<ApiDefinitionVersionDTO> getApiDefinitionByRefId(@Param("refId") String refId);
@BaseConditionFilter
void batchMove(@Param("request") ApiDefinitionBatchMoveRequest request, @Param("ids") List<String> ids, @Param("userId") String userId); 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); 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); void updateLatestVersion(@Param("id") String id, @Param("projectId") String projectId);
@BaseConditionFilter
List<ApiDefinitionDetail> importList(@Param("request") ApiDefinitionPageRequest request); List<ApiDefinitionDetail> importList(@Param("request") ApiDefinitionPageRequest request);
List<String> selectIdsByIdsAndDeleted(@Param("ids") List<String> ids, @Param("deleted") boolean deleted); List<String> selectIdsByIdsAndDeleted(@Param("ids") List<String> ids, @Param("deleted") boolean deleted);

View File

@ -279,13 +279,9 @@
<property name="filter" value="request.filter"/> <property name="filter" value="request.filter"/>
</include> </include>
<if test="request.combine != null and request.combine != ''">
<include refid="combine"> <include refid="combine">
<property name="condition" value="request.combine"/> <property name="combineSearch" value="request.combineSearch"/>
<property name="name" value="request.name"/>
<property name="ObjectTags" value="request.combine.tags"/>
</include> </include>
</if>
<include refid="queryVersionCondition"> <include refid="queryVersionCondition">
<property name="versionTable" value="api_definition"/> <property name="versionTable" value="api_definition"/>
@ -367,108 +363,71 @@
</sql> </sql>
<sql id="combine"> <sql id="combine">
-- todo 待修改 <trim prefix="AND" suffixOverrides="AND|OR">
<!-- <if test='${condition}.name != null and (${name} == null or ${name} == "")'>--> <if test="${combineSearch} != null">
<!-- and api_definition.name--> <foreach collection="${combineSearch}.userViewConditions" item="condition">
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> <if test="condition.name == 'createUser'">
<!-- <property name="object" value="${condition}.name"/>--> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<!-- </include>--> <property name="condition" value="condition"/>
<!-- </if>--> <property name="column" value="api_definition.create_user"/>
</include>
<!-- <if test='${condition}.id != null'>--> </if>
<!-- and api_definition.num--> <if test="condition.name == 'follower'">
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> api_definition.id in (
<!-- <property name="object" value="${condition}.id"/>--> select api_definition_id from api_definition_follower where
<!-- </include>--> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<!-- </if>--> <property name="condition" value="condition"/>
<property name="column" value="user_id"/>
<!-- <if test="${condition}.updateTime != null">--> </include>
<!-- and api_definition.update_time--> )
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> </if>
<!-- <property name="object" value="${condition}.updateTime"/>--> <include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<!-- </include>--> <property name="searchMode" value="${combineSearch}.searchMode"/>
<!-- </if>--> </include>
</foreach>
<!-- <if test="${condition}.createTime != null">--> <foreach collection="${combineSearch}.systemFieldConditions" item="condition">
<!-- and api_definition.create_time--> <include refid="io.metersphere.system.mapper.BaseMapper.commonSystemFieldConditions">
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> <property name="condition" value="condition"/>
<!-- <property name="object" value="${condition}.createTime"/>--> <property name="tablePrefix" value="api_definition"/>
<!-- </include>--> </include>
<!-- </if>--> <if test="condition.name == 'protocol'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<!-- <if test="${condition}.status != null">--> <property name="condition" value="condition"/>
<!-- and api_definition.status--> <property name="column" value="api_definition.protocol"/>
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> </include>
<!-- <property name="object" value="${condition}.status"/>--> </if>
<!-- </include>--> <if test="condition.name == 'status'">
<!-- </if>--> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<!-- <if test="${condition}.path != null">--> <property name="column" value="api_definition.status"/>
<!-- and api_definition.path--> </include>
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> </if>
<!-- <property name="object" value="${condition}.path"/>--> <if test="condition.name == 'method'">
<!-- </include>--> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<!-- </if>--> <property name="condition" value="condition"/>
<property name="column" value="api_definition.method"/>
<!-- <if test="${condition}.method != null">--> </include>
<!-- and api_definition.method--> </if>
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> <if test="condition.name == 'path'">
<!-- <property name="object" value="${condition}.method"/>--> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<!-- </include>--> <property name="condition" value="condition"/>
<!-- </if>--> <property name="column" value="api_definition.path"/>
</include>
<!-- <if test='${condition}.tags != null and ${ObjectTags}.operator == "not like"'>--> </if>
<!-- and (api_definition.tags is null or api_definition.tags--> <include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> <property name="searchMode" value="${combineSearch}.searchMode"/>
<!-- <property name="object" value="${condition}.tags"/>--> </include>
<!-- </include>--> </foreach>
<!-- )--> <if test="${combineSearch}.customFiledConditions.size() > 0">
<!-- </if>--> api_definition.id in (
select api_id from api_definition_custom_field where
<!-- <if test='${condition}.tags != null and ${ObjectTags}.operator == "like"'>--> <include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions">
<!-- and api_definition.tags--> <property name="conditions" value="${combineSearch}.customFiledConditions"/>
<!-- <include refid="io.metersphere.system.mapper.BaseMapper.condition">--> </include>
<!-- <property name="object" value="${condition}.tags"/>--> )
<!-- </include>--> </if>
<!-- </if>--> </if>
</trim>
<!-- <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>-->
</sql> </sql>
<sql id="queryVersionCondition"> <sql id="queryVersionCondition">
@ -492,11 +451,9 @@
</sql> </sql>
<sql id="queryWhereConditionByBaseQueryRequest"> <sql id="queryWhereConditionByBaseQueryRequest">
<if test="request.condition.combine != null">
<include refid="combine"> <include refid="combine">
<property name="condition" value="request.condition.combine"/> <property name="combineSearch" value="request.condition.combineSearch"/>
</include> </include>
</if>
<if test="request.condition.keyword != null"> <if test="request.condition.keyword != null">
and ( and (
api_definition.num like concat('%', #{request.condition.keyword},'%') 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.mapper.ProjectMapper;
import io.metersphere.project.service.FileAssociationService; import io.metersphere.project.service.FileAssociationService;
import io.metersphere.sdk.constants.*; 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.exception.MSException;
import io.metersphere.sdk.file.FileCenter; import io.metersphere.sdk.file.FileCenter;
import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
@ -988,10 +990,17 @@ public class ApiDefinitionControllerTests extends BaseTest {
filters.put("version_id", List.of("1005704995741369851")); filters.put("version_id", List.of("1005704995741369851"));
request.setFilter(filters); request.setFilter(filters);
Map<String, Object> map = new HashMap<>(); CombineSearch combineSearch = new CombineSearch();
map.put("name", Map.of("operator", "like", "value", "test-1")); CombineCondition condition = new CombineCondition();
map.put("method", Map.of("operator", "in", "value", Arrays.asList("GET", "POST"))); condition.setName("name");
request.setCombine(map); 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) { private void configureKeywordSearch(ApiDefinitionPageRequest request) {
@ -1011,26 +1020,30 @@ public class ApiDefinitionControllerTests extends BaseTest {
} }
private void configureCombineSearch(ApiDefinitionPageRequest request) { private void configureCombineSearch(ApiDefinitionPageRequest request) {
Map<String, Object> map = new HashMap<>(); CombineSearch combineSearch = new CombineSearch();
map.put("name", Map.of("operator", "like", "value", "test")); CombineCondition condition = new CombineCondition();
map.put("method", Map.of("operator", "in", "value", Arrays.asList("GET", "POST"))); condition.setName("name");
map.put("createUser", Map.of("operator", "current user", "value", StringUtils.EMPTY)); condition.setOperator(CombineCondition.CombineConditionOperator.CONTAINS.name());
List<Map<String, Object>> customs = new ArrayList<>(); condition.setValue("test");
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);
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) { private void configureDeleteSearch(ApiDefinitionPageRequest request) {

View File

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

View File

@ -1,6 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!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"> <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"> <sql id="customFiledConditions">
<trim suffixOverrides="AND|OR"> <trim suffixOverrides="AND|OR">
<foreach collection="${conditions}" item="condition"> <foreach collection="${conditions}" item="condition">