Browse Source

循环测点加测点名称id更换

dev
18209 3 days ago
parent
commit
1bf7fcc79a
  1. 26
      consumers/consumerSavoirTheme.go
  2. 5
      dbOperate/elasticsearchHelper.go

26
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,21 +184,20 @@ 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 {
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: sourceId,
SourceName: gap.StructName,
SourceId: fmt.Sprintf("%d", theme.Sensor),
SourceName: theme.SensorName,
AlarmTypeCode: "8004",
AlarmCode: "80040003",
Content: strings.Join(alarmDetails, ","),
Content: alarmDetails,
Time: time.Now().Format("2006-01-02T15:04:05+0800"),
SourceTypeId: 1, // 0:DTU, 1:传感器, 2:测点
Sponsor: "goInOut_savoirTheme",
@ -215,6 +211,8 @@ func (the *consumerSavoirTheme) judgeOffline() {
}
}
}
// 提取方括号 [] 内的内容

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

Loading…
Cancel
Save