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-05 14:57:23 +08:00
|
|
|
"modelRT/model"
|
2024-12-18 16:25:49 +08:00
|
|
|
realtimedata "modelRT/real-time-data"
|
2024-11-22 16:41:04 +08:00
|
|
|
|
2024-12-18 16:25:49 +08:00
|
|
|
"github.com/bitly/go-simplejson"
|
2024-11-22 16:41:04 +08:00
|
|
|
"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")
|
2024-12-18 16:25:49 +08:00
|
|
|
return
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancelCtx, cancel := context.WithTimeout(modelParseConfig.Context, 5*time.Second)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
result := pgClient.WithContext(cancelCtx).Table(tableName).Where("global_uuid = ?", modelParseConfig.ComponentInfo.GlobalUUID).Find(&unmarshalMap)
|
2024-11-22 16:41:04 +08:00
|
|
|
if result.Error != nil {
|
|
|
|
|
logger.Error("query component detail info failed", zap.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 {
|
|
|
|
|
logger.Error("query component detail info from table is empty", zap.String("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
|
|
|
|
2024-12-20 16:06:42 +08:00
|
|
|
uuid := modelParseConfig.ComponentInfo.GlobalUUID.String()
|
|
|
|
|
|
2024-12-18 16:25:49 +08:00
|
|
|
configsStr, exist := unmarshalMap["anchor_configs_list"]
|
|
|
|
|
if exist {
|
|
|
|
|
anchorConfigsJSON, err := simplejson.NewJson([]byte(configsStr.(string)))
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Error("formmat anchor configs json failed", zap.Error(err))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paramsList := anchorConfigsJSON.Get("params_list").MustArray()
|
2024-12-20 16:06:42 +08:00
|
|
|
for index := range paramsList {
|
|
|
|
|
anchorName := anchorConfigsJSON.Get("params_list").GetIndex(index).Get("upper_limit").MustString()
|
|
|
|
|
|
|
|
|
|
anchorParam := config.AnchorParamConfig{
|
|
|
|
|
AnchorParamBaseConfig: config.AnchorParamBaseConfig{
|
|
|
|
|
UUID: uuid,
|
|
|
|
|
AnchorName: anchorName,
|
|
|
|
|
CompareValUpperLimit: float32(anchorConfigsJSON.Get("params_list").GetIndex(index).Get("upper_limit").MustFloat64()),
|
|
|
|
|
CompareValLowerLimit: float32(anchorConfigsJSON.Get("params_list").GetIndex(index).Get("lower_limit").MustFloat64()),
|
|
|
|
|
},
|
2024-12-18 16:25:49 +08:00
|
|
|
}
|
2024-12-20 16:06:42 +08:00
|
|
|
anchorParam.CalculateFunc, anchorParam.CalculateParams = config.SelectAnchorCalculateFuncAndParams(modelParseConfig.ComponentInfo.ComponentType, anchorName, unmarshalMap)
|
|
|
|
|
diagram.StoreAnchorValue(modelParseConfig.ComponentInfo.GlobalUUID.String(), anchorName)
|
|
|
|
|
realtimedata.AnchorParamsChan <- anchorParam
|
|
|
|
|
|
2024-12-18 16:25:49 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unmarshalMap["id"] = modelParseConfig.ComponentInfo.ID
|
|
|
|
|
unmarshalMap["uuid"] = uuid
|
|
|
|
|
unmarshalMap["created_time"] = modelParseConfig.ComponentInfo.VisibleID
|
|
|
|
|
unmarshalMap["parent_id"] = modelParseConfig.ComponentInfo.GridID
|
|
|
|
|
unmarshalMap["type"] = modelParseConfig.ComponentInfo.ZoneID
|
|
|
|
|
unmarshalMap["created_time"] = modelParseConfig.ComponentInfo.StationID
|
|
|
|
|
unmarshalMap["updated_time"] = modelParseConfig.ComponentInfo.ComponentType
|
|
|
|
|
unmarshalMap["id"] = modelParseConfig.ComponentInfo.State
|
|
|
|
|
unmarshalMap["parent_id"] = modelParseConfig.ComponentInfo.ConnectedBus
|
|
|
|
|
unmarshalMap["type"] = modelParseConfig.ComponentInfo.Name
|
|
|
|
|
unmarshalMap["updated_time"] = modelParseConfig.ComponentInfo.Description
|
|
|
|
|
unmarshalMap["id"] = modelParseConfig.ComponentInfo.Context
|
|
|
|
|
unmarshalMap["parent_id"] = modelParseConfig.ComponentInfo.Comment
|
|
|
|
|
unmarshalMap["type"] = modelParseConfig.ComponentInfo.InService
|
|
|
|
|
|
|
|
|
|
diagram.StoreComponentMap(uuid, unmarshalMap)
|
2024-11-22 16:41:04 +08:00
|
|
|
return
|
|
|
|
|
}
|