-
Notifications
You must be signed in to change notification settings - Fork 0
fix: 주간 랭킹 데이터 조회 방식 수정 #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,9 +43,6 @@ public class WeeklyRankingService { | |
| @Transactional | ||
| public void updateWeeklyRanks(LocalDate weekStart, LocalDate weekEnd) { | ||
|
|
||
| // 기존 주차 랭킹 삭제 | ||
| weeklyRankingRepository.deleteByWeekStart(weekStart); | ||
|
|
||
| // 모든 회원 조회 | ||
| List<Member> allMembers = memberRepository.findAll(); | ||
| List<Long> memberIds = allMembers.stream() | ||
|
|
@@ -65,60 +62,62 @@ public void updateWeeklyRanks(LocalDate weekStart, LocalDate weekEnd) { | |
| MemberCertifiedCountProjection::getCertifiedCount | ||
| )); | ||
|
|
||
| List<WeeklyRanking> weeklyRankings = allMembers.stream() | ||
| .map(member -> { | ||
| BigDecimal point = memberPoints.getOrDefault(member.getId(), BigDecimal.ZERO); | ||
| int certificationCount = certifiedCounts.getOrDefault(member.getId(), 0); | ||
| String profileImageUrl = (member.getProfile() != null) ? | ||
| member.getProfile().getProfileImageUrl() : null; | ||
|
|
||
| return WeeklyRanking.builder() | ||
| .memberId(member.getId()) | ||
| .memberName(member.getName()) | ||
| .profileImageUrl(profileImageUrl) | ||
| .totalPoint(point) // DB 저장/정렬용 | ||
| .certificationCount(certificationCount) | ||
| .weekStart(weekStart) | ||
| .weekEnd(weekEnd) | ||
| .rank(0) | ||
| .build(); | ||
| }) | ||
| .toList(); | ||
| Map<Long, WeeklyRanking> existingMap = weeklyRankingRepository | ||
| .findByWeekStart(weekStart) | ||
| .stream() | ||
| .collect(Collectors.toMap( | ||
| WeeklyRanking::getMemberId, | ||
| w -> w | ||
| )); | ||
|
|
||
| List<WeeklyRanking> updatedRanks = new ArrayList<>(); | ||
|
|
||
| for (Member member : allMembers) { | ||
|
|
||
| BigDecimal point = memberPoints.getOrDefault(member.getId(), BigDecimal.ZERO); | ||
|
|
||
| int certificationCount = certifiedCounts.getOrDefault(member.getId(), 0); | ||
|
|
||
| String profileImageUrl = (member.getProfile() != null) ? | ||
| member.getProfile().getProfileImageUrl() : null; | ||
|
|
||
| WeeklyRanking existing = existingMap.get(member.getId()); | ||
|
|
||
| if (existing != null) { | ||
| existing.updatePointAndCertification(point, certificationCount); | ||
| updatedRanks.add(existing); | ||
| } | ||
| } | ||
|
|
||
| // 정렬 (포인트 내림차순, 동점이면 인증 수 내림차순) | ||
| weeklyRankings.sort( | ||
| updatedRanks.sort( | ||
| Comparator.comparing(WeeklyRanking::getTotalPoint, Comparator.reverseOrder()) | ||
| .thenComparing(WeeklyRanking::getCertificationCount, Comparator.reverseOrder()) | ||
| ); | ||
|
|
||
| int rankCounter = 1; | ||
| for (int i = 0; i < weeklyRankings.size(); i++) { | ||
| int ranking = 1; | ||
| for (int i = 0; i < updatedRanks.size(); i++) { | ||
|
|
||
| if (i > 0 && | ||
| weeklyRankings.get(i).getTotalPoint().compareTo(weeklyRankings.get(i - 1).getTotalPoint()) == 0 && | ||
| weeklyRankings.get(i).getCertificationCount() == | ||
| weeklyRankings.get(i - 1).getCertificationCount()) { | ||
| updatedRanks.get(i).getTotalPoint().compareTo(updatedRanks.get(i - 1).getTotalPoint()) == 0 && | ||
| updatedRanks.get(i).getCertificationCount() == | ||
| updatedRanks.get(i - 1).getCertificationCount()) { | ||
|
|
||
| // 완전 동점 → 이전 rank와 동일 | ||
| weeklyRankings.get(i).setRank(weeklyRankings.get(i - 1).getRank()); | ||
| updatedRanks.get(i).updateRank(updatedRanks.get(i - 1).getRank()); | ||
| } else { | ||
| weeklyRankings.get(i).setRank(rankCounter); | ||
| updatedRanks.get(i).updateRank(ranking); | ||
| } | ||
| rankCounter++; | ||
|
|
||
| ranking++; | ||
| } | ||
|
|
||
| // DB 저장 | ||
| weeklyRankingRepository.saveAll(weeklyRankings); | ||
| weeklyRankingRepository.saveAll(updatedRanks); | ||
| } | ||
|
|
||
| public List<TopMemberPointResponse> getAllRankData(LocalDate weekStart, int topN) { | ||
|
|
||
| // 상위 N명 랭킹 엔티티 조회 | ||
| List<WeeklyRanking> topMembersFromDb = weeklyRankingRepository.findTopNByWeekStart(weekStart, | ||
| topN); | ||
|
|
||
| if (topMembersFromDb.isEmpty()) { | ||
| return new ArrayList<>(); | ||
| } | ||
| List<WeeklyRanking> topMembersFromDb = weeklyRankingRepository.findTop8ByWeekStart(weekStart); | ||
|
Comment on lines
117
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The The method signature accepts Either use the parameter: -List<WeeklyRanking> topMembersFromDb = weeklyRankingRepository.findTop8ByWeekStart(weekStart);
+List<WeeklyRanking> topMembersFromDb = weeklyRankingRepository.findTopNByWeekStart(weekStart, topN);Or remove it from the signature if top-8 is always the requirement: -public List<TopMemberPointResponse> getAllRankData(LocalDate weekStart, int topN) {
+public List<TopMemberPointResponse> getAllRankData(LocalDate weekStart) {🤖 Prompt for AI Agents |
||
|
|
||
| // 엔티티 → DTO 변환 | ||
| return topMembersFromDb.stream() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New members will never appear in rankings.
The current logic only updates existing
WeeklyRankingentries. Members without a pre-existing entry forweekStartare silently skipped (lines 86-89). This means:If this is intentional (e.g., initial entries are created elsewhere), please clarify. Otherwise, you need to create new entries for members not in
existingMap.if (existing != null) { existing.updatePointAndCertification(point, certificationCount); updatedRanks.add(existing); +} else { + WeeklyRanking newRanking = WeeklyRanking.builder() + .memberId(member.getId()) + .memberName(member.getName()) + .profileImageUrl(profileImageUrl) + .totalPoint(point) + .certificationCount(certificationCount) + .rank(0) // will be set below + .weekStart(weekStart) + .weekEnd(weekEnd) + .build(); + updatedRanks.add(newRanking); }🤖 Prompt for AI Agents