Преглед на файлове

VideoCategory 添加一个 vip 字段, 标识该分区是否只有 vip 用户可访问. 若 parent category 的 vip 为 true, 那么它下面的 category 的 vip 则都为 true, 反之不亦然

reghao преди 1 година
родител
ревизия
00c0aca1e4

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

@@ -13,8 +13,11 @@ import java.util.List;
  */
  */
 @Mapper
 @Mapper
 public interface VideoCategoryMapper extends BaseMapper<VideoCategory> {
 public interface VideoCategoryMapper extends BaseMapper<VideoCategory> {
+    @Deprecated
     List<BiliRegion> findAllCategoryIds();
     List<BiliRegion> findAllCategoryIds();
-    VideoCategory findById(int id);
+    @Deprecated
     VideoCategory findByRid(int rid);
     VideoCategory findByRid(int rid);
+    VideoCategory findById(int id);
     List<VideoCategory> findAllCategory();
     List<VideoCategory> findAllCategory();
+    List<VideoCategory> findCategories(boolean vip);
 }
 }

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

@@ -16,6 +16,7 @@ public class VideoCategory extends BaseObject<Integer> {
     private String name;
     private String name;
     private String icon;
     private String icon;
     private int sort;
     private int sort;
+    private boolean vip;
 
 
     @Override
     @Override
     public int hashCode() {
     public int hashCode() {

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

@@ -23,6 +23,7 @@ import java.util.List;
  * @author reghao
  * @author reghao
  * @date 2023-05-31 11:15:22
  * @date 2023-05-31 11:15:22
  */
  */
+@Deprecated
 @Slf4j
 @Slf4j
 @Service
 @Service
 public class CrawledDataService {
 public class CrawledDataService {

+ 2 - 31
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/impl/CategoryServiceImpl.java

@@ -1,17 +1,13 @@
 package cn.reghao.tnb.content.app.vod.service.impl;
 package cn.reghao.tnb.content.app.vod.service.impl;
 
 
-import cn.reghao.tnb.common.db.GroupCount;
 import cn.reghao.tnb.content.api.dto.VideoRegion;
 import cn.reghao.tnb.content.api.dto.VideoRegion;
 import cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryMapper;
 import cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryMapper;
-import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
 import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
 import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
 import cn.reghao.tnb.content.app.vod.service.CategoryService;
 import cn.reghao.tnb.content.app.vod.service.CategoryService;
-import cn.reghao.tnb.content.app.util.redis.ds.RedisOps;
 import cn.reghao.tnb.content.app.util.redis.ds.RedisStringObject;
 import cn.reghao.tnb.content.app.util.redis.ds.RedisStringObject;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.util.*;
 import java.util.*;
-import java.util.stream.Collectors;
 
 
 /**
 /**
  * @author reghao
  * @author reghao
@@ -20,26 +16,20 @@ import java.util.stream.Collectors;
 @Service
 @Service
 public class CategoryServiceImpl implements CategoryService {
 public class CategoryServiceImpl implements CategoryService {
     private final VideoCategoryMapper videoCategoryMapper;
     private final VideoCategoryMapper videoCategoryMapper;
-    private final VideoPostMapper videoPostMapper;
     private final RedisStringObject redisStringObject;
     private final RedisStringObject redisStringObject;
-    private final RedisOps redisOps;
 
 
-    public CategoryServiceImpl(VideoCategoryMapper videoCategoryMapper, VideoPostMapper videoPostMapper,
-                               RedisStringObject redisStringObject, RedisOps redisOps) {
+    public CategoryServiceImpl(VideoCategoryMapper videoCategoryMapper, RedisStringObject redisStringObject) {
         this.videoCategoryMapper = videoCategoryMapper;
         this.videoCategoryMapper = videoCategoryMapper;
-        this.videoPostMapper = videoPostMapper;
         this.redisStringObject = redisStringObject;
         this.redisStringObject = redisStringObject;
-        this.redisOps = redisOps;
     }
     }
 
 
     public List<VideoCategory> getAllCategory() {
     public List<VideoCategory> getAllCategory() {
         List<VideoCategory> list = videoCategoryMapper.findAll();
         List<VideoCategory> list = videoCategoryMapper.findAll();
-        List<GroupCount> list1 = videoPostMapper.findGroupByCategoryId();
         return list;
         return list;
     }
     }
 
 
     public List<VideoRegion> getCategories(boolean vip) {
     public List<VideoRegion> getCategories(boolean vip) {
-        List<VideoCategory> list = videoCategoryMapper.findAll();
+        List<VideoCategory> list = videoCategoryMapper.findCategories(vip);
         setVideoCategory(list);
         setVideoCategory(list);
 
 
         Map<Integer, VideoRegion> map = new HashMap<>(list.size());
         Map<Integer, VideoRegion> map = new HashMap<>(list.size());
@@ -57,10 +47,6 @@ public class CategoryServiceImpl implements CategoryService {
             }
             }
         });
         });
 
 
-        if (!vip) {
-            map.remove(11);
-        }
-
         List<VideoRegion> parents = new ArrayList<>(map.values());
         List<VideoRegion> parents = new ArrayList<>(map.values());
         parents.sort(Comparator.comparingInt(VideoRegion::getSort));
         parents.sort(Comparator.comparingInt(VideoRegion::getSort));
         parents.forEach(videoRegion -> {
         parents.forEach(videoRegion -> {
@@ -87,19 +73,4 @@ public class CategoryServiceImpl implements CategoryService {
 
 
         return null;
         return null;
     }
     }
-
-    private List<VideoCategory> getVideoCategories() {
-        String keyPrefix = "tnb:content:video:category:*";
-        Set<String> keys = redisOps.keys(keyPrefix);
-        return keys.stream()
-                .map(key -> {
-                    Object value = redisStringObject.get(key);
-                    if (value instanceof VideoCategory) {
-                        return (VideoCategory) value;
-                    }
-                    return null;
-                })
-                .filter(Objects::nonNull)
-                .collect(Collectors.toList());
-    }
 }
 }

+ 7 - 2
content/content-service/src/main/resources/mapper/vod/VideoCategoryMapper.xml

@@ -4,9 +4,9 @@
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryMapper">
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into vod_video_category
         insert into vod_video_category
-        (`pid`,`name`,`region_id`,`icon`,`sort`)
+        (`pid`,`name`,`region_id`,`icon`,`sort`,`vip`)
         values 
         values 
-        (#{pid},#{name},#{regionId},#{icon},#{sort})
+        (#{pid},#{name},#{regionId},#{icon},#{sort},#{vip})
     </insert>
     </insert>
 
 
     <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
     <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
@@ -33,4 +33,9 @@
         from vod_video_category
         from vod_video_category
         where `pid` != 0
         where `pid` != 0
     </select>
     </select>
+    <select id="findCategories" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
+        select *
+        from vod_video_category
+        where `vip`=#{vip}
+    </select>
 </mapper>
 </mapper>