feat(功能用例): 评审详情页面高级搜索

--task=1016128 --user=陈建星 高级搜索-视图增删改查-后端 https://www.tapd.cn/55049933/s/1573254
This commit is contained in:
AgAngle 2024-09-06 22:03:25 +08:00 committed by jianxing
parent e3f971c17f
commit 3781f72523
7 changed files with 149 additions and 173 deletions

View File

@ -423,6 +423,7 @@
select api_id from api_definition_custom_field where select api_id from api_definition_custom_field where
<include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions"> <include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions">
<property name="conditions" value="${combineSearch}.customFiledConditions"/> <property name="conditions" value="${combineSearch}.customFiledConditions"/>
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include> </include>
) )
</if> </if>

View File

@ -7,6 +7,7 @@ import io.metersphere.functional.dto.ReviewFunctionalCaseDTO;
import io.metersphere.functional.request.BaseReviewCaseBatchRequest; import io.metersphere.functional.request.BaseReviewCaseBatchRequest;
import io.metersphere.functional.request.FunctionalCaseReviewListRequest; import io.metersphere.functional.request.FunctionalCaseReviewListRequest;
import io.metersphere.functional.request.ReviewFunctionalCasePageRequest; import io.metersphere.functional.request.ReviewFunctionalCasePageRequest;
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;
@ -15,13 +16,14 @@ import java.util.List;
* @author guoyuqi * @author guoyuqi
*/ */
public interface ExtCaseReviewFunctionalCaseMapper { public interface ExtCaseReviewFunctionalCaseMapper {
@BaseConditionFilter
List<FunctionalCaseReviewDTO> list(@Param("request") FunctionalCaseReviewListRequest request); List<FunctionalCaseReviewDTO> list(@Param("request") FunctionalCaseReviewListRequest request);
void updateStatus(@Param("caseId") String caseId, @Param("reviewId") String reviewId, @Param("status") String status); void updateStatus(@Param("caseId") String caseId, @Param("reviewId") String reviewId, @Param("status") String status);
List<String> getCaseIdsByReviewId(@Param("reviewId") String reviewId); List<String> getCaseIdsByReviewId(@Param("reviewId") String reviewId);
@BaseConditionFilter
List<ReviewFunctionalCaseDTO> page(@Param("request") ReviewFunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("userId") String userId, @Param("sort") String sort); List<ReviewFunctionalCaseDTO> page(@Param("request") ReviewFunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("userId") String userId, @Param("sort") String sort);
Long getPos(@Param("reviewId") String reviewId); Long getPos(@Param("reviewId") String reviewId);
@ -30,8 +32,10 @@ public interface ExtCaseReviewFunctionalCaseMapper {
Long getLastPos(@Param("reviewId") String reviewId, @Param("basePos") Long basePos); Long getLastPos(@Param("reviewId") String reviewId, @Param("basePos") Long basePos);
@BaseConditionFilter
List<String> getIds(@Param("request") BaseReviewCaseBatchRequest request, @Param("userId") String userId, @Param("deleted") boolean deleted); List<String> getIds(@Param("request") BaseReviewCaseBatchRequest request, @Param("userId") String userId, @Param("deleted") boolean deleted);
@BaseConditionFilter
List<CaseReviewFunctionalCase> getListByRequest(@Param("request") BaseReviewCaseBatchRequest request, @Param("userId") String userId, @Param("deleted") boolean deleted); List<CaseReviewFunctionalCase> getListByRequest(@Param("request") BaseReviewCaseBatchRequest request, @Param("userId") String userId, @Param("deleted") boolean deleted);
List<CaseReviewFunctionalCase> getList(@Param("reviewId") String reviewId, @Param("reviewIds") List<String> reviewIds, @Param("deleted") boolean deleted); List<CaseReviewFunctionalCase> getList(@Param("reviewId") String reviewId, @Param("reviewIds") List<String> reviewIds, @Param("deleted") boolean deleted);
@ -41,8 +45,10 @@ public interface ExtCaseReviewFunctionalCaseMapper {
List<CaseReviewFunctionalCase> getCaseIdsByIds(@Param("ids") List<String> ids); List<CaseReviewFunctionalCase> getCaseIdsByIds(@Param("ids") List<String> ids);
@BaseConditionFilter
List<FunctionalCaseModuleCountDTO> countModuleIdByRequest(@Param("request") ReviewFunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("userId") String userId); List<FunctionalCaseModuleCountDTO> countModuleIdByRequest(@Param("request") ReviewFunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("userId") String userId);
@BaseConditionFilter
long caseCount(@Param("request") ReviewFunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("userId") String userId); long caseCount(@Param("request") ReviewFunctionalCasePageRequest request, @Param("deleted") boolean deleted, @Param("userId") String userId);
} }

View File

@ -84,17 +84,10 @@
<include refid="filters"> <include refid="filters">
<property name="filter" value="request.filter"/> <property name="filter" value="request.filter"/>
</include> </include>
<choose>
<when test='request.searchMode == "AND"'> <include refid="combine">
AND <property name="combineSearch" value="request.combineSearch"/>
<include refid="queryCombine"/> </include>
</when>
<when test='request.searchMode == "OR"'>
and (
<include refid="queryCombine"/>
)
</when>
</choose>
</sql> </sql>
@ -145,121 +138,111 @@
</if> </if>
</sql> </sql>
<sql id="queryCombine">
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="searchMode" value="request.searchMode"/>
</include>
</if>
1=1
</sql>
<sql id="combine"> <sql id="combine">
<!-- 名称 --> <trim prefix="AND" suffixOverrides="AND|OR">
<if test='${condition}.name != null'> <if test="${combineSearch} != null">
functional_case.name <foreach collection="${combineSearch}.userViewConditions" item="condition">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <if test="condition.name == 'follower'">
<property name="object" value="${condition}.name"/> functional_case.id in (
</include> select case_id from functional_case_follower where
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- id -->
<if test='${condition}.id != null'>
functional_case.num
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.id"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 所属模块 -->
<if test='${condition}.moduleId != null'>
functional_case.moduleId
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.moduleId"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 创建人 -->
<if test='${condition}.createUser != null'>
functional_case.create_user
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.createUser"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 创建时间 -->
<if test='${condition}.createTime != null'>
functional_case.create_time
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.createTime"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 更新人 -->
<if test='${condition}.updateUser != null'>
functional_case.update_user
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.updateUser"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 更新时间 -->
<if test='${condition}.updateTime != null'>
functional_case.update_time
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="${condition}.updateTime"/>
</include>
<include refid="queryType">
<property name="searchMode" value="${searchMode}"/>
</include>
</if>
<!-- 标签 -->
<if test='${condition}.tags != null'>
<include refid="queryTag">
<property name="searchMode" value="${searchMode}"/>
<property name="combineTag" value="${condition}.tags"/>
</include>
</if>
<if test="${condition}.customs != null and ${condition}.customs.size() > 0">
<foreach collection="${condition}.customs" item="custom" separator="" open="" close="">
functional_case.id ${custom.operator} (
select case_id from functional_case_custom_field where field_id = #{custom.id}
<choose>
<when test="custom.type == 'List'">
and JSON_CONTAINS(`value`, json_array(#{custom.value}))
</when>
<when test="custom.type == 'date' or custom.type == 'datetime'">
and `value`
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="object" value="custom"/> <property name="condition" value="condition"/>
<property name="column" value="user_id"/>
</include> </include>
</when> )
<otherwise> </if>
and trim(both '"' from `value`) <include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${combineSearch}.searchMode"/>
</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.condition">
<property name="object" value="custom"/> <property name="condition" value="condition"/>
<property name="column" value="functional_case.name"/>
</include> </include>
</otherwise> </if>
</choose> <if test="condition.name == 'num'">
) <include refid="io.metersphere.system.mapper.BaseMapper.condition">
<include refid="queryType"> <property name="condition" value="condition"/>
<property name="searchMode" value="${searchMode}"/> <property name="column" value="functional_case.num"/>
</include> </include>
</foreach> </if>
</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 == '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 == 'createUser'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="crfc.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="crfc.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="crfc.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="crfc.create_time"/>
</include>
</if>
<if test="condition.name == 'status'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="crfc.status"/>
</include>
</if>
<if test="condition.name == 'demand'">
functional_case.id in (
select case_id from functional_case_demand where
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="demand_name"/>
</include>
)
</if>
<if test="condition.name == 'attachment'">
functional_case.id in (
select case_id from functional_case_attachment where
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="file_name"/>
</include>
)
</if>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include>
</foreach>
<if test="${combineSearch}.customFiledConditions.size() > 0">
functional_case.id in (
select case_id from functional_case_custom_field where
<include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions">
<property name="conditions" value="${combineSearch}.customFiledConditions"/>
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include>
)
</if>
</if>
</trim>
</sql> </sql>
<sql id="queryType"> <sql id="queryType">
@ -360,30 +343,11 @@
<include refid="filters"> <include refid="filters">
<property name="filter" value="request.condition.filter"/> <property name="filter" value="request.condition.filter"/>
</include> </include>
<choose> <include refid="combine">
<when test='request.condition.searchMode == "AND"'> <property name="combineSearch" value="request.condition.combineSearch"/>
AND </include>
<include refid="baseQueryCombine"/>
</when>
<when test='request.condition.searchMode == "OR"'>
and (
<include refid="baseQueryCombine"/>
)
</when>
</choose>
</sql> </sql>
<sql id="baseQueryCombine">
<if test="request.condition.combine != null">
<include refid="combine">
<property name="condition" value="request.condition.combine"/>
<property name="searchMode" value="request.condition.searchMode"/>
</include>
</if>
1=1
</sql>
<select id="getPos" resultType="java.lang.Long"> <select id="getPos" resultType="java.lang.Long">
SELECT pos SELECT pos
FROM case_review_functional_case FROM case_review_functional_case

View File

@ -342,6 +342,7 @@
select case_id from functional_case_custom_field where select case_id from functional_case_custom_field where
<include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions"> <include refid="io.metersphere.system.mapper.BaseMapper.customFiledConditions">
<property name="conditions" value="${combineSearch}.customFiledConditions"/> <property name="conditions" value="${combineSearch}.customFiledConditions"/>
<property name="searchMode" value="${combineSearch}.searchMode"/>
</include> </include>
) )
</if> </if>

View File

@ -10,6 +10,8 @@ import io.metersphere.functional.mapper.CaseReviewHistoryMapper;
import io.metersphere.functional.request.*; import io.metersphere.functional.request.*;
import io.metersphere.functional.service.CaseReviewFunctionalCaseService; import io.metersphere.functional.service.CaseReviewFunctionalCaseService;
import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.dto.CombineCondition;
import io.metersphere.sdk.dto.CombineSearch;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.base.BaseTest; import io.metersphere.system.base.BaseTest;
@ -94,17 +96,21 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
request.setCurrent(1); request.setCurrent(1);
request.setPageSize(10); request.setPageSize(10);
request.setReviewId("wx_review_id_1"); request.setReviewId("wx_review_id_1");
Map<String, Object> map = new HashMap<>(); request.setCombineSearch(getCustomCombineSearch());
map.put("customs", Arrays.asList(new LinkedHashMap() {{
put("id", "TEST_FIELD_ID");
put("operator", "in");
put("value", "222");
put("type", "List");
}}));
request.setCombine(map);
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request);
} }
private CombineSearch getCustomCombineSearch() {
CombineSearch combineSearch = new CombineSearch();
CombineCondition condition = new CombineCondition();
condition.setCustomField(true);
condition.setName("TEST_FIELD_ID");
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
condition.setValue(List.of("222"));
combineSearch.setConditions(List.of(condition));
return combineSearch;
}
@Test @Test
@Order(3) @Order(3)
@ -123,14 +129,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
this.requestPostWithOkAndReturn(REVIEW_CASE_PAGE, request); this.requestPostWithOkAndReturn(REVIEW_CASE_PAGE, request);
request.setReviewId("wx_review_id_1"); request.setReviewId("wx_review_id_1");
Map<String, Object> map = new HashMap<>(); request.setCombineSearch(getCustomCombineSearch());
map.put("customs", Arrays.asList(new LinkedHashMap() {{
put("id", "TEST_FIELD_ID");
put("operator", "in");
put("value", "222");
put("type", "List");
}}));
request.setCombine(map);
request.setViewFlag(true); request.setViewFlag(true);
request.setViewStatusFlag(true); request.setViewStatusFlag(true);
this.requestPostWithOkAndReturn(REVIEW_CASE_PAGE, request); this.requestPostWithOkAndReturn(REVIEW_CASE_PAGE, request);
@ -206,15 +205,8 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
request.setSelectIds(new ArrayList<>()); request.setSelectIds(new ArrayList<>());
request.setSelectAll(true); request.setSelectAll(true);
request.setExcludeIds(Arrays.asList("TEST_FUNCTIONAL_CASE_ID_1")); request.setExcludeIds(Arrays.asList("TEST_FUNCTIONAL_CASE_ID_1"));
Map<String, Object> map = new HashMap<>();
map.put("customs", Arrays.asList(new LinkedHashMap() {{
put("id", "TEST_FIELD_ID");
put("operator", "in");
put("value", "222");
put("type", "List");
}}));
BaseCondition baseCondition = new BaseCondition(); BaseCondition baseCondition = new BaseCondition();
baseCondition.setCombine(map); baseCondition.setCombineSearch(getCustomCombineSearch());
request.setCondition(baseCondition); request.setCondition(baseCondition);
this.requestPostWithOkAndReturn(BATCH_DELETE_URL, request); this.requestPostWithOkAndReturn(BATCH_DELETE_URL, request);

View File

@ -491,8 +491,8 @@ public class FunctionalCaseControllerTests extends BaseTest {
condition.setCustomField(true); condition.setCustomField(true);
condition.setName("TEST_FIELD_ID"); condition.setName("TEST_FIELD_ID");
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name()); condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
condition.setValue("222"); condition.setValue(List.of("222"));
combineSearch.setConditions(List.of()); combineSearch.setConditions(List.of(condition));
request.setCombineSearch(combineSearch); request.setCombineSearch(combineSearch);
MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_LIST_URL, request);
Pager<List<FunctionalCasePageDTO>> tableData = JSON.parseObject(JSON.toJSONString( Pager<List<FunctionalCasePageDTO>> tableData = JSON.parseObject(JSON.toJSONString(

View File

@ -65,7 +65,7 @@
</include> </include>
</trim> </trim>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType"> <include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="request.combineSearch.searchMode"/> <property name="searchMode" value="${searchMode}"/>
</include> </include>
</foreach> </foreach>
</trim> </trim>
@ -81,13 +81,25 @@
${column} not like CONCAT('%', #{condition.value},'%') ${column} not like CONCAT('%', #{condition.value},'%')
</when> </when>
<when test="${condition}.operator == 'IN'"> <when test="${condition}.operator == 'IN'">
${column} in <if test="'${column}' == 'value'">
`value`
</if>
<if test="'${column}' != 'value'">
${column}
</if>
in
<foreach collection="${condition}.value" item="v" separator="," open="(" close=")"> <foreach collection="${condition}.value" item="v" separator="," open="(" close=")">
#{v} #{v}
</foreach> </foreach>
</when> </when>
<when test="${condition}.operator == 'NOT_IN'"> <when test="${condition}.operator == 'NOT_IN'">
${column} not in <if test="'${column}' == 'value'">
`value`
</if>
<if test="'${column}' != 'value'">
${column}
</if>
not in
<foreach collection="${condition}.value" item="v" separator="," open="(" close=")"> <foreach collection="${condition}.value" item="v" separator="," open="(" close=")">
#{v} #{v}
</foreach> </foreach>