fix: 自定义KPI计算NaN导致序列化失败

This commit is contained in:
TsMask
2025-08-07 11:35:12 +08:00
parent 581fc441e0
commit 26fde7f1ca

View File

@@ -3,6 +3,7 @@ package service
import (
"encoding/json"
"fmt"
"math"
"time"
"be.ems/src/framework/utils/date"
@@ -91,7 +92,10 @@ func (s *KPI) saveKPIData(k oam.KPI, index int64) error {
KpiValues = append(KpiValues, item)
}
KpiValuesByte, _ := json.Marshal(KpiValues)
KpiValuesByte, err := json.Marshal(KpiValues)
if err != nil {
return err
}
// KPI 信息
kpiData := neDataModel.KpiReport{
@@ -180,13 +184,13 @@ func (s *KPI) saveKPIDataC(k oam.KPI, index int64) error {
} else {
if v.Unit == "%" {
resultV, ok := result.(float64)
if !ok {
if !ok || math.IsNaN(resultV) {
resultV = 0
}
if resultV > 100 {
result = 100
}
if resultV < 0 {
if resultV <= 0 {
result = 0
}
}
@@ -195,7 +199,10 @@ func (s *KPI) saveKPIDataC(k oam.KPI, index int64) error {
}
KpiValues = append(KpiValues, item)
}
KpiValuesByte, _ := json.Marshal(KpiValues)
KpiValuesByte, err := json.Marshal(KpiValues)
if err != nil {
return err
}
// KPI 信息
kpiCData := neDataModel.KpiCReport{