|
|
@@ -65,9 +65,6 @@ 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:";
|
|
|
-
|
|
|
/**
|
|
|
* 查询课堂视频
|
|
|
*
|
|
|
@@ -205,69 +202,18 @@ 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());
|
|
|
-
|
|
|
- // 批量查询Redis中的点赞信息
|
|
|
- List<String> likeKeys = videoIds.stream()
|
|
|
- .map(videoId -> LIKE_KEY_PREFIX + videoId + ":user:" + userId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<Boolean> redisLikes = redisTemplate.opsForValue().multiGet(likeKeys);
|
|
|
-
|
|
|
- // 批量查询Redis中的收藏信息
|
|
|
- List<String> favoriteKeys = videoIds.stream()
|
|
|
- .map(videoId -> FAVORITE_KEY_PREFIX + videoId + ":user:" + userId)
|
|
|
- .collect(Collectors.toList());
|
|
|
- List<Boolean> redisFavorites = redisTemplate.opsForValue().multiGet(favoriteKeys);
|
|
|
-
|
|
|
- // 缓存未命中的视频ID列表
|
|
|
- List<Long> missingLikeVideoIds = new ArrayList<>();
|
|
|
- List<Long> missingFavoriteVideoIds = new ArrayList<>();
|
|
|
-
|
|
|
- // 设置点赞和收藏信息
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- FsUserVideoListUVO vo = list.get(i);
|
|
|
+ Map<Long, VideoLikeStatusDTO> likeMap = fsUserVideoLikeMapper.checkLikes(videoIds, userId);
|
|
|
+ Map<Long, VideoFavoriteStatusDTO> favoriteMap = fsUserVideoFavoriteMapper.checkFavorites(videoIds, userId);
|
|
|
+ for (FsUserVideoListUVO vo : list) {
|
|
|
Long videoId = Long.parseLong(vo.getId());
|
|
|
- Integer commentCount = fsUserVideoCommentMapper.selectCommentCountByVideos(videoId);
|
|
|
- vo.setSmsNum(commentCount);
|
|
|
- // 优先使用Redis中的点赞数据
|
|
|
- if (redisLikes != null && redisLikes.get(i) != null) {
|
|
|
- vo.setLike(Boolean.TRUE.equals(redisLikes.get(i)) ? 1 : 0);
|
|
|
- } else {
|
|
|
- missingLikeVideoIds.add(videoId);
|
|
|
- }
|
|
|
-
|
|
|
- // 优先使用Redis中的收藏数据
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
+ 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);
|
|
|
}
|
|
|
-
|
|
|
fillTalentFollowInfo(userId, list);
|
|
|
}
|
|
|
return list;
|
|
|
@@ -416,16 +362,9 @@ public class FsUserVideoServiceImpl implements IFsUserVideoService {
|
|
|
@Override
|
|
|
public List<FsUserVideoListUVO> selectFsUserVideoListUVOByUser(Long talentId, boolean oneSelf, Long userId) {
|
|
|
List<FsUserVideoListUVO> list = fsUserVideoMapper.selectFsUserVideoListUVOByUser(talentId, oneSelf);
|
|
|
- /*if (param != null && param.getUserId() != null) {
|
|
|
- Long userId = param.getUserId();
|
|
|
+ if (userId != null && !list.isEmpty()) {
|
|
|
list = selectLikesAndFavorites(userId, list);
|
|
|
- }*/
|
|
|
- // 当前视频是否被自己喜欢或收藏
|
|
|
- if (list.size() > 0) {
|
|
|
- selectLikesAndFavoritesByMyself(list,userId);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
@@ -466,23 +405,6 @@ public class FsUserVideoServiceImpl implements IFsUserVideoService {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
- private void selectLikesAndFavoritesByMyself(List<FsUserVideoListUVO> list, long userId) {
|
|
|
- List<Long> videoIds = list.stream().map(vo -> Long.parseLong(vo.getId())).collect(Collectors.toList());
|
|
|
- Map<Long, VideoLikeStatusDTO> likeMaps = fsUserVideoLikeMapper.checkLikes(videoIds, userId);
|
|
|
- Map<Long, VideoFavoriteStatusDTO> FavoriteMaps = fsUserVideoFavoriteMapper.checkFavorites(videoIds, userId);
|
|
|
- long videoId;
|
|
|
- for (FsUserVideoListUVO entity : list) {
|
|
|
- videoId = Long.parseLong(entity.getId());
|
|
|
- if (likeMaps.containsKey(videoId)) {
|
|
|
- entity.setLike(1);
|
|
|
- }
|
|
|
- if (FavoriteMaps.containsKey(videoId)) {
|
|
|
- entity.setFavorite(1);
|
|
|
- }
|
|
|
- }
|
|
|
- fillTalentFollowInfo(userId, list);
|
|
|
- }
|
|
|
-
|
|
|
public static String updateUrlPrefix(String url) {
|
|
|
final String oldPrefix = "https://obs.ylrztop.com";
|
|
|
final String newPrefix = "https://rtobs.ylrztop.com";
|