|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
"goInOut/monitors" |
|
|
|
"gopkg.in/yaml.v3" |
|
|
|
"log" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
@ -25,6 +26,7 @@ type consumerAlarmCombination struct { |
|
|
|
infoPg *dbOperate.DBHelper |
|
|
|
//数据库配置信息
|
|
|
|
combinationInfo []AlarmCombination.CombinationInfo |
|
|
|
stationIdName map[int]string |
|
|
|
} |
|
|
|
|
|
|
|
func (the *consumerAlarmCombination) LoadConfigJson(cfgStr string) { |
|
|
@ -80,7 +82,9 @@ func (the *consumerAlarmCombination) OutputInitial() error { |
|
|
|
func (the *consumerAlarmCombination) infoComponentInitial() error { |
|
|
|
//数据出口
|
|
|
|
pgConnStr := the.Info.QueryComponent.Pg.Connect |
|
|
|
//redisConnStr := the.Info.QueryComponent.Redis.Address
|
|
|
|
the.infoPg = dbOperate.NewDBHelper("postgres", pgConnStr) |
|
|
|
//the.infoRedis = dbOperate.NewRedisHelper("", redisConnStr)
|
|
|
|
return nil |
|
|
|
} |
|
|
|
func (the *consumerAlarmCombination) Work() { |
|
|
@ -111,7 +115,9 @@ func (the *consumerAlarmCombination) Work() { |
|
|
|
|
|
|
|
func (the *consumerAlarmCombination) getAdaptor() (adaptor adaptors.Adaptor_ZWY_AlarmCombin) { |
|
|
|
|
|
|
|
return adaptors.Adaptor_ZWY_AlarmCombin{} |
|
|
|
return adaptors.Adaptor_ZWY_AlarmCombin{ |
|
|
|
Info: the.stationIdName, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (the *consumerAlarmCombination) getEs1minAlarmData() { |
|
|
@ -150,19 +156,46 @@ func (the *consumerAlarmCombination) updateCombinationInfo() { |
|
|
|
log.Printf("查询数据库异常:err-> %s", err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var stationIds []int |
|
|
|
for i, info := range the.combinationInfo { |
|
|
|
err := json.Unmarshal([]byte(info.ConfigStr), &info.ConfigItems) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
the.combinationInfo[i].ConfigItems = info.ConfigItems |
|
|
|
for _, item := range info.ConfigItems { |
|
|
|
stationIds = append(stationIds, item.StationIds...) |
|
|
|
} |
|
|
|
} |
|
|
|
log.Printf("共刷新%d条配置", len(the.combinationInfo)) |
|
|
|
//每次重新赋值
|
|
|
|
the.stationIdName = the.queryStationNameByIds(stationIds) |
|
|
|
|
|
|
|
//立即触发
|
|
|
|
the.getEs1minAlarmData() |
|
|
|
} |
|
|
|
|
|
|
|
func (the *consumerAlarmCombination) queryStationNameByIds(stationIds []int) map[int]string { |
|
|
|
strIds := make([]string, len(stationIds)) |
|
|
|
for i, num := range stationIds { |
|
|
|
strIds[i] = fmt.Sprint(num) |
|
|
|
} |
|
|
|
idStr := strings.Join(strIds, ",") |
|
|
|
sqlStation := fmt.Sprintf(`SELECT id,structure,name,factor FROM "t_sensor" where id in(%s)`, idStr) |
|
|
|
var stationInfos []AlarmCombination.StationInfo |
|
|
|
err := the.infoPg.Query(&stationInfos, sqlStation) |
|
|
|
idNames := map[int]string{} |
|
|
|
if err != nil { |
|
|
|
log.Printf("查询数据库异常:err-> %s", err.Error()) |
|
|
|
return idNames |
|
|
|
} |
|
|
|
for _, info := range stationInfos { |
|
|
|
idNames[info.Id] = info.Name |
|
|
|
} |
|
|
|
return idNames |
|
|
|
} |
|
|
|
|
|
|
|
func (the *consumerAlarmCombination) getESAlarmAggQueryStr(onceConfig AlarmCombination.CombinationInfo) string { |
|
|
|
structureId := onceConfig.StructId |
|
|
|
var allStationId []int |
|
|
|