modelRT/model/model_parse.go

56 lines
2.1 KiB
Go
Raw Normal View History

package model
import (
"context"
"errors"
"time"
"modelRT/config"
"modelRT/database"
"modelRT/diagram"
"go.uber.org/zap"
)
var ParseFunc = func(parseConfig interface{}) {
logger := zap.L()
modelParseConfig, ok := parseConfig.(config.ModelParseConfig)
if !ok {
logger.Error("conversion model parse config type failed")
panic(errors.New("conversion model parse config type failed"))
}
cancelCtx, cancel := context.WithTimeout(modelParseConfig.Context, 5*time.Second)
defer cancel()
pgClient := database.GetPostgresDBClient()
componentKey := modelParseConfig.ComponentInfo.GlobalUUID.String()
unmarshalMap, err := diagram.GetComponentMap(componentKey)
if err != nil {
logger.Error("get component map from overviewMap failed", zap.String("component_key", componentKey), zap.Error(err))
panic(err)
}
tableName := SelectModelByType(modelParseConfig.ComponentInfo.ComponentType)
result := pgClient.Table(tableName).WithContext(cancelCtx).Find(&unmarshalMap)
if result.Error != nil {
logger.Error("query component detail info failed", zap.Error(result.Error))
} else if result.RowsAffected == 0 {
logger.Error("query component detail info from table is empty", zap.String("table_name", tableName))
}
unmarshalMap.Set("id", modelParseConfig.ComponentInfo.ID)
unmarshalMap.Set("created_time", modelParseConfig.ComponentInfo.VisibleID)
unmarshalMap.Set("parent_id", modelParseConfig.ComponentInfo.GridID)
unmarshalMap.Set("type", modelParseConfig.ComponentInfo.ZoneID)
unmarshalMap.Set("created_time", modelParseConfig.ComponentInfo.StationID)
unmarshalMap.Set("updated_time", modelParseConfig.ComponentInfo.ComponentType)
unmarshalMap.Set("id", modelParseConfig.ComponentInfo.State)
unmarshalMap.Set("parent_id", modelParseConfig.ComponentInfo.ConnectedBus)
unmarshalMap.Set("type", modelParseConfig.ComponentInfo.Name)
unmarshalMap.Set("updated_time", modelParseConfig.ComponentInfo.Description)
unmarshalMap.Set("id", modelParseConfig.ComponentInfo.Context)
unmarshalMap.Set("parent_id", modelParseConfig.ComponentInfo.Comment)
unmarshalMap.Set("type", modelParseConfig.ComponentInfo.InService)
return
}