diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekKingQueenUserContributeQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekKingQueenUserContributeQueryExe.java index 8b8fbc31..7dfcbc85 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekKingQueenUserContributeQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekKingQueenUserContributeQueryExe.java @@ -32,14 +32,21 @@ public class WeekKingQueenUserContributeQueryExe { public UserCharmWealthContributeCO execute(AppExtCommand cmd) { UserProfile baseInfo = userProfileGateway.getByUserId(cmd.getReqUserId()); + + // 获取带排名的魅力和财富数据 + WeekKingQueenCount charmData = getContributeWithRank(cmd, KingQueenType.CHARM); + WeekKingQueenCount wealthData = getContributeWithRank(cmd, KingQueenType.WEALTH); + return new UserCharmWealthContributeCO() .setUserId(baseInfo.getId()) .setUserSex(baseInfo.getUserSex()) .setAccount(baseInfo.getAccount()) .setUserAvatar(baseInfo.getUserAvatar()) .setUserNickname(baseInfo.getUserNickname()) - .setCharmQuantity(getContribute(cmd, KingQueenType.CHARM)) - .setWealthQuantity(getContribute(cmd, KingQueenType.WEALTH)); + .setCharmQuantity(charmData != null ? NumUtils.formatLong(charmData.getQuantity()) : "0") + .setWealthQuantity(wealthData != null ? NumUtils.formatLong(wealthData.getQuantity()) : "0") + .setCharmRank(charmData != null ? charmData.getRank() : null) + .setWealthRank(wealthData != null ? wealthData.getRank() : null); } private String getContribute(AppExtCommand cmd, KingQueenType type) { @@ -50,6 +57,15 @@ public class WeekKingQueenUserContributeQueryExe { .orElse("0"); } + /** + * 获取带排名的贡献数据. + */ + private WeekKingQueenCount getContributeWithRank(AppExtCommand cmd, KingQueenType type) { + return weekKingQueenCountService + .getUserThisWeekCountWithRank(cmd.getReqSysOrigin().getOrigin(), type, + cmd.getReqUserId()); + } + private UserRankCO getUserProfile(WeekKingQueenCount charm, Map userBaseMap) { return Optional.ofNullable(charm) diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserCharmWealthContributeCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserCharmWealthContributeCO.java index 9ae03357..5846f89f 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserCharmWealthContributeCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserCharmWealthContributeCO.java @@ -53,4 +53,14 @@ public class UserCharmWealthContributeCO extends ClientObject { */ private String wealthQuantity; + /** + * 魅力排名. + */ + private Integer charmRank; + + /** + * 财富排名. + */ + private Integer wealthRank; + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/WeekKingQueenCountService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/WeekKingQueenCountService.java index 9b5873d0..1d3de7fe 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/WeekKingQueenCountService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/WeekKingQueenCountService.java @@ -24,6 +24,11 @@ public interface WeekKingQueenCountService { */ WeekKingQueenCount getUserThisWeekCount(String sysOrigin, KingQueenType type, Long userId); + /** + * 获取用户在本周的排名信息. + */ + WeekKingQueenCount getUserThisWeekCountWithRank(String sysOrigin, KingQueenType type, Long userId); + /** * 获取本周统计记录top. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java index 1bcf26de..f1736942 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/activity/impl/WeekKingQueenCountServiceImpl.java @@ -44,6 +44,15 @@ public class WeekKingQueenCountServiceImpl implements WeekKingQueenCountService private final MongoPrimaryService mongoPrimaryService; private final UserProfileGateway userProfileGateway; + @Override + public WeekKingQueenCount getUserThisWeekCount(String sysOrigin, KingQueenType type, + Long userId) { + return mongoTemplate + .findOne(Query.query(getUniquenessCriteria(userId, type) + .and("sysOrigin").is(sysOrigin)) + , WeekKingQueenCount.class); + } + @Override public void incrThisWeekQuantity(String sysOrigin, Long userId, KingQueenType type, Long quantity) { @@ -57,12 +66,36 @@ public class WeekKingQueenCountServiceImpl implements WeekKingQueenCountService } @Override - public WeekKingQueenCount getUserThisWeekCount(String sysOrigin, KingQueenType type, - Long userId) { - return mongoTemplate - .findOne(Query.query(getUniquenessCriteria(userId, type) - .and("sysOrigin").is(sysOrigin)) - , WeekKingQueenCount.class); + public WeekKingQueenCount getUserThisWeekCountWithRank(String sysOrigin, KingQueenType type, Long userId) { + // 先获取用户的本周数据 + WeekKingQueenCount userCount = getUserThisWeekCount(sysOrigin, type, userId); + if (userCount == null) { + return null; + } + + // 构建查询条件(根据业务规则过滤性别) + Criteria criteria = Criteria.where("sysOrigin").is(sysOrigin) + .and("group").is(getThisWeekDate()) + .and("type").is(type); + + // 根据类型过滤性别 + if (type == KingQueenType.CHARM) { + // 魅力类型:只显示女性(0) + criteria.and("userSex").is(0); + } else if (type == KingQueenType.WEALTH) { + // 财富类型:只显示男性(1) + criteria.and("userSex").is(1); + } + + // 统计比用户数量更高的人数(即排名) + long rank = mongoTemplate.count( + Query.query(criteria.and("quantity").gt(userCount.getQuantity())), + WeekKingQueenCount.class + ) + 1; + + // 设置排名并返回 + userCount.setRank((int) rank); + return userCount; } @Override