diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekKingQueenController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekKingQueenController.java index ecf58c03..9bf1177f 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekKingQueenController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/room/WeekKingQueenController.java @@ -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 history(AppExtCommand cmd) { + public List history(AppExtCommand cmd) { List top1List = weekKingQueenCountService.listLastThreeMonthsTop1(cmd.getReqSysOrigin().getOrigin()); Set userIds = top1List.stream().map(WeekKingQueenCount::getUserId).collect(Collectors.toSet()); Map profileMap = userProfileGateway.mapByUserIds(userIds); - return top1List.stream().map(e -> { - WeekKingQueenHistoryVO weekKingQueenHistoryVO = new WeekKingQueenHistoryVO(); - BeanUtils.copyProperties(e, weekKingQueenHistoryVO); + // 先按 group 分组 + Map> 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 result = new ArrayList<>(); + for (Map.Entry> 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; } /** diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/WeekKingQueenGroupVO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/WeekKingQueenGroupVO.java new file mode 100644 index 00000000..60295415 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/WeekKingQueenGroupVO.java @@ -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 +}