Forráskód Böngészése

定时获取内容晋级溯源

wangyunpeng 8 hónapja
szülő
commit
2fe971faa0

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

@@ -9,7 +9,7 @@ import java.util.List;
 @Repository
 public interface ArticlePoolPromotionSourceRepository extends JpaRepository<ArticlePoolPromotionSource, String> {
 
-    List<ArticlePoolPromotionSource> getByChannelContentId(String channelContentId);
+    ArticlePoolPromotionSource getByChannelContentId(String channelContentId);
 
     List<ArticlePoolPromotionSource> getByChannelContentIdInAndStatusAndDeleted(List<String> channelContentIds, Integer status, Integer deleted);
 

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

@@ -151,7 +151,7 @@ public class ArticleService {
         crawlerBaseMapper.updateArticleAigcId(wxSn, publishContentId, channelContentId);
         // 查找记录根记录
         long start = System.currentTimeMillis();
-        RootPublishContentVO result = getRootPublishContent(channelContentId, null, publishContentId, 0);
+        RootPublishContentVO result = getRootPublishContent(channelContentId, null, publishContentId, null, 0);
         log.info("syncAigcIdByWxSn getRootPublishContent finish cost:{}", System.currentTimeMillis() - start);
         // 更新source root publish_content_id
         crawlerBaseMapper.updateArticleSourceRootId(wxSn, result.getSourcePublishContentId(), result.getRootPublishContentId());
@@ -191,23 +191,16 @@ public class ArticleService {
     public RootPublishContentVO getRootPublishContent(String channelContentId,
                                                       String sourcePublishContentId,
                                                       String rootPublishContentId,
+                                                      String rootProduceContentId,
                                                       int times) {
         RootPublishContentVO result = new RootPublishContentVO();
         result.setChannelContentId(channelContentId);
         result.setSourcePublishContentId(sourcePublishContentId);
         result.setRootPublishContentId(rootPublishContentId);
+        result.setRootProduceContentId(rootProduceContentId);
         if (times > 20) {
             return result;
         }
-        List<Article> articleList = articleRepository.getByChannelContentIdAndRootPublishContentIdIsNotNull(channelContentId);
-        if (CollectionUtils.isNotEmpty(articleList)) {
-            if (!StringUtils.hasText(sourcePublishContentId)) {
-                result.setSourcePublishContentId(articleList.get(0).getSourcePublishContentId());
-            }
-            result.setRootPublishContentId(articleList.get(0).getRootPublishContentId());
-            return result;
-        }
-        result.setRootPublishContentId(rootPublishContentId);
         CrawlerContent crawlerContent = aigcBaseMapper.getCrawlerContentByChannelContentId(channelContentId);
         if (Objects.isNull(crawlerContent) || !StringUtils.hasText(crawlerContent.getGhId())) {
             return result;
@@ -256,7 +249,8 @@ public class ArticleService {
         if (channelContentId.equals(crawlerContent.getChannelContentId())) {
             return result;
         } else {
-            result = getRootPublishContent(channelContentId, result.getSourcePublishContentId(), result.getRootPublishContentId(), ++times);
+            result = getRootPublishContent(channelContentId, result.getSourcePublishContentId(),
+                    result.getRootPublishContentId(), result.getRootProduceContentId(), ++times);
             if (!channelContentId.equals(result.getChannelContentId())) {
                 result.getMidChannelContentIds().add(channelContentId);
             }
@@ -266,15 +260,16 @@ public class ArticleService {
 
     public void articlePromotionTraceability(String channelContentId) {
         // 查找待处理任务
-        List<ArticlePoolPromotionSource> tasks;
+        List<ArticlePoolPromotionSource> tasks = new ArrayList<>();
         if (StringUtils.hasText(channelContentId)) {
-            tasks = articlePoolPromotionSourceRepository.getByChannelContentId(channelContentId);
+            ArticlePoolPromotionSource item = articlePoolPromotionSourceRepository.getByChannelContentId(channelContentId);
+            tasks.add(item);
         } else {
             tasks = articlePoolPromotionSourceRepository.getByStatus(0);
         }
         for (ArticlePoolPromotionSource task : tasks) {
             // 溯源
-            RootPublishContentVO source = getRootPublishContent(task.getChannelContentId(), null, null, 0);
+            RootPublishContentVO source = getRootPublishContent(task.getChannelContentId(), null, null, null, 0);
             // 更新
             if (StringUtils.hasText(source.getRootProduceContentId())) {
                 task.setStatus(1);
@@ -284,16 +279,23 @@ public class ArticleService {
                 task.setUpdateTimestamp(System.currentTimeMillis());
                 articlePoolPromotionSourceRepository.save(task);
                 // 保存中间环节 晋级溯源
-                List<ArticlePoolPromotionSource> insertList = new ArrayList<>();
                 for (String midChannelContentId : source.getMidChannelContentIds()) {
                     ArticlePoolPromotionSource item = new ArticlePoolPromotionSource();
                     BeanUtils.copyProperties(task, item);
+                    ArticlePoolPromotionSource dto = articlePoolPromotionSourceRepository.getByChannelContentId(midChannelContentId);
+                    if (Objects.nonNull(dto)) {
+                        BeanUtils.copyProperties(dto, item);
+                        item.setRootProduceContentId(task.getRootProduceContentId());
+                        item.setStatus(task.getStatus());
+                        item.setDeleted(task.getDeleted());
+                        item.setLevel(task.getLevel());
+                        item.setUpdateTimestamp(task.getUpdateTimestamp());
+                    }
                     item.setChannelContentId(midChannelContentId);
-                    item.setCreateTimestamp(item.getUpdateTimestamp());
-                    insertList.add(item);
-                }
-                if (CollectionUtils.isNotEmpty(insertList)) {
-                    longArticleBaseMapper.batchInsertArticlePoolPromotionSource(insertList);
+                    if (Objects.isNull(item.getCreateTimestamp())) {
+                        item.setCreateTimestamp(item.getUpdateTimestamp());
+                    }
+                    articlePoolPromotionSourceRepository.save(item);
                 }
                 longArticleBaseMapper.updateRootProduceContentLevel(task.getRootProduceContentId(), task.getLevel());
             } else {

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/FilterService.java

@@ -93,7 +93,7 @@ public class FilterService {
         strategies.add(ServiceBeanFactory.getBean(SensitiveStrategy.class));
         strategies.add(ServiceBeanFactory.getBean(DeDuplicationStrategy.class));
         strategies.add(ServiceBeanFactory.getBean(KeywordStrategy.class));
-        strategies.add(ServiceBeanFactory.getBean(ContentPoolStrategy.class));
+        strategies.add(ServiceBeanFactory.getBean(ArticlePromotionStrategy.class));
         if (param.getScene().equals(FWH_COLD_START)) {
             strategies.add(ServiceBeanFactory.getBean(HistoryTitleForFwhColdStartStrategy.class));
         } else {

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/strategy/ContentPoolStrategy.java → long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/filter/strategy/ArticlePromotionStrategy.java

@@ -18,7 +18,7 @@ import java.util.stream.Collectors;
 
 @Component
 @Slf4j
-public class ContentPoolStrategy implements FilterStrategy {
+public class ArticlePromotionStrategy implements FilterStrategy {
 
     @Autowired
     ArticlePoolPromotionSourceRepository repository;

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

@@ -45,9 +45,12 @@
         insert into article_pool_promotion_source
             (channel_content_id, source_publish_content_id, root_publish_content_id, root_produce_content_id, title,
              title_md5, level, status, deleted, create_timestamp, update_timestamp)
-        values(#{item.channelContentId}, #{item.sourcePublishContentId}, #{item.rootPublishContentId},
+        values
+        <foreach collection="list" item="item" separator=",">
+            (#{item.channelContentId}, #{item.sourcePublishContentId}, #{item.rootPublishContentId},
                #{item.rootProduceContentId}, #{item.title}, #{item.titleMd5}, #{item.level}, #{item.status},
                #{item.deleted}, #{item.createTimestamp}, #{item.updateTimestamp})
+        </foreach>
     </insert>
 
     <update id="updateRootProduceContentLevel">