fix: 多语言字典数据源同步更新
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
type localeItem struct {
|
type localeItem struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
|
Code string `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// localeMap 国际化数据组
|
// localeMap 国际化数据组
|
||||||
@@ -30,30 +31,43 @@ func LoadLocaleData(language string) []localeItem {
|
|||||||
localeData = append(localeData, localeItem{
|
localeData = append(localeData, localeItem{
|
||||||
Key: v.DictLabel,
|
Key: v.DictLabel,
|
||||||
Value: v.DictValue,
|
Value: v.DictValue,
|
||||||
|
Code: v.DictCode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
localeMap[language] = localeData
|
localeMap[language] = localeData
|
||||||
return localeData
|
return localeData
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValueKey 值转换键
|
// UpdateKeyValue 更新键对应的值
|
||||||
func ValueKey(language, value string) string {
|
func UpdateKeyValue(language, key, value string) bool {
|
||||||
key := value
|
|
||||||
if value == "" {
|
|
||||||
return key
|
|
||||||
}
|
|
||||||
arr, ok := localeMap[language]
|
arr, ok := localeMap[language]
|
||||||
if !ok || len(arr) == 0 {
|
if !ok || len(arr) == 0 {
|
||||||
arr = LoadLocaleData(language)
|
arr = LoadLocaleData(language)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code := ""
|
||||||
|
if key == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
if v.Value == value {
|
if v.Key == key {
|
||||||
key = v.Key
|
code = v.Code
|
||||||
break
|
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 翻译键
|
// TKey 翻译键
|
||||||
|
|||||||
@@ -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)
|
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, body.JobID)
|
||||||
if !uniqueJob {
|
if !uniqueJob {
|
||||||
@@ -174,6 +182,19 @@ func (s *SysJobController) Edit(c *gin.Context) {
|
|||||||
return
|
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)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysJobService.UpdateJob(body)
|
rows := s.sysJobService.UpdateJob(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ func (s *SysConfigController) Export(c *gin.Context) {
|
|||||||
|
|
||||||
// 参数配置修改配置参数
|
// 参数配置修改配置参数
|
||||||
//
|
//
|
||||||
// PUT /changeConfigValue
|
// PUT /changeValue
|
||||||
func (s *SysConfigController) ConfigValue(c *gin.Context) {
|
func (s *SysConfigController) ConfigValue(c *gin.Context) {
|
||||||
language := ctx.AcceptLanguage(c)
|
language := ctx.AcceptLanguage(c)
|
||||||
var body struct {
|
var body struct {
|
||||||
@@ -282,13 +282,21 @@ func (s *SysConfigController) ConfigValue(c *gin.Context) {
|
|||||||
return
|
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")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "config.errValueEq")))
|
||||||
return
|
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)
|
info.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysConfigService.UpdateConfig(info)
|
rows := s.sysConfigService.UpdateConfig(info)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
@@ -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)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysDeptService.UpdateDept(body)
|
rows := s.sysDeptService.UpdateDept(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ func (s *SysDictDataController) Edit(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查字典编码是否存在
|
// 检查字典编码是否存在
|
||||||
SysDictDataController := s.sysDictDataService.SelectDictDataByCode(body.DictCode)
|
sysDictData := s.sysDictDataService.SelectDictDataByCode(body.DictCode)
|
||||||
if SysDictDataController.DictCode != body.DictCode {
|
if sysDictData.DictCode != body.DictCode {
|
||||||
// 没有可访问字典编码数据!
|
// 没有可访问字典编码数据!
|
||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "dictData.noData")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "dictData.noData")))
|
||||||
return
|
return
|
||||||
@@ -156,6 +156,19 @@ func (s *SysDictDataController) Edit(c *gin.Context) {
|
|||||||
return
|
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)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysDictDataService.UpdateDictData(body)
|
rows := s.sysDictDataService.UpdateDictData(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
@@ -151,6 +151,19 @@ func (s *SysDictTypeController) Edit(c *gin.Context) {
|
|||||||
return
|
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)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysDictTypeService.UpdateDictType(body)
|
rows := s.sysDictTypeService.UpdateDictType(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
@@ -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)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysMenuService.UpdateMenu(body)
|
rows := s.sysMenuService.UpdateMenu(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ func (s *SysPostController) Edit(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否存在
|
// 检查是否存在
|
||||||
post := s.sysPostService.SelectPostById(body.PostID)
|
postInfo := s.sysPostService.SelectPostById(body.PostID)
|
||||||
if post.PostID != body.PostID {
|
if postInfo.PostID != body.PostID {
|
||||||
// 没有可访问岗位数据!
|
// 没有可访问岗位数据!
|
||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "post.noData")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "post.noData")))
|
||||||
return
|
return
|
||||||
@@ -150,6 +150,19 @@ func (s *SysPostController) Edit(c *gin.Context) {
|
|||||||
return
|
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)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysPostService.UpdatePost(body)
|
rows := s.sysPostService.UpdatePost(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
@@ -139,8 +139,8 @@ func (s *SysRoleController) Edit(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否存在
|
// 检查是否存在
|
||||||
role := s.sysRoleService.SelectRoleById(body.RoleID)
|
roleInfo := s.sysRoleService.SelectRoleById(body.RoleID)
|
||||||
if role.RoleID != body.RoleID {
|
if roleInfo.RoleID != body.RoleID {
|
||||||
// 没有可访问角色数据!
|
// 没有可访问角色数据!
|
||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData")))
|
||||||
return
|
return
|
||||||
@@ -166,6 +166,19 @@ func (s *SysRoleController) Edit(c *gin.Context) {
|
|||||||
return
|
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)
|
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||||
rows := s.sysRoleService.UpdateRole(body)
|
rows := s.sysRoleService.UpdateRole(body)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user