modelRT/pool/concurrency_model_parse.go

66 lines
2.3 KiB
Go

// Package pool define concurrency call function in ants
package pool
import (
"context"
"time"
"modelRT/config"
"modelRT/database"
"modelRT/diagram"
"modelRT/logger"
"modelRT/model"
)
// ParseFunc defines func that parses the model data from postgres
var ParseFunc = func(parseConfig interface{}) {
modelParseConfig, ok := parseConfig.(config.ModelParseConfig)
if !ok {
logger.Error(modelParseConfig.Ctx, "conversion model parse config type failed")
return
}
cancelCtx, cancel := context.WithTimeout(modelParseConfig.Ctx, 5*time.Second)
defer cancel()
pgClient := database.GetPostgresDBClient()
unmarshalMap := make(map[string]interface{})
tableName := model.SelectModelNameByType(modelParseConfig.ComponentInfo.ComponentType)
result := pgClient.WithContext(cancelCtx).Table(tableName).Where("component_id = ?", modelParseConfig.ComponentInfo.ID).Find(&unmarshalMap)
if result.Error != nil {
logger.Error(modelParseConfig.Ctx, "query component detail info failed", "error", result.Error)
return
} else if result.RowsAffected == 0 {
logger.Error(modelParseConfig.Ctx, "query component detail info from table is empty", "table_name", tableName)
return
}
var anchorName string
if anchoringV := unmarshalMap["anchor_v"].(bool); anchoringV {
anchorName = "voltage"
} else {
anchorName = "current"
}
diagram.StoreAnchorValue(modelParseConfig.ComponentInfo.ID, anchorName)
GetComponentChan(modelParseConfig.Ctx, modelParseConfig.ComponentInfo.ID)
uuid := modelParseConfig.ComponentInfo.GlobalUUID.String()
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
diagram.StoreComponentMap(modelParseConfig.ComponentInfo.ID, unmarshalMap)
return
}