From 6e16a9a39ac6a3d25aac92f699f59d6a1f36968c Mon Sep 17 00:00:00 2001 From: douxu Date: Wed, 24 Dec 2025 09:06:42 +0800 Subject: [PATCH] fix bug of measurement recommend injection func --- constants/recommend_keys.go | 8 ++++---- .../measurments-recommend/measurement_injection.go | 12 ++++++------ model/attribute_group_model.go | 8 +++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/constants/recommend_keys.go b/constants/recommend_keys.go index b4901d3..684b1cc 100644 --- a/constants/recommend_keys.go +++ b/constants/recommend_keys.go @@ -24,16 +24,16 @@ const ( RedisAllMeasTagSetKey = "measurement_tag_keys" // 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 = "%s_stations_keys" + RedisSpecZoneStationSetKey = "%s_station_keys" // 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 = "%s_components_tag_keys" + RedisSpecStationCompTagSetKey = "%s_component_tag_keys" // RedisSpecCompTagMeasSetKey define redis set key which store all measurement keys under specific component tag RedisSpecCompTagMeasSetKey = "%s_measurement_keys" diff --git a/deploy/redis-test-data/measurments-recommend/measurement_injection.go b/deploy/redis-test-data/measurments-recommend/measurement_injection.go index 701c727..bab52b2 100644 --- a/deploy/redis-test-data/measurments-recommend/measurement_injection.go +++ b/deploy/redis-test-data/measurments-recommend/measurement_injection.go @@ -28,13 +28,13 @@ const ( measurementTagKeysSet = "measurement_tag_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) - zoneStationSetKeyFormat = "zone%d_%d_stations_keys" + zoneStationSetKeyFormat = "zone%d_%d_station_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) - 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) compTagMeasKeyFormat = "comptag%d_%d_%d_%d_%d_measurement_keys" ) @@ -86,7 +86,7 @@ func insertStaticSets(ctx context.Context, rdb *redis.Client) error { } // 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) } @@ -141,7 +141,7 @@ func insertDynamicHierarchy(ctx context.Context, rdb *redis.Client) error { // I: CompTag Index (1-3) for I := 1; I <= 3; I++ { compTagID := fmt.Sprintf("%s_%d", nsPathID, I) - compTagKey := "cmptag" + compTagID + compTagKey := "comptag" + compTagID allCompTagKeys = append(allCompTagKeys, compTagKey) nsCompTagMembers = append(nsCompTagMembers, compTagKey) diff --git a/model/attribute_group_model.go b/model/attribute_group_model.go index 307de30..e56d833 100644 --- a/model/attribute_group_model.go +++ b/model/attribute_group_model.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "modelRT/constants" "modelRT/diagram" "modelRT/logger" @@ -95,13 +96,13 @@ func TraverseAttributeGroupTables(ctx context.Context, db *gorm.DB, compParamMap AttributeType: attributeType, AttributeGroup: attributeGroup, } - go storeAttributeGroup(ctx, attrSet, componentUUIDStr, columnParam) + go storeAttributeGroup(ctx, attrSet, columnParam) } } 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() pipe := rdb.Pipeline() @@ -112,7 +113,7 @@ func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, com specCompMeasKey := fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, attributeSet.CompTag) attrNameMembers := make([]string, 0, len(colParams.AttributeGroup)) 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 { attrbutesGroups = append(attrbutesGroups, attrName, attrValue) attrNameMembers = append(attrNameMembers, attrName) @@ -126,6 +127,7 @@ func storeAttributeGroup(ctx context.Context, attributeSet orm.AttributeSet, com pipe.SAdd(ctx, specCompMeasKey, attrNameMembers) } + // TODO 增加 suggestion 索引内容 _, err := pipe.Exec(ctx) if err != nil { logger.Error(ctx, "init component attribute group recommend content failed", "error", err)