作者 yangfu

fix: table preview

@@ -26,7 +26,6 @@ require ( @@ -26,7 +26,6 @@ require (
26 github.com/sergi/go-diff v1.2.0 // indirect 26 github.com/sergi/go-diff v1.2.0 // indirect
27 github.com/shopspring/decimal v1.3.1 27 github.com/shopspring/decimal v1.3.1
28 github.com/smartystreets/goconvey v1.7.2 // indirect 28 github.com/smartystreets/goconvey v1.7.2 // indirect
29 - github.com/sony/sonyflake v1.1.0 // indirect  
30 github.com/stretchr/testify v1.7.1 29 github.com/stretchr/testify v1.7.1
31 github.com/valyala/fasthttp v1.38.0 // indirect 30 github.com/valyala/fasthttp v1.38.0 // indirect
32 github.com/xeipuuv/gojsonschema v1.2.0 // indirect 31 github.com/xeipuuv/gojsonschema v1.2.0 // indirect
@@ -162,23 +162,23 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon @@ -162,23 +162,23 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
162 } 162 }
163 if queryComponent.Aggregation != nil { 163 if queryComponent.Aggregation != nil {
164 res.DatabaseTableName = queryComponent.MasterTable.SQLName 164 res.DatabaseTableName = queryComponent.MasterTable.SQLName
165 - for i, f := range queryComponent.Aggregation.ValueFields { 165 + if len(queryComponent.Aggregation.ValueFields)>0 || len(queryComponent.Aggregation.RowFields)>0{
  166 + res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
  167 + DatabaseTableName: queryComponent.MasterTable.SQLName,
  168 + FieldSchema: NewFieldSchemaFromField(&domain.Field{
  169 + Name: "序号",
  170 + SQLName: "id",
  171 + SQLType: domain.String.ToString(),
  172 + }),
  173 + CalculateExpression: fmt.Sprintf("max(%s.%s)", queryComponent.MasterTable.SQLName, "id"),
  174 + CalculateFieldName: "id",
  175 + })
  176 + }
  177 + for _, f := range queryComponent.Aggregation.ValueFields {
166 tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName}) 178 tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName})
167 if !ok { 179 if !ok {
168 continue 180 continue
169 } 181 }
170 - if i == 0 {  
171 - res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{  
172 - DatabaseTableName: queryComponent.MasterTable.SQLName,  
173 - FieldSchema: NewFieldSchemaFromField(&domain.Field{  
174 - Name: "序号",  
175 - SQLName: "id",  
176 - SQLType: domain.String.ToString(),  
177 - }),  
178 - CalculateExpression: fmt.Sprintf("max(%s.%s)", queryComponent.MasterTable.SQLName, "id"),  
179 - CalculateFieldName: "id",  
180 - })  
181 - }  
182 res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{ 182 res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
183 DatabaseTableName: queryComponent.MasterTable.SQLName, 183 DatabaseTableName: queryComponent.MasterTable.SQLName,
184 FieldSchema: NewFieldSchemaFromField(f.Field), 184 FieldSchema: NewFieldSchemaFromField(f.Field),