diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java index 43955b9d..f24e509a 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java @@ -22,6 +22,8 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.stream.Stream; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -66,16 +68,26 @@ public class WeekCpUserGiftQueryExe { .setThisUser(currentUser); } - private ActivityCpUserRankingCO queryCurrentUserCO(Long reqUserId) { + private ActivityCpUserRankingCO queryCurrentUserCO(Long reqUserId, Long cpUserId) { + Set collect = Stream.of(reqUserId, cpUserId).filter(Objects::nonNull).collect(Collectors.toSet()); Map userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( - userProfileGateway.mapByUserIds(Set.of(reqUserId))); + userProfileGateway.mapByUserIds(collect)); ActivityCpUserRankingCO rankingCO = new ActivityCpUserRankingCO(); UserProfileDTO userProfileDTO = userProfileMap.get(reqUserId); if (userProfileDTO != null) { + rankingCO.setUserId(userProfileDTO.getId()); rankingCO.setUserAvatar(userProfileDTO.getUserAvatar()); rankingCO.setUserNickname(userProfileDTO.getUserNickname()); rankingCO.setUserSex(userProfileDTO.getUserSex()); } + + UserProfileDTO cpUserProfileDTO = userProfileMap.get(cpUserId); + if (cpUserProfileDTO != null) { + rankingCO.setCpUserId(cpUserProfileDTO.getId()); + rankingCO.setCpUserAvatar(cpUserProfileDTO.getUserAvatar()); + rankingCO.setCpUserNickname(cpUserProfileDTO.getUserNickname()); + rankingCO.setCpUserSex(cpUserProfileDTO.getUserSex()); + } rankingCO.setRank(999); rankingCO.setTotalNumber(0L); rankingCO.setTotal("0"); @@ -86,7 +98,7 @@ public class WeekCpUserGiftQueryExe { List topList) { List cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId()); if (cpUserIdList.isEmpty()) { - return queryCurrentUserCO(cmd.getReqUserId()); + return queryCurrentUserCO(cmd.getReqUserId(), null); } ActivityCpUserRankingCO userInTop = new ActivityCpUserRankingCO(); @@ -99,7 +111,7 @@ public class WeekCpUserGiftQueryExe { } if (Objects.isNull(userInTop.getUserId())) { - return queryCurrentUserCO(cmd.getReqUserId()); + return queryCurrentUserCO(cmd.getReqUserId(), cpUserIdList.get(0)); } return userInTop; diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java index 55248994..40a79cbc 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java @@ -12,11 +12,7 @@ import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipS import com.red.circle.other.infra.enums.user.user.CpRelationshipStatus; import java.math.BigDecimal; import java.sql.Timestamp; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; import com.red.circle.tool.core.date.TimestampUtils; import lombok.RequiredArgsConstructor; @@ -74,10 +70,12 @@ public class CpRelationshipServiceImpl extends @Override public List getCpUserId(Long userId) { - return query().select(CpRelationship::getCpUserId) + return query().select(CpRelationship::getCpUserId, TimestampBaseEntity::getCreateTime) .eq(CpRelationship::getUserId, userId) .list() - .stream().map(CpRelationship::getCpUserId) + .stream() + .sorted(Comparator.comparing(CpRelationship::getCreateTime).reversed()) + .map(CpRelationship::getCpUserId) .toList(); }