Browse Source

定时获取内容晋级溯源

wangyunpeng 8 months ago
parent
commit
6126be1e1c

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mapper/longArticle/LongArticleBaseMapper.java

@@ -14,4 +14,6 @@ public interface LongArticleBaseMapper {
 
     void batchInsertDatastatSortStrategy(List<DatastatSortStrategy> list);
 
+    void updateRootProduceContentLevel(String rootProduceContentId, String level);
+
 }

+ 41 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/longArticle/ArticlePoolPromotionSource.java

@@ -0,0 +1,41 @@
+package com.tzld.longarticle.recommend.server.model.entity.longArticle;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@Table(name = "article_pool_promotion_source")
+public class ArticlePoolPromotionSource implements Serializable {
+
+    @Id
+    @Column(name = "channel_content_id")
+    private String channelContentId;
+    @Column(name = "source_publish_content_id")
+    private String sourcePublishContentId;
+    @Column(name = "root_publish_content_id")
+    private String rootPublishContentId;
+    @Column(name = "root_produce_content_id")
+    private String rootProduceContentId;
+    @Column(name = "title")
+    private String title;
+    @Column(name = "title_md5")
+    private String titleMd5;
+    @Column(name = "level")
+    private String level;
+    @Column(name = "status")
+    private Integer status;
+    @Column(name = "deleted")
+    private Integer deleted;
+    @Column(name = "create_timestamp")
+    private Long createTimestamp;
+    @Column(name = "update_timestamp")
+    private Long updateTimestamp;
+
+}

+ 13 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/vo/RootPublishContentVO.java

@@ -0,0 +1,13 @@
+package com.tzld.longarticle.recommend.server.model.vo;
+
+import lombok.Data;
+
+@Data
+public class RootPublishContentVO {
+
+    private String channelContentId;
+    private String sourcePublishContentId;
+    private String rootPublishContentId;
+    private String rootProduceContentId;
+
+}

+ 15 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/ArticlePoolPromotionSourceRepository.java

@@ -0,0 +1,15 @@
+package com.tzld.longarticle.recommend.server.repository.longArticle;
+
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticlePoolPromotionSource;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ArticlePoolPromotionSourceRepository extends JpaRepository<ArticlePoolPromotionSource, String> {
+
+    List<ArticlePoolPromotionSource> getByChannelContentId(String channelContentId);
+
+    List<ArticlePoolPromotionSource> getByStatus(Integer status);
+}

+ 6 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/XxlJobService.java

@@ -339,4 +339,10 @@ public class XxlJobService {
         articleService.findSource(findSourceParam);
         return ReturnT.SUCCESS;
     }
+
+    @XxlJob("articlePromotionTraceability")
+    public ReturnT<String> articlePromotionTraceability(String channelContentId) {
+        articleService.articlePromotionTraceability(channelContentId);
+        return ReturnT.SUCCESS;
+    }
 }

+ 42 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/ArticleService.java

@@ -5,16 +5,20 @@ import com.tzld.longarticle.recommend.server.common.CommonThreadPoolExecutor;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishContentTypeEnum;
 import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
 import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
+import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
 import com.tzld.longarticle.recommend.server.model.dto.CrawlerContent;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishContent;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishContentOutput;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticlePoolPromotionSource;
 import com.tzld.longarticle.recommend.server.model.param.ArticleFindSourceParam;
+import com.tzld.longarticle.recommend.server.model.vo.RootPublishContentVO;
 import com.tzld.longarticle.recommend.server.repository.aigc.PublishAccountRepository;
 import com.tzld.longarticle.recommend.server.repository.aigc.PublishContentOutputRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
+import com.tzld.longarticle.recommend.server.repository.longArticle.ArticlePoolPromotionSourceRepository;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountIndexAvgViewCountService;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
@@ -51,6 +55,10 @@ public class ArticleService {
     AigcBaseMapper aigcBaseMapper;
     @Autowired
     CrawlerBaseMapper crawlerBaseMapper;
+    @Autowired
+    LongArticleBaseMapper longArticleBaseMapper;
+    @Autowired
+    ArticlePoolPromotionSourceRepository articlePoolPromotionSourceRepository;
 
     private final static ExecutorService pool = new CommonThreadPoolExecutor(
             32,
@@ -141,7 +149,7 @@ public class ArticleService {
         crawlerBaseMapper.updateArticleAigcId(wxSn, publishContentId, channelContentId);
         // 查找记录根记录
         long start = System.currentTimeMillis();
-        Article result = getRootPublishContent(channelContentId, null, publishContentId, 0);
+        RootPublishContentVO result = getRootPublishContent(channelContentId, null, publishContentId, 0);
         log.info("syncAigcIdByWxSn getRootPublishContent finish cost:{}", System.currentTimeMillis() - start);
         // 更新source root publish_content_id
         crawlerBaseMapper.updateArticleSourceRootId(wxSn, result.getSourcePublishContentId(), result.getRootPublishContentId());
@@ -178,9 +186,11 @@ public class ArticleService {
         return result;
     }
 
-    public Article getRootPublishContent(String channelContentId, String sourcePublishContentId, String rootPublishContentId,
-                                         int times) {
-        Article result = new Article();
+    public RootPublishContentVO getRootPublishContent(String channelContentId,
+                                                      String sourcePublishContentId,
+                                                      String rootPublishContentId,
+                                                      int times) {
+        RootPublishContentVO result = new RootPublishContentVO();
         result.setSourcePublishContentId(sourcePublishContentId);
         result.setRootPublishContentId(rootPublishContentId);
         if (times > 20) {
@@ -223,6 +233,7 @@ public class ArticleService {
                 result.setSourcePublishContentId(publishContent.getId());
             }
             result.setRootPublishContentId(publishContent.getId());
+            result.setRootProduceContentId(publishContent.getSourceId());
             channelContentId = publishContent.getCrawlerChannelContentId();
         } else {
             for (String aTitle : titles) {
@@ -233,6 +244,7 @@ public class ArticleService {
                         result.setSourcePublishContentId(publishContent.getId());
                     }
                     result.setRootPublishContentId(publishContent.getId());
+                    result.setRootProduceContentId(publishContent.getSourceId());
                     channelContentId = publishContent.getCrawlerChannelContentId();
                     break;
                 }
@@ -245,4 +257,30 @@ public class ArticleService {
         }
     }
 
+    public void articlePromotionTraceability(String channelContentId) {
+        // 查找待处理任务
+        List<ArticlePoolPromotionSource> tasks;
+        if (StringUtils.hasText(channelContentId)) {
+            tasks = articlePoolPromotionSourceRepository.getByChannelContentId(channelContentId);
+        } else {
+            tasks = articlePoolPromotionSourceRepository.getByStatus(0);
+        }
+        for (ArticlePoolPromotionSource task : tasks) {
+            // 溯源
+            RootPublishContentVO source = getRootPublishContent(task.getChannelContentId(), null, null, 0);
+            // 更新
+            if (StringUtils.hasText(source.getRootProduceContentId())) {
+                task.setStatus(1);
+                task.setSourcePublishContentId(source.getSourcePublishContentId());
+                task.setRootProduceContentId(source.getRootProduceContentId());
+                task.setRootPublishContentId(source.getRootPublishContentId());
+                task.setUpdateTimestamp(System.currentTimeMillis());
+                articlePoolPromotionSourceRepository.save(task);
+                longArticleBaseMapper.updateRootProduceContentLevel(task.getRootProduceContentId(), task.getLevel());
+            } else {
+                task.setDeleted(1);
+                articlePoolPromotionSourceRepository.save(task);
+            }
+        }
+    }
 }

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/XxlJobController.java

@@ -43,4 +43,9 @@ public class XxlJobController {
     public void syncArticleRootPublishId(String dateStr) {
         service.syncArticleRootPublishId(dateStr);
     }
+
+    @GetMapping("/articlePromotionTraceability")
+    public void articlePromotionTraceability(String channelContentId) {
+        service.articlePromotionTraceability(channelContentId);
+    }
 }

+ 4 - 0
long-article-recommend-service/src/main/resources/mapper/longArticle/LongArticleBaseMapper.xml

@@ -41,4 +41,8 @@
         </foreach>
     </insert>
 
+    <update id="updateRootProduceContentLevel">
+        update article_pool_promotion_source set level = #{level} where root_produce_content_id = #{rootProduceContentId}
+    </update>
+
 </mapper>