From 76f357497da364d9fa4d2a922a479fa1ccb636b4 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 14 Jan 2026 14:16:14 +0800 Subject: [PATCH] =?UTF-8?q?cp=20=E6=A6=9C=E5=8D=95=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../room/WeekCpGiftRestController.java | 26 ++-- .../query/LastWeekCpUsersTop3QueryExe.java | 5 +- .../activity/query/SeasonCpTop1QueryExe.java | 92 ++++++++++++ .../query/WeekCpUserGiftQueryExe.java | 131 ++++++------------ .../gift/strategy/RankCountStrategy.java | 18 +-- .../CleanExpiredDismissingCpTask.java | 3 + .../activity/WeekCpUserGiftServiceImpl.java | 15 +- .../dto/cmd/activity/CpRankingQueryCmd.java | 25 ++++ .../activity/WeekCpUserGiftService.java | 5 +- .../user/count/WeekCpValueCountService.java | 25 ++++ .../impl/WeekCpValueCountServiceImpl.java | 79 +++++++++++ .../other/infra/utils}/SeasonUtils.java | 44 +++++- 12 files changed, 344 insertions(+), 124 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/SeasonCpTop1QueryExe.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/CpRankingQueryCmd.java rename rc-service/rc-service-other/{other-application/src/main/java/com/red/circle/other/app/util => other-infrastructure/src/main/java/com/red/circle/other/infra/utils}/SeasonUtils.java (73%) diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekCpGiftRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekCpGiftRestController.java index 2494a600..fcf7ab80 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekCpGiftRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekCpGiftRestController.java @@ -5,9 +5,11 @@ import com.red.circle.framework.web.controller.BaseController; import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO; import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO; import com.red.circle.other.app.dto.clientobject.activity.RewardPoolCO; +import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd; import com.red.circle.other.app.dto.cmd.activity.RewardPoolCmd; import com.red.circle.other.app.service.activity.WeekCpUserGiftService; import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum; +import jakarta.validation.Valid; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; @@ -45,29 +47,29 @@ public class WeekCpGiftRestController extends BaseController { } /** - * 上周与这周. + * cp排行榜(周榜和赛季榜) * - * @eo.name 上周与这周 - * @eo.url /week-data + * @eo.name CP排行榜 + * @eo.url /ranking-data * @eo.method get * @eo.request-type formdata */ - @GetMapping("/week-data") - public ActivityWeekCpGiftCO weekData(AppExtCommand cmd) { - return weekCpUserGiftService.weekData(cmd); + @GetMapping("/ranking-data") + public ActivityWeekCpGiftCO rankingData(@Valid CpRankingQueryCmd cmd) { + return weekCpUserGiftService.rankingData(cmd); } /** - * 上周前三名用户. + * 赛季榜Top1 * - * @eo.name 上周前三名用户 - * @eo.url /last-week-users-top3 + * @eo.name 赛季榜Top1 + * @eo.url /season-top1 * @eo.method get * @eo.request-type formdata */ - @GetMapping("/last-week-users-top3") - public List lastWeekUsersTop3(AppExtCommand cmd) { - return weekCpUserGiftService.lastWeekUsersTop3(cmd); + @GetMapping("/season-top1") + public List seasonTop1(AppExtCommand cmd) { + return weekCpUserGiftService.seasonTop1(cmd); } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/LastWeekCpUsersTop3QueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/LastWeekCpUsersTop3QueryExe.java index b7052c81..05cf4b45 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/LastWeekCpUsersTop3QueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/LastWeekCpUsersTop3QueryExe.java @@ -39,7 +39,7 @@ public class LastWeekCpUsersTop3QueryExe { public List execute(AppExtCommand cmd) { return assemble(weekCpValueCountService.listLastWeekTop( - cmd.getReqSysOrigin().getOrigin(), 3) + cmd.getReqSysOrigin().getOrigin(), 1) ); } @@ -78,8 +78,7 @@ public class LastWeekCpUsersTop3QueryExe { ranking.setCpUserNickname(cpUserProfile.getUserNickname()); ranking.setCpUserSex(cpUserProfile.getUserSex()); - ranking.setUserProfiles(List.of(userProfile, - cpUserProfile)); +// ranking.setUserProfiles(List.of(userProfile,cpUserProfile)); return ranking; }) .filter(Objects::nonNull) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/SeasonCpTop1QueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/SeasonCpTop1QueryExe.java new file mode 100644 index 00000000..7b66787c --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/SeasonCpTop1QueryExe.java @@ -0,0 +1,92 @@ +package com.red.circle.other.app.command.activity.query; + +import com.google.common.collect.Lists; +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; +import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.infra.common.user.UserCpUtils; +import com.red.circle.other.infra.database.mongo.entity.user.count.WeekCpValueCount; +import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService; +import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.other.inner.model.dto.user.WeekCpUserIdDTO; +import com.red.circle.tool.core.collection.CollectionUtils; +import com.red.circle.tool.core.num.NumUtils; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * 赛季榜Top1查询. + */ +@Service +@RequiredArgsConstructor +public class SeasonCpTop1QueryExe { + + private final UserProfileGateway userProfileGateway; + private final WeekCpValueCountService weekCpValueCountService; + private final UserProfileAppConvertor userProfileAppConvertor; + + public List execute(AppExtCommand cmd) { + List lastSeasonTop = weekCpValueCountService + .listLastSeasonTop(cmd.getReqSysOrigin().getOrigin(), 1); + + if (CollectionUtils.isEmpty(lastSeasonTop)) { + return Lists.newArrayList(); + } + + return assemble(lastSeasonTop); + } + + private List assemble(List weekCpValueCounts) { + if (CollectionUtils.isEmpty(weekCpValueCounts)) { + return Lists.newArrayList(); + } + + List results = weekCpValueCounts.stream().map(weekCpValueCount -> { + WeekCpUserIdDTO userIdPair = UserCpUtils.parseUserIdPair(weekCpValueCount.getId()); + return new ActivityCpUserRankingCO() + .setUserId(userIdPair.getUserIdOne()) + .setCpUserId(userIdPair.getUserIdTwo()) + .setTotalNumber(weekCpValueCount.getQuantity()) + .setTotal(NumUtils.formatLong(weekCpValueCount.getQuantity())); + } + ).toList(); + + Map userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( + userProfileGateway.mapByUserIds(getAllUserIds(results)) + ); + + return results.stream().map(ranking -> { + UserProfileDTO userProfile = userProfileMap.get(ranking.getUserId()); + UserProfileDTO cpUserProfile = userProfileMap.get(ranking.getCpUserId()); + if (Objects.isNull(userProfile) || Objects.isNull(cpUserProfile)) { + return null; + } + ranking.setUserAvatar(userProfile.getUserAvatar()); + ranking.setUserNickname(userProfile.getUserNickname()); + ranking.setUserSex(userProfile.getUserSex()); + + ranking.setCpUserAvatar(cpUserProfile.getUserAvatar()); + ranking.setCpUserNickname(cpUserProfile.getUserNickname()); + ranking.setCpUserSex(cpUserProfile.getUserSex()); + return ranking; + }) + .filter(Objects::nonNull) + .toList(); + } + + private Set getAllUserIds(List results) { + return results.stream() + .map(ranking -> Arrays.asList(ranking.getUserId(), ranking.getCpUserId())) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java index 67d669f2..17b9cb84 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java @@ -1,16 +1,14 @@ package com.red.circle.other.app.command.activity.query; import com.google.common.collect.Lists; -import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.other.infra.common.user.UserCpUtils; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO; import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO; +import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd; import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.infra.database.mongo.entity.user.count.WeekCpValueCount; import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService; -import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.model.dto.user.WeekCpUserIdDTO; @@ -27,101 +25,45 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; /** - * 每周CP用户礼物护送消耗. - * - * @author pengshigang on 2021/08/28 - * @since pengliang on 2022-03-25 + * CP排行榜查询. */ @Service @RequiredArgsConstructor public class WeekCpUserGiftQueryExe { - private final UserRegionGateway userRegionGateway; private final UserProfileGateway userProfileGateway; private final CpRelationshipService cpRelationshipService; private final WeekCpValueCountService weekCpValueCountService; private final UserProfileAppConvertor userProfileAppConvertor; - public ActivityWeekCpGiftCO execute(AppExtCommand cmd) { + public ActivityWeekCpGiftCO execute(CpRankingQueryCmd cmd) { + if (cmd.getType() == CpRankingQueryCmd.RankingType.WEEK) { + return getWeekRanking(cmd); + } else { + return getSeasonRanking(cmd); + } + } + + private ActivityWeekCpGiftCO getWeekRanking(CpRankingQueryCmd cmd) { return new ActivityWeekCpGiftCO() .setThisWeekUserTop(getThisWeekUser(cmd)) - .setLastWeekUserTop(getLastWeekUser(cmd)) - .setThisUser(getThisUser(cmd)); + .setThisUser(getThisWeekCurrentUser(cmd)); } - private List fill(AppExtCommand cmd, - List rankings) { - int resultSize = 20; - if (CollectionUtils.isEmpty(rankings)) { - return assembleFill(cpRelationshipService.listLatestCp( - cmd.getReqSysOrigin().getOrigin(), resultSize - ) - ); - } - - if (rankings.size() >= resultSize) { - return rankings; - } - - int fillSize = resultSize - rankings.size(); - List fillCo = assembleFill( - cpRelationshipService.listLatestCp( - cmd.getReqSysOrigin().getOrigin(), - getAllUserIds(rankings), - fillSize - ) - ); - if (CollectionUtils.isEmpty(fillCo)) { - return rankings; - } - rankings.addAll(fillCo); - return rankings; + private ActivityWeekCpGiftCO getSeasonRanking(CpRankingQueryCmd cmd) { + return new ActivityWeekCpGiftCO() + .setThisWeekUserTop(getThisSeasonUser(cmd)) + .setThisUser(getThisSeasonCurrentUser(cmd)); } - private List assembleFill( - List cpRelationships) { - if (CollectionUtils.isEmpty(cpRelationships)) { - return Lists.newArrayList(); - } - Map userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( - userProfileGateway.mapByUserIds( - cpRelationships.stream().map( - cpRelationship -> Arrays.asList(cpRelationship.getUserId(), - cpRelationship.getCpUserId()) - ).flatMap(Collection::stream).collect(Collectors.toSet()))); - - return cpRelationships.stream().map(cpRelationship -> { - UserProfileDTO userProfile = userProfileMap.get(cpRelationship.getUserId()); - UserProfileDTO cpUserProfile = userProfileMap.get(cpRelationship.getCpUserId()); - if (Objects.isNull(userProfile) || Objects.isNull(cpUserProfile)) { - return null; - } - return new ActivityCpUserRankingCO() - .setUserId(userProfile.getId()) - .setUserAvatar(userProfile.getUserAvatar()) - .setUserNickname(userProfile.getUserNickname()) - .setUserSex(userProfile.getUserSex()) - .setTotalNumber(0L) - .setTotal("0") - .setCpUserId(cpUserProfile.getId()) - .setCpUserAvatar(cpUserProfile.getUserAvatar()) - .setCpUserNickname(cpUserProfile.getUserNickname()) - .setCpUserSex(cpUserProfile.getUserSex()) - .setUserProfiles(List.of(userProfile, - cpUserProfile)); - }).filter(Objects::nonNull) - .toList(); - } - - private ActivityCpUserRankingCO getThisUser(AppExtCommand cmd) { - + private ActivityCpUserRankingCO getThisWeekCurrentUser(CpRankingQueryCmd cmd) { List cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId()); if (cpUserIdList.isEmpty()) { return new ActivityCpUserRankingCO(); } - Long cpUserId = cpUserIdList.get(0); - WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount( + Long cpUserId = cpUserIdList.get(0); + WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount( cmd.getReqSysOrigin().getOrigin(), cmd.getReqUserId(), cpUserId); if (Objects.isNull(thisUser)) { @@ -134,19 +76,33 @@ public class WeekCpUserGiftQueryExe { return users.get(0); } - private List getThisWeekUser(AppExtCommand cmd) { - return assemble(weekCpValueCountService.listThisWeekTop( + private ActivityCpUserRankingCO getThisSeasonCurrentUser(CpRankingQueryCmd cmd) { + List cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId()); + if (cpUserIdList.isEmpty()) { + return new ActivityCpUserRankingCO(); + } + + Long cpUserId = cpUserIdList.get(0); + WeekCpValueCount thisSeason = weekCpValueCountService.getUserThisSeasonCount( cmd.getReqSysOrigin().getOrigin(), - userRegionGateway.getRegionCode(cmd.getReqUserId()), - 20) + cmd.getReqUserId(), cpUserId); + if (Objects.isNull(thisSeason)) { + return new ActivityCpUserRankingCO(); + } + List users = assemble(Lists.newArrayList(thisSeason)); + if (CollectionUtils.isEmpty(users)) { + return new ActivityCpUserRankingCO(); + } + return users.get(0); + } + + private List getThisWeekUser(CpRankingQueryCmd cmd) { + return assemble(weekCpValueCountService.listThisWeekTop(cmd.getReqSysOrigin().getOrigin(), 20) ); } - private List getLastWeekUser(AppExtCommand cmd) { - return assemble(weekCpValueCountService.listLastWeekTop( - cmd.getReqSysOrigin().getOrigin(), - userRegionGateway.getRegionCode(cmd.getReqUserId()), - 3) + private List getThisSeasonUser(CpRankingQueryCmd cmd) { + return assemble(weekCpValueCountService.listThisSeasonTop(cmd.getReqSysOrigin().getOrigin(), 20) ); } @@ -183,8 +139,6 @@ public class WeekCpUserGiftQueryExe { ranking.setCpUserAvatar(cpUserProfile.getUserAvatar()); ranking.setCpUserNickname(cpUserProfile.getUserNickname()); ranking.setCpUserSex(cpUserProfile.getUserSex()); - ranking.setUserProfiles(List.of(userProfile, - cpUserProfile)); return ranking; }) .filter(Objects::nonNull) @@ -198,5 +152,4 @@ public class WeekCpUserGiftQueryExe { .collect(Collectors.toSet()); } - } 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 94b955d6..5e26f050 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 @@ -7,7 +7,6 @@ import com.red.circle.mq.business.model.event.gift.OfflineProcessGiftEvent; import com.red.circle.other.app.common.gift.GameLuckyGiftCommon; import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd; import com.red.circle.other.app.service.activity.RankingActivityService; -import com.red.circle.other.app.util.SeasonUtils; 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.ranking.RankingActivityType; @@ -320,6 +319,16 @@ public class RankCountStrategy implements GiftStrategy { acceptAmount.longValue()); cpRelationshipCacheService.remove(Arrays.asList(cp.getUserId(), cp.getCpUserId())); + + weekCpValueCountService.incrThisWeekQuantity(runningWater.getSysOrigin(), + cp.getUserId(), + cp.getCpUserId(), + acceptAmount.longValue()); + + weekCpValueCountService.incrThisSeasonQuantity(runningWater.getSysOrigin(), + cp.getUserId(), + cp.getCpUserId(), + acceptAmount.longValue()); }); // 更新cp用户赠送的礼物价值 // cpRelationshipService.updateAccountByUserId(cpRelationship.getUserId(), @@ -331,13 +340,6 @@ public class RankCountStrategy implements GiftStrategy { // ? userRegionGateway.getRegionCode(cpRelationship.getUserId()) : // userRegionGateway.getRegionCode(relationship.getUserId()); - /*weekCpValueCountService.incrThisWeekQuantity(runningWater.getSysOrigin(), - userRegionCode, - cpRelationship.getUserId(), - cpRelationship.getCpUserId(), - acceptAmount.longValue());*/ - - } private boolean isWeekStar(GiftValue giftValue) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/CleanExpiredDismissingCpTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/CleanExpiredDismissingCpTask.java index 4a41f9ae..eba57da3 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/CleanExpiredDismissingCpTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/CleanExpiredDismissingCpTask.java @@ -70,6 +70,9 @@ public class CleanExpiredDismissingCpTask { weekCpValueCountService.removeThisWeek(cpRelationship.getUserId(), cpRelationship.getCpUserId()); + weekCpValueCountService.removeThisSeason(cpRelationship.getUserId(), + cpRelationship.getCpUserId()); + // 删除CP值 cpValueService.deleteById(cpRelationship.getCpValId()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftServiceImpl.java index 414ec3f3..85a2efcb 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftServiceImpl.java @@ -1,21 +1,20 @@ package com.red.circle.other.app.service.activity; import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.other.app.command.activity.query.LastWeekCpUsersTop3QueryExe; import com.red.circle.other.app.command.activity.query.RewardPoolQueryExe; +import com.red.circle.other.app.command.activity.query.SeasonCpTop1QueryExe; import com.red.circle.other.app.command.activity.query.WeekCpUserGiftQueryExe; import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO; import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO; import com.red.circle.other.app.dto.clientobject.activity.RewardPoolCO; +import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd; import com.red.circle.other.app.dto.cmd.activity.RewardPoolCmd; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; /** - * 首充奖励池. - * - * @author pengshigang on 2021/8/3 + * CP排行榜服务. */ @Service @RequiredArgsConstructor @@ -23,7 +22,7 @@ public class WeekCpUserGiftServiceImpl implements WeekCpUserGiftService { private final RewardPoolQueryExe rewardPoolQueryExe; private final WeekCpUserGiftQueryExe weekCpUserGiftQueryExe; - private final LastWeekCpUsersTop3QueryExe lastWeekCpUsersTop3QueryExe; + private final SeasonCpTop1QueryExe seasonCpTop1QueryExe; @Override public List listRewardPool(RewardPoolCmd cmd) { @@ -31,12 +30,12 @@ public class WeekCpUserGiftServiceImpl implements WeekCpUserGiftService { } @Override - public ActivityWeekCpGiftCO weekData(AppExtCommand cmd) { + public ActivityWeekCpGiftCO rankingData(CpRankingQueryCmd cmd) { return weekCpUserGiftQueryExe.execute(cmd); } @Override - public List lastWeekUsersTop3(AppExtCommand cmd) { - return lastWeekCpUsersTop3QueryExe.execute(cmd); + public List seasonTop1(AppExtCommand cmd) { + return seasonCpTop1QueryExe.execute(cmd); } } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/CpRankingQueryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/CpRankingQueryCmd.java new file mode 100644 index 00000000..bdd58c0b --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/CpRankingQueryCmd.java @@ -0,0 +1,25 @@ +package com.red.circle.other.app.dto.cmd.activity; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * CP排行榜查询 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CpRankingQueryCmd extends AppExtCommand { + + /** + * 榜单类型: WEEK-周榜, SEASON-赛季榜 + */ + @NotNull(message = "榜单类型不能为空") + private RankingType type; + + public enum RankingType { + WEEK, + SEASON + } +} \ No newline at end of file diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftService.java index 02036c88..360b711c 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/activity/WeekCpUserGiftService.java @@ -4,6 +4,7 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO; import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO; import com.red.circle.other.app.dto.clientobject.activity.RewardPoolCO; +import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd; import com.red.circle.other.app.dto.cmd.activity.RewardPoolCmd; import java.util.List; @@ -16,8 +17,8 @@ public interface WeekCpUserGiftService { List listRewardPool(RewardPoolCmd cmd); - ActivityWeekCpGiftCO weekData(AppExtCommand cmd); + ActivityWeekCpGiftCO rankingData(CpRankingQueryCmd cmd); - List lastWeekUsersTop3(AppExtCommand cmd); + List seasonTop1(AppExtCommand cmd); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/WeekCpValueCountService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/WeekCpValueCountService.java index 4d8dfd85..eed99daa 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/WeekCpValueCountService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/count/WeekCpValueCountService.java @@ -52,6 +52,31 @@ public interface WeekCpValueCountService { */ void removeThisWeek(Long userIdOne, Long userIdTwo); + /** + * 累计本赛季统计. + */ + void incrThisSeasonQuantity(String sysOrigin, Long userIdOne, Long userIdTwo, Long quantity); + + /** + * 移除本赛季cp值. + */ + void removeThisSeason(Long userIdOne, Long userIdTwo); + + /** + * 获取我的本赛季贡献. + */ + WeekCpValueCount getUserThisSeasonCount(String sysOrigin, Long userIdOne, Long userIdTwo); + + /** + * 获取本赛季统计记录top. + */ + List listThisSeasonTop(String sysOrigin, Integer size); + + /** + * 获取上赛季统计记录top. + */ + List listLastSeasonTop(String sysOrigin, Integer size); + /** * 解析id中cp用户id. */ 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 16d341ad..c1aa21e5 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 @@ -1,5 +1,6 @@ package com.red.circle.other.infra.database.mongo.service.user.count.impl; +import com.red.circle.other.infra.utils.SeasonUtils; import com.red.circle.tool.core.date.DateFormatConstant; import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; @@ -57,6 +58,50 @@ public class WeekCpValueCountServiceImpl implements WeekCpValueCountService { addThisWeekV2(sysOrigin, userRegionCode, userIdOne, userIdTwo, quantity); } + @Override + public void incrThisSeasonQuantity(String sysOrigin, Long userIdOne, Long userIdTwo, + Long quantity) { + if (existsThisSeason(userIdOne, userIdTwo)) { + mongoTemplate.updateFirst(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo)), + new Update().inc("quantity", quantity), + WeekCpValueCount.class); + return; + } + addThisSeason(sysOrigin, userIdOne, userIdTwo, quantity); + } + + @Override + public void removeThisSeason(Long userIdOne, Long userIdTwo) { + mongoTemplate.remove(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo) + .and("group").is(getThisSeasonCycleKey())), WeekCpValueCount.class); + } + + @Override + public WeekCpValueCount getUserThisSeasonCount(String sysOrigin, Long userIdOne, Long userIdTwo) { + return mongoTemplate + .findOne(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo) + .and("sysOrigin").is(sysOrigin)) + , WeekCpValueCount.class); + } + + @Override + public List listThisSeasonTop(String sysOrigin, Integer size) { + return mongoTemplate + .find(Query.query(Criteria.where("sysOrigin").is(sysOrigin) + .and("group").is(getThisSeasonCycleKey())) + .with(Sort.by(Sort.Order.desc("quantity"))) + .limit(size), WeekCpValueCount.class); + } + + @Override + public List listLastSeasonTop(String sysOrigin, Integer size) { + return mongoTemplate + .find(Query.query(Criteria.where("sysOrigin").is(sysOrigin) + .and("group").is(getLastSeasonCycleKey())) + .with(Sort.by(Sort.Order.desc("quantity"))) + .limit(size), WeekCpValueCount.class); + } + private void addThisWeek(String sysOrigin, Long userIdOne, Long userIdTwo, Long quantity) { mongoTemplate.save(new WeekCpValueCount() .setId(getWeekUniqueId(userIdOne, userIdTwo)) @@ -81,6 +126,16 @@ public class WeekCpValueCountServiceImpl implements WeekCpValueCountService { ); } + private void addThisSeason(String sysOrigin, Long userIdOne, Long userIdTwo, Long quantity) { + mongoTemplate.save(new WeekCpValueCount() + .setId(getSeasonUniqueId(userIdOne, userIdTwo)) + .setSysOrigin(sysOrigin) + .setQuantity(quantity) + .setGroup(getThisSeasonCycleKey()) + .setCreateTime(TimestampUtils.now()) + .setExpiredTime(TimestampUtils.nowPlusDays(60)) + ); + } @Override public WeekCpValueCount getUserThisWeekCount(String sysOrigin, Long userIdOne, Long userIdTwo) { @@ -178,19 +233,43 @@ public class WeekCpValueCountServiceImpl implements WeekCpValueCountService { .concat(getThisWeekDate()); } + private String getSeasonUniqueId(Long userOne, Long userIdTwo) { + return StringUtils.sortAscNumberJoin("_", userOne, userIdTwo) + .concat("_") + .concat(getThisSeasonCycleKey()); + } + private boolean existsThisWeek(Long userIdOne, Long userIdTwo) { return mongoTemplate .exists(Query.query(getUniquenessCriteria(userIdOne, userIdTwo)), WeekCpValueCount.class); } + private boolean existsThisSeason(Long userIdOne, Long userIdTwo) { + return mongoTemplate + .exists(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo)), + WeekCpValueCount.class); + } + private Criteria getUniquenessCriteria(Long userIdOne, Long userIdTwo) { return Criteria.where("id").is(getWeekUniqueId(userIdOne, userIdTwo)); } + private Criteria getSeasonUniquenessCriteria(Long userIdOne, Long userIdTwo) { + return Criteria.where("id").is(getSeasonUniqueId(userIdOne, userIdTwo)); + } + private String getThisWeekDate() { return ZonedDateTimeUtils.format(ZonedDateTimeAsiaRiyadhUtils.nowWeekMonday(), DateFormatConstant.yyyyMMdd); } + private String getThisSeasonCycleKey() { + return SeasonUtils.getCurrentSeasonCycleKey(); + } + + private String getLastSeasonCycleKey() { + return SeasonUtils.getLastSeasonCycleKey(); + } + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/util/SeasonUtils.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/SeasonUtils.java similarity index 73% rename from rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/util/SeasonUtils.java rename to rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/SeasonUtils.java index 49928311..33fb234e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/util/SeasonUtils.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/SeasonUtils.java @@ -1,11 +1,12 @@ -package com.red.circle.other.app.util; +package com.red.circle.other.infra.utils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; +import com.red.circle.tool.core.date.ZonedId; import lombok.AllArgsConstructor; import lombok.Data; import java.time.LocalDate; -import java.time.ZonedDateTime; +import java.time.ZoneId;import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; @@ -43,6 +44,24 @@ public class SeasonUtils { return getSeasonCycleKey(now); } + /** + * 获取上一个赛季的cycleKey + * 通过获取当前赛季开始日期前一天,来定位到上一个赛季 + */ + public static String getLastSeasonCycleKey() { + ZonedDateTime now = ZonedDateTimeAsiaRiyadhUtils.now(); + SeasonPeriod currentSeason = getCurrentSeason(now); + + // 获取当前赛季的开始日期 + LocalDate currentSeasonStart = getSeasonStartDate(now, currentSeason); + + // 当前赛季开始日期前一天,一定在上一个赛季内 + ZonedDateTime lastSeasonDate = currentSeasonStart.minusDays(1) + .atStartOfDay(ZonedId.ASIA_RIYADH.getZonedId()); + + return getSeasonCycleKey(lastSeasonDate); + } + /** * 获取指定日期所在赛季的cycleKey */ @@ -76,6 +95,27 @@ public class SeasonUtils { return startDate.format(formatter) + "-" + endDate.format(formatter); } + /** + * 获取指定日期所在赛季的开始日期 + */ + private static LocalDate getSeasonStartDate(ZonedDateTime dateTime, SeasonPeriod season) { + int year = dateTime.getYear(); + + if (season.startMonth > season.endMonth) { + // 跨年赛季:摩羯座(12/22-1/19) + if (dateTime.getMonthValue() == season.endMonth) { + // 如果当前是结束月份(1月),开始日期在去年 + return LocalDate.of(year - 1, season.startMonth, season.startDay); + } else { + // 如果当前是开始月份(12月) + return LocalDate.of(year, season.startMonth, season.startDay); + } + } else { + // 同年赛季 + return LocalDate.of(year, season.startMonth, season.startDay); + } + } + /** * 获取当前所在的赛季信息 */