feat(用例管理): 高级搜索数据结构

--task=1016127 --user=陈建星 高级搜索-高级搜索数据结构设计-后端 https://www.tapd.cn/55049933/s/1570894
This commit is contained in:
AgAngle 2024-08-30 13:47:01 +08:00 committed by jianxing
parent 65c99f96fc
commit 185d45920a
3 changed files with 146 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package io.metersphere.system.dto.sdk;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@ -12,13 +13,20 @@ public class BaseCondition {
@Schema(description = "关键字")
private String keyword;
@Schema(description = "匹配模式 所有/任一", allowableValues = {"AND", "OR"})
private String searchMode = "AND";
@Schema(description = "过滤字段")
private Map<String, List<String>> filter;
@Schema(description = "高级搜索")
@Valid
private CombineSearch combineSearch;
/**
* todo 删除
*/
private String searchMode = "AND";
/**
* todo 删除
*/
private Map<String, Object> combine;
// 转JSON时会调用 前台数据传过来时可以顺便处理掉转义字符

View File

@ -0,0 +1,80 @@
package io.metersphere.system.dto.sdk;
import io.metersphere.system.valid.EnumValue;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
/**
* @Author: jianxing
* @CreateTime: 2024-08-28 17:31
*/
@Data
public class CombineCondition {
@Schema(description = "参数key")
private String key;
@Schema(description = "期望值, BETWEEN,IN,NOT_IN 时为数组, 其他为单值")
private Object value;
@Schema(description = "操作符",
allowableValues = {"IN", "NOT_IN", "BETWEEN", "GT", "LT", "EQUALS", "NOT_EQUALS", "CONTAINS", "NOT_CONTAINS", "EMPTY", "NOT_EMPTY", "CURRENT_USER"})
@EnumValue(enumClass = CombineConditionOperator.class)
private String operator;
public boolean valid() {
return StringUtils.isNotBlank(key) && StringUtils.isNotBlank(operator) && value != null;
}
public enum CombineConditionOperator {
/**
* 属于
*/
IN,
/**
* 不属于
*/
NOT_IN,
/**
* 区间
*/
BETWEEN,
/**
* 大于
*/
GT,
/**
* 小于
*/
LT,
/**
* 等于
*/
EQUALS,
/**
* 不等于
*/
NOT_EQUALS,
/**
* 包含
*/
CONTAINS,
/**
* 不包含
*/
NOT_CONTAINS,
/**
* 为空
*/
EMPTY,
/**
* 不为空
*/
NOT_EMPTY,
/**
* 当前用户
*/
CURRENT_USER
}
}

View File

@ -0,0 +1,55 @@
package io.metersphere.system.dto.sdk;
import io.metersphere.system.valid.EnumValue;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
/**
* @Author: jianxing
* @CreateTime: 2024-08-28 17:31
*/
@Data
public class CombineSearch {
@Schema(description = "匹配模式 所有/任一", allowableValues = {"AND", "OR"})
@EnumValue(enumClass = SearchMode.class)
private String searchMode = SearchMode.AND.name();
@Schema(description = "筛选条件")
@Valid
private List<CombineCondition> conditions;
@Schema(description = "自定义字段筛选条件")
@Valid
private List<CombineCondition> customFileConditions;
public List<CombineCondition> getValidConditions(List<CombineCondition> conditions) {
return conditions.stream().filter(CombineCondition::valid).toList();
}
public List<CombineCondition> getConditions() {
return getValidConditions(conditions);
}
public List<CombineCondition> getCustomFileConditions() {
return getValidConditions(customFileConditions);
}
public String getSearchMode() {
return StringUtils.isBlank(searchMode) ? SearchMode.AND.name() : searchMode;
}
public enum SearchMode {
/**
* 所有
*/
AND,
/**
* 任一
*/
OR
}
}