新增家族成员总榜top100接口

This commit is contained in:
tianfeng 2025-12-26 11:35:25 +08:00
parent 085f9aeba9
commit 9c80625799
5 changed files with 150 additions and 18 deletions

View File

@ -127,13 +127,21 @@ public class FamilyRestController extends BaseController {
}
/**
* 家族排行榜.
* 家族成员Top10周排行榜
*/
@GetMapping("/leaderboard")
public FamilyLeaderboardCO getLeaderboard(AppExtCommand cmd) {
@GetMapping("/member-top10")
public FamilyLeaderboardCO getMemberTop10(FamilyBaseInfoQueryCmd cmd) {
return familyService.getLeaderboard(cmd);
}
/**
* 家族成员Top100总排行榜
*/
@GetMapping("/member-top100")
public FamilyLeaderboardCO getMemberTop100(FamilyBaseInfoQueryCmd cmd) {
return familyService.getMemberTop100(cmd);
}
/**
* 家族等级配置
*/

View File

@ -5,6 +5,7 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.live.inner.endpoint.LiveMicClient;
import com.red.circle.other.app.dto.clientobject.family.FamilyLeaderboardCO;
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;
@ -39,18 +40,19 @@ public class FamilyLeaderboardExe {
private final FamilyMemberInfoService familyMemberInfoService;
private final FamilyMemberWeekExpService familyMemberWeekExpService;
public FamilyLeaderboardCO execute(AppExtCommand cmd) {
FamilyMemberInfo member = familyMemberInfoService.getFamilyMemberByUserId(cmd.getReqUserId());
public FamilyLeaderboardCO execute(FamilyBaseInfoQueryCmd cmd) {
Map<Long, FamilyMemberInfo> map = familyMemberInfoService.mapUserIdBaseInfo(cmd.getFamilyId(), Set.of(cmd.getReqUserId()));
FamilyMemberInfo member = map.get(cmd.getReqUserId());
if (Objects.isNull(member)) {
return new FamilyLeaderboardCO();
}
List<FamilyMemberWeekExp> top200Exp = getTop200WeekExp(member.getFamilyId());
if (CollectionUtils.isEmpty(top200Exp)) {
List<FamilyMemberWeekExp> top100Exp = getTop100WeekExp(member.getFamilyId());
if (CollectionUtils.isEmpty(top100Exp)) {
return new FamilyLeaderboardCO();
}
Set<Long> userIds = top200Exp.stream()
Set<Long> userIds = top100Exp.stream()
.map(FamilyMemberWeekExp::getFamilyMemberId)
.collect(Collectors.toSet());
@ -60,19 +62,19 @@ public class FamilyLeaderboardExe {
List<FamilyMemberWeekRankCO> hostRank = new ArrayList<>();
List<FamilyMemberWeekRankCO> supporterRank = new ArrayList<>();
for (FamilyMemberWeekExp exp : top200Exp) {
for (FamilyMemberWeekExp exp : top100Exp) {
Long userId = exp.getFamilyMemberId();
boolean isHost = hostUserIds.contains(userId);
FamilyMemberWeekRankCO rankCO = buildRankCO(exp, userProfileMap.get(userId), isHost);
if (isHost && hostRank.size() < 100) {
if (isHost && hostRank.size() < 10) {
hostRank.add(rankCO);
} else if (!isHost && supporterRank.size() < 100) {
} else if (!isHost && supporterRank.size() < 10) {
supporterRank.add(rankCO);
}
if (hostRank.size() >= 100 && supporterRank.size() >= 100) {
if (hostRank.size() >= 10 && supporterRank.size() >= 10) {
break;
}
}
@ -82,11 +84,11 @@ public class FamilyLeaderboardExe {
.setSupporterWeekRank(supporterRank);
}
private List<FamilyMemberWeekExp> getTop200WeekExp(Long familyId) {
private List<FamilyMemberWeekExp> getTop100WeekExp(Long familyId) {
return familyMemberWeekExpService.query()
.eq(FamilyMemberWeekExp::getFamilyId, familyId)
.orderByDesc(FamilyMemberWeekExp::getExp)
.last("LIMIT 200")
.last("LIMIT 100")
.list();
}

View File

@ -0,0 +1,110 @@
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.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;
import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService;
import com.red.circle.other.infra.database.rds.service.family.FamilyMemberTotalExpService;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.num.NumUtils;
import java.util.ArrayList;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 家族成员Top100总排行榜
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class FamilyMemberTop100Exe {
private final TeamMemberService teamMemberService;
private final UserProfileGateway userProfileGateway;
private final FamilyMemberInfoService familyMemberInfoService;
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());
if (Objects.isNull(member)) {
return new FamilyLeaderboardCO();
}
List<FamilyMemberTotalExp> top200Exp = getTop200TotalExp(member.getFamilyId());
if (CollectionUtils.isEmpty(top200Exp)) {
return new FamilyLeaderboardCO();
}
Set<Long> userIds = top200Exp.stream()
.map(FamilyMemberTotalExp::getFamilyMemberId)
.collect(Collectors.toSet());
Set<Long> hostUserIds = getHostUserIds(userIds);
Map<Long, UserProfile> userProfileMap = userProfileGateway.mapByUserIds(userIds);
List<FamilyMemberWeekRankCO> hostRank = new ArrayList<>();
List<FamilyMemberWeekRankCO> supporterRank = new ArrayList<>();
for (FamilyMemberTotalExp exp : top200Exp) {
Long userId = exp.getFamilyMemberId();
boolean isHost = hostUserIds.contains(userId);
FamilyMemberWeekRankCO rankCO = buildRankCO(exp, userProfileMap.get(userId), isHost);
if (isHost && hostRank.size() < 100) {
hostRank.add(rankCO);
} else if (!isHost && supporterRank.size() < 100) {
supporterRank.add(rankCO);
}
if (hostRank.size() >= 100 && supporterRank.size() >= 100) {
break;
}
}
return new FamilyLeaderboardCO()
.setHostWeekRank(hostRank)
.setSupporterWeekRank(supporterRank);
}
private List<FamilyMemberTotalExp> getTop200TotalExp(Long familyId) {
return familyMemberTotalExpService.query()
.eq(FamilyMemberTotalExp::getFamilyId, familyId)
.orderByDesc(FamilyMemberTotalExp::getExp)
.last("LIMIT 200")
.list();
}
private Set<Long> getHostUserIds(Set<Long> userIds) {
if (CollectionUtils.isEmpty(userIds)) {
return Set.of();
}
List<Long> hostIds = teamMemberService.listMemberIds(userIds);
return CollectionUtils.isEmpty(hostIds) ? Set.of() : Set.copyOf(hostIds);
}
private FamilyMemberWeekRankCO buildRankCO(FamilyMemberTotalExp exp,
UserProfile profile, boolean isHost) {
return new FamilyMemberWeekRankCO()
.setUserId(exp.getFamilyMemberId())
.setNickname(Objects.nonNull(profile) ? profile.getUserNickname() : "")
.setAvatar(Objects.nonNull(profile) ? profile.getUserAvatar() : "")
.setExp(NumUtils.formatLong(exp.getExp()))
.setIsHost(isHost);
}
}

View File

@ -32,6 +32,7 @@ import com.red.circle.other.app.command.family.FamilyListExe;
import com.red.circle.other.app.command.family.FamilyBoxContributeExe;
import com.red.circle.other.app.command.family.FamilyBoxClaimExe;
import com.red.circle.other.app.command.family.FamilyHomeListExe;
import com.red.circle.other.app.command.family.FamilyMemberTop100Exe;
import com.red.circle.other.app.dto.clientobject.family.*;
import com.red.circle.other.app.dto.clientobject.room.RoomVoiceProfileCO;
import com.red.circle.other.app.dto.cmd.family.*;
@ -86,8 +87,9 @@ public class FamilyServiceImpl implements FamilyService {
private final FamilyListExe familyListExe;
private final FamilyBoxContributeExe familyBoxContributeExe;
private final FamilyBoxClaimExe familyBoxClaimExe;
private final DistributedLockUtil distributedLockUtil;
private final FamilyHomeListExe familyHomeListExe;
private final FamilyMemberTop100Exe familyMemberTop100Exe;
private final DistributedLockUtil distributedLockUtil;
@Override
public Long create(FamilyCreateCmd cmd) {
@ -128,10 +130,15 @@ public class FamilyServiceImpl implements FamilyService {
}
@Override
public FamilyLeaderboardCO getLeaderboard(AppExtCommand cmd) {
public FamilyLeaderboardCO getLeaderboard(FamilyBaseInfoQueryCmd cmd) {
return familyLeaderboardExe.execute(cmd);
}
@Override
public FamilyLeaderboardCO getMemberTop100(FamilyBaseInfoQueryCmd cmd) {
return familyMemberTop100Exe.execute(cmd);
}
@Override
public List<FamilyLevelCO> listLevelConfig(AppExtCommand cmd) {
return familyLevelListExe.execute(cmd);

View File

@ -52,9 +52,14 @@ public interface FamilyService {
void grantUserRole(FamilyGrantUserRoleCmd cmd);
/**
* 家族排行榜 周榜月榜自己家族信息.
* 家族成员Top10周排行榜.
*/
FamilyLeaderboardCO getLeaderboard(AppExtCommand cmd);
FamilyLeaderboardCO getLeaderboard(FamilyBaseInfoQueryCmd cmd);
/**
* 家族成员Top100总排行榜.
*/
FamilyLeaderboardCO getMemberTop100(FamilyBaseInfoQueryCmd cmd);
/**
* 全部等级配置集合.