[feat] 依赖调整 git.fsdpf.net/go/contracts => git.fsdpf.net/go/req
This commit is contained in:
+11
-11
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.fsdpf.net/go/contracts"
|
||||
"git.fsdpf.net/go/condition/contracts"
|
||||
"git.fsdpf.net/go/contracts/support"
|
||||
"git.fsdpf.net/go/db"
|
||||
"github.com/samber/lo"
|
||||
@@ -50,19 +50,19 @@ func (this Condition) IsAlwaysRight() bool {
|
||||
flag := []bool{}
|
||||
|
||||
for _, expr := range this.exprs {
|
||||
if expr.GetOperator() != contracts.ConditionOperator_EQ {
|
||||
if expr.GetOperator() != contracts.EQ {
|
||||
flag = append(flag, false)
|
||||
continue
|
||||
}
|
||||
|
||||
if expr.GetTokenType() != contracts.ConditionTokenType_SQL {
|
||||
if expr.GetTokenType() != contracts.SQL {
|
||||
flag = append(flag, false)
|
||||
continue
|
||||
}
|
||||
|
||||
eRight := fmt.Sprintf("%s.%s", expr.GetFieldResource(), expr.GetField()) == strings.ReplaceAll(expr.GetTokenName(), "`", "")
|
||||
|
||||
if this.typ == contracts.ConditionType_OR && eRight {
|
||||
if this.typ == contracts.OR && eRight {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (this Condition) IsAlwaysRight() bool {
|
||||
for _, cond := range this.childrens {
|
||||
cRight := cond.IsAlwaysRight()
|
||||
|
||||
if this.typ == contracts.ConditionType_OR && cRight {
|
||||
if this.typ == contracts.OR && cRight {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func (this Condition) IsAlwaysRight() bool {
|
||||
}
|
||||
|
||||
// 生成 SQL 语句
|
||||
func (this Condition) ToSql(m contracts.ModelParam) db.Expression {
|
||||
func (this Condition) ToSql(m contracts.ConditionTokenValue) db.Expression {
|
||||
conditions := []string{}
|
||||
// 表达式
|
||||
for _, item := range this.exprs {
|
||||
@@ -106,16 +106,16 @@ func (this Condition) ToSql(m contracts.ModelParam) db.Expression {
|
||||
sql := strings.Join(conditions, " "+string(this.Type())+" ")
|
||||
|
||||
if sql == "" {
|
||||
if this.parent == nil && this.Type() == contracts.ConditionType_OR {
|
||||
if this.parent == nil && this.Type() == contracts.OR {
|
||||
return db.Raw("false")
|
||||
} else if this.parent == nil && this.Type() == contracts.ConditionType_AND {
|
||||
} else if this.parent == nil && this.Type() == contracts.AND {
|
||||
return db.Raw("true")
|
||||
}
|
||||
return db.Raw("")
|
||||
}
|
||||
|
||||
// 包裹 SQL, 避免语法表达错误
|
||||
if this.parent == nil || this.Type() == contracts.ConditionType_OR {
|
||||
if this.parent == nil || this.Type() == contracts.OR {
|
||||
sql = "(" + sql + ")"
|
||||
}
|
||||
|
||||
@@ -151,14 +151,14 @@ func (this *Condition) SetMatchPrefix(prefix string) contracts.Condition {
|
||||
return this
|
||||
}
|
||||
|
||||
func (this Condition) GetFieldsValue(m contracts.ModelParam, isWithResource bool) (result map[string]any) {
|
||||
func (this Condition) GetFieldsValue(m contracts.ConditionTokenValue, isWithResource bool) (result map[string]any) {
|
||||
if this.IsEmpty() {
|
||||
return
|
||||
}
|
||||
|
||||
// 表达式
|
||||
for _, item := range this.exprs {
|
||||
if item.GetOperator() != contracts.ConditionOperator_EQ {
|
||||
if item.GetOperator() != contracts.EQ {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user