add func of component param group recommend func
This commit is contained in:
parent
689d31c246
commit
df77f80475
|
|
@ -3,7 +3,9 @@ package model
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"modelRT/logger"
|
||||
"modelRT/orm"
|
||||
|
|
@ -31,18 +33,38 @@ func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB) error {
|
|||
continue
|
||||
}
|
||||
|
||||
exists := db.Migrator().HasTable(tableName)
|
||||
if !exists {
|
||||
logger.Warn(ctx, fmt.Sprintf("table %s does not exist in the database", tableName))
|
||||
}
|
||||
|
||||
// TODO 优化返回结构,尝试首先获取表的结构
|
||||
var records []map[string]any
|
||||
err := db.Table(tableName).Find(&records).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
logger.Error(ctx, fmt.Sprintf("query table '%s' data failed", tableName), "table_name", tableName, "err", err)
|
||||
continue
|
||||
return err
|
||||
}
|
||||
|
||||
migrator := db.Migrator()
|
||||
|
||||
if exists := migrator.HasTable(tableName); !exists {
|
||||
err := errors.New("can not find special table into database")
|
||||
logger.Error(ctx, "table does not exist in the database", "table _name", tableName, "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
columnTypes, err := migrator.ColumnTypes(tableName)
|
||||
if err != nil {
|
||||
logger.Error(ctx, "retrieving column structure for table failed", "table _name", tableName, "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
tableSchema := make(map[string]gorm.ColumnType)
|
||||
|
||||
for _, col := range columnTypes {
|
||||
name := col.Name()
|
||||
dataType, _ := col.ColumnType()
|
||||
log.Printf("column: %s, Type: %s", name, dataType)
|
||||
if name != "id" {
|
||||
tableSchema[name] = col
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 将筛选后的属性值加入到缓存系统中
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue