2024-12-05 14:57:23 +08:00
|
|
|
// Package pool define concurrency call function in ants
|
|
|
|
|
package pool
|
2024-11-22 16:41:04 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"modelRT/config"
|
|
|
|
|
"modelRT/database"
|
|
|
|
|
"modelRT/diagram"
|
2024-12-26 15:03:20 +08:00
|
|
|
"modelRT/logger"
|
2024-12-05 14:57:23 +08:00
|
|
|
"modelRT/model"
|
2024-11-22 16:41:04 +08:00
|
|
|
)
|
|
|
|
|
|
2024-12-26 15:03:20 +08:00
|
|
|
// ParseFunc defines func that parses the model data from postgres
|
2024-11-22 16:41:04 +08:00
|
|
|
var ParseFunc = func(parseConfig interface{}) {
|
|
|
|
|
modelParseConfig, ok := parseConfig.(config.ModelParseConfig)
|
|
|
|
|
if !ok {
|
2025-06-06 16:41:52 +08:00
|
|
|
logger.Error(modelParseConfig.Ctx, "conversion model parse config type failed")
|
2024-12-18 16:25:49 +08:00
|
|
|
return
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-06 16:41:52 +08:00
|
|
|
cancelCtx, cancel := context.WithTimeout(modelParseConfig.Ctx, 5*time.Second)
|
2024-11-22 16:41:04 +08:00
|
|
|
defer cancel()
|
2024-11-28 15:29:34 +08:00
|
|
|
pgClient := database.GetPostgresDBClient()
|
2024-11-22 16:41:04 +08:00
|
|
|
|
2024-12-18 16:25:49 +08:00
|
|
|
unmarshalMap := make(map[string]interface{})
|
2024-12-05 14:57:23 +08:00
|
|
|
tableName := model.SelectModelNameByType(modelParseConfig.ComponentInfo.ComponentType)
|
2024-12-18 16:25:49 +08:00
|
|
|
|
2025-01-07 16:45:52 +08:00
|
|
|
result := pgClient.WithContext(cancelCtx).Table(tableName).Where("component_id = ?", modelParseConfig.ComponentInfo.ID).Find(&unmarshalMap)
|
2024-11-22 16:41:04 +08:00
|
|
|
if result.Error != nil {
|
2025-06-06 16:41:52 +08:00
|
|
|
logger.Error(modelParseConfig.Ctx, "query component detail info failed", "error", result.Error)
|
2024-12-20 16:06:42 +08:00
|
|
|
return
|
2024-11-22 16:41:04 +08:00
|
|
|
} else if result.RowsAffected == 0 {
|
2025-06-06 16:41:52 +08:00
|
|
|
logger.Error(modelParseConfig.Ctx, "query component detail info from table is empty", "table_name", tableName)
|
2024-12-20 16:06:42 +08:00
|
|
|
return
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
2024-12-18 16:25:49 +08:00
|
|
|
|
2025-01-22 16:38:46 +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
|
|
|
}
|
2025-01-22 16:38:46 +08:00
|
|
|
diagram.StoreAnchorValue(modelParseConfig.ComponentInfo.ID, anchorName)
|
|
|
|
|
|
2025-06-06 16:41:52 +08:00
|
|
|
GetComponentChan(modelParseConfig.Ctx, modelParseConfig.ComponentInfo.ID)
|
2024-12-18 16:25:49 +08:00
|
|
|
|
2025-01-22 16:38:46 +08:00
|
|
|
uuid := modelParseConfig.ComponentInfo.GlobalUUID.String()
|
2024-12-18 16:25:49 +08:00
|
|
|
unmarshalMap["id"] = modelParseConfig.ComponentInfo.ID
|
|
|
|
|
unmarshalMap["uuid"] = uuid
|
2024-12-30 16:39:11 +08:00
|
|
|
unmarshalMap["uuid"] = modelParseConfig.ComponentInfo.Tag
|
|
|
|
|
unmarshalMap["grid_id"] = modelParseConfig.ComponentInfo.GridID
|
|
|
|
|
unmarshalMap["zone_id"] = modelParseConfig.ComponentInfo.ZoneID
|
|
|
|
|
unmarshalMap["station_id"] = modelParseConfig.ComponentInfo.StationID
|
|
|
|
|
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
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
diagram.StoreComponentMap(modelParseConfig.ComponentInfo.ID, unmarshalMap)
|
2024-11-22 16:41:04 +08:00
|
|
|
return
|
|
|
|
|
}
|