From 3380b6bfed850910ce45af6ecc0ee5a572d3c075 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 24 Feb 2025 16:44:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=9A=E8=AF=AD=E8=A8=80=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/install/sys_i18n.sql | 1 + src/framework/constants/cache_key.go | 2 +- src/modules/monitor/controller/sys_cache.go | 33 ++++++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/database/install/sys_i18n.sql b/database/install/sys_i18n.sql index 36931a5e..06013487 100644 --- a/database/install/sys_i18n.sql +++ b/database/install/sys_i18n.sql @@ -688,5 +688,6 @@ INSERT INTO `sys_i18n` VALUES (665, '0', 'system', 1699348237468, 'system', 1699 INSERT INTO `sys_i18n` VALUES (666, '0', 'system', 1699348237468, 'system', 1699348237468, 'menu.config.neOverview', '网元概览', 'NE Overview'); INSERT INTO `sys_i18n` VALUES (667, '0', 'system', 1699348237468, 'system', 1699348237468, 'menu.config.neOverviewRemark', '显示所有网元状态配置和license等概览信息', 'Displays overview information such as status, configuration and license of all network elements'); INSERT INTO `sys_i18n` VALUES (668, '0', 'system', 1699348237468, 'system', 1699348237468, 'job.exportSGWCCDR', '定期从漫游数据话单表导出文件至指定目录', 'Export regularly from Roaming Data CDR table'); +INSERT INTO `sys_i18n` VALUES (669, '0', 'system', 1699348237468, 'system', 1699348237468, 'cache.name.i18n', '国际化语言管理', 'Internationalized Language Management'); -- Dump completed on 2025-02-14 15:26:56 diff --git a/src/framework/constants/cache_key.go b/src/framework/constants/cache_key.go index a6cac630..901aa249 100644 --- a/src/framework/constants/cache_key.go +++ b/src/framework/constants/cache_key.go @@ -16,7 +16,7 @@ const ( CACHE_RATE_LIMIT = "rate_limit" // CACHE_PWD_ERR_COUNT 登录账户密码错误次数 CACHE_PWD_ERR_COUNT = "pwd_err_count" - // CACHE_I18N 多语言 + // CACHE_I18N 国际化语言管理 CACHE_I18N = "i18n" // CACHE_NE_INFO 网元信息管理 CACHE_NE_INFO = "ne_info" diff --git a/src/modules/monitor/controller/sys_cache.go b/src/modules/monitor/controller/sys_cache.go index e7ca18ba..f46c9a26 100644 --- a/src/modules/monitor/controller/sys_cache.go +++ b/src/modules/monitor/controller/sys_cache.go @@ -1,6 +1,7 @@ package controller import ( + "encoding/json" "fmt" "be.ems/src/framework/constants" @@ -54,6 +55,7 @@ func (s SysCacheController) Names(c *gin.Context) { model.NewNames(i18n.TKey(language, "cache.name.repeat_submit"), constants.CACHE_REPEAT_SUBMIT), model.NewNames(i18n.TKey(language, "cache.name.rate_limit"), constants.CACHE_RATE_LIMIT), model.NewNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), constants.CACHE_PWD_ERR_COUNT), + model.NewNames(i18n.TKey(language, "cache.name.i18n"), constants.CACHE_I18N), model.NewNames(i18n.TKey(language, "cache.name.ne_info"), constants.CACHE_NE_INFO), model.NewNames(i18n.TKey(language, "cache.name.ne_data"), constants.CACHE_NE_DATA), } @@ -96,11 +98,33 @@ func (s SysCacheController) Value(c *gin.Context) { return } - cacheValue, err := redis.Get("", query.CacheName+":"+query.CacheKey) - if err != nil { - c.JSON(200, resp.ErrMsg(err.Error())) - return + key := query.CacheName + ":" + query.CacheKey + + var cacheValue string + var err error + + if constants.CACHE_I18N == query.CacheName { + // i18n 多语言的hash对象 + m, err := redis.GetHashBatch("", []string{key}) + if err != nil { + c.JSON(200, resp.ErrMsg(err.Error())) + return + } + b, err := json.Marshal(m[key]) + if err != nil { + c.JSON(200, resp.ErrMsg(err.Error())) + return + } + cacheValue = string(b) + } else { + // 其他的字符串对象 + cacheValue, err = redis.Get("", query.CacheName+":"+query.CacheKey) + if err != nil { + c.JSON(200, resp.ErrMsg(err.Error())) + return + } } + sysCache := model.NewValue(query.CacheName, query.CacheKey, cacheValue) c.JSON(200, resp.OkData(sysCache)) } @@ -116,6 +140,7 @@ func (s SysCacheController) CleanNames(c *gin.Context) { model.NewNames(i18n.TKey(language, "cache.name.repeat_submit"), constants.CACHE_REPEAT_SUBMIT), model.NewNames(i18n.TKey(language, "cache.name.rate_limit"), constants.CACHE_RATE_LIMIT), model.NewNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), constants.CACHE_PWD_ERR_COUNT), + model.NewNames(i18n.TKey(language, "cache.name.i18n"), constants.CACHE_I18N), model.NewNames(i18n.TKey(language, "cache.name.ne_info"), constants.CACHE_NE_INFO), model.NewNames(i18n.TKey(language, "cache.name.ne_data"), constants.CACHE_NE_DATA), }