refactor(internal): 优化 OSS 预签名 URL 缓存刷新任务和英雄数据缓存逻辑
- 注释掉 OSS预签名 URL 缓存刷新任务的定时执行代码 - 在 hero/hero.go 中增加对 Redis缓存和英雄数据集的非空校验 - 修改 OSS预签名 URL 生成逻辑,自动替换为 CDN 域名
This commit is contained in:
@@ -732,3 +732,77 @@ func max(a, b int) int {
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// 修复历史数据,将epic_hero_info.hero_name和epic_artifact_info.artifact_name翻译为中文(基于code匹配)
|
||||
func FixHeroAndArtifactNameToChinese(ctx context.Context) error {
|
||||
// 1. 查询i18n hero映射(code->zh)
|
||||
var heroMappings []*entity.EpicI18NMappings
|
||||
err := dao.EpicI18NMappings.Ctx(ctx).
|
||||
Where(dao.EpicI18NMappings.Columns().Language, "zh").
|
||||
Where(dao.EpicI18NMappings.Columns().Category, "hero").
|
||||
Where(dao.EpicI18NMappings.Columns().Status, 1).
|
||||
Where(dao.EpicI18NMappings.Columns().Deleted, 0).
|
||||
Scan(&heroMappings)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询i18n hero映射失败: %v", err)
|
||||
}
|
||||
heroCodeToZh := make(map[string]string)
|
||||
for _, m := range heroMappings {
|
||||
heroCodeToZh[m.Code] = m.Value
|
||||
}
|
||||
|
||||
// 2. 修复英雄表
|
||||
var heroes []*entity.EpicHeroInfo
|
||||
err = dao.EpicHeroInfo.Ctx(ctx).Scan(&heroes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询epic_hero_info失败: %v", err)
|
||||
}
|
||||
for _, h := range heroes {
|
||||
if zh, ok := heroCodeToZh[h.HeroCode]; ok && zh != "" && zh != h.HeroName {
|
||||
_, err := dao.EpicHeroInfo.Ctx(ctx).
|
||||
Where(dao.EpicHeroInfo.Columns().HeroCode, h.HeroCode).
|
||||
Data(g.Map{dao.EpicHeroInfo.Columns().HeroName: zh}).
|
||||
Update()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "更新英雄中文名失败: %s(%s) -> %s, err: %v", h.HeroName, h.HeroCode, zh, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
g.Log().Info(ctx, "epic_hero_info英雄名修复完成")
|
||||
|
||||
// 3. 查询i18n artifact映射(code->zh)
|
||||
var artifactMappings []*entity.EpicI18NMappings
|
||||
err = dao.EpicI18NMappings.Ctx(ctx).
|
||||
Where(dao.EpicI18NMappings.Columns().Language, "zh").
|
||||
Where(dao.EpicI18NMappings.Columns().Category, "artifact").
|
||||
Where(dao.EpicI18NMappings.Columns().Status, 1).
|
||||
Where(dao.EpicI18NMappings.Columns().Deleted, 0).
|
||||
Scan(&artifactMappings)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询i18n artifact映射失败: %v", err)
|
||||
}
|
||||
artifactCodeToZh := make(map[string]string)
|
||||
for _, m := range artifactMappings {
|
||||
artifactCodeToZh[m.Code] = m.Value
|
||||
}
|
||||
|
||||
// 4. 修复神器表
|
||||
var artifacts []*entity.EpicArtifactInfo
|
||||
err = dao.EpicArtifactInfo.Ctx(ctx).Scan(&artifacts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询epic_artifact_info失败: %v", err)
|
||||
}
|
||||
for _, a := range artifacts {
|
||||
if zh, ok := artifactCodeToZh[a.ArtifactCode]; ok && zh != "" && zh != a.ArtifactName {
|
||||
_, err := dao.EpicArtifactInfo.Ctx(ctx).
|
||||
Where(dao.EpicArtifactInfo.Columns().ArtifactCode, a.ArtifactCode).
|
||||
Data(g.Map{dao.EpicArtifactInfo.Columns().ArtifactName: zh}).
|
||||
Update()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "更新神器中文名失败: %s(%s) -> %s, err: %v", a.ArtifactName, a.ArtifactCode, zh, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
g.Log().Info(ctx, "epic_artifact_info神器名修复完成")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user