作者 yangfu

fix: calculate table add pk field

... ... @@ -158,11 +158,23 @@ func NewFormulaCalculate(table *domain.Table, queryComponent *domain.QueryCompon
}
if queryComponent.Aggregation != nil {
res.DatabaseTableName = queryComponent.MasterTable.SQLName
for _, f := range queryComponent.Aggregation.ValueFields {
for i, f := range queryComponent.Aggregation.ValueFields {
tableField, ok := table.MatchField(&domain.Field{Name: f.DisplayName})
if !ok {
continue
}
if i == 0 {
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
DatabaseTableName: queryComponent.MasterTable.SQLName,
FieldSchema: NewFieldSchemaFromField(&domain.Field{
Name: "序号",
SQLName: "id",
SQLType: domain.String.ToString(),
}),
CalculateExpression: fmt.Sprintf("max(%s.%s)", queryComponent.MasterTable.SQLName, "id"),
CalculateFieldName: "id",
})
}
res.FormulaCalculateFields = append(res.FormulaCalculateFields, &FormulaCalculateField{
DatabaseTableName: queryComponent.MasterTable.SQLName,
FieldSchema: NewFieldSchemaFromField(f.Field),
... ...
... ... @@ -693,7 +693,7 @@ func (ptr *QuerySetService) CreateOrUpdateCalculateItemTable(ctx *domain.Context
field.SQLType = queryComponent.Formula.TableFields[0].FieldSQLType
}
var table *domain.Table = NewCopyTable(domain.TableType(querySet.Type), querySet.Name, []*domain.Field{field}, 1).WithContext(ctx).WithPrefix(strings.ToLower(querySet.Type))
table.PK = nil
//table.PK = nil
if querySet.QuerySetInfo.BindTableId > 0 {
table, err = tableRepository.FindOne(map[string]interface{}{"context": ctx, "tableId": querySet.QuerySetInfo.BindTableId})
if err != nil {
... ...