diff --git a/src/framework/i18n/i18n.go b/src/framework/i18n/i18n.go index d6d959f1..50f8e8cc 100644 --- a/src/framework/i18n/i18n.go +++ b/src/framework/i18n/i18n.go @@ -11,6 +11,7 @@ import ( type localeItem struct { Key string `json:"key"` Value string `json:"value"` + Code string `json:"code"` } // localeMap 国际化数据组 @@ -30,30 +31,43 @@ func LoadLocaleData(language string) []localeItem { localeData = append(localeData, localeItem{ Key: v.DictLabel, Value: v.DictValue, + Code: v.DictCode, }) } localeMap[language] = localeData return localeData } -// ValueKey 值转换键 -func ValueKey(language, value string) string { - key := value - if value == "" { - return key - } +// UpdateKeyValue 更新键对应的值 +func UpdateKeyValue(language, key, value string) bool { arr, ok := localeMap[language] if !ok || len(arr) == 0 { arr = LoadLocaleData(language) } + code := "" + if key == "" { + return false + } for _, v := range arr { - if v.Value == value { - key = v.Key + if v.Key == key { + code = v.Code break } } - return key + + // 更新字典数据 + sysDictDataService := systemService.NewSysDictDataImpl + item := sysDictDataService.SelectDictDataByCode(code) + if item.DictCode == code && item.DictLabel == key { + item.DictValue = value + row := sysDictDataService.UpdateDictData(item) + if row > 0 { + delete(localeMap, language) + return true + } + } + return false } // TKey 翻译键 diff --git a/src/modules/monitor/controller/sys_job.go b/src/modules/monitor/controller/sys_job.go index f09d9a3f..9db72f50 100644 --- a/src/modules/monitor/controller/sys_job.go +++ b/src/modules/monitor/controller/sys_job.go @@ -165,6 +165,14 @@ func (s *SysJobController) Edit(c *gin.Context) { } } + // 检查是否存在 + job := s.sysJobService.SelectJobById(body.JobID) + if job.JobID != body.JobID { + // 没有可访问调度任务数据! + c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.noData"))) + return + } + // 检查属性值唯一 uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, body.JobID) if !uniqueJob { @@ -174,6 +182,19 @@ func (s *SysJobController) Edit(c *gin.Context) { return } + // 多语言非原始值 + i18nValue := i18n.TKey(language, job.JobName) + if i18nValue != job.JobName { + i18n.UpdateKeyValue(language, job.JobName, body.JobName) + body.JobName = job.JobName + } + // 多语言非原始值 + i18nValue2 := i18n.TKey(language, job.Remark) + if i18nValue2 != job.Remark { + i18n.UpdateKeyValue(language, job.Remark, body.Remark) + body.Remark = job.Remark + } + body.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysJobService.UpdateJob(body) if rows > 0 { diff --git a/src/modules/system/controller/sys_config.go b/src/modules/system/controller/sys_config.go index 190815ab..e0824e12 100644 --- a/src/modules/system/controller/sys_config.go +++ b/src/modules/system/controller/sys_config.go @@ -262,7 +262,7 @@ func (s *SysConfigController) Export(c *gin.Context) { // 参数配置修改配置参数 // -// PUT /changeConfigValue +// PUT /changeValue func (s *SysConfigController) ConfigValue(c *gin.Context) { language := ctx.AcceptLanguage(c) var body struct { @@ -282,13 +282,21 @@ func (s *SysConfigController) ConfigValue(c *gin.Context) { return } - // 与旧值相等不变更 - if info.ConfigValue == body.Value { + // 与旧值相等 不变更 + i18nValue := i18n.TKey(language, info.ConfigValue) + if i18nValue == body.Value { // 变更状态与旧值相等! c.JSON(200, result.ErrMsg(i18n.TKey(language, "config.errValueEq"))) return } - info.ConfigValue = body.Value + + // 多语言非原始值 + if i18nValue != info.ConfigValue { + i18n.UpdateKeyValue(language, info.ConfigValue, body.Value) + } else { + info.ConfigValue = body.Value + } + info.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysConfigService.UpdateConfig(info) if rows > 0 { diff --git a/src/modules/system/controller/sys_dept.go b/src/modules/system/controller/sys_dept.go index dedbddf0..aaaffdb6 100644 --- a/src/modules/system/controller/sys_dept.go +++ b/src/modules/system/controller/sys_dept.go @@ -201,6 +201,13 @@ func (s *SysDeptController) Edit(c *gin.Context) { } } + // 多语言非原始值 + i18nValue := i18n.TKey(language, deptInfo.DeptName) + if i18nValue != deptInfo.DeptName { + i18n.UpdateKeyValue(language, deptInfo.DeptName, body.DeptName) + body.DeptName = deptInfo.DeptName + } + body.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysDeptService.UpdateDept(body) if rows > 0 { diff --git a/src/modules/system/controller/sys_dict_data.go b/src/modules/system/controller/sys_dict_data.go index 96ecd1e6..779a48d4 100644 --- a/src/modules/system/controller/sys_dict_data.go +++ b/src/modules/system/controller/sys_dict_data.go @@ -140,8 +140,8 @@ func (s *SysDictDataController) Edit(c *gin.Context) { } // 检查字典编码是否存在 - SysDictDataController := s.sysDictDataService.SelectDictDataByCode(body.DictCode) - if SysDictDataController.DictCode != body.DictCode { + sysDictData := s.sysDictDataService.SelectDictDataByCode(body.DictCode) + if sysDictData.DictCode != body.DictCode { // 没有可访问字典编码数据! c.JSON(200, result.ErrMsg(i18n.TKey(language, "dictData.noData"))) return @@ -156,6 +156,19 @@ func (s *SysDictDataController) Edit(c *gin.Context) { return } + // 多语言非原始值 + i18nValue := i18n.TKey(language, sysDictData.DictLabel) + if i18nValue != sysDictData.DictLabel { + i18n.UpdateKeyValue(language, sysDictData.DictLabel, body.DictLabel) + body.DictLabel = sysDictData.DictLabel + } + // 多语言非原始值 + i18nValue2 := i18n.TKey(language, sysDictData.Remark) + if i18nValue2 != sysDictData.Remark { + i18n.UpdateKeyValue(language, sysDictData.Remark, body.Remark) + body.Remark = sysDictData.Remark + } + body.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysDictDataService.UpdateDictData(body) if rows > 0 { diff --git a/src/modules/system/controller/sys_dict_type.go b/src/modules/system/controller/sys_dict_type.go index 80b83a2b..f115c887 100644 --- a/src/modules/system/controller/sys_dict_type.go +++ b/src/modules/system/controller/sys_dict_type.go @@ -151,6 +151,19 @@ func (s *SysDictTypeController) Edit(c *gin.Context) { return } + // 多语言非原始值 + i18nValue := i18n.TKey(language, dictInfo.DictName) + if i18nValue != dictInfo.DictName { + i18n.UpdateKeyValue(language, dictInfo.DictName, body.DictName) + body.DictName = dictInfo.DictName + } + // 多语言非原始值 + i18nValue2 := i18n.TKey(language, dictInfo.Remark) + if i18nValue2 != dictInfo.Remark { + i18n.UpdateKeyValue(language, dictInfo.Remark, body.Remark) + body.Remark = dictInfo.Remark + } + body.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysDictTypeService.UpdateDictType(body) if rows > 0 { diff --git a/src/modules/system/controller/sys_menu.go b/src/modules/system/controller/sys_menu.go index 47bacdb5..256718d1 100644 --- a/src/modules/system/controller/sys_menu.go +++ b/src/modules/system/controller/sys_menu.go @@ -216,6 +216,19 @@ func (s *SysMenuController) Edit(c *gin.Context) { } } + // 多语言非原始值 + i18nValue := i18n.TKey(language, menuInfo.MenuName) + if i18nValue != menuInfo.MenuName { + i18n.UpdateKeyValue(language, menuInfo.MenuName, body.MenuName) + body.MenuName = menuInfo.MenuName + } + // 多语言非原始值 + i18nValue2 := i18n.TKey(language, menuInfo.Remark) + if i18nValue2 != menuInfo.Remark { + i18n.UpdateKeyValue(language, menuInfo.Remark, body.Remark) + body.Remark = menuInfo.Remark + } + body.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysMenuService.UpdateMenu(body) if rows > 0 { diff --git a/src/modules/system/controller/sys_post.go b/src/modules/system/controller/sys_post.go index 65ca4089..489bbde7 100644 --- a/src/modules/system/controller/sys_post.go +++ b/src/modules/system/controller/sys_post.go @@ -125,8 +125,8 @@ func (s *SysPostController) Edit(c *gin.Context) { } // 检查是否存在 - post := s.sysPostService.SelectPostById(body.PostID) - if post.PostID != body.PostID { + postInfo := s.sysPostService.SelectPostById(body.PostID) + if postInfo.PostID != body.PostID { // 没有可访问岗位数据! c.JSON(200, result.ErrMsg(i18n.TKey(language, "post.noData"))) return @@ -150,6 +150,19 @@ func (s *SysPostController) Edit(c *gin.Context) { return } + // 多语言非原始值 + i18nValue := i18n.TKey(language, postInfo.PostName) + if i18nValue != postInfo.PostName { + i18n.UpdateKeyValue(language, postInfo.PostName, body.PostName) + body.PostName = postInfo.PostName + } + // 多语言非原始值 + i18nValue2 := i18n.TKey(language, postInfo.Remark) + if i18nValue2 != postInfo.Remark { + i18n.UpdateKeyValue(language, postInfo.Remark, body.Remark) + body.Remark = postInfo.Remark + } + body.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysPostService.UpdatePost(body) if rows > 0 { diff --git a/src/modules/system/controller/sys_role.go b/src/modules/system/controller/sys_role.go index c27e25ae..a4170cc4 100644 --- a/src/modules/system/controller/sys_role.go +++ b/src/modules/system/controller/sys_role.go @@ -139,8 +139,8 @@ func (s *SysRoleController) Edit(c *gin.Context) { } // 检查是否存在 - role := s.sysRoleService.SelectRoleById(body.RoleID) - if role.RoleID != body.RoleID { + roleInfo := s.sysRoleService.SelectRoleById(body.RoleID) + if roleInfo.RoleID != body.RoleID { // 没有可访问角色数据! c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData"))) return @@ -166,6 +166,19 @@ func (s *SysRoleController) Edit(c *gin.Context) { return } + // 多语言非原始值 + i18nValue := i18n.TKey(language, roleInfo.RoleName) + if i18nValue != roleInfo.RoleName { + i18n.UpdateKeyValue(language, roleInfo.RoleName, body.RoleName) + body.RoleName = roleInfo.RoleName + } + // 多语言非原始值 + i18nValue2 := i18n.TKey(language, roleInfo.Remark) + if i18nValue2 != roleInfo.Remark { + i18n.UpdateKeyValue(language, roleInfo.Remark, body.Remark) + body.Remark = roleInfo.Remark + } + body.UpdateBy = ctx.LoginUserToUserName(c) rows := s.sysRoleService.UpdateRole(body) if rows > 0 {