From 242dc047be18e4876ccebfd7ea92695d82c71e82 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 25 Dec 2025 16:22:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B6=E6=97=8F=E6=8E=92=E8=A1=8C=E6=A6=9C?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/family/FamilyLeaderboardExe.java | 207 +++++++----------- .../family/FamilyLeaderboardCO.java | 32 +-- .../family/FamilyMemberWeekRankCO.java | 44 ++++ 3 files changed, 128 insertions(+), 155 deletions(-) create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberWeekRankCO.java diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLeaderboardExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLeaderboardExe.java index 56aa22bc..8a34fc0e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLeaderboardExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLeaderboardExe.java @@ -1,169 +1,110 @@ package com.red.circle.other.app.command.family; -import com.google.common.collect.Sets; +import com.google.common.collect.Lists; import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.framework.core.dto.AppCommand; -import com.red.circle.other.app.dto.clientobject.family.FamilyExpCO; import com.red.circle.other.app.dto.clientobject.family.FamilyLeaderboardCO; -import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; -import com.red.circle.other.infra.common.family.FamilyCommon; -import com.red.circle.other.infra.database.rds.entity.family.FamilyBaseInfo; +import com.red.circle.other.app.dto.clientobject.family.FamilyMemberWeekRankCO; +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.FamilyMonthExp; -import com.red.circle.other.infra.database.rds.entity.family.FamilyWeekExp; -import com.red.circle.other.infra.database.rds.service.family.FamilyBaseInfoService; +import com.red.circle.other.infra.database.rds.entity.family.FamilyMemberWeekExp; import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService; -import com.red.circle.other.infra.database.rds.service.family.FamilyMonthExpService; -import com.red.circle.other.infra.database.rds.service.family.FamilyWeekExpService; -import com.red.circle.other.infra.enums.family.FamilyStatusEnum; -import com.red.circle.other.inner.model.dto.famliy.FamilyDetailsDTO; +import com.red.circle.other.infra.database.rds.service.family.FamilyMemberWeekExpService; +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.Optional; import java.util.Set; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; /** - *

- * 家族排行榜 周榜、月榜、自己家族信息. - *

- * - * @author pengshigang - * @since 2021-07-24 + * 家族成员周排行榜 */ +@Slf4j @Component @RequiredArgsConstructor public class FamilyLeaderboardExe { - private final FamilyCommon familyCommon; - private final UserRegionGateway userRegionGateway; - private final FamilyWeekExpService familyWeekExpService; - private final FamilyMonthExpService familyMonthExpService; - private final FamilyBaseInfoService familyBaseInfoService; + private final TeamMemberService teamMemberService; + private final UserProfileGateway userProfileGateway; private final FamilyMemberInfoService familyMemberInfoService; + private final FamilyMemberWeekExpService familyMemberWeekExpService; public FamilyLeaderboardCO execute(AppExtCommand cmd) { - - FamilyLeaderboardCO resultCO = new FamilyLeaderboardCO(); - - List weeks = getFamilyWeekExps(cmd); - List months = getFamilyMonthExps(cmd); - Map baseInfoMap = getBaseInfoMap(weeks, months); - - resultCO.setWeekDataList(listWeekCO(cmd, weeks, baseInfoMap)); -// resultCO.setMonthDataList(listMonthCO(cmd, months, baseInfoMap)); - - FamilyMemberInfo member = getMemberByUserId(cmd); + FamilyMemberInfo member = familyMemberInfoService.getFamilyMemberByUserId(cmd.getReqUserId()); if (Objects.isNull(member)) { - return resultCO; + return new FamilyLeaderboardCO(); } - FamilyBaseInfo baseInfo = getFamilyBaseInfo(member); - if (isNormal(baseInfo)) { - return resultCO; + + List top200Exp = getTop200WeekExp(member.getFamilyId()); + if (CollectionUtils.isEmpty(top200Exp)) { + return new FamilyLeaderboardCO(); } -// resultCO.setWeekData(getExpCO(cmd, baseInfo, Optional.ofNullable(getFamilyWeekExp(baseInfo)).map(FamilyWeekExp::getExp).orElse(0L))); -// resultCO.setMonthData(getExpCO(cmd, baseInfo, Optional.ofNullable(getFamilyMonthExp(baseInfo)).map(FamilyMonthExp::getExp).orElse(0L))); - return resultCO; - } - private String getRegionId(AppExtCommand cmd) { - return userRegionGateway.getRegionId(cmd.getReqUserId()); - } - - private FamilyMonthExp getFamilyMonthExp(FamilyBaseInfo baseInfo) { - return familyMonthExpService.getThisMonthByFamilyId(baseInfo.getId()); - } - - private FamilyWeekExp getFamilyWeekExp(FamilyBaseInfo baseInfo) { - return familyWeekExpService.getThisWeekByFamilyId(baseInfo.getId()); - } - - private boolean isNormal(FamilyBaseInfo familyBaseInfo) { - return Objects.isNull(familyBaseInfo) || !Objects.equals(familyBaseInfo.getFamilyStatus(), - FamilyStatusEnum.NORMAL.name()); - } - - private FamilyBaseInfo getFamilyBaseInfo(FamilyMemberInfo member) { - return familyBaseInfoService.getBaseInfoById(member.getFamilyId()); - } - - private FamilyMemberInfo getMemberByUserId(AppExtCommand cmd) { - return familyMemberInfoService.getFamilyMemberByUserId(cmd.getReqUserId()); - } - - private List listWeekCO(AppExtCommand cmd, List data, - Map baseInfoMap) { - - return data.stream() - .map(obj -> getExpCO(cmd, baseInfoMap.get(obj.getFamilyId()), obj.getExp())) - .collect(Collectors.toList()); - } - - private List listMonthCO(AppCommand cmd, List data, - Map baseInfoMap) { - - return data.stream() - .map(obj -> getExpCO(cmd, baseInfoMap.get(obj.getFamilyId()), obj.getExp())) - .collect(Collectors.toList()); - } - - private FamilyDetailsDTO getFamilyLevel(AppCommand cmd, Long familyId) { - return familyCommon.getFamilyDetails(cmd.getReqSysOrigin().getOrigin(), familyId); - } - - private Map getBaseInfoMap(List weeks, - List months) { - return familyBaseInfoService.mapBaseInfo(getFamilyIds(weeks, months)); - } - - private List getFamilyMonthExps(AppExtCommand cmd) { - return familyMonthExpService.listThisMonthBySysOrigin(cmd.requireReqSysOrigin(), - getRegionId(cmd)) - .stream() - .limit(20) - .collect(Collectors.toList()); - } - - private List getFamilyWeekExps(AppExtCommand cmd) { - - return familyWeekExpService.listThisWeekBySysOrigin(cmd.requireReqSysOrigin(), getRegionId(cmd)) - .stream() - .limit(20) - .collect(Collectors.toList()); - } - - private Set getFamilyIds(List weeks, List months) { - Set familyIds = Sets.newHashSet(); - Set weekIds = weeks.stream().map(FamilyWeekExp::getFamilyId).collect(Collectors.toSet()); - if (CollectionUtils.isNotEmpty(weekIds)) { - familyIds.addAll(weekIds); - } - Set monthIds = months.stream().map(FamilyMonthExp::getFamilyId) + Set userIds = top200Exp.stream() + .map(FamilyMemberWeekExp::getFamilyMemberId) .collect(Collectors.toSet()); - if (CollectionUtils.isNotEmpty(monthIds)) { - familyIds.addAll(monthIds); + + Set hostUserIds = getHostUserIds(userIds); + Map userProfileMap = userProfileGateway.mapByUserIds(userIds); + + List hostRank = new ArrayList<>(); + List supporterRank = new ArrayList<>(); + + for (FamilyMemberWeekExp 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 CollectionUtils.isEmpty(familyIds) ? Sets.newHashSet() : familyIds; + + return new FamilyLeaderboardCO() + .setHostWeekRank(hostRank) + .setSupporterWeekRank(supporterRank); } - private FamilyExpCO getExpCO(AppCommand cmd, FamilyBaseInfo baseInfo, Long exp) { - - FamilyDetailsDTO levelCache = getFamilyLevel(cmd, baseInfo.getId()); - - return new FamilyExpCO() - .setExp(NumUtils.formatLong(exp)) - .setFamilyId(baseInfo.getId()) - .setLevelKey(levelCache.getLevelKey()) - .setFamilyName(baseInfo.getFamilyName()) - .setFamilyAvatar(baseInfo.getFamilyAvatar()) - .setFamilyNotice(baseInfo.getFamilyNotice()) - .setAvatarFrameSvg(levelCache.getAvatarFrameSvg()) - .setAvatarFrameCover(levelCache.getAvatarFrameCover()); + private List getTop200WeekExp(Long familyId) { + return familyMemberWeekExpService.query() + .eq(FamilyMemberWeekExp::getFamilyId, familyId) + .orderByDesc(FamilyMemberWeekExp::getExp) + .last("LIMIT 200") + .list(); } + private Set getHostUserIds(Set userIds) { + if (CollectionUtils.isEmpty(userIds)) { + return Set.of(); + } + + List hostIds = teamMemberService.listMemberIds(userIds); + return CollectionUtils.isEmpty(hostIds) ? Set.of() : Set.copyOf(hostIds); + } + + private FamilyMemberWeekRankCO buildRankCO(FamilyMemberWeekExp 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); + } } 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 f8b377c4..ee2b2f04 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 @@ -7,12 +7,7 @@ import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** - *

- * 家族排行榜 周榜、月榜、自己家族信息. - *

- * - * @author pengshigang - * @since 2021-07-24 + * 家族排行榜 */ @Data @EqualsAndHashCode(callSuper = false) @@ -20,22 +15,15 @@ import lombok.experimental.Accessors; public class FamilyLeaderboardCO implements Serializable { private static final long serialVersionUID = 1L; - /** - * 周-自己家族贡献榜单. - */ -// private FamilyExpCO weekData; - /** - * 月-自己家族贡献榜单. - */ -// private FamilyExpCO monthData; - /** - * 周-家族贡献榜单. - */ - private List weekDataList; - /** - * 月-家族贡献榜单. - */ -// private List monthDataList; + /** + * 主播周榜 + */ + private List hostWeekRank; + + /** + * 支持者周榜 + */ + private List supporterWeekRank; } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberWeekRankCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberWeekRankCO.java new file mode 100644 index 00000000..40597d0e --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/family/FamilyMemberWeekRankCO.java @@ -0,0 +1,44 @@ +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 FamilyMemberWeekRankCO 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; + + /** + * 是否是主播 + */ + private Boolean isHost; + +}