|
|
package domain
|
|
|
|
|
|
import "fmt"
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/zeromicro/go-zero/core/collection"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
SchemaTable TableType = "Schema" // 方案
|
...
|
...
|
@@ -95,6 +99,50 @@ type FieldExpr struct { |
|
|
ExprSql string `json:"exprSql"`
|
|
|
}
|
|
|
|
|
|
func (expr *FieldExpr) Complete() string {
|
|
|
exprSql := expr.ExprSql
|
|
|
for _, f := range expr.TableFields {
|
|
|
sql := fmt.Sprintf("%s.%s", f.TableSqlName, f.FieldSqlName)
|
|
|
//zhSql := fmt.Sprintf("%s.%s", f.TableName, f.FieldSqlName)
|
|
|
sub := fmt.Sprintf("max(%s.%s)", f.TableSqlName, f.FieldSqlName)
|
|
|
//zhSub := fmt.Sprintf("max(%s.%s)", f.TableName, f.FieldSqlName)
|
|
|
if strings.Contains(expr.ExprSql, fmt.Sprintf("(%s)", sql)) {
|
|
|
continue
|
|
|
}
|
|
|
exprSql = strings.ReplaceAll(exprSql, sql, sub)
|
|
|
//expr.ExprSql = strings.ReplaceAll(expr.ExprSql, sql, sub)
|
|
|
//expr.ExprHuman = strings.ReplaceAll(expr.ExprHuman, zhSql, zhSub)
|
|
|
}
|
|
|
return exprSql
|
|
|
}
|
|
|
|
|
|
func (expr *FieldExpr) Tables() []int {
|
|
|
set := collection.NewSet()
|
|
|
for _, f := range expr.TableFields {
|
|
|
if f.TableId == 0 {
|
|
|
continue
|
|
|
}
|
|
|
set.Add(f.TableId)
|
|
|
}
|
|
|
return set.KeysInt()
|
|
|
}
|
|
|
|
|
|
func (expr *FieldExpr) MixTableModel() bool {
|
|
|
var result = 0
|
|
|
for _, f := range expr.TableFields {
|
|
|
if strings.HasPrefix(f.TableSqlName, strings.ToLower(CalculateItem.ToString())) {
|
|
|
if result&1 == 0 {
|
|
|
result += 1
|
|
|
}
|
|
|
} else {
|
|
|
if result&2 == 0 {
|
|
|
result += 2
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return result == 3
|
|
|
}
|
|
|
|
|
|
type LabelColumn struct {
|
|
|
Column TableField `json:"column,omitempty"`
|
|
|
LabelExpr string `json:"labelExpr"`
|
...
|
...
|
|