家族排行榜接口修改
This commit is contained in:
parent
944752c1a9
commit
242dc047be
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 家族排行榜 周榜、月榜、自己家族信息.
|
||||
* </p>
|
||||
*
|
||||
* @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<FamilyWeekExp> weeks = getFamilyWeekExps(cmd);
|
||||
List<FamilyMonthExp> months = getFamilyMonthExps(cmd);
|
||||
Map<Long, FamilyBaseInfo> 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<FamilyMemberWeekExp> 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<FamilyExpCO> listWeekCO(AppExtCommand cmd, List<FamilyWeekExp> data,
|
||||
Map<Long, FamilyBaseInfo> baseInfoMap) {
|
||||
|
||||
return data.stream()
|
||||
.map(obj -> getExpCO(cmd, baseInfoMap.get(obj.getFamilyId()), obj.getExp()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<FamilyExpCO> listMonthCO(AppCommand cmd, List<FamilyMonthExp> data,
|
||||
Map<Long, FamilyBaseInfo> 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<Long, FamilyBaseInfo> getBaseInfoMap(List<FamilyWeekExp> weeks,
|
||||
List<FamilyMonthExp> months) {
|
||||
return familyBaseInfoService.mapBaseInfo(getFamilyIds(weeks, months));
|
||||
}
|
||||
|
||||
private List<FamilyMonthExp> getFamilyMonthExps(AppExtCommand cmd) {
|
||||
return familyMonthExpService.listThisMonthBySysOrigin(cmd.requireReqSysOrigin(),
|
||||
getRegionId(cmd))
|
||||
.stream()
|
||||
.limit(20)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<FamilyWeekExp> getFamilyWeekExps(AppExtCommand cmd) {
|
||||
|
||||
return familyWeekExpService.listThisWeekBySysOrigin(cmd.requireReqSysOrigin(), getRegionId(cmd))
|
||||
.stream()
|
||||
.limit(20)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Set<Long> getFamilyIds(List<FamilyWeekExp> weeks, List<FamilyMonthExp> months) {
|
||||
Set<Long> familyIds = Sets.newHashSet();
|
||||
Set<Long> weekIds = weeks.stream().map(FamilyWeekExp::getFamilyId).collect(Collectors.toSet());
|
||||
if (CollectionUtils.isNotEmpty(weekIds)) {
|
||||
familyIds.addAll(weekIds);
|
||||
}
|
||||
Set<Long> monthIds = months.stream().map(FamilyMonthExp::getFamilyId)
|
||||
Set<Long> userIds = top200Exp.stream()
|
||||
.map(FamilyMemberWeekExp::getFamilyMemberId)
|
||||
.collect(Collectors.toSet());
|
||||
if (CollectionUtils.isNotEmpty(monthIds)) {
|
||||
familyIds.addAll(monthIds);
|
||||
|
||||
Set<Long> hostUserIds = getHostUserIds(userIds);
|
||||
Map<Long, UserProfile> userProfileMap = userProfileGateway.mapByUserIds(userIds);
|
||||
|
||||
List<FamilyMemberWeekRankCO> hostRank = new ArrayList<>();
|
||||
List<FamilyMemberWeekRankCO> 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<FamilyMemberWeekExp> getTop200WeekExp(Long familyId) {
|
||||
return familyMemberWeekExpService.query()
|
||||
.eq(FamilyMemberWeekExp::getFamilyId, familyId)
|
||||
.orderByDesc(FamilyMemberWeekExp::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(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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,12 +7,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 家族排行榜 周榜、月榜、自己家族信息.
|
||||
* </p>
|
||||
*
|
||||
* @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<FamilyExpCO> weekDataList;
|
||||
/**
|
||||
* 月-家族贡献榜单.
|
||||
*/
|
||||
// private List<FamilyExpCO> monthDataList;
|
||||
|
||||
/**
|
||||
* 主播周榜
|
||||
*/
|
||||
private List<FamilyMemberWeekRankCO> hostWeekRank;
|
||||
|
||||
/**
|
||||
* 支持者周榜
|
||||
*/
|
||||
private List<FamilyMemberWeekRankCO> supporterWeekRank;
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user