累计排行榜活动处理

This commit is contained in:
tianfeng 2025-11-06 15:19:33 +08:00
parent 34d7532f04
commit cbf67d93b3
5 changed files with 56 additions and 31 deletions

View File

@ -48,17 +48,4 @@ public class RankingActivityRestController extends BaseController {
public RankingListCO getRankingList(@RequestBody @Validated RankingListQueryCmd cmd) {
return rankingActivityService.getRankingList(cmd);
}
/**
* 查询用户排名
*
* 用途查询指定用户在某活动的排名信息
*
* @param cmd 查询命令
* @return 用户排名信息
*/
@PostMapping("/my-rank")
public UserRankInfoCO getUserRank(@RequestBody @Validated UserRankQueryCmd cmd) {
return rankingActivityService.getUserRank(cmd);
}
}

View File

@ -1,15 +1,21 @@
package com.red.circle.other.app.command.activity.query;
import com.red.circle.other.app.convertor.user.RankingActivityConvertor;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.app.dto.clientobject.activity.RankingActivityRecordCO;
import com.red.circle.other.app.dto.clientobject.activity.RankingListCO;
import com.red.circle.other.app.dto.clientobject.activity.UserRankInfoCO;
import com.red.circle.other.app.dto.cmd.activity.RankingListQueryCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.domain.ranking.RankingActivityType;
import com.red.circle.other.domain.ranking.RankingCycleType;
import com.red.circle.other.domain.ranking.RankingDimension;
import com.red.circle.other.infra.database.mongo.entity.activity.RankingActivityRecord;
import com.red.circle.other.infra.database.mongo.entity.activity.WeekKingQueenCount;
import com.red.circle.other.infra.gateway.RankingActivityGateway;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -17,7 +23,9 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ -31,28 +39,41 @@ public class RankingListQryExe {
private final RankingActivityGateway rankingActivityGateway;
private final RankingActivityConvertor convertor;
private final UserProfileGateway userProfileGateway;
private final UserProfileAppConvertor userProfileAppConvertor;
public RankingListCO execute(RankingListQueryCmd cmd) {
// 获取枚举
RankingActivityType activityType = RankingActivityType.getByCode(cmd.getActivityType());
RankingCycleType cycleType = RankingCycleType.getByCode(cmd.getCycleType());
RankingCycleType cycleType = RankingCycleType.WEEKLY;
// 查询排行榜列表
// 查询排行榜列表
List<RankingActivityRecord> records = rankingActivityGateway.getRankingList(
cmd.getReqSysOrigin().getOrigin(),
activityType,
cycleType,
cmd.getCycleKey(),
cmd.getUserSex(),
cycleType,
ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString(),
null,
cmd.getTopN()
);
// 转换为CO并设置排名
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
userProfileGateway
.mapByUserIds(getUserIds(records)));
// 转换为CO并设置排名
List<RankingActivityRecordCO> rankingList = IntStream.range(0, records.size())
.mapToObj(i -> {
RankingActivityRecord record = records.get(i);
RankingActivityRecordCO co = convertor.toRecordCO(record);
co.setRank(i + 1); // 排名从1开始
UserProfileDTO userProfileDTO = userProfileMap.get(record.getUserId());
if (userProfileDTO != null) {
co.setAccount(userProfileDTO.getAccount());
co.setNickname(userProfileDTO.getUserNickname());
co.setAvatar(userProfileDTO.getUserAvatar());
}
return co;
})
.collect(Collectors.toList());
@ -61,16 +82,14 @@ public class RankingListQryExe {
UserRankInfoCO currentUserRank = null;
if (cmd.getIncludeCurrentUser() && cmd.getReqUserId() != null) {
currentUserRank = queryCurrentUserRank(cmd, activityType, cycleType);
}
UserProfile userProfile = userProfileGateway.getByUserId(cmd.getReqUserId());
if (userProfile != null) {
currentUserRank.setAccount(userProfile.getAccount());
currentUserRank.setNickname(userProfile.getUserNickname());
currentUserRank.setAvatar(userProfile.getUserAvatar());
}
// 统计参与总人数
// Long totalParticipants = rankingActivityGateway.countTotalParticipants(
// cmd.getReqSysOrigin().getOrigin(),
// activityType,
// cycleType,
// cmd.getCycleKey(),
// cmd.getUserSex()
// );
}
// 构建返回结果
RankingListCO result = new RankingListCO();
@ -93,12 +112,17 @@ public class RankingListQryExe {
result.setRankingList(rankingList);
result.setCurrentUserRank(currentUserRank);
// result.setTotalParticipants(totalParticipants);
result.setUpdateTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
return result;
}
private Set<Long> getUserIds(List<RankingActivityRecord> weekStarGiftCounts) {
return weekStarGiftCounts.stream().map(RankingActivityRecord::getUserId)
.collect(Collectors.toSet());
}
/**
* 查询当前用户排名
*/

View File

@ -20,6 +20,8 @@ public class RankingActivityRecordCO implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long userId;
private String account;
/**
* 用户昵称
*/

View File

@ -21,6 +21,19 @@ public class UserRankInfoCO implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long userId;
private String account;
/**
* 用户昵称
*/
private String nickname;
/**
* 用户头像
*/
private String avatar;
/**
* 当前排名
*

View File

@ -27,7 +27,6 @@ public class RankingListQueryCmd extends AppExtCommand {
*
* RankingCycleType
*/
@NotNull(message = "周期类型不能为空")
private Integer cycleType;
/**
@ -52,7 +51,7 @@ public class RankingListQueryCmd extends AppExtCommand {
*/
@Min(value = 1, message = "查询数量最小为1")
@Max(value = 100, message = "查询数量最大为100")
private Integer topN = 50;
private Integer topN = 100;
/**
* 是否包含当前用户排名