Bladeren bron

update VideoPostTest

reghao 7 maanden geleden
bovenliggende
commit
d815dd0e61

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

@@ -409,7 +409,7 @@
     <select id="findAllById" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
         select *
         from vod_video_post
-        where deleted=0 and `status`=2 and category_pid!=11 and id > #{nextId}
+        where deleted=0 and `status` in (2,5) and id > #{nextId}
         order by id asc
         limit #{pageSize}
     </select>

+ 0 - 81
content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/SearchTest.java

@@ -1,81 +0,0 @@
-package cn.reghao.tnb.content.app.vod.service;
-
-import cn.reghao.jutil.jdk.db.PageList;
-import cn.reghao.tnb.content.api.constant.PostScope;
-import cn.reghao.tnb.content.api.dto.VideoCard;
-import cn.reghao.tnb.content.app.ContentApplication;
-import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
-import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
-import cn.reghao.tnb.search.api.dto.VideoSummary;
-import cn.reghao.tnb.search.api.iface.DataSearchService;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.dubbo.config.annotation.DubboReference;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * @author reghao
- * @date 2025-04-02 16:10:18
- */
-@Slf4j
-@ActiveProfiles("dev")
-@SpringBootTest(classes = ContentApplication.class)
-public class SearchTest {
-    @DubboReference(check = false)
-    DataSearchService dataSearchService;
-    @Autowired
-    SearchService searchService;
-    @Autowired
-    VideoPostMapper videoPostMapper;
-    @Test
-    public void searchTest() {
-        /*long userId = 10002L;
-        String itemsKey = RedisKeys.getUserItemKey(userId);
-        List<VideoCard> videoCards = new ArrayList<>();
-        List<Object> list = redisSet.spop(itemsKey, 12);
-        for (Object obj : list) {
-            if (obj instanceof VideoCard) {
-                videoCards.add((VideoCard) obj);
-            }
-        }*/
-
-        int pageSize = 1000;
-        int nextId = 0;
-        List<VideoPost> videoPosts = videoPostMapper.findAllById(pageSize, nextId);
-        while (!videoPosts.isEmpty()) {
-            List<VideoSummary> videoSummaryList = videoPosts.stream()
-                    .map(this::getVideoSummary)
-                    .collect(Collectors.toList());
-            if (!videoSummaryList.isEmpty()) {
-                dataSearchService.addVideoSummaryList(videoSummaryList);
-            }
-
-            nextId = videoPosts.get(videoPosts.size()-1).getId();
-            videoPosts = videoPostMapper.findAllById(pageSize, nextId);
-            log.info("start nextId {} with size {}", nextId, videoPosts.size());
-        }
-
-        int pn = 1;
-        String kw = "隔壁";
-        List<Integer> scopes = List.of(PostScope.PUBLIC.getCode(), PostScope.PROTECT.getCode());
-        //PageList<VideoSummary> pageList = dataSearchService.searchVideo(kw, scopes, pn);
-        /*Map<String, List<VideoSummary>> map = pageList.getList().stream()
-                .collect(Collectors.groupingBy(VideoSummary::getVideoId));*/
-//        PageList<VideoCard> pageList1 = searchService.searchByKeyword(kw, "", pn);
-//        System.out.println();
-    }
-
-    private VideoSummary getVideoSummary(VideoPost videoPost) {
-        String videoId = videoPost.getVideoId();
-        String title = videoPost.getTitle();
-        int scope = videoPost.getScope();
-        return new VideoSummary(videoId, title, scope);
-    }
-}

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

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.content.app.vod.service;
 
 import cn.reghao.jutil.jdk.converter.DateTimeConverter;
+import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.jdk.serializer.JsonConverter;
 import cn.reghao.jutil.jdk.text.TextFile;
 import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
@@ -15,9 +16,12 @@ import cn.reghao.tnb.content.app.util.redis.ds.RedisSortedSet;
 import cn.reghao.tnb.content.app.vod.model.vo.BannerVideoVO;
 import cn.reghao.tnb.content.app.vod.service.rcmd.RedisKeys;
 import cn.reghao.tnb.content.app.vod.service.rcmd.UserInterestBased;
+import cn.reghao.tnb.search.api.dto.VideoSummary;
+import cn.reghao.tnb.search.api.iface.DataSearchService;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -402,4 +406,47 @@ public class VideoPostTest {
         videoPostTagMapper.saveAll(list);
         System.out.println(sb.toString());
     }
+
+    @DubboReference(check = false, retries = 0, timeout = 60_000)
+    DataSearchService dataSearchService;
+    @Autowired
+    SearchService searchService;
+    @Test
+    public void putSearchDataTest() {
+        int pageSize = 1000;
+        int nextId = 0;
+        List<VideoPost> videoPosts = videoPostMapper.findAllById(pageSize, nextId);
+        while (!videoPosts.isEmpty()) {
+            List<VideoSummary> videoSummaryList = videoPosts.stream()
+                    .map(this::getVideoSummary)
+                    .collect(Collectors.toList());
+            if (!videoSummaryList.isEmpty()) {
+                dataSearchService.addVideoSummaryList(videoSummaryList);
+            }
+
+            nextId = videoPosts.get(videoPosts.size()-1).getId();
+            videoPosts = videoPostMapper.findAllById(pageSize, nextId);
+            log.info("start nextId {} with size {}", nextId, videoPosts.size());
+        }
+    }
+
+    private VideoSummary getVideoSummary(VideoPost videoPost) {
+        String videoId = videoPost.getVideoId();
+        String title = videoPost.getTitle();
+        int scope = videoPost.getScope();
+        long publishTime = DateTimeConverter.msTimestamp(videoPost.getPublishAt());
+        return new VideoSummary(videoId, title, scope, publishTime);
+    }
+
+    @Test
+    public void searchVideoTest() {
+        int pn = 1;
+        String kw = "隔壁";
+        List<Integer> scopes = List.of(PostScope.PUBLIC.getCode(), PostScope.PROTECT.getCode());
+        PageList<VideoSummary> pageList = dataSearchService.searchVideo(kw, scopes, pn);
+        Map<String, List<VideoSummary>> map = pageList.getList().stream()
+                .collect(Collectors.groupingBy(VideoSummary::getVideoId));
+        PageList<VideoCard> pageList1 = searchService.searchByKeyword(kw, "", pn);
+        System.out.println();
+    }
 }