[feat] 调整 接口文件
This commit is contained in:
+13
-8
@@ -10,6 +10,11 @@ import (
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
const (
|
||||
OR contracts.ConditionType = "OR"
|
||||
AND = "AND"
|
||||
)
|
||||
|
||||
type Condition struct {
|
||||
parent contracts.Condition
|
||||
typ contracts.ConditionType // 分组类型
|
||||
@@ -50,19 +55,19 @@ func (this Condition) IsAlwaysRight() bool {
|
||||
flag := []bool{}
|
||||
|
||||
for _, expr := range this.exprs {
|
||||
if expr.GetOperator() != contracts.EQ {
|
||||
if expr.GetOperator() != EQ {
|
||||
flag = append(flag, false)
|
||||
continue
|
||||
}
|
||||
|
||||
if expr.GetTokenType() != contracts.SQL {
|
||||
if expr.GetTokenType() != SQL {
|
||||
flag = append(flag, false)
|
||||
continue
|
||||
}
|
||||
|
||||
eRight := fmt.Sprintf("%s.%s", expr.GetFieldResource(), expr.GetField()) == strings.ReplaceAll(expr.GetTokenName(), "`", "")
|
||||
|
||||
if this.typ == contracts.OR && eRight {
|
||||
if this.typ == OR && eRight {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -72,7 +77,7 @@ func (this Condition) IsAlwaysRight() bool {
|
||||
for _, cond := range this.childrens {
|
||||
cRight := cond.IsAlwaysRight()
|
||||
|
||||
if this.typ == contracts.OR && cRight {
|
||||
if this.typ == OR && cRight {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -106,16 +111,16 @@ func (this Condition) ToSql(m contracts.ConditionTokenValue) db.Expression {
|
||||
sql := strings.Join(conditions, " "+string(this.Type())+" ")
|
||||
|
||||
if sql == "" {
|
||||
if this.parent == nil && this.Type() == contracts.OR {
|
||||
if this.parent == nil && this.Type() == OR {
|
||||
return db.Raw("false")
|
||||
} else if this.parent == nil && this.Type() == contracts.AND {
|
||||
} else if this.parent == nil && this.Type() == AND {
|
||||
return db.Raw("true")
|
||||
}
|
||||
return db.Raw("")
|
||||
}
|
||||
|
||||
// 包裹 SQL, 避免语法表达错误
|
||||
if this.parent == nil || this.Type() == contracts.OR {
|
||||
if this.parent == nil || this.Type() == OR {
|
||||
sql = "(" + sql + ")"
|
||||
}
|
||||
|
||||
@@ -158,7 +163,7 @@ func (this Condition) GetFieldsValue(m contracts.ConditionTokenValue, isWithReso
|
||||
|
||||
// 表达式
|
||||
for _, item := range this.exprs {
|
||||
if item.GetOperator() != contracts.EQ {
|
||||
if item.GetOperator() != EQ {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user