|
|
@@ -100,21 +100,6 @@ func (r Rule) checkAsLeaf() error {
|
|
|
return errors.New("操作符不支持")
|
|
|
}
|
|
|
|
|
|
- if r.Value == nil {
|
|
|
- switch r.FieldType {
|
|
|
- case rule.TypeString:
|
|
|
- r.Value = ""
|
|
|
- case rule.TypeTime:
|
|
|
- r.Value = ""
|
|
|
- case rule.TypeNumber:
|
|
|
- r.Value = 0
|
|
|
- case rule.TypeBool:
|
|
|
- r.Value = false
|
|
|
- default:
|
|
|
- return errors.New("字段类型不支持")
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -137,6 +122,16 @@ func HasRule(dbSchema string, scope string, domainName string, i *infrastructure
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+// GetRulesAndFormConditionClause 获取规则并返回条件语句
|
|
|
+// 参数:
|
|
|
+// - dbSchema: 数据库schema
|
|
|
+// - scope: 范围
|
|
|
+// - domainName: 领域名称
|
|
|
+// - i: 基础设施
|
|
|
+// - ruleParams: 规则参数
|
|
|
+// 返回值:
|
|
|
+// - 语句接口,当错误为nil时,语句接口也可能是nil,代表该规则并没有被赋值,所以是没有条件的
|
|
|
+// - 错误
|
|
|
func GetRulesAndFormConditionClause(dbSchema string, scope string, domainName string, i *infrastructure.Infrastructure, ruleParams map[string]any) (clause.Clause, error) {
|
|
|
r, err := getRule(dbSchema, scope, domainName, i)
|
|
|
if err != nil {
|
|
|
@@ -172,13 +167,17 @@ func getRule(dbSchema string, scope string, domainName string, i *infrastructure
|
|
|
}
|
|
|
|
|
|
func formConditionClause(r Rule, ruleParams map[string]any) (clause.Clause, error) {
|
|
|
- ruleValue := r.Value
|
|
|
- ruleParamValue, ok := ruleParams[r.ColumnName]
|
|
|
- if ok {
|
|
|
- ruleValue = ruleParamValue
|
|
|
- }
|
|
|
-
|
|
|
if strutils.IsStringEmpty(r.LogicalOperator) {
|
|
|
+ ruleValue := r.Value
|
|
|
+ ruleParamValue, ok := ruleParams[r.ColumnName]
|
|
|
+ if ok {
|
|
|
+ ruleValue = ruleParamValue
|
|
|
+ }
|
|
|
+
|
|
|
+ if ruleValue == nil {
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+
|
|
|
conditions := clause.NewConditions()
|
|
|
|
|
|
switch r.Operator {
|