modelRT/pool/concurrency_model_parse.go

70 lines
2.3 KiB
Go
Raw Normal View History

// Package pool define concurrency call function in ants
package pool
import (
"context"
"time"
"modelRT/config"
"modelRT/database"
"modelRT/diagram"
"modelRT/logger"
"modelRT/model"
"go.uber.org/zap"
)
// ParseFunc defines func that parses the model data from postgres
var ParseFunc = func(parseConfig interface{}) {
logger := logger.GetLoggerInstance()
modelParseConfig, ok := parseConfig.(config.ModelParseConfig)
if !ok {
logger.Error("conversion model parse config type failed")
2024-12-18 16:25:49 +08:00
return
}
cancelCtx, cancel := context.WithTimeout(modelParseConfig.Context, 5*time.Second)
defer cancel()
pgClient := database.GetPostgresDBClient()
2024-12-18 16:25:49 +08:00
unmarshalMap := make(map[string]interface{})
tableName := model.SelectModelNameByType(modelParseConfig.ComponentInfo.ComponentType)
2024-12-18 16:25:49 +08:00
result := pgClient.WithContext(cancelCtx).Table(tableName).Where("component_id = ?", modelParseConfig.ComponentInfo.ID).Find(&unmarshalMap)
if result.Error != nil {
logger.Error("query component detail info failed", zap.Error(result.Error))
return
} else if result.RowsAffected == 0 {
logger.Error("query component detail info from table is empty", zap.String("table_name", tableName))
return
}
2024-12-18 16:25:49 +08:00
var anchorName string
if anchoringV := unmarshalMap["anchor_v"].(bool); anchoringV {
anchorName = "voltage"
} else {
anchorName = "current"
2024-12-18 16:25:49 +08:00
}
diagram.StoreAnchorValue(modelParseConfig.ComponentInfo.ID, anchorName)
GetComponentChan(modelParseConfig.Context, modelParseConfig.ComponentInfo.ID)
2024-12-18 16:25:49 +08:00
uuid := modelParseConfig.ComponentInfo.GlobalUUID.String()
2024-12-18 16:25:49 +08:00
unmarshalMap["id"] = modelParseConfig.ComponentInfo.ID
unmarshalMap["uuid"] = uuid
unmarshalMap["uuid"] = modelParseConfig.ComponentInfo.Tag
unmarshalMap["grid_id"] = modelParseConfig.ComponentInfo.GridID
unmarshalMap["zone_id"] = modelParseConfig.ComponentInfo.ZoneID
unmarshalMap["station_id"] = modelParseConfig.ComponentInfo.StationID
unmarshalMap["page_id"] = modelParseConfig.ComponentInfo.PageID
unmarshalMap["component_type"] = modelParseConfig.ComponentInfo.ComponentType
unmarshalMap["name"] = modelParseConfig.ComponentInfo.Name
unmarshalMap["context"] = modelParseConfig.ComponentInfo.Context
unmarshalMap["op"] = modelParseConfig.ComponentInfo.Op
unmarshalMap["ts"] = modelParseConfig.ComponentInfo.Ts
2024-12-18 16:25:49 +08:00
diagram.StoreComponentMap(modelParseConfig.ComponentInfo.ID, unmarshalMap)
return
}