家族成员总榜top100接口新增我的排名信息

This commit is contained in:
tianfeng 2025-12-26 11:47:37 +08:00
parent 9c80625799
commit 3b97886fab
3 changed files with 114 additions and 6 deletions

View File

@ -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<Long, FamilyMemberInfo> 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<FamilyMemberWeekRankCO> hostRank = new ArrayList<>();
List<FamilyMemberWeekRankCO> 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<FamilyMemberTotalExp> 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);
}
}

View File

@ -26,4 +26,9 @@ public class FamilyLeaderboardCO implements Serializable {
*/
private List<FamilyMemberWeekRankCO> supporterWeekRank;
/**
* 我的排名信息
*/
private FamilyMemberRankInfoCO myRankInfo;
}

View File

@ -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;
}