|
@ -10,6 +10,7 @@ import ( |
|
|
"log" |
|
|
"log" |
|
|
"node/stages" |
|
|
"node/stages" |
|
|
"strconv" |
|
|
"strconv" |
|
|
|
|
|
"sync" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type ThresholdHandler struct { |
|
|
type ThresholdHandler struct { |
|
@ -34,7 +35,7 @@ func NewThresholdHandler() *ThresholdHandler { |
|
|
kafkaAlarmTopic: alarmTopic, |
|
|
kafkaAlarmTopic: alarmTopic, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
model.stage.AddProcess(model.processData) |
|
|
model.stage.AddProcess(model.processDatas) |
|
|
return model |
|
|
return model |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -43,6 +44,20 @@ func (t *ThresholdHandler) GetStage() stages.Stage { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 必须
|
|
|
// 必须
|
|
|
|
|
|
func (t *ThresholdHandler) processDatas(data []*common_models.ProcessData) []*common_models.ProcessData { |
|
|
|
|
|
go func() { |
|
|
|
|
|
var wg sync.WaitGroup // 初始化 WaitGroup
|
|
|
|
|
|
for _, processData := range data { |
|
|
|
|
|
wg.Add(1) |
|
|
|
|
|
go func(pd *common_models.ProcessData) { |
|
|
|
|
|
defer wg.Done() |
|
|
|
|
|
t.processData(pd) |
|
|
|
|
|
}(processData) |
|
|
|
|
|
} |
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
}() |
|
|
|
|
|
return data |
|
|
|
|
|
} |
|
|
func (t *ThresholdHandler) processData(resultData *common_models.ProcessData) *common_models.ProcessData { |
|
|
func (t *ThresholdHandler) processData(resultData *common_models.ProcessData) *common_models.ProcessData { |
|
|
if resultData == nil || resultData.Stations == nil || len(resultData.Stations) == 0 { |
|
|
if resultData == nil || resultData.Stations == nil || len(resultData.Stations) == 0 { |
|
|
return resultData |
|
|
return resultData |
|
@ -74,7 +89,7 @@ func (t *ThresholdHandler) processData(resultData *common_models.ProcessData) *c |
|
|
func (t *ThresholdHandler) judgeThreshold(station *common_models.Station) *common_models.AlarmMsg { |
|
|
func (t *ThresholdHandler) judgeThreshold(station *common_models.Station) *common_models.AlarmMsg { |
|
|
// 检查测点是否有阈值配置信息
|
|
|
// 检查测点是否有阈值配置信息
|
|
|
if station.Threshold == nil || station.Threshold.Items == nil { |
|
|
if station.Threshold == nil || station.Threshold.Items == nil { |
|
|
log.Printf("测点[%d-%s]未配置阈值,无须进行阈值判断\n", station.Info.Id, station.Info.Name) |
|
|
log.Printf("测点[%d-%s]未配置阈值,跳过\n", station.Info.Id, station.Info.Name) |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|