package managesdk type QueryOperator string const ( OperatorEqual QueryOperator = "=" OperatorNotEqual QueryOperator = "!=" OperatorGreaterThan QueryOperator = ">" OperatorGreaterEqual QueryOperator = ">=" OperatorLessThan QueryOperator = "<" OperatorLessEqual QueryOperator = "<=" OperatorLike QueryOperator = "like" OperatorNotLike QueryOperator = "not_like" OperatorStartsWith QueryOperator = "starts_with" OperatorEndsWith QueryOperator = "ends_with" OperatorIsNull QueryOperator = "is_null" OperatorIsNotNull QueryOperator = "is_not_null" OperatorIn QueryOperator = "in" OperatorNotIn QueryOperator = "not_in" ) type QueryOperatorInfo struct { Name string `json:"name"` Value QueryOperator `json:"value"` } func GetQueryOperators() []QueryOperatorInfo { return []QueryOperatorInfo{ {Name: "等于", Value: OperatorEqual}, {Name: "不等于", Value: OperatorNotEqual}, {Name: "大于", Value: OperatorGreaterThan}, {Name: "大于等于", Value: OperatorGreaterEqual}, {Name: "小于", Value: OperatorLessThan}, {Name: "小于等于", Value: OperatorLessEqual}, {Name: "模糊匹配", Value: OperatorLike}, {Name: "不模糊匹配", Value: OperatorNotLike}, {Name: "开头是", Value: OperatorStartsWith}, {Name: "结尾是", Value: OperatorEndsWith}, {Name: "为空", Value: OperatorIsNull}, {Name: "不为空", Value: OperatorIsNotNull}, {Name: "在列表中", Value: OperatorIn}, {Name: "不在列表中", Value: OperatorNotIn}, } } func StringToQueryOperator(op string) QueryOperator { switch op { case "eq", "=", "等于": return OperatorEqual case "ne", "!=", "不等于": return OperatorNotEqual case "gt", ">", "大于": return OperatorGreaterThan case "gte", ">=", "大于等于": return OperatorGreaterEqual case "lt", "<", "小于": return OperatorLessThan case "lte", "<=", "小于等于": return OperatorLessEqual case "like", "模糊匹配": return OperatorLike case "not_like", "不模糊匹配": return OperatorNotLike case "starts_with", "开头是": return OperatorStartsWith case "ends_with", "结尾是": return OperatorEndsWith case "is_null", "为空": return OperatorIsNull case "is_not_null", "不为空": return OperatorIsNotNull case "in", "在列表中": return OperatorIn case "not_in", "不在列表中": return OperatorNotIn default: return OperatorEqual } } type LogicOperator string const ( LogicAnd LogicOperator = "AND" LogicOr LogicOperator = "OR" ) type QueryCondition struct { Field string `json:"field"` Operator QueryOperator `json:"operator"` Value any `json:"value,omitempty"` } type ConditionGroup struct { Conditions []ConditionItem `json:"conditions"` Logic LogicOperator `json:"logic"` } type ConditionItem struct { Condition *ConditionGroup `json:"condition,omitempty"` SingleCondition *QueryCondition `json:"singleCondition,omitempty"` } type AdvancedQueryParams struct { ConditionGroups []ConditionGroup `json:"conditionGroups"` GroupLogic LogicOperator `json:"groupLogic"` } type AdvancedQueryRequest struct { AdvancedQuery *AdvancedQueryParams `json:"advancedQuery,omitempty"` BaseQueryParams } func NewConditionGroup(logic LogicOperator, conditions ...ConditionItem) ConditionGroup { return ConditionGroup{ Logic: logic, Conditions: conditions, } } func NewSingleCondition(field string, operator QueryOperator, value any) ConditionItem { return ConditionItem{ SingleCondition: &QueryCondition{ Field: field, Operator: operator, Value: value, }, } } func NewNestedConditionGroup(group ConditionGroup) ConditionItem { return ConditionItem{ Condition: &group, } } func NewAdvancedQueryParams(groupLogic LogicOperator, groups ...ConditionGroup) *AdvancedQueryParams { return &AdvancedQueryParams{ GroupLogic: groupLogic, ConditionGroups: groups, } } func Equal(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorEqual, value) } func NotEqual(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorNotEqual, value) } func GreaterThan(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorGreaterThan, value) } func GreaterEqual(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorGreaterEqual, value) } func LessThan(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorLessThan, value) } func LessEqual(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorLessEqual, value) } func Like(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorLike, value) } func NotLike(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorNotLike, value) } func StartsWith(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorStartsWith, value) } func EndsWith(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorEndsWith, value) } func IsNull(field string) ConditionItem { return NewSingleCondition(field, OperatorIsNull, nil) } func IsNotNull(field string) ConditionItem { return NewSingleCondition(field, OperatorIsNotNull, nil) } func In(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorIn, value) } func NotIn(field string, value any) ConditionItem { return NewSingleCondition(field, OperatorNotIn, value) } func AndGroup(conditions ...ConditionItem) ConditionGroup { return NewConditionGroup(LogicAnd, conditions...) } func OrGroup(conditions ...ConditionItem) ConditionGroup { return NewConditionGroup(LogicOr, conditions...) } func AndQuery(groups ...ConditionGroup) *AdvancedQueryParams { return NewAdvancedQueryParams(LogicAnd, groups...) } func OrQuery(groups ...ConditionGroup) *AdvancedQueryParams { return NewAdvancedQueryParams(LogicOr, groups...) }