...
|
...
|
@@ -2,14 +2,15 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/zeromicro/go-zero/core/collection"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
|
|
|
"gorm.io/gorm"
|
|
|
"sort"
|
|
|
)
|
|
|
|
|
|
func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *command.FieldOptionalValuesCommand) (interface{}, error) {
|
...
|
...
|
@@ -84,6 +85,28 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * |
|
|
if !domain.SQLType(field.SQLType).IsString() {
|
|
|
match = ""
|
|
|
}
|
|
|
|
|
|
if table.TableType == domain.CalculateSet.ToString() {
|
|
|
var querySet *domain.QuerySet
|
|
|
querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
|
|
|
querySet, err = querySetRepository.FindOne(map[string]interface{}{"BindTableId": cmd.ObjectId})
|
|
|
if err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
svr, _ := factory.FastQuerySetServices(transactionContext)
|
|
|
dataTable, err = svr.LoadCalculateSetData(ctx, querySet, querySet.QueryComponents)
|
|
|
if err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
values := removeDuplicate(dataTable.Values(field))
|
|
|
sort.SliceStable(values, func(i, j int) bool {
|
|
|
return values[i] < values[j]
|
|
|
})
|
|
|
return map[string]interface{}{
|
|
|
"values": values,
|
|
|
"total": len(values),
|
|
|
}, nil
|
|
|
}
|
|
|
options := &starrocks.QueryOptions{
|
|
|
Table: table,
|
|
|
TableName: table.SQLName,
|
...
|
...
|
@@ -127,3 +150,15 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd * |
|
|
"total": len(values),
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
func removeDuplicate(inputs []string) []string {
|
|
|
s := collection.NewSet()
|
|
|
var result = make([]string, 0)
|
|
|
for _, input := range inputs {
|
|
|
if !s.Contains(input) {
|
|
|
s.Add(input)
|
|
|
result = append(result, input)
|
|
|
}
|
|
|
}
|
|
|
return result
|
|
|
} |
...
|
...
|
|