作者 yangfu

chore: caculate item support const expr

fix: Date Type format error
@@ -71,7 +71,7 @@ func (t *DataTable) OptionalValue(args ...string) []string { @@ -71,7 +71,7 @@ func (t *DataTable) OptionalValue(args ...string) []string {
71 if len(match) > 0 && !strings.Contains(t.Data[i][0], match) { 71 if len(match) > 0 && !strings.Contains(t.Data[i][0], match) {
72 continue 72 continue
73 } 73 }
74 - if filedType == Float.ToString() { 74 + if filedType == Float.ToString() || filedType == Date.ToString() {
75 values = append(values, RoundFieldValue(&Field{SQLType: filedType}, t.Data[i][0])) 75 values = append(values, RoundFieldValue(&Field{SQLType: filedType}, t.Data[i][0]))
76 continue 76 continue
77 } 77 }
@@ -272,6 +272,10 @@ func RoundFieldValue(f *Field, v string) string { @@ -272,6 +272,10 @@ func RoundFieldValue(f *Field, v string) string {
272 } 272 }
273 return utils.AssertString(fv) //fmt.Sprintf("%v", fv) 273 return utils.AssertString(fv) //fmt.Sprintf("%v", fv)
274 } 274 }
  275 + // TODO:计算表 Count(日期)类型是日期类型,0 的话下面日期解析成当前时间,计算表类型需要修改
  276 + if fv, err := strconv.ParseFloat(v, 64); err == nil {
  277 + return utils.AssertString(fv)
  278 + }
275 if f.SQLType == Datetime.ToString() { 279 if f.SQLType == Datetime.ToString() {
276 fv, err := xtime.Parse(v) 280 fv, err := xtime.Parse(v)
277 if err != nil { 281 if err != nil {
@@ -336,6 +340,11 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} { @@ -336,6 +340,11 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} {
336 if fields[i].SQLType == Float.ToString() { 340 if fields[i].SQLType == Float.ToString() {
337 v = RoundFieldValue(fields[i], v) 341 v = RoundFieldValue(fields[i], v)
338 } 342 }
  343 + if fields[i].SQLType == Date.ToString() {
  344 + v = RoundFieldValue(fields[i], v)
  345 + output[i] = v
  346 + continue
  347 + }
339 convValue, err := ValueToType(v, fields[i].SQLType) 348 convValue, err := ValueToType(v, fields[i].SQLType)
340 if err == nil { 349 if err == nil {
341 output[i] = convValue 350 output[i] = convValue
@@ -140,7 +140,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon @@ -140,7 +140,7 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
140 } 140 }
141 if queryComponent.Formula != nil { 141 if queryComponent.Formula != nil {
142 formula := queryComponent.Formula 142 formula := queryComponent.Formula
143 - res.DatabaseTableName = formula.TableFields[0].TableSqlName 143 + // res.DatabaseTableName = formula.TableFields[0].TableSqlName
144 // TODO:支持常量 144 // TODO:支持常量
145 res.DatabaseTableName = "" 145 res.DatabaseTableName = ""
146 if len(formula.TableFields) > 0 { 146 if len(formula.TableFields) > 0 {
@@ -158,6 +158,14 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon @@ -158,6 +158,14 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
158 CalculateFieldName: table.DataFields[0].SQLName, 158 CalculateFieldName: table.DataFields[0].SQLName,
159 }) 159 })
160 } 160 }
  161 + if len(queryComponent.Formula.TableFields) == 0 && len(queryComponent.Formula.ExprSql) > 0 {
  162 + res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
  163 + DatabaseTableName: "",
  164 + FieldSchema: NewFieldSchema(domain.TableField{}),
  165 + CalculateExpression: exprSql,
  166 + CalculateFieldName: table.DataFields[0].SQLName,
  167 + })
  168 + }
161 //res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ 169 //res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
162 // DatabaseTableName: res.DatabaseTableName, 170 // DatabaseTableName: res.DatabaseTableName,
163 // FieldSchema: NewFieldSchemaFromField(table.DataFields[0]), 171 // FieldSchema: NewFieldSchemaFromField(table.DataFields[0]),