排行榜 fillCurrentUserRank 处理
This commit is contained in:
parent
0302bc1a40
commit
f634276f9f
@ -65,6 +65,7 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
|||||||
|
|
||||||
RankingListCO cachedResult = redisService.getStringToObject(cacheKey, RankingListCO.class);
|
RankingListCO cachedResult = redisService.getStringToObject(cacheKey, RankingListCO.class);
|
||||||
if (cachedResult != null) {
|
if (cachedResult != null) {
|
||||||
|
fillCurrentUserRank(cachedResult, cmd.getReqUserId());
|
||||||
return cachedResult;
|
return cachedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +117,39 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充当前用户排名信息.
|
||||||
|
*/
|
||||||
|
private void fillCurrentUserRank(RankingListCO result, Long currentUserId) {
|
||||||
|
if (result == null || currentUserId == null || CollectionUtils.isEmpty(result.getRankingList())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserProfile userProfile = userProfileGateway.getByUserId(currentUserId);
|
||||||
|
|
||||||
|
result.getRankingList().stream()
|
||||||
|
.filter(record -> Objects.equals(record.getUserId(), currentUserId))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(record -> {
|
||||||
|
UserRankInfoCO userRank = new UserRankInfoCO();
|
||||||
|
userRank.setUserId(record.getUserId());
|
||||||
|
userRank.setRank(record.getRank());
|
||||||
|
userRank.setQuantity(record.getQuantity());
|
||||||
|
userRank.setAccount(userProfile.getAccount());
|
||||||
|
userRank.setNickname(userProfile.getUserNickname());
|
||||||
|
userRank.setAvatar(userProfile.getUserAvatar());
|
||||||
|
result.setCurrentUserRank(userRank);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.getCurrentUserRank() == null) {
|
||||||
|
UserRankInfoCO userRank = new UserRankInfoCO();
|
||||||
|
userRank.setUserId(currentUserId);
|
||||||
|
userRank.setRank(null);
|
||||||
|
userRank.setQuantity("0");
|
||||||
|
result.setCurrentUserRank(userRank);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换RankingListCO为RankingUserVO列表(只取前4个).
|
* 转换RankingListCO为RankingUserVO列表(只取前4个).
|
||||||
*/
|
*/
|
||||||
@ -126,7 +160,7 @@ public class RankingActivityServiceImpl implements RankingActivityService {
|
|||||||
|
|
||||||
List<RankingActivityRecordCO> top4Users = result.getRankingList().stream()
|
List<RankingActivityRecordCO> top4Users = result.getRankingList().stream()
|
||||||
.limit(4)
|
.limit(4)
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
Set<Long> userIds = top4Users.stream()
|
Set<Long> userIds = top4Users.stream()
|
||||||
.map(RankingActivityRecordCO::getUserId)
|
.map(RankingActivityRecordCO::getUserId)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user