From 1bf7fcc79a31e24d5e86bd2c3b86f826f82a0c1d Mon Sep 17 00:00:00 2001 From: 18209 Date: Mon, 21 Jul 2025 16:34:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E6=B5=8B=E7=82=B9=E5=8A=A0?= =?UTF-8?q?=E6=B5=8B=E7=82=B9=E5=90=8D=E7=A7=B0id=E6=9B=B4=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumers/consumerSavoirTheme.go | 52 +++++++++++++++----------------- dbOperate/elasticsearchHelper.go | 5 +-- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/consumers/consumerSavoirTheme.go b/consumers/consumerSavoirTheme.go index f7d6f41..d34c86a 100644 --- a/consumers/consumerSavoirTheme.go +++ b/consumers/consumerSavoirTheme.go @@ -12,7 +12,6 @@ import ( "gopkg.in/yaml.v3" "log" "regexp" - "strings" "sync" "time" ) @@ -132,7 +131,7 @@ where off.is_open=true order by off.struct_id` func (the *consumerSavoirTheme) judgeOffline() { now := time.Now() for _, gap := range the.pgOffLineGaps { - var alarmDetails []string + var alarmDetails string if !gap.IsOpen { continue } @@ -160,14 +159,12 @@ func (the *consumerSavoirTheme) judgeOffline() { detailPoint := extractSensorName(alarmTheme.Detail) if theme.SensorName == detailPoint { if offlineMin < float64(gap.OfflineGap) { - prefix := "offline-" - sourceId := prefix + fmt.Sprintf("%d-%d", gap.StructId, gap.FactorId) alarmMsg := models.KafkaAlarm{ MessageMode: "AlarmAutoElimination", StructureId: gap.StructId, StructureName: gap.StructName, - SourceId: sourceId, - SourceName: gap.StructName, + SourceId: fmt.Sprintf("%d", theme.Sensor), + SourceName: theme.SensorName, AlarmTypeCode: "3004", AlarmCode: "********", Content: "", @@ -187,30 +184,31 @@ func (the *consumerSavoirTheme) judgeOffline() { if offlineMin > float64(gap.OfflineGap) { msg := fmt.Sprintf("测点[%s]离线%f min > %d min", theme.SensorName, offlineMin, gap.OfflineGap) log.Printf("----- > %s", msg) - alarmDetails = append(alarmDetails, msg) + alarmDetails = msg } - } - prefix := "offline-" - sourceId := prefix + fmt.Sprintf("%d-%d", gap.StructId, gap.FactorId) - if len(alarmDetails) > 0 { - alarmMsg := models.KafkaAlarm{ - MessageMode: "AlarmGeneration", - StructureId: gap.StructId, - StructureName: gap.StructName, - SourceId: sourceId, - SourceName: gap.StructName, - AlarmTypeCode: "8004", - AlarmCode: "80040003", - Content: strings.Join(alarmDetails, ","), - Time: time.Now().Format("2006-01-02T15:04:05+0800"), - SourceTypeId: 1, // 0:DTU, 1:传感器, 2:测点 - Sponsor: "goInOut_savoirTheme", - Extras: nil, - SubDevices: nil, + + log.Printf("len(alarmDetails) > 0 %d,%f", len(alarmDetails), float64(gap.OfflineGap)) + if alarmDetails != "" { + alarmMsg := models.KafkaAlarm{ + MessageMode: "AlarmGeneration", + StructureId: gap.StructId, + StructureName: gap.StructName, + SourceId: fmt.Sprintf("%d", theme.Sensor), + SourceName: theme.SensorName, + AlarmTypeCode: "8004", + AlarmCode: "80040003", + Content: alarmDetails, + Time: time.Now().Format("2006-01-02T15:04:05+0800"), + SourceTypeId: 1, // 0:DTU, 1:传感器, 2:测点 + Sponsor: "goInOut_savoirTheme", + Extras: nil, + SubDevices: nil, + } + + payload, _ := json.Marshal(alarmMsg) + the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) } - payload, _ := json.Marshal(alarmMsg) - the.InKafka.Publish(the.Info.IoConfig.In.Kafka.AlarmTopic, payload) } } diff --git a/dbOperate/elasticsearchHelper.go b/dbOperate/elasticsearchHelper.go index 1cac397..05d734d 100644 --- a/dbOperate/elasticsearchHelper.go +++ b/dbOperate/elasticsearchHelper.go @@ -199,8 +199,9 @@ func (the *ESHelper) SearchThemeData(index string, queryBody string) ([]models.E themesResp, err := the.searchThemes(index, queryBody) var theme models.EsTheme - if len(themesResp.Hits.Hits) > 0 { - theme = themesResp.Hits.Hits[0].Source + for _, themesResptheme := range themesResp.Hits.Hits { + + theme = themesResptheme.Source themes = append(themes, theme) }