Browse Source

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

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

52
consumers/consumerSavoirTheme.go

@ -12,7 +12,6 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"log" "log"
"regexp" "regexp"
"strings"
"sync" "sync"
"time" "time"
) )
@ -132,7 +131,7 @@ where off.is_open=true order by off.struct_id`
func (the *consumerSavoirTheme) judgeOffline() { func (the *consumerSavoirTheme) judgeOffline() {
now := time.Now() now := time.Now()
for _, gap := range the.pgOffLineGaps { for _, gap := range the.pgOffLineGaps {
var alarmDetails []string var alarmDetails string
if !gap.IsOpen { if !gap.IsOpen {
continue continue
} }
@ -160,14 +159,12 @@ func (the *consumerSavoirTheme) judgeOffline() {
detailPoint := extractSensorName(alarmTheme.Detail) detailPoint := extractSensorName(alarmTheme.Detail)
if theme.SensorName == detailPoint { if theme.SensorName == detailPoint {
if offlineMin < float64(gap.OfflineGap) { if offlineMin < float64(gap.OfflineGap) {
prefix := "offline-"
sourceId := prefix + fmt.Sprintf("%d-%d", gap.StructId, gap.FactorId)
alarmMsg := models.KafkaAlarm{ alarmMsg := models.KafkaAlarm{
MessageMode: "AlarmAutoElimination", MessageMode: "AlarmAutoElimination",
StructureId: gap.StructId, StructureId: gap.StructId,
StructureName: gap.StructName, StructureName: gap.StructName,
SourceId: sourceId, SourceId: fmt.Sprintf("%d", theme.Sensor),
SourceName: gap.StructName, SourceName: theme.SensorName,
AlarmTypeCode: "3004", AlarmTypeCode: "3004",
AlarmCode: "********", AlarmCode: "********",
Content: "", Content: "",
@ -187,30 +184,31 @@ func (the *consumerSavoirTheme) judgeOffline() {
if offlineMin > float64(gap.OfflineGap) { if offlineMin > float64(gap.OfflineGap) {
msg := fmt.Sprintf("测点[%s]离线%f min > %d min", theme.SensorName, offlineMin, gap.OfflineGap) msg := fmt.Sprintf("测点[%s]离线%f min > %d min", theme.SensorName, offlineMin, gap.OfflineGap)
log.Printf("----- > %s", msg) log.Printf("----- > %s", msg)
alarmDetails = append(alarmDetails, msg) alarmDetails = msg
} }
}
prefix := "offline-" log.Printf("len(alarmDetails) > 0 %d,%f", len(alarmDetails), float64(gap.OfflineGap))
sourceId := prefix + fmt.Sprintf("%d-%d", gap.StructId, gap.FactorId) if alarmDetails != "" {
if len(alarmDetails) > 0 { alarmMsg := models.KafkaAlarm{
alarmMsg := models.KafkaAlarm{ MessageMode: "AlarmGeneration",
MessageMode: "AlarmGeneration", StructureId: gap.StructId,
StructureId: gap.StructId, StructureName: gap.StructName,
StructureName: gap.StructName, SourceId: fmt.Sprintf("%d", theme.Sensor),
SourceId: sourceId, SourceName: theme.SensorName,
SourceName: gap.StructName, AlarmTypeCode: "8004",
AlarmTypeCode: "8004", AlarmCode: "80040003",
AlarmCode: "80040003", Content: alarmDetails,
Content: strings.Join(alarmDetails, ","), Time: time.Now().Format("2006-01-02T15:04:05+0800"),
Time: time.Now().Format("2006-01-02T15:04:05+0800"), SourceTypeId: 1, // 0:DTU, 1:传感器, 2:测点
SourceTypeId: 1, // 0:DTU, 1:传感器, 2:测点 Sponsor: "goInOut_savoirTheme",
Sponsor: "goInOut_savoirTheme", Extras: nil,
Extras: nil, SubDevices: 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)
} }
} }

5
dbOperate/elasticsearchHelper.go

@ -199,8 +199,9 @@ func (the *ESHelper) SearchThemeData(index string, queryBody string) ([]models.E
themesResp, err := the.searchThemes(index, queryBody) themesResp, err := the.searchThemes(index, queryBody)
var theme models.EsTheme var theme models.EsTheme
if len(themesResp.Hits.Hits) > 0 { for _, themesResptheme := range themesResp.Hits.Hits {
theme = themesResp.Hits.Hits[0].Source
theme = themesResptheme.Source
themes = append(themes, theme) themes = append(themes, theme)
} }

Loading…
Cancel
Save