[feat] 重新梳理导出
This commit is contained in:
+40
-32
@@ -6,54 +6,62 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"git.fsdpf.net/go/condition/contracts"
|
||||
"git.fsdpf.net/go/db"
|
||||
"git.fsdpf.net/go/req"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type ConditionOperator string
|
||||
type ConditionTokenType string
|
||||
|
||||
const (
|
||||
SQL contracts.ConditionTokenType = "sql"
|
||||
FUNC = "func"
|
||||
PARAM = "param"
|
||||
STRING = "string"
|
||||
SQL ConditionTokenType = "sql"
|
||||
FUNC = "func"
|
||||
PARAM = "param"
|
||||
STRING = "string"
|
||||
)
|
||||
|
||||
const (
|
||||
IS_NULL contracts.ConditionOperator = "IS NULL"
|
||||
IS_NOT_NULL = "IS NOT NULL"
|
||||
EQ = "="
|
||||
NE = "!="
|
||||
GT = ">"
|
||||
GE = ">="
|
||||
LT = "<"
|
||||
LE = "<="
|
||||
LIKE = "LIKE"
|
||||
NOT_LIKE = "NOT LIKE"
|
||||
IN = "IN"
|
||||
NOT_IN = "NOT IN"
|
||||
REGEXP = "REGEXP"
|
||||
NOT_REGEXP = "NOT REGEXP"
|
||||
IS_NULL ConditionOperator = "IS NULL"
|
||||
IS_NOT_NULL = "IS NOT NULL"
|
||||
EQ = "="
|
||||
NE = "!="
|
||||
GT = ">"
|
||||
GE = ">="
|
||||
LT = "<"
|
||||
LE = "<="
|
||||
LIKE = "LIKE"
|
||||
NOT_LIKE = "NOT LIKE"
|
||||
IN = "IN"
|
||||
NOT_IN = "NOT IN"
|
||||
REGEXP = "REGEXP"
|
||||
NOT_REGEXP = "NOT REGEXP"
|
||||
)
|
||||
|
||||
type ConditionTokenValue interface {
|
||||
GetParam(k string) req.GlobalParams
|
||||
GetGlobalParamsUser() req.User
|
||||
}
|
||||
|
||||
type ConditionExpr struct {
|
||||
parent contracts.Condition
|
||||
operator contracts.ConditionOperator
|
||||
parent *Condition
|
||||
operator ConditionOperator
|
||||
field string
|
||||
fieldResource string
|
||||
fieldSqlFunc string
|
||||
fieldSqlFuncParam string
|
||||
ignoreEmptyParma bool
|
||||
tokenType contracts.ConditionTokenType
|
||||
tokenType ConditionTokenType
|
||||
token string
|
||||
matchPrefix string // 匹配前缀
|
||||
}
|
||||
|
||||
func (this ConditionExpr) GetOperator() contracts.ConditionOperator {
|
||||
func (this ConditionExpr) GetOperator() ConditionOperator {
|
||||
return this.operator
|
||||
}
|
||||
|
||||
func (this *ConditionExpr) SetMatchPrefix(s string) contracts.ConditionExpr {
|
||||
func (this *ConditionExpr) SetMatchPrefix(s string) *ConditionExpr {
|
||||
this.matchPrefix = s
|
||||
return this
|
||||
}
|
||||
@@ -66,11 +74,11 @@ func (this ConditionExpr) GetFieldResource() string {
|
||||
return this.fieldResource
|
||||
}
|
||||
|
||||
func (this *ConditionExpr) AppendTo(c contracts.Condition) {
|
||||
func (this *ConditionExpr) AppendTo(c *Condition) {
|
||||
this.parent = c
|
||||
}
|
||||
|
||||
func (this ConditionExpr) ToSql(m contracts.ConditionTokenValue) db.Expression {
|
||||
func (this ConditionExpr) ToSql(m ConditionTokenValue) db.Expression {
|
||||
first := "`" + this.fieldResource + "`.`" + this.field + "`"
|
||||
|
||||
if strings.Contains(this.field, "->") {
|
||||
@@ -79,7 +87,7 @@ func (this ConditionExpr) ToSql(m contracts.ConditionTokenValue) db.Expression {
|
||||
|
||||
value := this.GetTokenSqlValue(m)
|
||||
|
||||
operator := contracts.ConditionOperator(strings.ToUpper(string(this.GetOperator())))
|
||||
operator := ConditionOperator(strings.ToUpper(string(this.GetOperator())))
|
||||
|
||||
if value == "" {
|
||||
// @todo return true
|
||||
@@ -137,11 +145,11 @@ func (this ConditionExpr) GetTokenName() string {
|
||||
return this.token
|
||||
}
|
||||
|
||||
func (this ConditionExpr) GetTokenType() contracts.ConditionTokenType {
|
||||
func (this ConditionExpr) GetTokenType() ConditionTokenType {
|
||||
return this.tokenType
|
||||
}
|
||||
|
||||
func (this *ConditionExpr) GetTokenSqlValue(m contracts.ConditionTokenValue) string {
|
||||
func (this *ConditionExpr) GetTokenSqlValue(m ConditionTokenValue) string {
|
||||
if this.GetTokenType() == SQL {
|
||||
return this.token
|
||||
}
|
||||
@@ -178,7 +186,7 @@ func (this *ConditionExpr) GetTokenSqlValue(m contracts.ConditionTokenValue) str
|
||||
}
|
||||
}
|
||||
|
||||
func (this ConditionExpr) GetTokenValue(m contracts.ConditionTokenValue) any {
|
||||
func (this ConditionExpr) GetTokenValue(m ConditionTokenValue) any {
|
||||
switch this.GetTokenType() {
|
||||
case PARAM:
|
||||
if this.matchPrefix != "" {
|
||||
@@ -206,7 +214,7 @@ func (this ConditionExpr) GetTokenValue(m contracts.ConditionTokenValue) any {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this ConditionExpr) IsIgnoreEmptyParma(m contracts.ConditionTokenValue) bool {
|
||||
func (this ConditionExpr) IsIgnoreEmptyParma(m ConditionTokenValue) bool {
|
||||
if !this.ignoreEmptyParma {
|
||||
return false
|
||||
}
|
||||
@@ -224,7 +232,7 @@ func (this ConditionExpr) IsIgnoreEmptyParma(m contracts.ConditionTokenValue) bo
|
||||
return false
|
||||
}
|
||||
|
||||
func NewExpr(rResource, rField, token string, operator contracts.ConditionOperator, tType contracts.ConditionTokenType, ignoreEmptyParma bool, fn, fnParam string) contracts.ConditionExpr {
|
||||
func NewExpr(rResource, rField, token string, operator ConditionOperator, tType ConditionTokenType, ignoreEmptyParma bool, fn, fnParam string) *ConditionExpr {
|
||||
return &ConditionExpr{
|
||||
operator: operator,
|
||||
field: rField,
|
||||
|
||||
Reference in New Issue
Block a user