[feat] 依赖调整 git.fsdpf.net/go/contracts => git.fsdpf.net/go/req
This commit is contained in:
+21
-21
@@ -6,7 +6,7 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"git.fsdpf.net/go/contracts"
|
||||
"git.fsdpf.net/go/condition/contracts"
|
||||
"git.fsdpf.net/go/db"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cast"
|
||||
@@ -46,7 +46,7 @@ func (this *ConditionExpr) AppendTo(c contracts.Condition) {
|
||||
this.parent = c
|
||||
}
|
||||
|
||||
func (this ConditionExpr) ToSql(m contracts.ModelParam) db.Expression {
|
||||
func (this ConditionExpr) ToSql(m contracts.ConditionTokenValue) db.Expression {
|
||||
first := "`" + this.fieldResource + "`.`" + this.field + "`"
|
||||
|
||||
if strings.Contains(this.field, "->") {
|
||||
@@ -65,24 +65,24 @@ func (this ConditionExpr) ToSql(m contracts.ModelParam) db.Expression {
|
||||
//
|
||||
secondary := ""
|
||||
switch operator {
|
||||
case contracts.ConditionOperator_IS_NULL:
|
||||
case contracts.ConditionOperator_IS_NOT_NULL:
|
||||
case contracts.IS_NULL:
|
||||
case contracts.IS_NOT_NULL:
|
||||
|
||||
secondary = ""
|
||||
case contracts.ConditionOperator_EQ, contracts.ConditionOperator_NE,
|
||||
contracts.ConditionOperator_GT, contracts.ConditionOperator_GE,
|
||||
contracts.ConditionOperator_LT, contracts.ConditionOperator_LE,
|
||||
contracts.ConditionOperator_REGEXP, contracts.ConditionOperator_NOT_REGEXP:
|
||||
case contracts.EQ, contracts.NE,
|
||||
contracts.GT, contracts.GE,
|
||||
contracts.LT, contracts.LE,
|
||||
contracts.REGEXP, contracts.NOT_REGEXP:
|
||||
|
||||
if this.GetTokenType() == contracts.ConditionTokenType_SQL {
|
||||
if this.GetTokenType() == contracts.SQL {
|
||||
secondary = value
|
||||
} else {
|
||||
secondary = "'" + strings.Trim(value, "'") + "'"
|
||||
}
|
||||
|
||||
case contracts.ConditionOperator_LIKE, contracts.ConditionOperator_NOT_LIKE:
|
||||
case contracts.LIKE, contracts.NOT_LIKE:
|
||||
secondary = "'%" + strings.Trim(value, "'") + "%'"
|
||||
case contracts.ConditionOperator_IN, contracts.ConditionOperator_NOT_IN:
|
||||
case contracts.IN, contracts.NOT_IN:
|
||||
secondary = "(" + lo.Ternary(value == "", "''", value) + ")"
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ func (this ConditionExpr) GetTokenType() contracts.ConditionTokenType {
|
||||
return this.tokenType
|
||||
}
|
||||
|
||||
func (this *ConditionExpr) GetTokenSqlValue(m contracts.ModelParam) string {
|
||||
if this.GetTokenType() == contracts.ConditionTokenType_SQL {
|
||||
func (this *ConditionExpr) GetTokenSqlValue(m contracts.ConditionTokenValue) string {
|
||||
if this.GetTokenType() == contracts.SQL {
|
||||
return this.token
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ func (this *ConditionExpr) GetTokenSqlValue(m contracts.ModelParam) string {
|
||||
}
|
||||
|
||||
// 强制使用 in
|
||||
if this.operator == contracts.ConditionOperator_EQ {
|
||||
this.operator = contracts.ConditionOperator_IN
|
||||
if this.operator == contracts.EQ {
|
||||
this.operator = contracts.IN
|
||||
}
|
||||
|
||||
return strings.Join(aStr, ", ")
|
||||
@@ -154,16 +154,16 @@ func (this *ConditionExpr) GetTokenSqlValue(m contracts.ModelParam) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (this ConditionExpr) GetTokenValue(m contracts.ModelParam) any {
|
||||
func (this ConditionExpr) GetTokenValue(m contracts.ConditionTokenValue) any {
|
||||
switch this.GetTokenType() {
|
||||
case contracts.ConditionTokenType_PARAM:
|
||||
case contracts.PARAM:
|
||||
if this.matchPrefix != "" {
|
||||
return m.GetParam(fmt.Sprintf("%s.%s", this.matchPrefix, this.token)).Value()
|
||||
}
|
||||
return m.GetParam(this.token).Value()
|
||||
case contracts.ConditionTokenType_STRING:
|
||||
case contracts.STRING:
|
||||
return this.token
|
||||
case contracts.ConditionTokenType_FUNC:
|
||||
case contracts.FUNC:
|
||||
switch this.token {
|
||||
case "UserID":
|
||||
return m.GetGlobalParamsUser().ID()
|
||||
@@ -182,12 +182,12 @@ func (this ConditionExpr) GetTokenValue(m contracts.ModelParam) any {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this ConditionExpr) IsIgnoreEmptyParma(m contracts.ModelParam) bool {
|
||||
func (this ConditionExpr) IsIgnoreEmptyParma(m contracts.ConditionTokenValue) bool {
|
||||
if !this.ignoreEmptyParma {
|
||||
return false
|
||||
}
|
||||
|
||||
if this.tokenType != contracts.ConditionTokenType_PARAM {
|
||||
if this.tokenType != contracts.PARAM {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user