From 3b97886fabc2105c528cc777559ecd1c8cdde589 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 26 Dec 2025 11:47:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B6=E6=97=8F=E6=88=90=E5=91=98=E6=80=BB?= =?UTF-8?q?=E6=A6=9Ctop100=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9E=E6=88=91?= =?UTF-8?q?=E7=9A=84=E6=8E=92=E5=90=8D=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/family/FamilyMemberTop100Exe.java | 66 +++++++++++++++++-- .../family/FamilyLeaderboardCO.java | 5 ++ .../family/FamilyMemberRankInfoCO.java | 49 ++++++++++++++ 3 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberRankInfoCO.java diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyMemberTop100Exe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyMemberTop100Exe.java index 8e8fa0bc..08527d71 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyMemberTop100Exe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyMemberTop100Exe.java @@ -1,11 +1,11 @@ package com.red.circle.other.app.command.family; import com.red.circle.other.app.dto.clientobject.family.FamilyLeaderboardCO; +import com.red.circle.other.app.dto.clientobject.family.FamilyMemberRankInfoCO; import com.red.circle.other.app.dto.clientobject.family.FamilyMemberWeekRankCO; import com.red.circle.other.app.dto.cmd.family.FamilyBaseInfoQueryCmd; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.model.user.UserProfile; -import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberService; import com.red.circle.other.infra.database.rds.entity.family.FamilyMemberInfo; import com.red.circle.other.infra.database.rds.entity.family.FamilyMemberTotalExp; @@ -38,8 +38,7 @@ public class FamilyMemberTop100Exe { private final FamilyMemberTotalExpService familyMemberTotalExpService; public FamilyLeaderboardCO execute(FamilyBaseInfoQueryCmd cmd) { - Map map = familyMemberInfoService.mapUserIdBaseInfo(cmd.getFamilyId(), Set.of(cmd.getReqUserId())); - FamilyMemberInfo member = map.get(cmd.getReqUserId()); + FamilyMemberInfo member = familyMemberInfoService.getFamilyMemberByUserId(cmd.getReqUserId()); if (Objects.isNull(member)) { return new FamilyLeaderboardCO(); } @@ -58,27 +57,58 @@ public class FamilyMemberTop100Exe { List hostRank = new ArrayList<>(); List supporterRank = new ArrayList<>(); + + int myRankInHost = -1; + int myRankInSupporter = -1; + FamilyMemberTotalExp myExp = null; - for (FamilyMemberTotalExp exp : top200Exp) { + for (int i = 0; i < top200Exp.size(); i++) { + FamilyMemberTotalExp exp = top200Exp.get(i); Long userId = exp.getFamilyMemberId(); boolean isHost = hostUserIds.contains(userId); + if (userId.equals(cmd.getReqUserId())) { + myExp = exp; + } + FamilyMemberWeekRankCO rankCO = buildRankCO(exp, userProfileMap.get(userId), isHost); if (isHost && hostRank.size() < 100) { + if (userId.equals(cmd.getReqUserId())) { + myRankInHost = hostRank.size() + 1; + } hostRank.add(rankCO); } else if (!isHost && supporterRank.size() < 100) { + if (userId.equals(cmd.getReqUserId())) { + myRankInSupporter = supporterRank.size() + 1; + } supporterRank.add(rankCO); + } else if (userId.equals(cmd.getReqUserId())) { + if (isHost) { + myRankInHost = 101; + } else { + myRankInSupporter = 101; + } } - if (hostRank.size() >= 100 && supporterRank.size() >= 100) { + if (hostRank.size() >= 100 && supporterRank.size() >= 100 && Objects.nonNull(myExp)) { break; } } + FamilyMemberRankInfoCO myRankInfo = buildMyRankInfo( + cmd.getReqUserId(), + myExp, + userProfileMap.get(cmd.getReqUserId()), + myRankInHost, + myRankInSupporter, + hostUserIds.contains(cmd.getReqUserId()) + ); + return new FamilyLeaderboardCO() .setHostWeekRank(hostRank) - .setSupporterWeekRank(supporterRank); + .setSupporterWeekRank(supporterRank) + .setMyRankInfo(myRankInfo); } private List getTop200TotalExp(Long familyId) { @@ -107,4 +137,28 @@ public class FamilyMemberTop100Exe { .setExp(NumUtils.formatLong(exp.getExp())) .setIsHost(isHost); } + + private FamilyMemberRankInfoCO buildMyRankInfo( + Long userId, + FamilyMemberTotalExp myExp, + UserProfile profile, + int myRankInHost, + int myRankInSupporter, + boolean isHost + ) { + String rank; + if (isHost) { + rank = myRankInHost > 0 ? (myRankInHost > 100 ? "100+" : String.valueOf(myRankInHost)) : "100+"; + } else { + rank = myRankInSupporter > 0 ? (myRankInSupporter > 100 ? "100+" : String.valueOf(myRankInSupporter)) : "100+"; + } + + return new FamilyMemberRankInfoCO() + .setUserId(userId) + .setNickname(Objects.nonNull(profile) ? profile.getUserNickname() : "") + .setAvatar(Objects.nonNull(profile) ? profile.getUserAvatar() : "") + .setExp(Objects.nonNull(myExp) ? NumUtils.formatLong(myExp.getExp()) : "0") + .setRank(rank) + .setIsHost(isHost); + } } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyLeaderboardCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyLeaderboardCO.java index ee2b2f04..0ccff8d6 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyLeaderboardCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyLeaderboardCO.java @@ -26,4 +26,9 @@ public class FamilyLeaderboardCO implements Serializable { */ private List supporterWeekRank; + /** + * 我的排名信息 + */ + private FamilyMemberRankInfoCO myRankInfo; + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberRankInfoCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberRankInfoCO.java new file mode 100644 index 00000000..42dc1304 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberRankInfoCO.java @@ -0,0 +1,49 @@ +package com.red.circle.other.app.dto.clientobject.family; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import java.io.Serializable; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 家族成员排名信息 + */ +@Data +@Accessors(chain = true) +public class FamilyMemberRankInfoCO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long userId; + + /** + * 用户昵称 + */ + private String nickname; + + /** + * 用户头像 + */ + private String avatar; + + /** + * 经验值 + */ + private String exp; + + /** + * 排名(100+表示100名之外) + */ + private String rank; + + /** + * 是否是主播 + */ + private Boolean isHost; + +}