|
|
@@ -126,13 +126,13 @@ func HasRule(dbSchema string, scope string, domainName string, i *infrastructure
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func GetRulesAndFormConditionClause(dbSchema string, scope string, domainName string, i *infrastructure.Infrastructure) (clause.Clause, error) {
|
|
|
+func GetRulesAndFormConditionClause(dbSchema string, scope string, domainName string, i *infrastructure.Infrastructure, queryParams map[string]any) (clause.Clause, error) {
|
|
|
r, err := getRule(dbSchema, scope, domainName, i)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- c, err := formConditionClause(r)
|
|
|
+ c, err := formConditionClause(r, queryParams)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
@@ -160,56 +160,62 @@ func getRule(dbSchema string, scope string, domainName string, i *infrastructure
|
|
|
return *r, nil
|
|
|
}
|
|
|
|
|
|
-func formConditionClause(r Rule) (clause.Clause, error) {
|
|
|
+func formConditionClause(r Rule, queryParams map[string]any) (clause.Clause, error) {
|
|
|
+ ruleValue := r.Value
|
|
|
+ queryParamValue, ok := queryParams[r.ColumnName]
|
|
|
+ if ok {
|
|
|
+ ruleValue = queryParamValue
|
|
|
+ }
|
|
|
+
|
|
|
if strutils.IsStringEmpty(r.LogicalOperator) {
|
|
|
conditions := clause.NewConditions()
|
|
|
|
|
|
switch r.Operator {
|
|
|
case opEqual:
|
|
|
- conditions.Equal(r.ColumnName, r.Value)
|
|
|
+ conditions.Equal(r.ColumnName, ruleValue)
|
|
|
case opNotEqual:
|
|
|
- conditions.Not(r.ColumnName, r.Value)
|
|
|
+ conditions.Not(r.ColumnName, ruleValue)
|
|
|
case opLessThan:
|
|
|
- conditions.LessThan(r.ColumnName, r.Value)
|
|
|
+ conditions.LessThan(r.ColumnName, ruleValue)
|
|
|
case opLessThanOrEqual:
|
|
|
- conditions.LessThanAndEqual(r.ColumnName, r.Value)
|
|
|
+ conditions.LessThanAndEqual(r.ColumnName, ruleValue)
|
|
|
case opGreaterThan:
|
|
|
- conditions.GreaterThan(r.ColumnName, r.Value)
|
|
|
+ conditions.GreaterThan(r.ColumnName, ruleValue)
|
|
|
case opGreaterThanOrEqual:
|
|
|
- conditions.GreaterThanAndEqual(r.ColumnName, r.Value)
|
|
|
+ conditions.GreaterThanAndEqual(r.ColumnName, ruleValue)
|
|
|
case opIn:
|
|
|
- if reflect.TypeOf(r.Value).Kind() != reflect.Slice {
|
|
|
+ if reflect.TypeOf(ruleValue).Kind() != reflect.Slice {
|
|
|
return nil, errors.New("使用\"包含在列表\"操作符必须使用列表")
|
|
|
}
|
|
|
|
|
|
- conditions.In(r.FieldName, r.Value)
|
|
|
+ conditions.In(r.ColumnName, ruleValue)
|
|
|
case opNotIn:
|
|
|
- if reflect.TypeOf(r.Value).Kind() != reflect.Slice {
|
|
|
+ if reflect.TypeOf(ruleValue).Kind() != reflect.Slice {
|
|
|
return nil, errors.New("使用\"不包含在列表\"操作符必须使用列表")
|
|
|
}
|
|
|
|
|
|
- conditions.NotIn(r.FieldName, r.Value)
|
|
|
+ conditions.NotIn(r.ColumnName, ruleValue)
|
|
|
case opPrefix:
|
|
|
- strValue, err := reflectutils.ToString(r.Value)
|
|
|
+ strValue, err := reflectutils.ToString(ruleValue)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- conditions.Like(r.FieldName, strValue+"%")
|
|
|
+ conditions.Like(r.ColumnName, strValue+"%")
|
|
|
case opSuffix:
|
|
|
- strValue, err := reflectutils.ToString(r.Value)
|
|
|
+ strValue, err := reflectutils.ToString(ruleValue)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- conditions.Like(r.FieldName, "%"+strValue)
|
|
|
+ conditions.Like(r.ColumnName, "%"+strValue)
|
|
|
case opContains:
|
|
|
- strValue, err := reflectutils.ToString(r.Value)
|
|
|
+ strValue, err := reflectutils.ToString(ruleValue)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- conditions.Like(r.FieldName, "%"+strValue+"%")
|
|
|
+ conditions.Like(r.ColumnName, "%"+strValue+"%")
|
|
|
default:
|
|
|
return nil, errors.Errorf("不支持的操作符%v", r.Operator)
|
|
|
}
|
|
|
@@ -217,12 +223,12 @@ func formConditionClause(r Rule) (clause.Clause, error) {
|
|
|
return conditions.And(), nil
|
|
|
}
|
|
|
|
|
|
- leftClause, err := formConditionClause(*r.Left)
|
|
|
+ leftClause, err := formConditionClause(*r.Left, queryParams)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- rightClause, err := formConditionClause(*r.Right)
|
|
|
+ rightClause, err := formConditionClause(*r.Right, queryParams)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|