|
|
@@ -65,6 +65,9 @@ public class FsUserVideoServiceImpl implements IFsUserVideoService {
|
|
|
|
|
|
@Autowired
|
|
|
private IVodService vodService;
|
|
|
+ private static final String LIKE_KEY_PREFIX = "like:video:";
|
|
|
+ private static final String FAVORITE_KEY_PREFIX = "favorite:video:";
|
|
|
+
|
|
|
/**
|
|
|
* 查询课堂视频
|
|
|
*
|
|
|
@@ -202,18 +205,62 @@ public class FsUserVideoServiceImpl implements IFsUserVideoService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- // 查询点赞、收藏、评论数(仅数据库,便于本地联调线上库)
|
|
|
+ //查询点赞信息和收藏信息
|
|
|
public List<FsUserVideoListUVO> selectLikesAndFavorites(Long userId, List<FsUserVideoListUVO> list) {
|
|
|
if (list != null && !list.isEmpty()) {
|
|
|
List<Long> videoIds = list.stream().map(vo -> Long.parseLong(vo.getId())).collect(Collectors.toList());
|
|
|
- Map<Long, VideoLikeStatusDTO> likeMap = fsUserVideoLikeMapper.checkLikes(videoIds, userId);
|
|
|
- Map<Long, VideoFavoriteStatusDTO> favoriteMap = fsUserVideoFavoriteMapper.checkFavorites(videoIds, userId);
|
|
|
- for (FsUserVideoListUVO vo : list) {
|
|
|
+
|
|
|
+ List<String> likeKeys = videoIds.stream()
|
|
|
+ .map(videoId -> LIKE_KEY_PREFIX + videoId + ":user:" + userId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Boolean> redisLikes = redisTemplate.opsForValue().multiGet(likeKeys);
|
|
|
+
|
|
|
+ List<String> favoriteKeys = videoIds.stream()
|
|
|
+ .map(videoId -> FAVORITE_KEY_PREFIX + videoId + ":user:" + userId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Boolean> redisFavorites = redisTemplate.opsForValue().multiGet(favoriteKeys);
|
|
|
+
|
|
|
+ List<Long> missingLikeVideoIds = new ArrayList<>();
|
|
|
+ List<Long> missingFavoriteVideoIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ FsUserVideoListUVO vo = list.get(i);
|
|
|
Long videoId = Long.parseLong(vo.getId());
|
|
|
- vo.setSmsNum(fsUserVideoCommentMapper.selectCommentCountByVideos(videoId));
|
|
|
- vo.setLike(likeMap.getOrDefault(videoId, new VideoLikeStatusDTO()).getLiked() ? 1 : 0);
|
|
|
- vo.setFavorite(favoriteMap.getOrDefault(videoId, new VideoFavoriteStatusDTO()).getFavorite() ? 1 : 0);
|
|
|
+ Integer commentCount = fsUserVideoCommentMapper.selectCommentCountByVideos(videoId);
|
|
|
+ vo.setSmsNum(commentCount);
|
|
|
+ if (redisLikes != null && redisLikes.get(i) != null) {
|
|
|
+ vo.setLike(Boolean.TRUE.equals(redisLikes.get(i)) ? 1 : 0);
|
|
|
+ } else {
|
|
|
+ missingLikeVideoIds.add(videoId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (redisFavorites != null && redisFavorites.get(i) != null) {
|
|
|
+ vo.setFavorite(Boolean.TRUE.equals(redisFavorites.get(i)) ? 1 : 0);
|
|
|
+ } else {
|
|
|
+ missingFavoriteVideoIds.add(videoId);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ if (!missingLikeVideoIds.isEmpty()) {
|
|
|
+ Map<Long, VideoLikeStatusDTO> likeMap = fsUserVideoLikeMapper.checkLikes(missingLikeVideoIds, userId);
|
|
|
+ for (FsUserVideoListUVO vo : list) {
|
|
|
+ Long videoId = Long.parseLong(vo.getId());
|
|
|
+ if (missingLikeVideoIds.contains(videoId)) {
|
|
|
+ vo.setLike(likeMap.getOrDefault(videoId, new VideoLikeStatusDTO()).getLiked() ? 1 : 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!missingFavoriteVideoIds.isEmpty()) {
|
|
|
+ Map<Long, VideoFavoriteStatusDTO> favoriteMap = fsUserVideoFavoriteMapper.checkFavorites(missingFavoriteVideoIds, userId);
|
|
|
+ for (FsUserVideoListUVO vo : list) {
|
|
|
+ Long videoId = Long.parseLong(vo.getId());
|
|
|
+ if (missingFavoriteVideoIds.contains(videoId)) {
|
|
|
+ vo.setFavorite(favoriteMap.getOrDefault(videoId, new VideoFavoriteStatusDTO()).getFavorite() ? 1 : 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
fillTalentFollowInfo(userId, list);
|
|
|
}
|
|
|
return list;
|