From eac06dfed3b6a4654b17e28b971eec25e69b6f53 Mon Sep 17 00:00:00 2001 From: hxt Date: Sun, 22 Jun 2025 22:37:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(hero):=20=E8=8B=B1=E9=9B=84=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E5=A5=97=E8=A3=85?= =?UTF-8?q?=E5=92=8C=E7=A5=9E=E5=99=A8=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增英雄详情接口,包含60级属性、套装平均属性、套装占比、神器占比等信息- 优化数据处理逻辑,提高查询效率 - 增加缓存机制,减少数据库访问- 新增数据传输对象HeroSetData和HeroSetItem,用于处理套装数据 --- internal/logic/hero/hero.go | 120 +++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 56 deletions(-) diff --git a/internal/logic/hero/hero.go b/internal/logic/hero/hero.go index d161c5b..7813953 100644 --- a/internal/logic/hero/hero.go +++ b/internal/logic/hero/hero.go @@ -148,63 +148,10 @@ func (l *Logic) GetHeroDetailByCode(ctx context.Context, code string) (*v1.HeroD allItems []dto.HeroSetItem ) //now := time.Now() - setTypeNameMap := map[string]string{ - "set_speed": "速度", - "set_cri": "暴击", - "set_revenge": "复仇", - "set_counter": "反击", - "set_vampire": "吸血", - "set_immune": "免疫", - "set_cri_dmg": "破灭", - "set_torrent": "激流", - "set_max_hp": "生命", - "set_penetrate": "穿透", - "set_scar": "伤口", - "set_shield": "护盾", - "set_def": "防御", - "set_acc": "命中", - "set_res": "抵抗", - } - isTwoSet := func(setType string) bool { - twoSet := map[string]struct{}{ - "set_acc": {}, "set_cri": {}, "set_immune": {}, "set_torrent": {}, - "set_max_hp": {}, "set_penetrate": {}, "set_def": {}, "set_res": {}, - } - _, ok := twoSet[setType] - return ok - } - isFourSet := func(setType string) bool { - fourSet := map[string]struct{}{ - "set_speed": {}, "set_cri_dmg": {}, "set_revenge": {}, "set_counter": {}, - "set_vampire": {}, "set_scar": {}, "set_shield": {}, - } - _, ok := fourSet[setType] - return ok - } for i := range heroSetData.Data { item := &heroSetData.Data[i] // 1. 解析 SetsName - var fourNames, twoNames []string - for setType, count := range item.Sets { - if isFourSet(setType) && count >= 4 { - if cn, ok := setTypeNameMap[setType]; ok { - fourNames = append(fourNames, cn) - } else { - fourNames = append(fourNames, setType) - } - } - } - for setType, count := range item.Sets { - if isTwoSet(setType) && count >= 2 { - if cn, ok := setTypeNameMap[setType]; ok { - twoNames = append(twoNames, cn) - } else { - twoNames = append(twoNames, setType) - } - } - } - allNames := append(fourNames, twoNames...) - item.SetsName = strings.Join(allNames, ",") + item.SetsName = GetSetNames(item.Sets) // 2. 累加属性 totalCp += item.Gs totalAtk += item.Atk @@ -420,8 +367,8 @@ func (l *Logic) GetHeroDetailByCode(ctx context.Context, code string) (*v1.HeroD Dac: 0, Eff: float64(item.Eff), Efr: float64(item.Efr), - Hds: "", - Ctr: "", + Hds: GetSetNames(item.Sets), + Ctr: item.CreateDate, ArfName: func() string { info := artifactInfoMap[item.ArtifactCode] if info != nil { @@ -465,3 +412,64 @@ func (l *Logic) ClearHeroCache(ctx context.Context, code string) error { return nil } + +// 公用套装名称映射和判断 +var setTypeNameMap = map[string]string{ + "set_speed": "速度", + "set_cri": "暴击", + "set_revenge": "复仇", + "set_counter": "反击", + "set_vampire": "吸血", + "set_immune": "免疫", + "set_cri_dmg": "破灭", + "set_torrent": "激流", + "set_max_hp": "生命", + "set_penetrate": "穿透", + "set_scar": "伤口", + "set_shield": "护盾", + "set_def": "防御", + "set_acc": "命中", + "set_res": "抵抗", +} + +func isTwoSet(setType string) bool { + twoSet := map[string]struct{}{ + "set_acc": {}, "set_cri": {}, "set_immune": {}, "set_torrent": {}, + "set_max_hp": {}, "set_penetrate": {}, "set_def": {}, "set_res": {}, + } + _, ok := twoSet[setType] + return ok +} +func isFourSet(setType string) bool { + fourSet := map[string]struct{}{ + "set_speed": {}, "set_cri_dmg": {}, "set_revenge": {}, "set_counter": {}, + "set_vampire": {}, "set_scar": {}, "set_shield": {}, + } + _, ok := fourSet[setType] + return ok +} + +// GetSetNames 公用方法:根据套装 map 生成套装中文名 +func GetSetNames(sets map[string]int) string { + var fourNames, twoNames []string + for setType, count := range sets { + if isFourSet(setType) && count >= 4 { + if cn, ok := setTypeNameMap[setType]; ok { + fourNames = append(fourNames, cn) + } else { + fourNames = append(fourNames, setType) + } + } + } + for setType, count := range sets { + if isTwoSet(setType) && count >= 2 { + if cn, ok := setTypeNameMap[setType]; ok { + twoNames = append(twoNames, cn) + } else { + twoNames = append(twoNames, setType) + } + } + } + allNames := append(fourNames, twoNames...) + return strings.Join(allNames, ",") +}