fix: 更新多语言刷新缓存数据
This commit is contained in:
@@ -2,15 +2,15 @@ package model
|
||||
|
||||
// SysI18n 系统_多语言 sys_i18n
|
||||
type SysI18n struct {
|
||||
ID int64 `json:"id" gorm:"column:config_id;primaryKey;autoIncrement"` // ID
|
||||
DelFlag string `json:"delFlag" gorm:"column:del_flag"` // 删除标记(0存在 1删除)
|
||||
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
|
||||
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
|
||||
Key string `json:"key" gorm:"column:key"` // 多语言属性名
|
||||
ValueZh string `json:"valueZh" gorm:"column:value_zh"` // 中文
|
||||
ValueEn string `json:"valueEn" gorm:"column:value_en"` // 英文
|
||||
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"` // ID
|
||||
DelFlag string `json:"delFlag" gorm:"column:del_flag"` // 删除标记(0存在 1删除)
|
||||
CreateBy string `json:"createBy" gorm:"column:create_by"` // 创建者
|
||||
CreateTime int64 `json:"createTime" gorm:"column:create_time"` // 创建时间
|
||||
UpdateBy string `json:"updateBy" gorm:"column:update_by"` // 更新者
|
||||
UpdateTime int64 `json:"updateTime" gorm:"column:update_time"` // 更新时间
|
||||
KeyLable string `json:"key" gorm:"column:key_lable"` // 多语言属性名
|
||||
ValueZh string `json:"valueZh" gorm:"column:value_zh"` // 中文
|
||||
ValueEn string `json:"valueEn" gorm:"column:value_en"` // 英文
|
||||
}
|
||||
|
||||
// TableName 表名称
|
||||
|
||||
@@ -19,8 +19,8 @@ func (r SysI18n) Select(param model.SysI18n) []model.SysI18n {
|
||||
tx := db.DB("").Model(&model.SysI18n{})
|
||||
tx = tx.Where("del_flag = '0'")
|
||||
// 查询条件拼接
|
||||
if param.Key != "" {
|
||||
tx = tx.Where("key = ?", param.Key)
|
||||
if param.KeyLable != "" {
|
||||
tx = tx.Where("key_lable = ?", param.KeyLable)
|
||||
}
|
||||
if param.ValueZh != "" {
|
||||
tx = tx.Where("value_zh = ?", param.ValueZh)
|
||||
|
||||
@@ -71,7 +71,7 @@ func (s SysI18n) CheckUniqueByKey(key string, id int64) bool {
|
||||
// UpdateKeyValue 更新键对应的值
|
||||
func (s SysI18n) UpdateKeyValue(language, key, value string) bool {
|
||||
rows := s.sysI18nRepository.Select(model.SysI18n{
|
||||
Key: key,
|
||||
KeyLable: key,
|
||||
})
|
||||
if len(rows) != 1 {
|
||||
return false
|
||||
@@ -90,19 +90,29 @@ func (s SysI18n) UpdateKeyValue(language, key, value string) bool {
|
||||
if language == "en" {
|
||||
item.ValueEn = value
|
||||
}
|
||||
return s.sysI18nRepository.Update(item) > 0
|
||||
if s.sysI18nRepository.Update(item) > 0 {
|
||||
key := constants.CACHE_I18N + ":" + key
|
||||
_ = redis.Del("", key)
|
||||
value := map[string]any{
|
||||
"zh": item.ValueZh,
|
||||
"en": item.ValueEn,
|
||||
}
|
||||
_ = redis.SetHash("", key, value)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CacheLoad 加载多语言数据 传入*查询全部
|
||||
func (s SysI18n) CacheLoad(langKey string) {
|
||||
param := model.SysI18n{
|
||||
DelFlag: constants.STATUS_NO,
|
||||
Key: langKey,
|
||||
DelFlag: constants.STATUS_NO,
|
||||
KeyLable: langKey,
|
||||
}
|
||||
|
||||
// 指定属性名
|
||||
if langKey == "*" || langKey == "" {
|
||||
param.Key = ""
|
||||
param.KeyLable = ""
|
||||
}
|
||||
|
||||
arr := s.sysI18nRepository.Select(param)
|
||||
@@ -112,7 +122,7 @@ func (s SysI18n) CacheLoad(langKey string) {
|
||||
|
||||
// 放入缓存
|
||||
for _, v := range arr {
|
||||
key := constants.CACHE_I18N + ":" + v.Key
|
||||
key := constants.CACHE_I18N + ":" + v.KeyLable
|
||||
_ = redis.Del("", key)
|
||||
value := map[string]any{
|
||||
"zh": v.ValueZh,
|
||||
|
||||
Reference in New Issue
Block a user