fix bug of measurement recommend injection func

This commit is contained in:
douxu 2025-12-24 09:06:42 +08:00
parent c29f58f388
commit 6e16a9a39a
3 changed files with 15 additions and 13 deletions

View File

@ -24,16 +24,16 @@ const (
RedisAllMeasTagSetKey = "measurement_tag_keys" RedisAllMeasTagSetKey = "measurement_tag_keys"
// RedisSpecGridZoneSetKey define redis set key which store all zone keys under specific grid // RedisSpecGridZoneSetKey define redis set key which store all zone keys under specific grid
RedisSpecGridZoneSetKey = "%s_zones_keys" RedisSpecGridZoneSetKey = "%s_zone_keys"
// RedisSpecZoneStationSetKey define redis set key which store all station keys under specific zone // RedisSpecZoneStationSetKey define redis set key which store all station keys under specific zone
RedisSpecZoneStationSetKey = "%s_stations_keys" RedisSpecZoneStationSetKey = "%s_station_keys"
// RedisSpecStationCompNSPATHSetKey define redis set key which store all component nspath keys under specific station // RedisSpecStationCompNSPATHSetKey define redis set key which store all component nspath keys under specific station
RedisSpecStationCompNSPATHSetKey = "%s_components_nspath_keys" RedisSpecStationCompNSPATHSetKey = "%s_component_nspath_keys"
// RedisSpecStationCompTagSetKey define redis set key which store all component tag keys under specific station // RedisSpecStationCompTagSetKey define redis set key which store all component tag keys under specific station
RedisSpecStationCompTagSetKey = "%s_components_tag_keys" RedisSpecStationCompTagSetKey = "%s_component_tag_keys"
// RedisSpecCompTagMeasSetKey define redis set key which store all measurement keys under specific component tag // RedisSpecCompTagMeasSetKey define redis set key which store all measurement keys under specific component tag
RedisSpecCompTagMeasSetKey = "%s_measurement_keys" RedisSpecCompTagMeasSetKey = "%s_measurement_keys"

View File

@ -28,13 +28,13 @@ const (
measurementTagKeysSet = "measurement_tag_keys" measurementTagKeysSet = "measurement_tag_keys"
// Grid -> Zone (e.g., grid1_zones_keys) // Grid -> Zone (e.g., grid1_zones_keys)
gridZoneSetKeyFormat = "grid%d_zones_keys" gridZoneSetKeyFormat = "grid%d_zone_keys"
// Zone -> Station (e.g., zone1_1_stations_keys) // Zone -> Station (e.g., zone1_1_stations_keys)
zoneStationSetKeyFormat = "zone%d_%d_stations_keys" zoneStationSetKeyFormat = "zone%d_%d_station_keys"
// Station -> NSPath (e.g., station1_1_1_components_nspath_keys) // Station -> NSPath (e.g., station1_1_1_components_nspath_keys)
stationNSPathKeyFormat = "station%d_%d_%d_components_nspath_keys" stationNSPathKeyFormat = "station%d_%d_%d_component_nspath_keys"
// NSPath -> CompTag (e.g., ns1_1_1_1_components_tag_keys) // NSPath -> CompTag (e.g., ns1_1_1_1_components_tag_keys)
nsPathCompTagKeyFormat = "ns%d_%d_%d_%d_components_tag_keys" nsPathCompTagKeyFormat = "ns%d_%d_%d_%d_component_tag_keys"
// CompTag -> Measurement (e.g., comptag1_1_1_1_1_measurement_keys) // CompTag -> Measurement (e.g., comptag1_1_1_1_1_measurement_keys)
compTagMeasKeyFormat = "comptag%d_%d_%d_%d_%d_measurement_keys" compTagMeasKeyFormat = "comptag%d_%d_%d_%d_%d_measurement_keys"
) )
@ -86,7 +86,7 @@ func insertStaticSets(ctx context.Context, rdb *redis.Client) error {
} }
// config_keys // config_keys
if err := rdb.SAdd(ctx, configKeysSet, configMetrics...).Err(); err != nil { if err := rdb.SAdd(ctx, configKeysSet, "bay").Err(); err != nil {
return fmt.Errorf("sadd failed for %s: %w", configKeysSet, err) return fmt.Errorf("sadd failed for %s: %w", configKeysSet, err)
} }
@ -141,7 +141,7 @@ func insertDynamicHierarchy(ctx context.Context, rdb *redis.Client) error {
// I: CompTag Index (1-3) // I: CompTag Index (1-3)
for I := 1; I <= 3; I++ { for I := 1; I <= 3; I++ {
compTagID := fmt.Sprintf("%s_%d", nsPathID, I) compTagID := fmt.Sprintf("%s_%d", nsPathID, I)
compTagKey := "cmptag" + compTagID compTagKey := "comptag" + compTagID
allCompTagKeys = append(allCompTagKeys, compTagKey) allCompTagKeys = append(allCompTagKeys, compTagKey)
nsCompTagMembers = append(nsCompTagMembers, compTagKey) nsCompTagMembers = append(nsCompTagMembers, compTagKey)

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"modelRT/constants" "modelRT/constants"
"modelRT/diagram" "modelRT/diagram"
"modelRT/logger" "modelRT/logger"
@ -95,13 +96,13 @@ func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compParamMap
AttributeType: attributeType, AttributeType: attributeType,
AttributeGroup: attributeGroup, AttributeGroup: attributeGroup,
} }
go storeAttributeGroup(ctx, attrSet, componentUUIDStr, columnParam) go storeAttributeGroup(ctx, attrSet, columnParam)
} }
} }
return nil return nil
} }
func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, compUUIDStr string, colParams columnParam) { func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, colParams columnParam) {
rdb := diagram.GetRedisClientInstance() rdb := diagram.GetRedisClientInstance()
pipe := rdb.Pipeline() pipe := rdb.Pipeline()
@ -112,7 +113,7 @@ func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, com
specCompMeasKey := fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, attributeSet.CompTag) specCompMeasKey := fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, attributeSet.CompTag)
attrNameMembers := make([]string, 0, len(colParams.AttributeGroup)) attrNameMembers := make([]string, 0, len(colParams.AttributeGroup))
attrbutesGroups := make([]any, 0, len(colParams.AttributeGroup)*2) attrbutesGroups := make([]any, 0, len(colParams.AttributeGroup)*2)
attributeGroupKey := fmt.Sprintf("%s_%s", compUUIDStr, colParams.AttributeType) attributeGroupKey := fmt.Sprintf("%s_%s", attributeSet.CompTag, colParams.AttributeType)
for attrName, attrValue := range colParams.AttributeGroup { for attrName, attrValue := range colParams.AttributeGroup {
attrbutesGroups = append(attrbutesGroups, attrName, attrValue) attrbutesGroups = append(attrbutesGroups, attrName, attrValue)
attrNameMembers = append(attrNameMembers, attrName) attrNameMembers = append(attrNameMembers, attrName)
@ -126,6 +127,7 @@ func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, com
pipe.SAdd(ctx, specCompMeasKey, attrNameMembers) pipe.SAdd(ctx, specCompMeasKey, attrNameMembers)
} }
// TODO 增加 suggestion 索引内容
_, err := pipe.Exec(ctx) _, err := pipe.Exec(ctx)
if err != nil { if err != nil {
logger.Error(ctx, "init component attribute group recommend content failed", "error", err) logger.Error(ctx, "init component attribute group recommend content failed", "error", err)