Преглед изворни кода

VideoPostTag 添加一个 scope 字段, 获取带有相同标签的视频时使用此字段来过滤用户可看到的内容

reghao пре 11 месеци
родитељ
комит
059bacb47e

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

@@ -15,5 +15,5 @@ import java.util.List;
 @Mapper
 public interface VideoPostTagMapper extends BaseMapper<VideoPostTag> {
     int countVideosByTag(String tagId);
-    List<String> findVideosByPage(Page page, String tagId);
+    List<String> findVideosByPage(Page page, String tagId, List<Integer> scopes);
 }

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

@@ -14,5 +14,6 @@ import lombok.NoArgsConstructor;
 @Getter
 public class VideoPostTag extends BaseObject<Integer> {
     private String videoId;
+    private Integer scope;
     private String tagId;
 }

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

@@ -170,10 +170,12 @@ public class VideoPostQueryImpl implements VideoPostQuery {
             return PageList.empty();
         }
 
+        long loginUser = UserContext.getUser();
+        List<Integer> userScopes = contentPermission.getUserScopes(loginUser);
         String tagId = videoTag.getTagId();
         int total = videoPostTagMapper.countVideosByTag(tagId);
         Page page = new Page(pn, pageSize);
-        List<String> videoIds = videoPostTagMapper.findVideosByPage(page, tagId);
+        List<String> videoIds = videoPostTagMapper.findVideosByPage(page, tagId, userScopes);
         List<VideoPostCard> list = videoPostMapper.findVideoCardByVideoIds(videoIds);
         List<VideoCard> list1 = list.stream()
                 .map(videoPostCard -> getVideoCard(videoPostCard, true))

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

@@ -145,7 +145,7 @@ public class VideoPostServiceImpl implements VideoPostService {
         VideoStatistic videoStatistic = new VideoStatistic(videoId);
         setVideoCategoryPost(videoPost);
         videoRepository.savePostVideo(videoFile, videoPost, videoStatistic);
-        setVideoTags(videoId, tags);
+        setVideoTags(videoId, videoPost.getScope(), tags);
     }
 
     @Deprecated
@@ -167,7 +167,7 @@ public class VideoPostServiceImpl implements VideoPostService {
         String videoId = videoPost.getVideoId();
         videoPostMapper.save(videoPost);
         videoStatisticMapper.save(videoStatistic);
-        setVideoTags(videoId, tags);
+        setVideoTags(videoId, videoPost.getScope(), tags);
     }
 
     private void setVideoCategoryPost(VideoPost videoPost) {
@@ -185,7 +185,7 @@ public class VideoPostServiceImpl implements VideoPostService {
         }
     }
 
-    private void setVideoTags(String videoId, String tags) {
+    private void setVideoTags(String videoId, int scope, String tags) {
         if (tags.isBlank()) {
             return;
         }
@@ -196,11 +196,11 @@ public class VideoPostServiceImpl implements VideoPostService {
             String tag = StringUtils.trimAllWhitespace(str);
             VideoTag videoTag = videoTagMapper.findByName(tag);
             if (videoTag != null) {
-                list1.add(new VideoPostTag(videoId, videoTag.getTagId()));
+                list1.add(new VideoPostTag(videoId, scope, videoTag.getTagId()));
             } else {
                 String tagId = UUID.randomUUID().toString().replace("-", "");
                 list.add(new VideoTag(tagId, tag));
-                list1.add(new VideoPostTag(videoId, tagId));
+                list1.add(new VideoPostTag(videoId, scope, tagId));
             }
         }
 

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

@@ -4,16 +4,16 @@
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoPostTagMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into vod_video_tags
-        (`video_id`, `tag_id`)
+        (`video_id`,`scope`,`tag_id`)
         values
-        (#{videoId},#{tagId})
+        (#{videoId},#{scope},#{tagId})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
         insert ignore into vod_video_tags
-        (`video_id`, `tag_id`)
+        (`video_id`,`scope`,`tag_id`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.videoId},#{item.tagId})
+            (#{item.videoId},#{item.scope},#{item.tagId})
         </foreach>
     </insert>
 
@@ -30,6 +30,9 @@
     <select id="findVideosByPage" resultType="java.lang.String">
         select video_id
         from vod_video_tags
-        where tag_id=#{tagId}
+        where tag_id=#{tagId} and scope in
+        <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
     </select>
 </mapper>