From 3afd652431a06f1fd725c3f7e867f065a104f9f9 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 19 Dec 2025 10:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E7=8E=8B=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=A5=96=E5=8A=B1=20=E5=A4=84=E7=90=86=E5=A5=96=E5=8A=B1?= =?UTF-8?q?=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/RankingRewardGrantCmdExe.java | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/RankingRewardGrantCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/RankingRewardGrantCmdExe.java index da3ba62e..eb3c769a 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/RankingRewardGrantCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/RankingRewardGrantCmdExe.java @@ -90,22 +90,54 @@ public class RankingRewardGrantCmdExe { Integer currentRank = currentUser.getRank(); RankingRewardSnapshot.RankingUserSnapshot lastUser = lastUserMap.get(userId); - + List currentRewards = getRewardsForRank(currentRank, activityConfig); if (lastUser == null) { log.info("用户新获得排名,发放奖励, userId: {}, rank: {}", userId, currentRank); - List rewards = getRewardsForRank(currentRank, activityConfig); - grantRewards(userId, rewards); - + grantRewards(userId, currentRewards); } else if (!Objects.equals(lastUser.getRank(), currentRank)) { log.info("用户排名变化, userId: {}, 旧排名: {}, 新排名: {}", userId, lastUser.getRank(), currentRank); - revokeRewards(userId, lastUser.getRewards()); - List rewards = getRewardsForRank(currentRank, activityConfig); - grantRewards(userId, rewards); + processRewardDiff(userId, lastUser.getRewards(), currentRewards); } } } + /** + * 处理奖励差异 + */ + private void processRewardDiff(Long userId, + List oldRewards, + List newRewards) { + + Set oldRewardKeys = oldRewards.stream() + .map(r -> r.getType() + ":" + r.getContent()) + .collect(Collectors.toSet()); + + Set newRewardKeys = newRewards.stream() + .map(r -> r.getType() + ":" + r.getContent()) + .collect(Collectors.toSet()); + + List toRevoke = oldRewards.stream() + .filter(r -> !newRewardKeys.contains(r.getType() + ":" + r.getContent())) + .collect(Collectors.toList()); + + List toGrant = newRewards.stream() + .filter(r -> !oldRewardKeys.contains(r.getType() + ":" + r.getContent())) + .collect(Collectors.toList()); + + if (CollectionUtils.isNotEmpty(toGrant)) { + grantRewards(userId, toGrant); + } + + if (CollectionUtils.isNotEmpty(toRevoke)) { + revokeRewards(userId, toRevoke); + } + + if (CollectionUtils.isEmpty(toGrant) && CollectionUtils.isEmpty(toRevoke)) { + log.info("奖励未发生变化, userId: {}", userId); + } + } + /** * 发放奖励. */