From cbf67d93b3de58fb2122c1f4fc1544479aebcb2c Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 6 Nov 2025 15:19:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=AF=E8=AE=A1=E6=8E=92=E8=A1=8C=E6=A6=9C?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RankingActivityRestController.java | 13 ----- .../activity/query/RankingListQryExe.java | 56 +++++++++++++------ .../activity/RankingActivityRecordCO.java | 2 + .../clientobject/activity/UserRankInfoCO.java | 13 +++++ .../dto/cmd/activity/RankingListQueryCmd.java | 3 +- 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/RankingActivityRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/RankingActivityRestController.java index 11817ed4..ea19853f 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/RankingActivityRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/activity/RankingActivityRestController.java @@ -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); - } } \ No newline at end of file diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java index 1d0cedf0..3c72a946 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/RankingListQryExe.java @@ -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 records = rankingActivityGateway.getRankingList( cmd.getReqSysOrigin().getOrigin(), activityType, - cycleType, - cmd.getCycleKey(), - cmd.getUserSex(), + cycleType, + ZonedDateTimeAsiaRiyadhUtils.nowWeekMondayToInt().toString(), + null, cmd.getTopN() ); - // 转换为CO并设置排名 + Map userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( + userProfileGateway + .mapByUserIds(getUserIds(records))); + + // 转换为CO并设置排名 List 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 getUserIds(List weekStarGiftCounts) { + + return weekStarGiftCounts.stream().map(RankingActivityRecord::getUserId) + .collect(Collectors.toSet()); + } + /** * 查询当前用户排名 */ diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/RankingActivityRecordCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/RankingActivityRecordCO.java index 2a5758c8..30164b4e 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/RankingActivityRecordCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/RankingActivityRecordCO.java @@ -20,6 +20,8 @@ public class RankingActivityRecordCO implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long userId; + private String account; + /** * 用户昵称 */ diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserRankInfoCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserRankInfoCO.java index eab638e8..dbb2be71 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserRankInfoCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/activity/UserRankInfoCO.java @@ -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; + /** * 当前排名 * diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/RankingListQueryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/RankingListQueryCmd.java index 820d0b97..75eebb8c 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/RankingListQueryCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/RankingListQueryCmd.java @@ -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; /** * 是否包含当前用户排名