From e97867d156eec7f24619a255f2fa8e40f7a5fa27 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 14 Jan 2026 17:30:24 +0800 Subject: [PATCH] =?UTF-8?q?cp=E6=A6=9C=E5=8D=95key=E6=8B=BC=E6=8E=A5?= =?UTF-8?q?=E6=8C=89=E7=94=B7=E5=A5=B3=E9=A1=BA=E5=BA=8F=E6=8E=92=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gift/strategy/RankCountStrategy.java | 44 +++++++++++++++++-- .../impl/WeekCpValueCountServiceImpl.java | 8 +--- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java index 5e26f050..d8df8c5a 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java @@ -9,6 +9,7 @@ import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd; import com.red.circle.other.app.service.activity.RankingActivityService; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; +import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.domain.ranking.RankingActivityType; import com.red.circle.other.domain.ranking.RankingCycleType; import com.red.circle.other.domain.ranking.RankingDimension; @@ -53,6 +54,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.ImmutablePair; import org.springframework.stereotype.Service; /** @@ -313,6 +315,11 @@ public class RankCountStrategy implements GiftStrategy { .forEach(cp -> { cpValueService.incrValue(cp.getCpValId(), acceptAmount); + // 排序CP用户ID + ImmutablePair sortedPair = sortCpUserIds(cp.getUserId(), cp.getCpUserId()); + Long orderedUserOne = sortedPair.getLeft(); + Long orderedUserTwo = sortedPair.getRight(); + // 累计cp总额 userCpValueCacheService.incr(cp.getUserId(), cp.getCpUserId(), @@ -321,13 +328,13 @@ public class RankCountStrategy implements GiftStrategy { cpRelationshipCacheService.remove(Arrays.asList(cp.getUserId(), cp.getCpUserId())); weekCpValueCountService.incrThisWeekQuantity(runningWater.getSysOrigin(), - cp.getUserId(), - cp.getCpUserId(), + orderedUserOne, + orderedUserTwo, acceptAmount.longValue()); weekCpValueCountService.incrThisSeasonQuantity(runningWater.getSysOrigin(), - cp.getUserId(), - cp.getCpUserId(), + orderedUserOne, + orderedUserTwo, acceptAmount.longValue()); }); // 更新cp用户赠送的礼物价值 @@ -342,6 +349,35 @@ public class RankCountStrategy implements GiftStrategy { } + /** + * 确保CP用户ID顺序:男前女后,性别相同则ID小的在前 + */ + private ImmutablePair sortCpUserIds(Long userIdOne, Long userIdTwo) { + UserProfile userOne = userProfileGateway.getByUserId(userIdOne); + UserProfile userTwo = userProfileGateway.getByUserId(userIdTwo); + + if (userOne == null || userTwo == null) { + return userIdOne < userIdTwo ? + ImmutablePair.of(userIdOne, userIdTwo) : + ImmutablePair.of(userIdTwo, userIdOne); + } + + Integer sexOne = userOne.getUserSex(); + Integer sexTwo = userTwo.getUserSex(); + + // 性别不同:男(1)在前,女(0)在后 + if (!Objects.equals(sexOne, sexTwo)) { + return Objects.equals(sexOne, 1) ? + ImmutablePair.of(userIdOne, userIdTwo) : + ImmutablePair.of(userIdTwo, userIdOne); + } + + // 性别相同:ID小的在前 + return userIdOne < userIdTwo ? + ImmutablePair.of(userIdOne, userIdTwo) : + ImmutablePair.of(userIdTwo, userIdOne); + } + private boolean isWeekStar(GiftValue giftValue) { return giftValue.getGiftType().contains(GiftSpecialEnum.STAR.name()); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/impl/WeekCpValueCountServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/impl/WeekCpValueCountServiceImpl.java index c1aa21e5..6670924f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/impl/WeekCpValueCountServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/impl/WeekCpValueCountServiceImpl.java @@ -228,15 +228,11 @@ public class WeekCpValueCountServiceImpl implements WeekCpValueCountService { } private String getWeekUniqueId(Long userOne, Long userIdTwo) { - return StringUtils.sortAscNumberJoin("_", userOne, userIdTwo) - .concat("_") - .concat(getThisWeekDate()); + return userOne + "_" + userIdTwo + "_" + getThisWeekDate(); } private String getSeasonUniqueId(Long userOne, Long userIdTwo) { - return StringUtils.sortAscNumberJoin("_", userOne, userIdTwo) - .concat("_") - .concat(getThisSeasonCycleKey()); + return userOne + "_" + userIdTwo + "_" + getThisSeasonCycleKey(); } private boolean existsThisWeek(Long userIdOne, Long userIdTwo) {