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) }