diff --git a/src/modules/oam/service/kpi.go b/src/modules/oam/service/kpi.go index 3a3766bf..d5e82ad6 100644 --- a/src/modules/oam/service/kpi.go +++ b/src/modules/oam/service/kpi.go @@ -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{