diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java index 08e9fdb9..b27d6781 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java @@ -81,7 +81,7 @@ public class RankingListQryExe { // 查询当前用户排名(如果需要) UserRankInfoCO currentUserRank = null; if (cmd.getIncludeCurrentUser() && cmd.getReqUserId() != null) { - currentUserRank = queryCurrentUserRank(cmd, activityType, cycleType); + currentUserRank = queryCurrentUserRank(cmd, rankingList); UserProfile userProfile = userProfileGateway.getByUserId(cmd.getReqUserId()); if (userProfile != null) { currentUserRank.setAccount(userProfile.getAccount()); @@ -117,6 +117,47 @@ public class RankingListQryExe { return result; } + /** + * 从排行榜列表中查询当前用户排名 + */ + private UserRankInfoCO queryCurrentUserRank( + RankingListQueryCmd cmd, + List rankingList) { + + UserRankInfoCO rankInfo = new UserRankInfoCO(); + rankInfo.setUserId(cmd.getReqUserId()); + + // 从排行榜列表中查找当前用户 + Optional userInList = rankingList.stream() + .filter(record -> record.getUserId().equals(cmd.getReqUserId())) + .findFirst(); + + if (userInList.isPresent()) { + // 用户在榜单中 + RankingActivityRecordCO userRecord = userInList.get(); + rankInfo.setRank(userRecord.getRank()); + rankInfo.setQuantity(userRecord.getQuantity()); + rankInfo.setIsRanked(true); + } else { + // 用户不在榜单中,显示为0 + rankInfo.setRank(0); + rankInfo.setQuantity(0L); + rankInfo.setIsRanked(false); + } + + Optional userRecord = rankingActivityGateway.getUserRecord( + cmd.getReqSysOrigin().getOrigin(), + cmd.getReqUserId(), + RankingActivityType.getByCode(cmd.getActivityType()), + cmd.getCycleKey() + ); + + userRecord.ifPresent(rankingActivityRecord -> rankInfo.setQuantity(rankingActivityRecord.getQuantity())); + + + return rankInfo; + } + private Set getUserIds(List weekStarGiftCounts) { return weekStarGiftCounts.stream().map(RankingActivityRecord::getUserId)