add code of component attribute group store
This commit is contained in:
parent
df77f80475
commit
70bcb00062
|
|
@ -57,7 +57,7 @@ func ParseAttrToken(ctx context.Context, tx *gorm.DB, attrToken, clientToken str
|
|||
|
||||
// FillingShortAttrModel define filling short attribute model info
|
||||
func FillingShortAttrModel(ctx context.Context, tx *gorm.DB, attrItems []string, attrModel *model.ShortAttrInfo) error {
|
||||
component, err := QueryComponentByNsPath(ctx, tx, attrItems[0])
|
||||
component, err := QueryComponentByNSPath(ctx, tx, attrItems[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ func FillingLongAttrModel(ctx context.Context, tx *gorm.DB, attrItems []string,
|
|||
return err
|
||||
}
|
||||
attrModel.StationInfo = &station
|
||||
component, err := QueryComponentByNsPath(ctx, tx, attrItems[3])
|
||||
component, err := QueryComponentByNSPath(ctx, tx, attrItems[3])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ func QueryComponentByPageID(ctx context.Context, tx *gorm.DB, uuid uuid.UUID) (o
|
|||
return component, nil
|
||||
}
|
||||
|
||||
// QueryComponentByNsPath return the result of query circuit diagram component info by ns path from postgresDB
|
||||
func QueryComponentByNsPath(ctx context.Context, tx *gorm.DB, nsPath string) (orm.Component, error) {
|
||||
// QueryComponentByNSPath return the result of query circuit diagram component info by ns path from postgresDB
|
||||
func QueryComponentByNSPath(ctx context.Context, tx *gorm.DB, nsPath string) (orm.Component, error) {
|
||||
var component orm.Component
|
||||
// ctx超时判断
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
|
|
@ -137,3 +137,22 @@ func QueryShortIdentModelInfoByToken(ctx context.Context, tx *gorm.DB, measTag s
|
|||
}
|
||||
return &resultComp, &meauserment, nil
|
||||
}
|
||||
|
||||
// GetGlobalUUIDTagStringMap define func to query global_uuid、tag、nspath field
|
||||
func GetGlobalUUIDTagStringMap(db *gorm.DB) (map[string]orm.AttributeSet, error) {
|
||||
var results []orm.Component
|
||||
resMap := make(map[string]orm.AttributeSet)
|
||||
|
||||
err := db.Model(&orm.Component{}).Select("global_uuid", "station", "tag", "nspath").Find(&results).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, r := range results {
|
||||
resMap[r.GlobalUUID.String()] = orm.AttributeSet{
|
||||
Tag: r.Tag,
|
||||
NSPath: r.NSPath,
|
||||
}
|
||||
}
|
||||
return resMap, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,22 +5,27 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"modelRT/logger"
|
||||
"modelRT/orm"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type columnParam struct {
|
||||
AttributeType string
|
||||
AttributeGroup map[string]any
|
||||
}
|
||||
|
||||
// TraverseAttributeGroupTables define func to traverse component attribute group tables
|
||||
func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB) error {
|
||||
func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compParamMap map[string]orm.AttributeSet) error {
|
||||
var tableNames []string
|
||||
|
||||
result := db.Model(&orm.ProjectManager{}).Pluck("name", &tableNames)
|
||||
fmt.Println(result)
|
||||
if result.Error != nil && result.Error != gorm.ErrRecordNotFound {
|
||||
logger.Error(ctx, "query name column data from postgres table failed", "err", result.Error)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
if len(tableNames) == 0 {
|
||||
|
|
@ -54,19 +59,54 @@ func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB) error {
|
|||
return err
|
||||
}
|
||||
|
||||
tableSchema := make(map[string]gorm.ColumnType)
|
||||
for _, record := range records {
|
||||
attributeGroup := make(map[string]any)
|
||||
var componentUUIDStr string
|
||||
var attrSet orm.AttributeSet
|
||||
var attributeType string
|
||||
for _, col := range columnTypes {
|
||||
colName := col.Name()
|
||||
|
||||
for _, col := range columnTypes {
|
||||
name := col.Name()
|
||||
dataType, _ := col.ColumnType()
|
||||
log.Printf("column: %s, Type: %s", name, dataType)
|
||||
if name != "id" {
|
||||
tableSchema[name] = col
|
||||
value, exists := record[colName]
|
||||
if !exists {
|
||||
err := errors.New("can not find value from record by column name")
|
||||
logger.Error(ctx, "query value by column name failed", "column_name", colName, "error", err)
|
||||
return err
|
||||
}
|
||||
switch colName {
|
||||
case "id":
|
||||
case "global_uuid":
|
||||
componentUUIDStr = value.(string)
|
||||
attrSet, exists = compParamMap[componentUUIDStr]
|
||||
if !exists {
|
||||
err := errors.New("can not find component tag from record by global uuid")
|
||||
logger.Error(ctx, "check component info by global uuid failed", "global_uuid", componentUUIDStr, "error", err)
|
||||
return err
|
||||
}
|
||||
case "attribute_group":
|
||||
attributeType = value.(string)
|
||||
default:
|
||||
attributeGroup[colName] = value
|
||||
}
|
||||
}
|
||||
|
||||
columnParam := columnParam{
|
||||
AttributeType: attributeType,
|
||||
AttributeGroup: attributeGroup,
|
||||
}
|
||||
|
||||
// TODO 将筛选后的 recordSchema 属性值加入到缓存系统中
|
||||
// TODO 增加 station tag的获取
|
||||
go storeAttributeGroup(ctx, attrSet, componentUUIDStr, columnParam)
|
||||
}
|
||||
|
||||
// TODO 将筛选后的属性值加入到缓存系统中
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, compUUIDStr string, params columnParam) {
|
||||
fmt.Println(ctx)
|
||||
fmt.Println(attributeSet)
|
||||
uuid, err := uuid.FromString(compUUIDStr)
|
||||
fmt.Println(uuid, err)
|
||||
fmt.Println(params)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,9 +68,8 @@ func ConvertComponentCreateInfosToComponents(info ComponentCreateInfo) (*orm.Com
|
|||
|
||||
component := &orm.Component{
|
||||
GlobalUUID: uuidVal,
|
||||
// NsPath: info.NsPath,
|
||||
Tag: info.Tag,
|
||||
Name: info.Name,
|
||||
Tag: info.Tag,
|
||||
Name: info.Name,
|
||||
// ModelName: info.ModelName,
|
||||
// Description: info.Description,
|
||||
// GridID: info.GridID,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
// Package orm define database data struct
|
||||
package orm
|
||||
|
||||
// AttributeSet define struct to return station tag、component Tag、 NSPath field
|
||||
type AttributeSet struct {
|
||||
Tag string
|
||||
NSPath string
|
||||
StationTag string
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ import (
|
|||
// Component structure define abstracted info set of electrical component
|
||||
type Component struct {
|
||||
GlobalUUID uuid.UUID `gorm:"column:global_uuid;primaryKey"`
|
||||
NsPath string `gorm:"column:nspath"`
|
||||
NSPath string `gorm:"column:nspath"`
|
||||
Tag string `gorm:"column:tag"`
|
||||
Name string `gorm:"column:name"`
|
||||
ModelName string `gorm:"column:model_name"`
|
||||
|
|
@ -41,5 +41,5 @@ func (c Component) GetTagName() string {
|
|||
|
||||
// GetNSPath define func to inplement CircuitDiagramNodeInterface interface
|
||||
func (c Component) GetNSPath() string {
|
||||
return c.NsPath
|
||||
return c.NSPath
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue