Procházet zdrojové kódy

更新 content 的 UserContentService 接口

reghao před 1 rokem
rodič
revize
9ed6992826

+ 17 - 3
content/content-api/src/main/java/cn/reghao/tnb/content/api/dto/VideoSearch.java

@@ -15,9 +15,23 @@ import java.io.Serializable;
 public class VideoSearch implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    @NotNull
-    private Integer page;
-    @NotNull
     private Integer type;
     private String content;
+    private Integer pageNo;
+
+    private Integer pageNumber;
+    private Integer pageSize;
+    private Integer categoryPid;
+    private Integer categoryId;
+    private Integer durationGt;
+    private Boolean horizontal;
+    private String orderBy;
+    private String orderDirection;
+
+    public VideoSearch() {
+        this.pageNumber = 1;
+        this.pageSize = 10;
+        this.orderBy = "id";
+        this.orderDirection = "ASC";
+    }
 }

+ 1 - 1
content/content-api/src/main/java/cn/reghao/tnb/content/api/iface/UserContentService.java

@@ -16,6 +16,6 @@ public interface UserContentService {
      * @return
      * @date 2024-08-03 23:08:488
      */
-    List<Long> getContentUser();
+    List<Long> getContentUser(int publishType);
     Result publishVideoPost(String videoId);
 }

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

@@ -40,6 +40,9 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
     List<VideoPost> findVideoPostByPage(Page page, VideoQuery videoQuery);
     List<VideoPostCard> findVideoCardByPage(Page page, VideoQuery videoQuery);
 
+    int countAdminVideo(VideoQuery videoQuery);
+    List<VideoPost> findAdminVideoByPage(Page page, VideoQuery videoQuery);
+
     List<Integer> countByCriteriaAndUserGroup(VideoQuery videoQuery);
     List<VideoPostCard> findCriteriaAndUserGroupByPage(Page page, VideoQuery videoQuery);
     List<VideoPostCard> findByNextVideos(VideoQuery videoQuery, LocalDateTime publishAt);
@@ -54,7 +57,9 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
     List<VideoPost> findSearchCriteriaByPage(Page page, SearchCriteria searchCriteria);
     List<VideoPost> findAllById(int pageSize, int nextId);
     List<BannerVideo> findBannerVideos(List<String> videoIds);
-    List<GroupCount> findGroupByPublishBy();
+    List<GroupCount> findPublishByPost();
+    List<GroupCount> findPublishByVideo();
+    List<GroupCount> findPublishByImage();
     List<GroupCount> findGroupByCategoryId();
     List<String> findRandomVideoIds(List<Integer> scopes, int size);
     List<String> findShortVideo(List<Integer> scopes);

+ 11 - 2
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/repository/VideoRepository.java

@@ -93,8 +93,17 @@ public class VideoRepository {
     }
 
     //@Cacheable(cacheNames = "tnb:content:publishBy", key = "publishBy", unless = "#result == null")
-    public List<GroupCount> getPublishUsers() {
-        return videoPostMapper.findGroupByPublishBy();
+    public List<GroupCount> getPublishUsers(int publishType) {
+        List<GroupCount> list;
+        if (publishType == 1) {
+            list = videoPostMapper.findPublishByVideo();
+        } else if (publishType == 2) {
+            list = videoPostMapper.findPublishByImage();
+        } else {
+            list = videoPostMapper.findPublishByPost();
+        }
+
+        return list;
     }
 
     @Cacheable(cacheNames = "tnb:content:short_video", unless = "#result == null")

+ 13 - 5
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/query/VideoQuery.java

@@ -17,11 +17,12 @@ public class VideoQuery {
     private Integer categoryId;
     private Long userId;
     private String videoId;
+    private String title;
     private Boolean horizontal;
     private Integer duration;
     private String groupBy;
     private String orderBy;
-    private String order;
+    private String orderDirection;
 
     private VideoQuery(Builder builder) {
         this.status = builder.status;
@@ -30,11 +31,12 @@ public class VideoQuery {
         this.categoryId = builder.categoryId;
         this.userId = builder.userId;
         this.videoId = builder.videoId;
+        this.title = builder.title;
         this.horizontal = builder.horizontal;
         this.duration = builder.duration;
         this.groupBy = builder.groupBy;
         this.orderBy = builder.orderBy;
-        this.order = builder.order;
+        this.orderDirection = builder.orderDirection;
     }
 
     public static final class Builder {
@@ -44,11 +46,12 @@ public class VideoQuery {
         private Integer categoryId;
         private Long userId;
         private String videoId;
+        private String title;
         private Boolean horizontal;
         private Integer duration;
         private String groupBy;
         private String orderBy;
-        private String order;
+        private String orderDirection;
 
         public Builder() {
             this.status = List.of(VideoStatus.publish.getCode(), VideoStatus.noVideoFile.getCode());
@@ -95,6 +98,11 @@ public class VideoQuery {
             return this;
         }
 
+        public Builder title(String title) {
+            this.title = title;
+            return this;
+        }
+
         public Builder groupBy(String groupBy) {
             this.groupBy = groupBy;
             return this;
@@ -105,8 +113,8 @@ public class VideoQuery {
             return this;
         }
 
-        public Builder order(String order) {
-            this.order = order;
+        public Builder orderDirection(String orderDirection) {
+            this.orderDirection = orderDirection;
             return this;
         }
 

+ 14 - 19
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/rpc/AdminVideoServiceImpl.java

@@ -18,7 +18,6 @@ import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
 import cn.reghao.tnb.content.app.vod.model.query.VideoQuery;
 import cn.reghao.tnb.content.app.vod.service.CategoryService;
 import cn.reghao.tnb.content.app.vod.service.VideoPostQuery;
-import cn.reghao.tnb.content.app.vod.model.dto.SearchCriteria;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.apache.dubbo.config.annotation.DubboService;
@@ -92,26 +91,22 @@ public class AdminVideoServiceImpl implements AdminVideoService {
     }
 
     public PageList<UserVideoPost> getVideoPosts(VideoSearch videoSearch) {
-        int pageNumber = videoSearch.getPage();
-        Page page = new Page(pageNumber, 20);
+        int pageNumber = videoSearch.getPageNumber();
+        int pageSize = videoSearch.getPageSize();
+        Page page = new Page(pageNumber, pageSize);
         String content = videoSearch.getContent();
 
-        int total;
-        List<UserVideoPost> list;
-        if (content != null) {
-            SearchCriteria searchCriteria = new SearchCriteria.Builder().status(null).scope(null).title(content).build();
-            total = videoPostMapper.countBySearchCriteria(searchCriteria);
-            list = videoPostMapper.findSearchCriteriaByPage(page, searchCriteria).stream()
-                    .map(videoPostQuery::getUserVideoPost)
-                    .collect(Collectors.toList());
-        } else {
-            VideoQuery videoQuery = new VideoQuery.Builder().status(null).build();
-            total = videoPostMapper.countByCriteria(videoQuery);
-            list = videoPostMapper.findVideoPostByPage(page, videoQuery).stream()
-                    .map(videoPostQuery::getUserVideoPost)
-                    .collect(Collectors.toList());
-        }
-
+        VideoQuery videoQuery = new VideoQuery.Builder()
+                .status(null)
+                .scope(null)
+                .title(content)
+                .orderBy(videoSearch.getOrderBy())
+                .orderDirection(videoSearch.getOrderDirection())
+                .build();
+        int total = videoPostMapper.countAdminVideo(videoQuery);
+        List<UserVideoPost>list = videoPostMapper.findAdminVideoByPage(page, videoQuery).stream()
+                .map(videoPostQuery::getUserVideoPost)
+                .collect(Collectors.toList());
         return PageList.pageList(pageNumber, 20, total, list);
     }
 

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

@@ -26,8 +26,8 @@ public class UserContentServiceImpl implements UserContentService {
     }
 
     @Override
-    public List<Long> getContentUser() {
-        List<GroupCount> list = videoRepository.getPublishUsers();
+    public List<Long> getContentUser(int publishType) {
+        List<GroupCount> list = videoRepository.getPublishUsers(publishType);
         return list.stream()
                 .map(groupCount -> Long.valueOf(groupCount.getId()))
                 .collect(Collectors.toList());

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

@@ -93,7 +93,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
                     .categoryPid(categoryId)
                     .groupBy("publish_by")
                     .orderBy("publish_at")
-                    .order("desc")
+                    .orderDirection("desc")
                     .build();
         } else {
             videoQuery = new VideoQuery.Builder()
@@ -101,7 +101,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
                     .categoryId(categoryId)
                     .groupBy("publish_by")
                     .orderBy("publish_at")
-                    .order("desc")
+                    .orderDirection("desc")
                     .build();
         }
 

+ 94 - 1
content/content-service/src/main/resources/mapper/vod/VideoPostMapper.xml

@@ -155,6 +155,79 @@
         order by post.publish_at desc
     </select>
 
+    <select id="countAdminVideo" resultType="java.lang.Integer">
+        select count(*)
+        from vod_video_post
+        <where>
+            deleted=0
+            <if test="status != null">
+                and `status` in
+                <foreach collection="status" item="id" index="index" open="(" close=")" separator=",">
+                    #{id}
+                </foreach>
+            </if>
+            <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>
+            <if test="videoId != null">
+                and video_id=#{videoId}
+            </if>
+            <if test="title != null">
+                and match(title) against(#{title})
+            </if>
+        </where>
+    </select>
+    <select id="findAdminVideoByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
+        select *
+        from vod_video_post
+        <where>
+            deleted=0
+            <if test="videoQuery.status != null">
+                and `status` in
+                <foreach collection="videoQuery.status" item="id" index="index" open="(" close=")" separator=",">
+                    #{id}
+                </foreach>
+            </if>
+            <if test="videoQuery.scope != null">
+                and scope in
+                <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
+                    #{id}
+                </foreach>
+            </if>
+            <if test="videoQuery.categoryPid != null">
+                and category_pid=#{videoQuery.categoryPid}
+            </if>
+            <if test="videoQuery.categoryId != null">
+                and category_id=#{videoQuery.categoryId}
+            </if>
+            <if test="videoQuery.userId != null">
+                and publish_by=#{videoQuery.userId}
+            </if>
+            <if test="videoQuery.horizontal != null">
+                and horizontal=#{videoQuery.horizontal}
+            </if>
+            <if test="videoQuery.title != null">
+                and match(title) against(#{videoQuery.title})
+            </if>
+        </where>
+        order by #{videoQuery.orderBy} #{videoQuery.orderDirection}
+    </select>
+
     <select id="countByCriteriaAndUserGroup" resultType="java.lang.Integer">
         select count(*)
         from vod_video_post
@@ -413,13 +486,33 @@
         order by publish_at desc
         limit 10
     </select>
-    <select id="findGroupByPublishBy" resultType="cn.reghao.tnb.common.db.GroupCount">
+    <select id="findPublishByPost" resultType="cn.reghao.tnb.common.db.GroupCount">
         select publish_by as id,count(*) total
         from vod_video_post
         where deleted=0 and category_pid=11
         group by publish_by
         order by total desc
     </select>
+    <select id="findPublishByImage" resultType="cn.reghao.tnb.common.db.GroupCount">
+        select user_id as id,count(*) as total
+        from image_post
+        where user_id not in
+        (
+        select publish_by
+        from vod_video_post
+        where category_pid=11
+        group by publish_by
+        )
+        group by user_id
+        order by total desc
+    </select>
+    <select id="findPublishByVideo" resultType="cn.reghao.tnb.common.db.GroupCount">
+        select publish_by as id,count(*) total
+        from vod_video_post
+        where category_pid=11
+        group by publish_by
+        order by total desc
+    </select>
     <select id="findGroupByCategoryId" resultType="cn.reghao.tnb.common.db.GroupCount">
         select category_id as id,count(*) total
         from vod_video_post