From 317652ced8dd6176e55827e045ca4fe0c9cd0967 Mon Sep 17 00:00:00 2001 From: longtao <1273211023@qq.com> Date: Thu, 30 Mar 2023 14:37:22 +0800 Subject: [PATCH] update special award rank rule --- internal/app/service/subscribe.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/app/service/subscribe.go b/internal/app/service/subscribe.go index cfa5e24..4f8859d 100644 --- a/internal/app/service/subscribe.go +++ b/internal/app/service/subscribe.go @@ -135,11 +135,32 @@ func (svc *SubscribeService) SpecialAwards() (*dto.ChallengeScoreDTO, error) { } var challengeScore dto.ChallengeScoreDTO if len(res) > 0 { + var scoreNums ScoreNums + sMap := make(map[int]int) + for _, v := range res { + sMap[v.FinalScore] += 1 + } + for k, v := range sMap { + var scoreNum ScoreNum + scoreNum.Score = k + scoreNum.Num = v + scoreNums = append(scoreNums, scoreNum) + } + sort.Sort(scoreNums) + challengeScore.UpdateTime = res[0].UpdateTime var scores dto.Scores for _, v := range res { var scoreRank dto.ScoreRank - scoreRank.Rank = v.Rank + rank := 1 + for _, sn := range scoreNums { + if v.FinalScore == sn.Score { + scoreRank.Rank = rank + break + } + rank += sn.Num + } + //scoreRank.Rank = v.Rank scoreRank.TeamName = v.TeamName scoreRank.TaskCompleted = v.TaskCompleted scoreRank.FinalScore = v.FinalScore