// Package pool define concurrency call function in ants package pool import ( "context" "time" "modelRT/config" "modelRT/database" "modelRT/diagram" "modelRT/model" realtimedata "modelRT/real-time-data" "github.com/bitly/go-simplejson" "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") return } cancelCtx, cancel := context.WithTimeout(modelParseConfig.Context, 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("global_uuid = ?", modelParseConfig.ComponentInfo.GlobalUUID).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)) } // TODO 判断对应 model 是否有锚定参量 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() for _, param := range paramsList { if baseConfig, ok := param.(config.AnchorParamBaseConfig); ok { anchorParam := config.AnchorParamConfig{ AnchorParamBaseConfig: baseConfig, } anchorParam.CalculateFunc, anchorParam.CalculateParams = config.SelectFuncAndParamsByAnchorName(baseConfig.AnchorName) realtimedata.AnchorParamsChan <- anchorParam } } } uuid := modelParseConfig.ComponentInfo.GlobalUUID.String() 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) return }