From 97f80f5a332435b7df53b6d669efcb17b4154d80 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 5 Feb 2024 18:32:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BC=93=E5=AD=9810=E5=88=86=E9=92=9FUP?= =?UTF-8?q?F=E6=80=BB=E6=B5=81=E9=87=8F=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/constants/cachekey/cachekey.go | 3 +++ src/modules/monitor/controller/sys_cache.go | 2 ++ .../network_data/service/perf_kpi.impl.go | 26 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/framework/constants/cachekey/cachekey.go b/src/framework/constants/cachekey/cachekey.go index 5be7c4bd..dd7c11fe 100644 --- a/src/framework/constants/cachekey/cachekey.go +++ b/src/framework/constants/cachekey/cachekey.go @@ -25,3 +25,6 @@ const PWD_ERR_CNT_KEY = "pwd_err_cnt:" // 网元信息管理 const NE_KEY = "ne_info:" + +// 网元数据管理 +const NE_DATA_KEY = "ne_data:" diff --git a/src/modules/monitor/controller/sys_cache.go b/src/modules/monitor/controller/sys_cache.go index 729d87a3..abfeddb1 100644 --- a/src/modules/monitor/controller/sys_cache.go +++ b/src/modules/monitor/controller/sys_cache.go @@ -44,6 +44,7 @@ func (s *SysCacheController) Names(c *gin.Context) { model.NewSysCacheNames(i18n.TKey(language, "cache.name.rate_limit"), cachekey.RATE_LIMIT_KEY), model.NewSysCacheNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), cachekey.PWD_ERR_CNT_KEY), model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_info"), cachekey.NE_KEY), + model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_data"), cachekey.NE_DATA_KEY), } c.JSON(200, result.OkData(caches)) } @@ -148,6 +149,7 @@ func (s *SysCacheController) ClearCacheSafe(c *gin.Context) { model.NewSysCacheNames(i18n.TKey(language, "cache.name.rate_limit"), cachekey.RATE_LIMIT_KEY), model.NewSysCacheNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), cachekey.PWD_ERR_CNT_KEY), model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_info"), cachekey.NE_KEY), + model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_data"), cachekey.NE_DATA_KEY), } for _, v := range caches { cacheKeys, err := redis.GetKeys("", v.CacheName+":*") diff --git a/src/modules/network_data/service/perf_kpi.impl.go b/src/modules/network_data/service/perf_kpi.impl.go index 42f405ef..4e193d78 100644 --- a/src/modules/network_data/service/perf_kpi.impl.go +++ b/src/modules/network_data/service/perf_kpi.impl.go @@ -1,8 +1,12 @@ package service import ( + "encoding/json" + "fmt" "time" + "ems.agt/src/framework/constants/cachekey" + "ems.agt/src/framework/redis" "ems.agt/src/modules/network_data/model" "ems.agt/src/modules/network_data/repository" ) @@ -48,5 +52,25 @@ func (r *PerfKPIImpl) SelectUPFTotalFlow(neType, rmUID string, day int) map[stri afterDays := now.AddDate(0, 0, -day) startDate := afterDays.Format("2006-01-02") - return r.perfKPIRepository.SelectUPFTotalFlow(neType, rmUID, startDate, endDate) + var info map[string]any + + // 读取缓存数据 + key := fmt.Sprintf("%sUPFTotalFlow_%s_%d", cachekey.NE_DATA_KEY, rmUID, day) + infoStr, _ := redis.Get("", key) + if infoStr != "" { + json.Unmarshal([]byte(infoStr), &info) + expireSecond, _ := redis.GetExpire("", key) + expireMinute := (time.Duration(int64(expireSecond)) * time.Second) + if expireMinute > 1*time.Minute { + return info + } + } + + info = r.perfKPIRepository.SelectUPFTotalFlow(neType, rmUID, startDate, endDate) + + // 保存到缓存 + infoJSON, _ := json.Marshal(info) + redis.SetByExpire("", key, string(infoJSON), time.Duration(10)*time.Minute) + + return info }