Kaynağa Gözat

content-service 添加一个 VideoCategoryPost model, 用于存放每个用户在每个分区发布的最新稿件, 因此 categoryId-userId 组成唯一约束

reghao 1 yıl önce
ebeveyn
işleme
a7056a2e0c

+ 19 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/VideoCategoryPostMapper.java

@@ -0,0 +1,19 @@
+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.VideoCategoryPost;
+import cn.reghao.tnb.content.app.vod.model.query.VideoQuery;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2024-12-07 15:19:16
+ */
+@Mapper
+public interface VideoCategoryPostMapper extends BaseMapper<VideoCategoryPost> {
+    int countByCriteria(VideoQuery videoQuery);
+    List<VideoCategoryPost> findVideoCategoryPostByPage(Page page, VideoQuery videoQuery);
+}

+ 37 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/VideoCategoryPost.java

@@ -0,0 +1,37 @@
+package cn.reghao.tnb.content.app.vod.model.po;
+
+import cn.reghao.jutil.jdk.db.BaseObject;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author reghao
+ * @date 2024-12-07 15:16:57
+ */
+@NoArgsConstructor
+@Setter
+@Getter
+public class VideoCategoryPost extends BaseObject<Integer> {
+    private String videoId;
+    private Integer categoryPid;
+    private Integer categoryId;
+    private int duration;
+    private Boolean horizontal;
+    private int scope;
+    private LocalDateTime publishAt;
+    private Long publishBy;
+
+    public VideoCategoryPost(VideoPost videoPost) {
+        this.videoId = videoPost.getVideoId();
+        this.categoryPid = videoPost.getCategoryPid();
+        this.categoryId = videoPost.getCategoryId();
+        this.duration = videoPost.getDuration();
+        this.horizontal = videoPost.getHorizontal();
+        this.scope = videoPost.getScope();
+        this.publishAt = videoPost.getPublishAt();
+        this.publishBy = videoPost.getPublishBy();
+    }
+}

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

@@ -12,11 +12,13 @@ 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.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.api.dto.BannerVideo;
 import cn.reghao.tnb.content.app.vod.model.vo.VideoDetail;
@@ -49,16 +51,18 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     private final int pageSize = 12;
     private final VideoPostMapper videoPostMapper;
     private final VideoStatisticMapper videoStatisticMapper;
+    private final VideoCategoryPostMapper videoCategoryPostMapper;
     private final VideoTagMapper videoTagMapper;
     private final ContentPermission contentPermission;
     private final CategoryService categoryService;
 
     public VideoPostQueryImpl(VideoPostMapper videoPostMapper, VideoTagMapper videoTagMapper,
-                          VideoStatisticMapper videoStatisticMapper, ContentPermission contentPermission,
-                          CategoryService categoryService) {
+                              VideoStatisticMapper videoStatisticMapper, VideoCategoryPostMapper videoCategoryPostMapper,
+                              ContentPermission contentPermission, CategoryService categoryService) {
         this.videoPostMapper = videoPostMapper;
         this.videoTagMapper = videoTagMapper;
         this.videoStatisticMapper = videoStatisticMapper;
+        this.videoCategoryPostMapper = videoCategoryPostMapper;
         this.contentPermission = contentPermission;
         this.categoryService = categoryService;
     }
@@ -110,17 +114,22 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     }
 
     private PageList<VideoCard> getVideoCardsByUserGroup(VideoQuery videoQuery, int pageNumber) {
-        int total = videoPostMapper.countByCriteriaAndUserGroup(videoQuery).size();
+        // int total = videoPostMapper.countByCriteriaAndUserGroup(videoQuery).size();
+        int total = videoCategoryPostMapper.countByCriteria(videoQuery);
         if (total > pageSize*100) {
             total = pageSize*100;
-
             if (pageNumber > 100) {
                 pageNumber = 100;
             }
+        } else if (total == 0) {
+            return PageList.empty();
         }
 
         Page page = new Page(pageNumber, pageSize);
-        List<VideoPostCard> list = videoPostMapper.findCriteriaAndUserGroupByPage(page, videoQuery);
+        //List<VideoPostCard> list = videoPostMapper.findCriteriaAndUserGroupByPage(page, videoQuery);
+        List<VideoCategoryPost> list0 = videoCategoryPostMapper.findVideoCategoryPostByPage(page, videoQuery);
+        List<String> videoIds = list0.stream().map(VideoCategoryPost::getVideoId).collect(Collectors.toList());
+        List<VideoPostCard> list = videoPostMapper.findVideoCardByVideoIds(videoIds);
         List<VideoCard> list1 = list.stream()
                 .map(videoPostCard -> getVideoCard(videoPostCard, true))
                 .collect(Collectors.toList());

+ 79 - 0
content/content-service/src/main/resources/mapper/vod/VideoPostCategoryMapper.xml

@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryPostMapper">
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        insert into vod_video_category_post
+        (`video_id`,`category_pid`,`category_id`,`scope`,`horizontal`,`duration`,`publish_at`,`publish_by`)
+        values
+        (#{videoId},#{categoryPid},#{categoryId},#{scope},#{horizontal},#{duration},#{publishAt},#{publishBy})
+    </insert>
+    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
+        insert into vod_video_category_post
+        (`video_id`,`category_pid`,`category_id`,`scope`,`horizontal`,`duration`,`publish_at`,`publish_by`)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.videoId},#{item.categoryPid},#{item.categoryId},#{item.scope},#{item.horizontal},#{item.duration},#{item.publishAt},#{item.publishBy})
+        </foreach>
+    </insert>
+
+    <update id="updateVideoScope">
+        update vod_video_category_post
+        set update_time=now(),scope=#{scope}
+        where video_id=#{videoId}
+    </update>
+
+    <delete id="deleteByVideoId">
+        delete from vod_video_category_post
+        where video_id=#{videoId}
+    </delete>
+
+    <select id="countByCriteria" resultType="java.lang.Integer">
+        select count(*)
+        from vod_video_category_post
+        <where>
+            deleted=0
+            <if test="scope != null">
+                and scope in
+                <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
+                    #{id}
+                </foreach>
+            </if>
+            <if test="categoryPid != null">
+                and category_pid=#{categoryPid}
+            </if>
+            <if test="categoryId != null">
+                and category_id=#{categoryId}
+            </if>
+            <if test="userId != null">
+                and publish_by=#{userId}
+            </if>
+            <if test="horizontal != null">
+                and horizontal=#{horizontal}
+            </if>
+        </where>
+    </select>
+    <select id="findVideoCategoryPostByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategoryPost">
+        select *
+        from vod_video_category_post post
+        <where>
+            deleted=0
+            <if test="videoQuery.scope != null">
+                and post.scope in
+                <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
+                    #{id}
+                </foreach>
+            </if>
+            <if test="videoQuery.categoryPid != null">
+                and post.category_pid=#{videoQuery.categoryPid}
+            </if>
+            <if test="videoQuery.categoryId != null">
+                and post.category_id=#{videoQuery.categoryId}
+            </if>
+            <if test="videoQuery.horizontal != null">
+                and post.horizontal=#{videoQuery.horizontal}
+            </if>
+        </where>
+        order by post.publish_at desc
+    </select>
+</mapper>