58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
// Package pool define concurrency call function in ants
|
|
package pool
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"modelRT/config"
|
|
"modelRT/database"
|
|
"modelRT/diagram"
|
|
"modelRT/model"
|
|
|
|
cmap "github.com/orcaman/concurrent-map/v2"
|
|
"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()
|
|
uuid := modelParseConfig.ComponentInfo.GlobalUUID.String()
|
|
unmarshalMap := cmap.New[any]()
|
|
|
|
tableName := model.SelectModelNameByType(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("uuid", modelParseConfig.ComponentInfo.GlobalUUID.String())
|
|
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)
|
|
|
|
diagram.StoreComponentMap(uuid, &unmarshalMap)
|
|
return
|
|
}
|