cp榜单我的cp处理

This commit is contained in:
tianfeng 2026-01-22 11:43:28 +08:00
parent bf65d36868
commit acf72c9b0f
2 changed files with 21 additions and 11 deletions

View File

@ -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<Long> collect = Stream.of(reqUserId, cpUserId).filter(Objects::nonNull).collect(Collectors.toSet());
Map<Long, UserProfileDTO> 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<ActivityCpUserRankingCO> topList) {
List<Long> 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;

View File

@ -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<Long> 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();
}