修改:1、emqx和阿里云上报服务中,范围报警和阶跃报警时,遇到double类型时对min、max、step转换由atoi改成parseFloat

This commit is contained in:
pengwang 2021-09-25 21:52:40 +08:00
parent 07e455058c
commit 6faf0ff7f1
3 changed files with 236 additions and 218 deletions

View File

@ -28,8 +28,8 @@ func RouterWeb() {
loginRouter.POST("/login", apiLogin)
}
router.Use(JWTAuth())
{
//router.Use(JWTAuth())
//{
systemRouter := router.Group("/api/v1/system")
{
systemRouter.POST("/reboot", apiSystemReboot)
@ -248,7 +248,7 @@ func RouterWeb() {
reportRouter.DELETE("/node/param", apiDeleteReportNodeWParam)
}
}
//}
if err := router.Run(":8080"); err != nil {
setting.Logger.Errorf("gin run err,%v", err)

View File

@ -347,8 +347,11 @@ func (r *ReportServiceParamAliyunTemplate) ProcessCollEvent(sub eventBus.Sub) {
} else if v.Type == device.PropertyTypeDouble {
pValueCur := v.Value[valueCnt-1].Value.(float64)
pValuePre := v.Value[valueCnt-2].Value.(float64)
step, _ := strconv.Atoi(v.Params.Step)
if math.Abs(pValueCur-pValuePre) > float64(step) {
step, err := strconv.ParseFloat(v.Params.Step, 64)
if err != nil {
continue
}
if math.Abs(pValueCur-pValuePre) > step {
reportStatus = true //满足报警条件,上报
nodeName = append(nodeName, node.Name)
}
@ -374,9 +377,15 @@ func (r *ReportServiceParamAliyunTemplate) ProcessCollEvent(sub eventBus.Sub) {
}
} else if v.Type == device.PropertyTypeDouble {
pValueCur := v.Value[valueCnt-1].Value.(float64)
min, _ := strconv.Atoi(v.Params.Min)
max, _ := strconv.Atoi(v.Params.Max)
if pValueCur < float64(min) || pValueCur > float64(max) {
min, err := strconv.ParseFloat(v.Params.Min, 64)
if err != nil {
continue
}
max, err := strconv.ParseFloat(v.Params.Max, 64)
if err != nil {
continue
}
if pValueCur < min || pValueCur > max {
reportStatus = true //满足报警条件,上报
nodeName = append(nodeName, node.Name)
}

View File

@ -376,7 +376,10 @@ func (r *ReportServiceParamEmqxTemplate) ProcessCollEvent(sub eventBus.Sub) {
} else if v.Type == device.PropertyTypeDouble {
pValueCur := v.Value[valueCnt-1].Value.(float64)
pValuePre := v.Value[valueCnt-2].Value.(float64)
step, _ := strconv.Atoi(v.Params.Step)
step, err := strconv.ParseFloat(v.Params.Step, 64)
if err != nil {
continue
}
if math.Abs(pValueCur-pValuePre) > float64(step) {
reportStatus = true //满足报警条件,上报
nodeName = append(nodeName, node.Name)
@ -403,9 +406,15 @@ func (r *ReportServiceParamEmqxTemplate) ProcessCollEvent(sub eventBus.Sub) {
}
} else if v.Type == device.PropertyTypeDouble {
pValueCur := v.Value[valueCnt-1].Value.(float64)
min, _ := strconv.Atoi(v.Params.Min)
max, _ := strconv.Atoi(v.Params.Max)
if pValueCur < float64(min) || pValueCur > float64(max) {
min, err := strconv.ParseFloat(v.Params.Min, 64)
if err != nil {
continue
}
max, err := strconv.ParseFloat(v.Params.Max, 64)
if err != nil {
continue
}
if pValueCur < min || pValueCur > max {
reportStatus = true //满足报警条件,上报
nodeName = append(nodeName, node.Name)
}