From 26fde7f1cae110285457acd36a47e62a9d856e76 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Thu, 7 Aug 2025 11:35:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=AE=9A=E4=B9=89KPI=E8=AE=A1?= =?UTF-8?q?=E7=AE=97NaN=E5=AF=BC=E8=87=B4=E5=BA=8F=E5=88=97=E5=8C=96?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/oam/service/kpi.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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{