Przeglądaj źródła

content-service 的 VideoCategory 修改为 PostCategory, 数据库表名修改为 vod_post_category

reghao 4 miesięcy temu
rodzic
commit
8748b66f3e

+ 0 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/service/ChartService.java

@@ -5,7 +5,6 @@ import cn.reghao.jutil.jdk.text.TextFile;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.api.dto.VideoRegion;
 import cn.reghao.tnb.content.app.exam.model.chart.LineChartData;
-import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
 import cn.reghao.tnb.content.app.vod.service.CategoryService;
 import org.springframework.stereotype.Service;
 

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

@@ -3,7 +3,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.api.dto.spider.BiliRegion;
-import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
+import cn.reghao.tnb.content.app.vod.model.po.PostCategory;
 import cn.reghao.tnb.content.app.vod.model.query.CategoryQuery;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -15,11 +15,11 @@ import java.util.List;
  * @date 2021-11-22 10:41:35
  */
 @Mapper
-public interface VideoCategoryMapper extends BaseMapper<VideoCategory> {
+public interface VideoCategoryMapper extends BaseMapper<PostCategory> {
     @Deprecated
     List<BiliRegion> findAllCategoryIds();
     @Deprecated
-    VideoCategory findByRid(int rid);
-    VideoCategory findById(int id);
-    List<VideoCategory> findVideoCategoryByPage(@Param("page") Page page, @Param("categoryQuery") CategoryQuery categoryQuery);
+    PostCategory findByRid(int rid);
+    PostCategory findById(int id);
+    List<PostCategory> findVideoCategoryByPage(@Param("page") Page page, @Param("categoryQuery") CategoryQuery categoryQuery);
 }

+ 5 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/VideoCategory.java → content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/PostCategory.java

@@ -13,7 +13,7 @@ import lombok.Setter;
 @NoArgsConstructor
 @Setter
 @Getter
-public class VideoCategory extends BaseObject<Integer> {
+public class PostCategory extends BaseObject<Integer> {
     private int pid;
     private int regionId;
     private String name;
@@ -21,12 +21,12 @@ public class VideoCategory extends BaseObject<Integer> {
     private int sort;
     private boolean vip;
 
-    public VideoCategory(int pid, String name) {
+    public PostCategory(int pid, String name) {
         this.pid = pid;
         this.name = name;
     }
 
-    public VideoCategory(CategoryAdd categoryAdd) {
+    public PostCategory(CategoryAdd categoryAdd) {
         this.pid = categoryAdd.getPid();
         this.name = categoryAdd.getName();
     }
@@ -44,8 +44,8 @@ public class VideoCategory extends BaseObject<Integer> {
             return true;
         }
 
-        if (other instanceof VideoCategory) {
-            VideoCategory o = (VideoCategory) other;
+        if (other instanceof PostCategory) {
+            PostCategory o = (PostCategory) other;
             return o.name.equals(name);
         } else {
             return false;

+ 2 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/CategoryService.java

@@ -3,7 +3,7 @@ package cn.reghao.tnb.content.app.vod.service;
 import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.tnb.content.api.dto.VideoRegion;
 import cn.reghao.tnb.content.app.vod.model.dto.CategoryAdd;
-import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
+import cn.reghao.tnb.content.app.vod.model.po.PostCategory;
 import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
 import cn.reghao.tnb.content.app.vod.model.query.VideoQuery;
 
@@ -15,7 +15,7 @@ import java.util.*;
  */
 public interface CategoryService {
     List<VideoRegion> getCategories(boolean vip);
-    VideoCategory getVideoCategory(int id);
+    PostCategory getVideoCategory(int id);
     void addVideoCategory(CategoryAdd categoryAdd);
     void setVideoCategoryPost(VideoPost videoPost);
     PageList<String> getVideoIdsByCategory(VideoQuery videoQuery, int pageNumber, int pageSize);

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

@@ -6,7 +6,7 @@ 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.VideoCategoryPostMapper;
 import cn.reghao.tnb.content.app.vod.model.dto.CategoryAdd;
-import cn.reghao.tnb.content.app.vod.model.po.VideoCategory;
+import cn.reghao.tnb.content.app.vod.model.po.PostCategory;
 import cn.reghao.tnb.content.app.vod.model.po.VideoCategoryPost;
 import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
 import cn.reghao.tnb.content.app.vod.model.query.CategoryQuery;
@@ -38,11 +38,11 @@ public class CategoryServiceImpl implements CategoryService {
     @Override
     public List<VideoRegion> getCategories(boolean vip) {
         CategoryQuery categoryQuery = new CategoryQuery.Builder().build();
-        List<VideoCategory> list = getVideoCategories(categoryQuery);
+        List<PostCategory> list = getVideoCategories(categoryQuery);
         setVideoCategory(list);
 
         Map<Integer, VideoRegion> map = new HashMap<>(list.size());
-        for (VideoCategory category : list) {
+        for (PostCategory category : list) {
             if (category.isVip() && !vip) {
                 continue;
             }
@@ -70,11 +70,11 @@ public class CategoryServiceImpl implements CategoryService {
         return parents;
     }
 
-    private List<VideoCategory> getVideoCategories(CategoryQuery categoryQuery) {
+    private List<PostCategory> getVideoCategories(CategoryQuery categoryQuery) {
         int pageNumber = 1;
         int pageSize = 1000;
         Page page = new Page(pageNumber, pageSize);
-        List<VideoCategory> list = videoCategoryMapper.findVideoCategoryByPage(page, categoryQuery);
+        List<PostCategory> list = videoCategoryMapper.findVideoCategoryByPage(page, categoryQuery);
         if (list.isEmpty()) {
             initVideoCategory();
         }
@@ -83,15 +83,15 @@ public class CategoryServiceImpl implements CategoryService {
     }
 
     private void initVideoCategory() {
-        VideoCategory videoCategory1 = new VideoCategory(0, "大杂烩");
-        videoCategoryMapper.save(videoCategory1);
+        PostCategory postCategory1 = new PostCategory(0, "大杂烩");
+        videoCategoryMapper.save(postCategory1);
 
-        int pid = videoCategory1.getId();
-        VideoCategory videoCategory2 = new VideoCategory(pid, "杂");
-        videoCategoryMapper.save(videoCategory2);
+        int pid = postCategory1.getId();
+        PostCategory postCategory2 = new PostCategory(pid, "杂");
+        videoCategoryMapper.save(postCategory2);
     }
 
-    private void setVideoCategory(List<VideoCategory> list) {
+    private void setVideoCategory(List<PostCategory> list) {
         String keyPrefix = "tnb:content:video:category";
         list.forEach(videoCategory -> {
             int id = videoCategory.getId();
@@ -101,11 +101,11 @@ public class CategoryServiceImpl implements CategoryService {
     }
 
     @Override
-    public VideoCategory getVideoCategory(int id) {
+    public PostCategory getVideoCategory(int id) {
         String key = String.format("tnb:content:video:category:%s", id);
         Object value = redisStringObject.get(key);
-        if (value instanceof VideoCategory) {
-            return (VideoCategory) value;
+        if (value instanceof PostCategory) {
+            return (PostCategory) value;
         }
 
         return null;
@@ -113,8 +113,8 @@ public class CategoryServiceImpl implements CategoryService {
 
     @Override
     public void addVideoCategory(CategoryAdd categoryAdd) {
-        VideoCategory videoCategory1 = new VideoCategory(categoryAdd);
-        List<VideoCategory> list = List.of(videoCategory1);
+        PostCategory postCategory1 = new PostCategory(categoryAdd);
+        List<PostCategory> list = List.of(postCategory1);
         videoCategoryMapper.saveAll(list);
     }
 

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

@@ -17,7 +17,7 @@ import cn.reghao.tnb.content.api.dto.VideoPostCard;
 import cn.reghao.tnb.content.app.vod.db.mapper.BannerVideoMapper;
 import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
 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.PostCategory;
 import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
 import cn.reghao.tnb.content.app.vod.model.po.VideoStatistic;
 import cn.reghao.tnb.content.app.vod.model.vo.BannerVideoVO;
@@ -74,14 +74,14 @@ public class VideoPostQueryImpl implements VideoPostQuery {
     }
 
     public PageList<VideoCard> getCategoryVideos(int categoryId, int pageNumber) {
-        VideoCategory videoCategory = categoryService.getVideoCategory(categoryId);
-        if (videoCategory == null) {
+        PostCategory postCategory = categoryService.getVideoCategory(categoryId);
+        if (postCategory == null) {
             return PageList.empty();
         }
 
         List<Integer> scopes = contentPermission.getUserScopes();
         VideoQuery videoQuery;
-        int pid = videoCategory.getPid();
+        int pid = postCategory.getPid();
         if (pid == 0) {
             videoQuery = new VideoQuery.Builder()
                     .scope(scopes)

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

@@ -3,13 +3,13 @@
 
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoCategoryMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
-        insert into vod_video_category
+        insert into vod_post_category
         (`pid`,`name`,`region_id`,`icon`,`sort`,`vip`)
         values 
         (#{pid},#{name},#{regionId},#{icon},#{sort},#{vip})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
-        insert into vod_video_category
+        insert into vod_post_category
         (`pid`,`name`,`region_id`,`icon`,`sort`,`vip`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
@@ -19,22 +19,22 @@
 
     <select id="findAllCategoryIds" resultType="cn.reghao.tnb.content.api.dto.spider.BiliRegion">
         select region_id,pid as category_pid,id as category_id
-        from vod_video_category
+        from vod_post_category
         where pid not in (0, 3, 11)
     </select>
-    <select id="findById" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
+    <select id="findById" resultType="cn.reghao.tnb.content.app.vod.model.po.PostCategory">
         select *
-        from vod_video_category
+        from vod_post_category
         where id=#{id}
     </select>
-    <select id="findByRid" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
+    <select id="findByRid" resultType="cn.reghao.tnb.content.app.vod.model.po.PostCategory">
         select *
-        from vod_video_category
+        from vod_post_category
         where region_id=#{rid}
     </select>
-    <select id="findVideoCategoryByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoCategory">
+    <select id="findVideoCategoryByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.PostCategory">
         select *
-        from vod_video_category
+        from vod_post_category
         <where>
             deleted=0
             <if test="categoryQuery.categoryPid != null">

+ 3 - 3
content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/VideoPostTest.java

@@ -429,10 +429,10 @@ public class VideoPostTest {
 
     @Test
     public void videoCategoryTest() {
-        VideoCategory videoCategory1 = new VideoCategory(0, "杂");
-        VideoCategory videoCategory2 = new VideoCategory(1, "bili");
+        PostCategory postCategory1 = new PostCategory(0, "杂");
+        PostCategory postCategory2 = new PostCategory(1, "bili");
 
-        List<VideoCategory> list = List.of(videoCategory1, videoCategory2);
+        List<PostCategory> list = List.of(postCategory1, postCategory2);
         videoCategoryMapper.saveAll(list);
     }
 }