[feat] 重新梳理导出
This commit is contained in:
+18
-17
@@ -4,31 +4,32 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.fsdpf.net/go/condition/contracts"
|
||||
"git.fsdpf.net/go/contracts/support"
|
||||
"git.fsdpf.net/go/db"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type ConditionType string
|
||||
|
||||
const (
|
||||
OR contracts.ConditionType = "OR"
|
||||
AND = "AND"
|
||||
OR ConditionType = "OR"
|
||||
AND ConditionType = "AND"
|
||||
)
|
||||
|
||||
type Condition struct {
|
||||
parent contracts.Condition
|
||||
typ contracts.ConditionType // 分组类型
|
||||
describe string // 描述
|
||||
exprs []contracts.ConditionExpr // 分组表达式成员
|
||||
childrens []contracts.Condition // 分组子集
|
||||
parent *Condition
|
||||
typ ConditionType // 分组类型
|
||||
describe string // 描述
|
||||
exprs []*ConditionExpr // 分组表达式成员
|
||||
childrens []*Condition // 分组子集
|
||||
}
|
||||
|
||||
func (this *Condition) AppendTo(c contracts.Condition) {
|
||||
func (this *Condition) AppendTo(c *Condition) {
|
||||
this.parent = c
|
||||
}
|
||||
|
||||
// 条件类型
|
||||
func (this Condition) Type() contracts.ConditionType {
|
||||
func (this Condition) Type() ConditionType {
|
||||
return this.typ
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ func (this Condition) IsAlwaysRight() bool {
|
||||
}
|
||||
|
||||
// 生成 SQL 语句
|
||||
func (this Condition) ToSql(m contracts.ConditionTokenValue) db.Expression {
|
||||
func (this Condition) ToSql(m ConditionTokenValue) db.Expression {
|
||||
conditions := []string{}
|
||||
// 表达式
|
||||
for _, item := range this.exprs {
|
||||
@@ -132,21 +133,21 @@ func (this Condition) ToSql(m contracts.ConditionTokenValue) db.Expression {
|
||||
}
|
||||
|
||||
// 设置条件表达式
|
||||
func (this *Condition) SetExpr(expr contracts.ConditionExpr) contracts.Condition {
|
||||
func (this *Condition) SetExpr(expr *ConditionExpr) *Condition {
|
||||
expr.AppendTo(this)
|
||||
this.exprs = append(this.exprs, expr)
|
||||
return this
|
||||
}
|
||||
|
||||
// 设置条件子集
|
||||
func (this *Condition) SetCondition(c contracts.Condition) contracts.Condition {
|
||||
func (this *Condition) SetCondition(c *Condition) *Condition {
|
||||
c.AppendTo(this)
|
||||
this.childrens = append(this.childrens, c)
|
||||
return this
|
||||
}
|
||||
|
||||
// 设置 Token 匹配前缀
|
||||
func (this *Condition) SetMatchPrefix(prefix string) contracts.Condition {
|
||||
func (this *Condition) SetMatchPrefix(prefix string) *Condition {
|
||||
for _, expr := range this.exprs {
|
||||
expr.SetMatchPrefix(prefix)
|
||||
}
|
||||
@@ -156,7 +157,7 @@ func (this *Condition) SetMatchPrefix(prefix string) contracts.Condition {
|
||||
return this
|
||||
}
|
||||
|
||||
func (this Condition) GetFieldsValue(m contracts.ConditionTokenValue, isWithResource bool) (result map[string]any) {
|
||||
func (this Condition) GetFieldsValue(m ConditionTokenValue, isWithResource bool) (result map[string]any) {
|
||||
if this.IsEmpty() {
|
||||
return
|
||||
}
|
||||
@@ -188,7 +189,7 @@ func (this Condition) GetFieldsValue(m contracts.ConditionTokenValue, isWithReso
|
||||
* @param contracts.ConditionTokenType types
|
||||
* @return map[string][string] // 如: {"TestA.field_a": "param"}
|
||||
*/
|
||||
func (this Condition) GetFields(operator contracts.ConditionOperator, types ...contracts.ConditionTokenType) map[string]string {
|
||||
func (this Condition) GetFields(operator ConditionOperator, types ...ConditionTokenType) map[string]string {
|
||||
result := make(map[string]string)
|
||||
|
||||
if this.IsEmpty() {
|
||||
@@ -212,6 +213,6 @@ func (this Condition) GetFields(operator contracts.ConditionOperator, types ...c
|
||||
return result
|
||||
}
|
||||
|
||||
func New(typ contracts.ConditionType, describe string) contracts.Condition {
|
||||
func New(typ ConditionType, describe string) *Condition {
|
||||
return &Condition{typ: typ, describe: describe}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user