Pārlūkot izejas kodu

更新 VideoQueryController 的 /short 接口

reghao 1 gadu atpakaļ
vecāks
revīzija
2c327f7bcb

+ 2 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/mobile/service/AndroidService.java

@@ -110,7 +110,8 @@ public class AndroidService {
         //PageList<VideoCard> pageList = PageList.empty();
         int categoryId = 5;
         int pn = 1;
-        PageList<VideoCard> pageList = videoPostQuery.getCategoryShortVideos(categoryId, pn);
+        //PageList<VideoCard> pageList = videoPostQuery.getCategoryShortVideos(categoryId, pn);
+        PageList<VideoCard> pageList = PageList.empty();
 
         List<VideoBean> list =  pageList.getList().stream().map(VideoBean::new).collect(Collectors.toList());
         return new VideoBeanResult(list);

+ 5 - 4
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/controller/VideoQueryController.java

@@ -8,6 +8,7 @@ import cn.reghao.tnb.common.db.PageScroll;
 import cn.reghao.tnb.content.app.aop.TimeConsumed;
 import cn.reghao.tnb.content.api.dto.BannerVideo;
 import cn.reghao.tnb.content.api.dto.VideoCard;
+import cn.reghao.tnb.content.app.vod.model.vo.VideoDetail;
 import cn.reghao.tnb.content.app.vod.service.RecommendService;
 import cn.reghao.tnb.content.app.vod.service.VideoPostQuery;
 import io.swagger.annotations.Api;
@@ -46,10 +47,10 @@ public class VideoQueryController {
 
     @TimeConsumed
     @ApiOperation(value = "获取分区短视频", notes = "N")
-    @GetMapping(value = "/category/short", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getCategoryShortVideos(@RequestParam("categoryId") int categoryId, @RequestParam("page") int page) {
-        PageList<VideoCard> pageList = videoPostQuery.getCategoryShortVideos(categoryId, page);
-        return WebResult.success(pageList);
+    @GetMapping(value = "/short", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getCategoryShortVideos() {
+        VideoDetail videoDetail = videoPostQuery.getShortVideo();
+        return WebResult.success(videoDetail);
     }
 
     @ApiOperation(value = "获取某个用户发布的视频", notes = "N")

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

@@ -57,4 +57,5 @@ public interface VideoPostMapper extends BaseMapper<VideoPost> {
     List<GroupCount> findGroupByPublishBy();
     List<GroupCount> findGroupByCategoryId();
     List<String> findRandomVideoIds(List<Integer> scopes, int size);
+    VideoPost findShortVideo(List<Integer> scopes);
 }

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

@@ -5,6 +5,7 @@ import cn.reghao.oss.sdk.model.dto.media.VideoInfo;
 import cn.reghao.tnb.content.api.dto.*;
 import cn.reghao.tnb.content.api.dto.BannerVideo;
 import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
+import cn.reghao.tnb.content.app.vod.model.vo.VideoDetail;
 
 import java.util.*;
 
@@ -15,7 +16,7 @@ import java.util.*;
 public interface VideoPostQuery {
     List<VideoCard> getVideoCards(List<String> videoIds);
     PageList<VideoCard> getCategoryVideos(int categoryId, int pageNumber);
-    PageList<VideoCard> getCategoryShortVideos(int categoryId, int page);
+    VideoDetail getShortVideo();
     PageList<VideoCard> getUserVideos(long userId, int page);
     VideoCard getVideoCard(VideoPostCard videoPostCard, boolean user);
     String getVideoPostData(String videoId);

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

@@ -102,15 +102,16 @@ public class VideoPostQueryImpl implements VideoPostQuery {
         return getVideoCardsByUserGroup(videoQuery, pageNumber);
     }
 
-    public PageList<VideoCard> getCategoryShortVideos(int categoryId, int page) {
-        VideoCategory videoCategory = categoryService.getVideoCategory(categoryId);
-        if (videoCategory == null) {
-            return PageList.empty();
-        }
-
-        List<Integer> scopes = contentPermission.getUserScopes();
-        VideoQuery videoQuery = new VideoQuery.Builder().scope(scopes).duration(60).horizontal(false).build();
-        return getVideoCards(videoQuery, page, true);
+    public VideoDetail getShortVideo() {
+        long loginUser = UserContext.getUser();
+        List<Integer> userScopes = contentPermission.getUserScopes(loginUser);
+        VideoPost videoPost = videoPostMapper.findShortVideo(userScopes);
+        String videoId = videoPost.getVideoId();
+        VideoStatistic videoStatistic = videoStatisticMapper.findByVideoId(videoId);
+        VideoDetail videoDetail = new VideoDetail(videoPost, videoStatistic);
+        List<String> tags = videoTagMapper.findVideoTags(videoId);
+        videoDetail.setTags(tags);
+        return videoDetail;
     }
 
     private PageList<VideoCard> getVideoCardsByUserGroup(VideoQuery videoQuery, int pageNumber) {

+ 11 - 0
content/content-service/src/main/resources/mapper/vod/VideoPostMapper.xml

@@ -438,4 +438,15 @@
         ORDER BY t1.id
         LIMIT #{size}
     </select>
+    <select id="findShortVideo" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
+        SELECT t1.*
+        FROM vod_video_post AS t1
+        JOIN (SELECT ROUND(RAND()*(SELECT MAX(id) FROM vod_video_post)) AS id) AS t2
+        WHERE t1.id>=t2.id and t1.duration&lt;=120 and t1.`status`=2 and t1.scope in
+        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+        ORDER BY t1.id
+        LIMIT 1
+    </select>
 </mapper>