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

View File

@ -315,6 +315,12 @@
<property name="column" value="functional_case.review_status"/>
</include>
</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'">
functional_case.id in (
select case_id from functional_case_demand where

View File

@ -46,7 +46,7 @@
</include>
</if>
<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="column" value="${tablePrefix}.tags"/>
</include>
@ -59,10 +59,20 @@
<trim prefix="(" suffix=")">
field_id = #{condition.name}
and
<choose>
<when test="condition.customFieldType != null and (condition.customFieldType == 'MULTIPLE_SELECT' or condition.customFieldType == 'MULTIPLE_SELECT' or condition.customFieldType == 'MULTIPLE_INPUT')">
<include refid="io.metersphere.system.mapper.BaseMapper.arrayValueCondition">
<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>
<include refid="io.metersphere.system.mapper.BaseMapper.queryType">
<property name="searchMode" value="${searchMode}"/>
@ -71,6 +81,48 @@
</trim>
</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">
<trim prefix="(" suffix=")">
<choose>
@ -120,10 +172,10 @@
JSON_LENGTH(${column}) &lt; #{condition.value}
</when>
<when test="${condition}.operator == 'EMPTY'">
${column} is null or ${column} #{condition.value} = ''
${column} is null or ${column} = ''
</when>
<when test="${condition}.operator == 'NOT_EMPTY'">
${column} is not null and ${column} #{condition.value} = ''
${column} is not null and ${column} != ''
</when>
<when test="${condition}.operator == 'EQUALS'">
${column} = #{condition.value}

View File

@ -279,7 +279,7 @@ public class UserViewService {
.andScopeIdEqualTo(scopeId)
.andViewTypeEqualTo(viewType.name());
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());
UserViewListGroupedDTO groupedDTO = new UserViewListGroupedDTO();

View File

@ -181,7 +181,7 @@ public class UserViewControllerTests extends BaseTest {
UserViewListGroupedDTO result = getResultData(mvcResult, UserViewListGroupedDTO.class);
Assertions.assertEquals(result.getInternalViews().size(), 3);
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