历史top1 数据结构更改

This commit is contained in:
tianfeng 2025-09-12 19:01:08 +08:00
parent 68d6dfe882
commit 7ef5f600e8
2 changed files with 49 additions and 14 deletions

View File

@ -5,19 +5,20 @@ import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.activity.UserCharmWealthContributeCO;
import com.red.circle.other.app.dto.clientobject.activity.UserRankCO;
import com.red.circle.other.app.dto.clientobject.activity.WeekKingQueenGroupVO;
import com.red.circle.other.app.dto.clientobject.activity.WeekKingQueenHistoryVO;
import com.red.circle.other.app.dto.clientobject.sys.ActivityConfigVO;
import com.red.circle.other.app.dto.cmd.activity.WeekKingQueenRankingQueryCmd;
import com.red.circle.other.app.service.activity.WeekKingQueenService;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
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.activity.WeekKingQueenCount;
import com.red.circle.other.infra.database.mongo.service.activity.WeekKingQueenCountService;
import com.red.circle.other.inner.enums.activity.KingQueenType;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
@ -60,24 +61,48 @@ public class WeekKingQueenController extends BaseController {
* 历史top1
*/
@GetMapping("/history")
public List<WeekKingQueenHistoryVO> history(AppExtCommand cmd) {
public List<WeekKingQueenGroupVO> history(AppExtCommand cmd) {
List<WeekKingQueenCount> top1List = weekKingQueenCountService.listLastThreeMonthsTop1(cmd.getReqSysOrigin().getOrigin());
Set<Long> userIds = top1List.stream().map(WeekKingQueenCount::getUserId).collect(Collectors.toSet());
Map<Long, UserProfile> profileMap = userProfileGateway.mapByUserIds(userIds);
return top1List.stream().map(e -> {
WeekKingQueenHistoryVO weekKingQueenHistoryVO = new WeekKingQueenHistoryVO();
BeanUtils.copyProperties(e, weekKingQueenHistoryVO);
// 先按 group 分组
Map<String, List<WeekKingQueenCount>> groupMap = top1List.stream()
.collect(Collectors.groupingBy(WeekKingQueenCount::getGroup));
UserProfile userProfile = profileMap.get(e.getUserId());
if (userProfile != null) {
weekKingQueenHistoryVO.setAccount(userProfile.getAccount());
weekKingQueenHistoryVO.setUserAvatar(userProfile.getUserAvatar());
weekKingQueenHistoryVO.setUserNickname(userProfile.getUserNickname());
// 转成最终返回的结构
List<WeekKingQueenGroupVO> result = new ArrayList<>();
for (Map.Entry<String, List<WeekKingQueenCount>> entry : groupMap.entrySet()) {
WeekKingQueenGroupVO vo = new WeekKingQueenGroupVO();
vo.setGroup(entry.getKey());
// 遍历同一周的数据 WEALTH / CHARM 分开
for (WeekKingQueenCount e : entry.getValue()) {
WeekKingQueenHistoryVO historyVO = new WeekKingQueenHistoryVO();
BeanUtils.copyProperties(e, historyVO);
UserProfile userProfile = profileMap.get(e.getUserId());
if (userProfile != null) {
historyVO.setAccount(userProfile.getAccount());
historyVO.setUserAvatar(userProfile.getUserAvatar());
historyVO.setUserNickname(userProfile.getUserNickname());
}
if (e.getType() == KingQueenType.WEALTH) {
vo.setWealth(historyVO);
} else if (e.getType() == KingQueenType.CHARM) {
vo.setCharm(historyVO);
}
}
return weekKingQueenHistoryVO;
}).collect(Collectors.toList());
result.add(vo);
}
// group 排序可选
result.sort(Comparator.comparing(WeekKingQueenGroupVO::getGroup).reversed());
return result;
}
/**

View File

@ -0,0 +1,10 @@
package com.red.circle.other.app.dto.clientobject.activity;
import lombok.Data;
@Data
public class WeekKingQueenGroupVO {
private String group; //
private WeekKingQueenHistoryVO wealth; // 财富榜 top1
private WeekKingQueenHistoryVO charm; // 魅力榜 top1
}