fxi(功能用例): 自定义字段高级搜索结果有误

--task=1016128 --user=陈建星 高级搜索-视图增删改查-后端 https://www.tapd.cn/55049933/s/1573254
This commit is contained in:
AgAngle 2024-09-10 14:40:06 +08:00 committed by Craftsman
parent 72bc243cea
commit 7ed7a70e84
5 changed files with 77 additions and 10 deletions

View File

@ -27,12 +27,21 @@ public class CombineCondition {
@NotNull @NotNull
private Boolean customField = false; private Boolean customField = false;
@Schema(description = "自定义字段的类型")
private String customFieldType;
@Schema(description = "操作符", @Schema(description = "操作符",
allowableValues = {"IN", "NOT_IN", "BETWEEN", "GT", "LT", "COUNT_GT", "COUNT_LT", "EQUALS", "NOT_EQUALS", "CONTAINS", "NOT_CONTAINS", "EMPTY", "NOT_EMPTY"}) allowableValues = {"IN", "NOT_IN", "BETWEEN", "GT", "LT", "COUNT_GT", "COUNT_LT", "EQUALS", "NOT_EQUALS", "CONTAINS", "NOT_CONTAINS", "EMPTY", "NOT_EMPTY"})
@EnumValue(enumClass = CombineConditionOperator.class) @EnumValue(enumClass = CombineConditionOperator.class)
private String operator; private String operator;
public boolean valid() { public boolean valid() {
if (StringUtils.isBlank(name) || StringUtils.isBlank(operator)) {
return false;
}
if (StringUtils.equalsAny(operator, CombineConditionOperator.EMPTY.name(), CombineConditionOperator.NOT_EMPTY.name())) {
return true;
}
if (value == null) { if (value == null) {
return false; return false;
} }
@ -42,7 +51,7 @@ public class CombineCondition {
if (value instanceof String valueStr && StringUtils.isBlank(valueStr)) { if (value instanceof String valueStr && StringUtils.isBlank(valueStr)) {
return false; return false;
} }
return StringUtils.isNotBlank(name) && StringUtils.isNotBlank(operator); return true;
} }
public enum CombineConditionOperator { public enum CombineConditionOperator {

View File

@ -315,6 +315,12 @@
<property name="column" value="functional_case.review_status"/> <property name="column" value="functional_case.review_status"/>
</include> </include>
</if> </if>
<if test="condition.name == 'lastExecuteResult'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="functional_case.last_execute_result"/>
</include>
</if>
<if test="condition.name == 'demand'"> <if test="condition.name == 'demand'">
functional_case.id in ( functional_case.id in (
select case_id from functional_case_demand where select case_id from functional_case_demand where

View File

@ -46,7 +46,7 @@
</include> </include>
</if> </if>
<if test="condition.name == 'tags'"> <if test="condition.name == 'tags'">
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <include refid="io.metersphere.system.mapper.BaseMapper.arrayValueCondition">
<property name="condition" value="condition"/> <property name="condition" value="condition"/>
<property name="column" value="${tablePrefix}.tags"/> <property name="column" value="${tablePrefix}.tags"/>
</include> </include>
@ -59,10 +59,20 @@
<trim prefix="(" suffix=")"> <trim prefix="(" suffix=")">
field_id = #{condition.name} field_id = #{condition.name}
and and
<include refid="io.metersphere.system.mapper.BaseMapper.condition"> <choose>
<property name="condition" value="condition"/> <when test="condition.customFieldType != null and (condition.customFieldType == 'MULTIPLE_SELECT' or condition.customFieldType == 'MULTIPLE_SELECT' or condition.customFieldType == 'MULTIPLE_INPUT')">
<property name="column" value="value"/> <include refid="io.metersphere.system.mapper.BaseMapper.arrayValueCondition">
</include> <property name="condition" value="condition"/>
<property name="column" value="value"/>
</include>
</when>
<otherwise>
<include refid="io.metersphere.system.mapper.BaseMapper.condition">
<property name="condition" value="condition"/>
<property name="column" value="value"/>
</include>
</otherwise>
</choose>
</trim> </trim>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType"> <include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${searchMode}"/> <property name="searchMode" value="${searchMode}"/>
@ -71,6 +81,48 @@
</trim> </trim>
</sql> </sql>
<sql id="arrayValueCondition">
<trim prefix="(" suffix=")">
<choose>
<when test="${condition}.operator == 'CONTAINS'">
<foreach collection="${condition}.value" item="tag" separator="or" open="(" close=")">
JSON_CONTAINS(${column}, JSON_ARRAY(#{tag}))
</foreach>
</when>
<when test="${condition}.operator == 'IN'">
<foreach collection="${condition}.value" item="tag" separator="or" open="(" close=")">
JSON_CONTAINS(${column}, JSON_ARRAY(#{tag}))
</foreach>
</when>
<when test="${condition}.operator == 'NOT_CONTAINS'">
${column} is null or ${column} = '[]' or
<foreach collection="${condition}.value" item="tag" separator="and" open="(" close=")">
!JSON_CONTAINS(${column}, JSON_ARRAY(#{tag}))
</foreach>
</when>
<when test="${condition}.operator == 'NOT_IN'">
${column} is null or ${column} = '[]' or
<foreach collection="${condition}.value" item="tag" separator="and" open="(" close=")">
!JSON_CONTAINS(${column}, JSON_ARRAY(#{tag}))
</foreach>
</when>
<when test="${condition}.operator == 'COUNT_GT'">
JSON_LENGTH(${column}) &gt; #{condition.value}
</when>
<when test="${condition}.operator == 'COUNT_LT'">
${column} is null or ${column} = '[]' or
JSON_LENGTH(${column}) &lt; #{condition.value}
</when>
<when test="${condition}.operator == 'EMPTY'">
${column} is null or ${column} = '[]'
</when>
<when test="${condition}.operator == 'NOT_EMPTY'">
${column} is not null and ${column} = '[]'
</when>
</choose>
</trim>
</sql>
<sql id="condition"> <sql id="condition">
<trim prefix="(" suffix=")"> <trim prefix="(" suffix=")">
<choose> <choose>
@ -120,10 +172,10 @@
JSON_LENGTH(${column}) &lt; #{condition.value} JSON_LENGTH(${column}) &lt; #{condition.value}
</when> </when>
<when test="${condition}.operator == 'EMPTY'"> <when test="${condition}.operator == 'EMPTY'">
${column} is null or ${column} #{condition.value} = '' ${column} is null or ${column} = ''
</when> </when>
<when test="${condition}.operator == 'NOT_EMPTY'"> <when test="${condition}.operator == 'NOT_EMPTY'">
${column} is not null and ${column} #{condition.value} = '' ${column} is not null and ${column} != ''
</when> </when>
<when test="${condition}.operator == 'EQUALS'"> <when test="${condition}.operator == 'EQUALS'">
${column} = #{condition.value} ${column} = #{condition.value}

View File

@ -279,7 +279,7 @@ public class UserViewService {
.andScopeIdEqualTo(scopeId) .andScopeIdEqualTo(scopeId)
.andViewTypeEqualTo(viewType.name()); .andViewTypeEqualTo(viewType.name());
List<UserView> customUserViews = userViewMapper.selectByExample(example).stream() List<UserView> customUserViews = userViewMapper.selectByExample(example).stream()
.sorted(Comparator.comparing(UserView::getPos)) .sorted((a, b) -> Comparator.comparing(UserView::getPos).compare(b, a))
.collect(Collectors.toList()); .collect(Collectors.toList());
UserViewListGroupedDTO groupedDTO = new UserViewListGroupedDTO(); UserViewListGroupedDTO groupedDTO = new UserViewListGroupedDTO();

View File

@ -181,7 +181,7 @@ public class UserViewControllerTests extends BaseTest {
UserViewListGroupedDTO result = getResultData(mvcResult, UserViewListGroupedDTO.class); UserViewListGroupedDTO result = getResultData(mvcResult, UserViewListGroupedDTO.class);
Assertions.assertEquals(result.getInternalViews().size(), 3); Assertions.assertEquals(result.getInternalViews().size(), 3);
Assertions.assertEquals(result.getCustomViews().size(), 2); Assertions.assertEquals(result.getCustomViews().size(), 2);
Assertions.assertEquals(result.getCustomViews().get(0), BeanUtils.copyBean(new UserView(), addUserViewDTO)); Assertions.assertEquals(result.getCustomViews().getLast(), BeanUtils.copyBean(new UserView(), addUserViewDTO));
} }
@Test @Test