query_set_service_load_calculate_item.go
948 字节
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
package domainService
import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain/astexpr"
)
func (ptr *QuerySetService) LoadCalculateItemData(ctx *domain.Context, t *domain.Table, formula *domain.FieldFormulaExpr) (*domain.DataTable, error) {
var (
res = &domain.DataTable{}
err error
)
calc, err := astexpr.NewCalculator(formula.ExprSql)
if err != nil {
return nil, err
}
if len(formula.TableFields) > 0 {
var tableId = formula.TableFields[0].TableId
mapTable, _ := ptr.loadDataTables(ctx, []int{tableId})
calc.SetDataTable(mapTable[tableId])
}
result, err := calc.ExprASTResult(calc.ExprAST)
if err != nil {
return nil, err
}
res.Data = [][]string{
result.Data(),
}
if t != nil {
res.Fields = t.Fields(false)
}
res.Total = int64(len(res.Data))
// 数据持久化
return res, nil
}