From 78adb501f667086c83a31ea509317c3a221bb3b1 Mon Sep 17 00:00:00 2001 From: 18209 Date: Mon, 21 Jul 2025 18:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E5=91=8A=E8=AD=A6=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consumers/consumerSavoirTheme.go | 5 ++--- dbOperate/elasticsearchHelper.go | 14 +++++++------- models/esTheme.go | 14 +++----------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/consumers/consumerSavoirTheme.go b/consumers/consumerSavoirTheme.go index d34c86a..f5e8c1a 100644 --- a/consumers/consumerSavoirTheme.go +++ b/consumers/consumerSavoirTheme.go @@ -155,9 +155,8 @@ func (the *consumerSavoirTheme) judgeOffline() { if err != nil { log.Printf("查询es 异常") } - for _, alarmTheme := range allAlarmThemes { - detailPoint := extractSensorName(alarmTheme.Detail) - if theme.SensorName == detailPoint { + for _, alarmThemeName := range allAlarmThemes { + if theme.SensorName == alarmThemeName { if offlineMin < float64(gap.OfflineGap) { alarmMsg := models.KafkaAlarm{ MessageMode: "AlarmAutoElimination", diff --git a/dbOperate/elasticsearchHelper.go b/dbOperate/elasticsearchHelper.go index 05d734d..587e198 100644 --- a/dbOperate/elasticsearchHelper.go +++ b/dbOperate/elasticsearchHelper.go @@ -208,17 +208,17 @@ func (the *ESHelper) SearchThemeData(index string, queryBody string) ([]models.E return themes, err } -func (the *ESHelper) SearchAlarmThemeData(index string, queryBody string) ([]models.EsAlarmTheme, error) { - var themes []models.EsAlarmTheme +func (the *ESHelper) SearchAlarmThemeData(index string, queryBody string) ([]string, error) { + var sensorNames []string themesResp, err := the.searchAlarmThemes(index, queryBody) - var theme models.EsAlarmTheme - if len(themesResp.Hits.Hits) > 0 { - theme = models.EsAlarmTheme(themesResp.Hits.Hits[0].Source) - themes = append(themes, theme) + var sensorName string + for _, themesResptheme := range themesResp.Hits.Hits { + sensorName = themesResptheme.Source.SensorName + sensorNames = append(sensorNames, sensorName) } - return themes, err + return sensorNames, err } func (the *ESHelper) BulkWrite(index, reqBody string) { diff --git a/models/esTheme.go b/models/esTheme.go index 13cf737..8b2a00a 100644 --- a/models/esTheme.go +++ b/models/esTheme.go @@ -17,17 +17,9 @@ type EsTheme struct { } type EsAlarmTheme struct { - SensorName string `json:"sensor_name"` - FactorName string `json:"factor_name"` - FactorProtoCode string `json:"factor_proto_code"` - Data map[string]any `json:"data"` - Detail string `json:"detail"` - Factor int `json:"factor"` - CollectTime time.Time `json:"collect_time"` - Sensor int `json:"sensor"` - Structure int `json:"structure"` - IotaDevice []string `json:"iota_device"` - CreateTime time.Time `json:"create_time"` + SensorName string `json:"sensor_name"` + SensorId string `json:"source_id"` + Detail string `json:"detail"` } type EsThemeResp struct {