cp榜单key拼接按男女顺序排列

This commit is contained in:
tianfeng 2026-01-14 17:30:24 +08:00
parent 1bd9d17ffb
commit e97867d156
2 changed files with 42 additions and 10 deletions

View File

@ -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<Long, Long> 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<Long, Long> 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());
}

View File

@ -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) {