...
|
...
|
@@ -6,6 +6,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/cache"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -23,13 +24,38 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var dataTable *domain.DataTable
|
|
|
var table *domain.Table
|
|
|
var cacheMiss bool
|
|
|
_, table, err = factory.FastPgTable(transactionContext, cmd.TableId)
|
|
|
if err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
|
|
|
// 方案 计算项 计算集 做缓存
|
|
|
if cmd.UseCache && table.AssertTableType(domain.SchemaTable, domain.CalculateItem, domain.CalculateSet) {
|
|
|
if d, ok := cache.GetDataTable(table.TableId); ok {
|
|
|
dataTable = d
|
|
|
} else {
|
|
|
cacheMiss = true
|
|
|
}
|
|
|
}
|
|
|
response := &dto.TablePreviewDto{}
|
|
|
if dataTable == nil {
|
|
|
switch table.TableType {
|
|
|
case domain.CalculateSet.ToString():
|
|
|
querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
|
|
|
querySet, err := querySetRepository.FindOne(map[string]interface{}{"BindTableId": table.TableId})
|
|
|
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)
|
|
|
}
|
|
|
response.Fields = dataTable.Fields
|
|
|
response.Data = domain.GripData(domain.ToFieldData(dataTable.Fields, dataTable.Data, false), int64(len(dataTable.Data)))
|
|
|
default:
|
|
|
var options = starrocks.QueryOptions{
|
|
|
Table: table,
|
|
|
TableName: table.SQLName,
|
...
|
...
|
@@ -37,12 +63,19 @@ func (tableService *TableService) TablePreview(ctx *domain.Context, cmd *command |
|
|
}
|
|
|
options.SetCondition(cmd.Where.Conditions).SetDefaultOrder()
|
|
|
options.SetOffsetLimit(cmd.Where.PageNumber, cmd.Where.PageSize)
|
|
|
var dataTable *domain.DataTable
|
|
|
|
|
|
dataTable, err = factory.FastDataTable(options)
|
|
|
if err != nil {
|
|
|
return nil, factory.FastError(err)
|
|
|
}
|
|
|
response := (&dto.TablePreviewDto{}).Load(table, dataTable, domain.ObjectMetaTable)
|
|
|
response.Load(table, dataTable, domain.ObjectMetaTable)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if cacheMiss && dataTable != nil {
|
|
|
// 存储缓存
|
|
|
cache.SetDataTable(table.TableId, dataTable)
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
...
|
...
|
|