package medal_cv import ( "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" "hilo-user/domain/model/res_m" "sort" ) type CvMedal struct { Id uint32 `json:"id"` PicUrl mysql.Str `json:"picUrl"` EffectUrl mysql.Str `json:"effectUrl"` } type ReturnGroupMedal struct { PicUrl string `json:"picUrl"` SvgaUrl string `json:"svgaUrl"` } type PicElement struct { PicUrl string `json:"picUrl"` SvgaUrl string `json:"svgaUrl"` } func GetMedalInfoMap(db *gorm.DB, medals map[uint64][]uint32) (map[uint64][]uint32, map[uint64][]CvMedal, error) { resMedals, err := res_m.MedalGetAllMap(db) if err != nil { return nil, nil, err } medalIds := make(map[uint64][]uint32) medalMap := make(map[uint64][]CvMedal, 0) // 只选择合法的勋章 for u, i := range medals { medalIds[u] = make([]uint32, 0) medalMap[u] = make([]CvMedal, 0) for _, j := range i { if e, ok := resMedals[j]; ok { medalIds[u] = append(medalIds[u], j) medalMap[u] = append(medalMap[u], CvMedal{ Id: j, PicUrl: e.PicUrl, EffectUrl: e.SvgaUrl, }) } } // 按照勋章排序 sort.Slice(medalIds[u], func(i, j int) bool { return resMedals[medalIds[u][i]].Sort < resMedals[medalIds[u][j]].Sort }) sort.Slice(medalMap[u], func(i, j int) bool { return resMedals[medalMap[u][i].Id].Sort < resMedals[medalMap[u][j].Id].Sort }) } return medalIds, medalMap, nil }