作者 yangfu

chore: caculate item support const expr

fix: Date Type format error
... ... @@ -71,7 +71,7 @@ func (t *DataTable) OptionalValue(args ...string) []string {
if len(match) > 0 && !strings.Contains(t.Data[i][0], match) {
continue
}
if filedType == Float.ToString() {
if filedType == Float.ToString() || filedType == Date.ToString() {
values = append(values, RoundFieldValue(&Field{SQLType: filedType}, t.Data[i][0]))
continue
}
... ...
... ... @@ -272,6 +272,10 @@ func RoundFieldValue(f *Field, v string) string {
}
return utils.AssertString(fv) //fmt.Sprintf("%v", fv)
}
// TODO:计算表 Count(日期)类型是日期类型,0 的话下面日期解析成当前时间,计算表类型需要修改
if fv, err := strconv.ParseFloat(v, 64); err == nil {
return utils.AssertString(fv)
}
if f.SQLType == Datetime.ToString() {
fv, err := xtime.Parse(v)
if err != nil {
... ... @@ -336,6 +340,11 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} {
if fields[i].SQLType == Float.ToString() {
v = RoundFieldValue(fields[i], v)
}
if fields[i].SQLType == Date.ToString() {
v = RoundFieldValue(fields[i], v)
output[i] = v
continue
}
convValue, err := ValueToType(v, fields[i].SQLType)
if err == nil {
output[i] = convValue
... ...
... ... @@ -140,7 +140,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
}
if queryComponent.Formula != nil {
formula := queryComponent.Formula
res.DatabaseTableName = formula.TableFields[0].TableSqlName
// res.DatabaseTableName = formula.TableFields[0].TableSqlName
// TODO:支持常量
res.DatabaseTableName = ""
if len(formula.TableFields) > 0 {
... ... @@ -158,6 +158,14 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
CalculateFieldName: table.DataFields[0].SQLName,
})
}
if len(queryComponent.Formula.TableFields) == 0 && len(queryComponent.Formula.ExprSql) > 0 {
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
DatabaseTableName: "",
FieldSchema: NewFieldSchema(domain.TableField{}),
CalculateExpression: exprSql,
CalculateFieldName: table.DataFields[0].SQLName,
})
}
//res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
// DatabaseTableName: res.DatabaseTableName,
// FieldSchema: NewFieldSchemaFromField(table.DataFields[0]),
... ...