Browse Source

VideoQueryController 添加 getTagVideos 获取拥有某个标签的视频列表接口

reghao 11 months ago
parent
commit
878f685aa7

+ 7 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/VideoQueryController.java

@@ -65,6 +65,13 @@ public class VideoQueryController {
         return WebResult.success(pageList);
     }
 
+    @ApiOperation(value = "获取某个标签下的视频", notes = "N")
+    @GetMapping(value = "/tag", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getTagVideos(@RequestParam("tag") String tag, @RequestParam("page") int page) {
+        PageList<VideoCard> pageList = videoPostQuery.getTagVideos(tag, page);
+        return WebResult.success(pageList);
+    }
+
     @ApiOperation(value = "获取视频详情", notes = "N")
     @GetMapping(value = "/detail/{videoId}", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getVideoPost(@PathVariable("videoId") String videoId) {

+ 3 - 4
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/VideoPostTagMapper.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.content.app.vod.db.mapper;
 
 import cn.reghao.jutil.jdk.db.BaseMapper;
+import cn.reghao.jutil.jdk.db.Page;
 import cn.reghao.tnb.content.app.vod.model.po.VideoPostTag;
 import cn.reghao.tnb.common.db.GroupCount;
 import org.apache.ibatis.annotations.Mapper;
@@ -13,8 +14,6 @@ import java.util.List;
  */
 @Mapper
 public interface VideoPostTagMapper extends BaseMapper<VideoPostTag> {
-    void deleteByTagId(String tagId);
-
-    List<String> findByTagId(String tagId);
-    List<GroupCount> findByGroupBy();
+    int countVideosByTag(String tagId);
+    List<String> findVideosByPage(Page page, String tagId);
 }

+ 1 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/VideoPostQuery.java

@@ -21,6 +21,7 @@ public interface VideoPostQuery {
     VideoCard getVideoCard(VideoPostCard videoPostCard, boolean user);
     String getVideoPostData(String videoId);
     UserVideoPost getUserVideoPost(VideoPost videoPost);
+    PageList<VideoCard> getTagVideos(String tag, int pn);
     List<BannerVideo> getBannerVideos(List<String> videoIds);
     List<String> getRandomTags(int size);
     List<String> getRandomVideoIds(List<Integer> userScopes, int size);

+ 26 - 10
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/VideoPostQueryImpl.java

@@ -13,15 +13,9 @@ import cn.reghao.tnb.content.api.constant.VideoStatus;
 import cn.reghao.tnb.content.api.dto.UserVideoPost;
 import cn.reghao.tnb.content.api.dto.VideoCard;
 import cn.reghao.tnb.content.api.dto.VideoPostCard;
-import cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryPostMapper;
-import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
-import cn.reghao.tnb.content.app.vod.db.mapper.VideoStatisticMapper;
-import cn.reghao.tnb.content.app.vod.db.mapper.VideoTagMapper;
+import cn.reghao.tnb.content.app.vod.db.mapper.*;
 import cn.reghao.tnb.content.app.vod.db.repository.VideoRepository;
-import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
-import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
-import cn.reghao.tnb.content.app.vod.model.po.VideoCategoryPost;
-import cn.reghao.tnb.content.app.vod.model.po.VideoStatistic;
+import cn.reghao.tnb.content.app.vod.model.po.*;
 import cn.reghao.tnb.content.api.dto.BannerVideo;
 import cn.reghao.tnb.content.app.vod.model.vo.VideoDetail;
 import cn.reghao.tnb.content.app.vod.model.query.VideoQuery;
@@ -57,15 +51,17 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     private final VideoStatisticMapper videoStatisticMapper;
     private final VideoCategoryPostMapper videoCategoryPostMapper;
     private final VideoTagMapper videoTagMapper;
+    private final VideoPostTagMapper videoPostTagMapper;
     private final ContentPermission contentPermission;
     private final CategoryService categoryService;
     private final VideoRepository videoRepository;
     private final Random random = new SecureRandom();
-    private IDObfuscation userIdObfuscation;
+    private final IDObfuscation userIdObfuscation;
 
     public VideoPostQueryImpl(VideoPostMapper videoPostMapper, VideoTagMapper videoTagMapper,
                               VideoStatisticMapper videoStatisticMapper, VideoCategoryPostMapper videoCategoryPostMapper,
-                              ContentPermission contentPermission, CategoryService categoryService, VideoRepository videoRepository) {
+                              ContentPermission contentPermission, CategoryService categoryService,
+                              VideoRepository videoRepository, VideoPostTagMapper videoPostTagMapper) {
         this.videoPostMapper = videoPostMapper;
         this.videoTagMapper = videoTagMapper;
         this.videoStatisticMapper = videoStatisticMapper;
@@ -74,6 +70,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
         this.categoryService = categoryService;
         this.videoRepository = videoRepository;
         this.userIdObfuscation = new IDObfuscation(0x12345);
+        this.videoPostTagMapper = videoPostTagMapper;
     }
 
     public List<VideoCard> getVideoCards(List<String> videoIds) {
@@ -166,6 +163,25 @@ public class VideoPostQueryImpl implements VideoPostQuery {
         return PageList.pageList(pageNumber, pageSize, total, list1);
     }
 
+    @Override
+    public PageList<VideoCard> getTagVideos(String tag, int pn) {
+        VideoTag videoTag = videoTagMapper.findByName(tag);
+        if (videoTag == null) {
+            return PageList.empty();
+        }
+
+        String tagId = videoTag.getTagId();
+        int total = videoPostTagMapper.countVideosByTag(tagId);
+        Page page = new Page(pn, pageSize);
+        List<String> videoIds = videoPostTagMapper.findVideosByPage(page, tagId);
+        List<VideoPostCard> list = videoPostMapper.findVideoCardByVideoIds(videoIds);
+        List<VideoCard> list1 = list.stream()
+                .map(videoPostCard -> getVideoCard(videoPostCard, true))
+                .collect(Collectors.toList());
+
+        return PageList.pageList(pn, pageSize, total, list1);
+    }
+
     public PageList<VideoCard> getUserVideos(long userId, int page) {
         VideoQuery videoQuery;
         long loginUser = UserContext.getUser();

+ 8 - 11
content/content-service/src/main/resources/mapper/vod/VideoPostTagMapper.xml

@@ -17,22 +17,19 @@
         </foreach>
     </insert>
 
-    <delete id="deleteByTagId">
-        delete from vod_video_tags
-        where tag_id=#{tagId}
-    </delete>
-
     <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPostTag">
-        select * from vod_video_tags
+        select *
+        from vod_video_tags
+        limit 1000
     </select>
-    <select id="findByTagId" resultType="java.lang.String">
-        select video_id
+    <select id="countVideosByTag" resultType="java.lang.Integer">
+        select count(*)
         from vod_video_tags
         where tag_id=#{tagId}
     </select>
-    <select id="findByGroupBy" resultType="cn.reghao.tnb.common.db.GroupCount">
-        select tag_id as id, count(*) as total
+    <select id="findVideosByPage" resultType="java.lang.String">
+        select video_id
         from vod_video_tags
-        group by tag_id
+        where tag_id=#{tagId}
     </select>
 </mapper>