|
@@ -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),
|