query_set_components_aggregation_rule.go
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package domain
import (
"bytes"
"fmt"
)
type AggregationRule struct {
Aggregation
}
type Aggregation struct {
// 行
RowFields []*AggregationField `json:"rowFields"`
// 值
ValueFields []*AggregationField `json:"valueFields"`
// 选择列表 【字段名称】
SelectFields []string `json:"selectFields"`
}
type AggregationField struct {
Id string `json:"id"`
Field *Field `json:"field"`
DisplayName string `json:"displayName"`
AggregationFlag string `json:"aggregationFlag"` // 行:row 列:column 值:value
Order string `json:"order"` // 降序:desc 升序asc 默认:"" 无排序
Expr FieldExpr `json:"expr"`
}
func (ar *AggregationRule) Fields() []*Field {
fields := make([]*Field, 0)
for _, f := range ar.RowFields {
fields = append(fields, f.Field)
}
for _, f := range ar.ValueFields {
fields = append(fields, f.Field)
}
return fields
}
func (ar *AggregationRule) AggregationFields() []*AggregationField {
fields := make([]*AggregationField, 0)
for _, f := range ar.RowFields {
fields = append(fields, f)
}
for _, f := range ar.ValueFields {
fields = append(fields, f)
}
return fields
}
func (ar *AggregationRule) OrderFields() []*Field {
aggregationFields := ar.AggregationFields()
var fields = make([]*Field, 0)
for _, f := range aggregationFields {
if f.Order != "" {
copyField := f.Field.Copy()
copyField.Order = f.Order
fields = append(fields, copyField)
}
}
return fields
}
func (ar *AggregationField) Diff(c *AggregationField) bool {
if ar.Expr.ExprSql != c.Expr.ExprSql {
return true
}
if ar.Order != c.Order {
return true
}
if ar.AggregationFlag != c.AggregationFlag {
return true
}
return false
}
func (ar *AggregationField) Info() string {
buf := bytes.NewBuffer(nil)
buf.WriteString("(")
buf.WriteString(fmt.Sprintf("%s|", ar.DisplayName))
buf.WriteString(fmt.Sprintf("%s,", ar.Expr.ExprHuman))
if ar.AggregationFlag == "row" {
buf.WriteString("分组,")
} else {
buf.WriteString("不分组,")
}
if ar.Order == "asc" {
buf.WriteString("升序")
} else if ar.Order == "desc" {
buf.WriteString("降序")
} else {
buf.WriteString("默认")
}
buf.WriteString(")")
return buf.String()
}