Kaynağa Gözat

title dedumplicate

wangyunpeng 2 gün önce
ebeveyn
işleme
450d5e5fb4

+ 15 - 3
api-module/src/main/java/com/tzld/piaoquan/api/job/GzhReplyVideoRefreshJob.java

@@ -125,6 +125,7 @@ public class GzhReplyVideoRefreshJob {
                 .map(Map.Entry::getValue)
                 .collect(Collectors.toList());
         List<VideoDetail> searchVideos = new ArrayList<>();
+        List<String> existTitles = new ArrayList<>();
         for (JSONObject obj : sortedList) {
             String text = obj.getString("title");
             // 提取关键词
@@ -159,8 +160,10 @@ public class GzhReplyVideoRefreshJob {
             if (aiResult.isSuccess()) {
                 List<String> keywords = JSONObject.parseArray(aiResult.getResponse().getChoices().get(0).getMessage().getContent(), String.class);
                 log.info("GzhReplyVideoRefreshJob accountName:{} text:{} keywords:{}", accountName, text, keywords);
-                VideoDetail videoDetail = searchVideoByKeyword(keywords, searchVideos);
+                VideoDetail videoDetail = searchVideoByKeyword(keywords, searchVideos, existTitles);
                 if (videoDetail != null) {
+                    existTitles.add(videoDetail.getTitle());
+                    existTitles.add(text);
                     videoDetail.setTitle(text);
                     videoDetail.setCover(obj.getString("coverImgUrl"));
                     searchVideos.add(videoDetail);
@@ -214,7 +217,7 @@ public class GzhReplyVideoRefreshJob {
         return creativeIdTextMap;
     }
 
-    private VideoDetail searchVideoByKeyword(List<String> keywords, List<VideoDetail> searchVideos) {
+    private VideoDetail searchVideoByKeyword(List<String> keywords, List<VideoDetail> searchVideos, List<String> existTitles) {
         if (CollectionUtils.isNotEmpty(keywords)) {
             String searchVideoSql = "SELECT v.id, v.title, v.cover_img_path\n" +
                     "FROM videoods.wx_video v\n" +
@@ -229,11 +232,20 @@ public class GzhReplyVideoRefreshJob {
                     // 过滤重复视频
                     boolean filter = false;
                     for (VideoDetail searchVideo : searchVideos) {
-                        if (searchVideo.getId().equals(videoId) || TitleSimilarCheckUtil.isSimilar(title, searchVideo.getTitle(), TitleSimilarCheckUtil.SIMILARITY_THRESHOLD)) {
+                        if (searchVideo.getId().equals(videoId)) {
                             filter = true;
                             break;
                         }
                     }
+                    // 过滤重复标题
+                    if (!filter && CollectionUtils.isNotEmpty(existTitles)) {
+                        for (String existTitle : existTitles) {
+                            if (TitleSimilarCheckUtil.isSimilar(title, existTitle, TitleSimilarCheckUtil.SIMILARITY_THRESHOLD)) {
+                                filter = true;
+                                break;
+                            }
+                        }
+                    }
                     if (filter) {
                         continue;
                     }