Просмотр исходного кода

Merge branch '20260421-wyp-videoSearch' of Server/growth-manager into master

wangyunpeng 1 месяц назад
Родитель
Сommit
83b225ecac

+ 33 - 0
api-module/src/main/java/com/tzld/piaoquan/api/component/ManagerApiService.java

@@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.Objects;
 
 @Slf4j
@@ -135,4 +137,35 @@ public class ManagerApiService {
     }
 
 
+    /**
+     * 按标题搜索视频(调用 manager 平台开放分页接口,无需鉴权)
+     *
+     * @param title    搜索关键词
+     * @param pageNum  页码
+     * @param pageSize 每页数量
+     * @return 接口返回的 content 对象,包含 totalSize 和 objs 列表
+     */
+    public JSONObject searchVideoByTitle(String title, int pageNum, int pageSize) {
+        try {
+            String encodedTitle = URLEncoder.encode(title, StandardCharsets.UTF_8.name());
+            String url = managerApiHost + "/openapi/video/page?pageNum=" + pageNum + "&pageSize=" + pageSize
+                    + "&title=" + encodedTitle
+                    + "&sortField=4&sortType=desc&status=1&recommendStatus=-6&auditStaus=5&categoryId=55&muid=7";
+            String response = httpPoolClient.get(url);
+            if (response == null) {
+                return null;
+            }
+            JSONObject res = JSONObject.parseObject(response);
+            if (res != null && res.getInteger("code") == 0) {
+                return res.getJSONObject("content");
+            }
+            log.error("ManagerApiService searchVideoByTitle failed, title={} pageNum={} pageSize={} res={}",
+                    title, pageNum, pageSize, res);
+        } catch (Exception e) {
+            log.error("ManagerApiService searchVideoByTitle error, title={} pageNum={} pageSize={}",
+                    title, pageNum, pageSize, e);
+        }
+        return null;
+    }
+
 }

+ 64 - 0
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformPlanServiceImpl.java

@@ -108,6 +108,9 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
     @Value("${video.min.score:0.6}")
     private Double videoMinScore;
 
+    @Value("${video.title.search.max.count:500}")
+    private int videoTitleSearchMaxCount;
+
     @Value("${small_page_url}")
     private String GET_SMALL_PAGE_URL;
 
@@ -592,6 +595,10 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
     @Override
     public Page<VideoContentItemVO> getVideoContentList(VideoContentListParam param) {
         ContentPlatformAccount user = LoginUserContext.getUser();
+        // 如果 title 有内容,调用 manager 平台接口搜索
+        if (StringUtils.hasText(param.getTitle())) {
+            return getVideoContentListByTitle(param);
+        }
         Page<VideoContentItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
         int offset = (param.getPageNum() - 1) * param.getPageSize();
         String dt = planMapperExt.getVideoMaxDt();
@@ -613,6 +620,63 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         return result;
     }
 
+    /**
+     * 按标题通过 manager 平台接口查询视频列表,支持最大查询条数限制
+     */
+    private Page<VideoContentItemVO> getVideoContentListByTitle(VideoContentListParam param) {
+        Page<VideoContentItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
+        int pageSize = param.getPageSize() > 0 ? param.getPageSize() : 10;
+        int offset = (param.getPageNum() - 1) * pageSize;
+
+        // 查询前判断:如果请求的偏移量已超出最大条数限制,直接返回,不发起远程查询
+        if (offset >= videoTitleSearchMaxCount) {
+            result.setTotalSize(videoTitleSearchMaxCount);
+            result.setObjs(new ArrayList<>());
+            return result;
+        }
+
+        JSONObject pageData = managerApiService.searchVideoByTitle(param.getTitle(), param.getPageNum(), pageSize);
+        if (pageData == null) {
+            result.setTotalSize(0);
+            result.setObjs(new ArrayList<>());
+            return result;
+        }
+
+        int totalSize = pageData.getIntValue("totalSize");
+        // 限制最大可查询条数
+        int effectiveTotalSize = Math.min(totalSize, videoTitleSearchMaxCount);
+        result.setTotalSize(effectiveTotalSize);
+
+        JSONArray objs = pageData.getJSONArray("objs");
+        result.setObjs(buildVideoContentItemVOFromRemote(objs));
+        return result;
+    }
+
+    /**
+     * 将 manager 接口返回的 objs 数据转换为 VideoContentItemVO 列表
+     */
+    private List<VideoContentItemVO> buildVideoContentItemVOFromRemote(JSONArray objs) {
+        if (objs == null || objs.isEmpty()) {
+            return new ArrayList<>();
+        }
+        List<VideoContentItemVO> result = new ArrayList<>();
+        for (int i = 0; i < objs.size(); i++) {
+            JSONObject obj = objs.getJSONObject(i);
+            VideoContentItemVO item = new VideoContentItemVO();
+            item.setVideoId(obj.getLong("id"));
+            item.setTitle(obj.getString("title"));
+            item.setVideo(obj.getString("transedVideoPath"));
+            String cover = obj.getString("selfCoverImgPath");
+            if (cover.contains("?")) {
+                cover = cover.substring(0, cover.indexOf("?"));
+            }
+            cover += "?x-oss-process=image/resize,m_fill,w_600,h_480,limit_0/format,jpg/watermark,image_eXNoL3BpYy93YXRlcm1hcmtlci9pY29uX3BsYXlfd2hpdGUucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLHdfMTQ0,g_center";
+            item.setCover(cover);
+            result.add(item);
+        }
+        return result;
+    }
+
     private String getVideoContentListType(Integer type) {
         switch (type) {
             case 0:

+ 7 - 0
api-module/src/test/java/com/tzld/piaoquan/api/GhDetailTest.java

@@ -130,4 +130,11 @@ public class GhDetailTest {
         }
     }
 
+    @Test
+    public void searchVideoByTitle() {
+        String title = "历史";
+        JSONObject res = managerApiService.searchVideoByTitle(title, 1, 10);
+        System.out.println(res.toJSONString());
+    }
+
 }