ソースを参照

Merge branch 'wyp/1206-articlePromotionTraceability' of Server/long-article-recommend into master

wangyunpeng 7 ヶ月 前
コミット
e44004a5e5

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

@@ -33,6 +33,8 @@ public interface AigcBaseMapper {
 
     List<PublishContent> getNearestPublishContent(String publishAccountId, Long publishTimestamp, Integer size);
 
+    List<PublishContent> getLateNearestPublishContent(String publishAccountId, Long publishTimestamp);
+
     CrawlerContent getCrawlerContentByChannelContentId(String channelContentId);
 
     List<CrawlerContent> getCrawlerContentByChannelContentIdIn(List<String> channelContentIds);

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

@@ -153,6 +153,13 @@ public class ArticleService {
         if (Objects.nonNull(publishContent)) {
             publishContentId = publishContent.getId();
             channelContentId = publishContent.getCrawlerChannelContentId();
+        } else {
+            publishContentList = aigcBaseMapper.getLateNearestPublishContent(publishAccount.getId(), publishTimestamp);
+            publishContent = findPublishContent(publishContentList, article.getTitle(), publishTimestamp);
+            if (Objects.nonNull(publishContent)) {
+                publishContentId = publishContent.getId();
+                channelContentId = publishContent.getCrawlerChannelContentId();
+            }
         }
         log.info("syncAigcIdByWxSn titleMatch finish");
         if (Objects.isNull(channelContentId)) {
@@ -172,6 +179,9 @@ public class ArticleService {
     private PublishContent findPublishContent(List<PublishContent> publishContentList,
                                               String title,
                                               Long publishTimestamp) {
+        if (CollectionUtils.isEmpty(publishContentList)) {
+            return null;
+        }
         Map<String, PublishContent> publishContentMap = publishContentList.stream().collect(
                 Collectors.toMap(PublishContent::getId, publishContent -> publishContent));
         List<String> publishContentIds = publishContentList.stream().map(PublishContent::getId).collect(Collectors.toList());
@@ -262,6 +272,17 @@ public class ArticleService {
             result.setRootPublishContentId(publishContent.getId());
             result.setRootProduceContentId(publishContent.getSourceId());
             channelContentId = publishContent.getCrawlerChannelContentId();
+        } else {
+            publishContentList = aigcBaseMapper.getLateNearestPublishContent(publishAccount.getId(), publishTimestamp);
+            publishContent = findPublishContent(publishContentList, title, publishTimestamp);
+            if (Objects.nonNull(publishContent)) {
+                if (!StringUtils.hasText(sourcePublishContentId)) {
+                    result.setSourcePublishContentId(publishContent.getId());
+                }
+                result.setRootPublishContentId(publishContent.getId());
+                result.setRootProduceContentId(publishContent.getSourceId());
+                channelContentId = publishContent.getCrawlerChannelContentId();
+            }
         }
         // channelContentId未被修改,说明未找到
         if (channelContentId.equals(crawlerContent.getChannelContentId())) {
@@ -287,64 +308,72 @@ public class ArticleService {
         }
         long now = System.currentTimeMillis();
         for (ArticlePoolPromotionSource task : tasks) {
-            // 判断文章是否被抓回来,如果没有抓回来,不进行处理 临时方案
-            CrawlerContent crawlerContent = aigcBaseMapper.getCrawlerContentByChannelContentId(task.getChannelContentId());
-            if (Objects.isNull(crawlerContent)) {
-                continue;
-            }
-            // 溯源
-            Article article = articleRepository.getByWxSn(task.getWxSn());
-            if (Objects.isNull(article)) {
-                task.setDeleted(StatusEnum.ONE.getCode());
-                articlePoolPromotionSourceRepository.save(task);
-                continue;
-            }
-            PublishAccount publishAccount = publishAccountRepository.getByGhId(article.getGhId());
-            if (Objects.isNull(publishAccount)) {
-                continue;
-            }
-            long publishTimestamp = article.getPublishTimestamp() > 0 ? article.getPublishTimestamp() * 1000 : article.getUpdateTime() * 1000;
-            List<PublishContent> publishContentList = aigcBaseMapper.getNearestPublishContent(publishAccount.getId(), publishTimestamp, 100);
-            PublishContent publishContent = findPublishContent(publishContentList, task.getTitle(), publishTimestamp);
-            if (Objects.isNull(publishContent)) {
-                task.setDeleted(StatusEnum.ONE.getCode());
-                articlePoolPromotionSourceRepository.save(task);
-                continue;
-            }
-            RootPublishContentVO source = getRootPublishContent(publishContent.getCrawlerChannelContentId(), null, publishContent.getId(), publishContent.getSourceId(), 0);
-            // 更新
-            if (StringUtils.hasText(source.getRootProduceContentId())) {
-                task.setStatus(ArticlePoolPromotionSourceStatusEnum.FINISH.getCode());
-                task.setSourcePublishContentId(source.getSourcePublishContentId());
-                task.setRootProduceContentId(source.getRootProduceContentId());
-                task.setRootPublishContentId(source.getRootPublishContentId());
-                task.setUpdateTimestamp(now);
-                articlePoolPromotionSourceRepository.save(task);
-                // 保存中间环节 晋级溯源
-                for (String midChannelContentId : source.getMidChannelContentIds()) {
-                    ArticlePoolPromotionSource item = new ArticlePoolPromotionSource();
-                    BeanUtils.copyProperties(task, item);
-                    ArticlePoolPromotionSource dto = articlePoolPromotionSourceRepository.getByChannelContentId(midChannelContentId);
-                    if (Objects.nonNull(dto)) {
-                        // 以dto为基础
-                        dto.setRootProduceContentId(task.getRootProduceContentId());
-                        dto.setRootPublishContentId(task.getRootPublishContentId());
-                        dto.setStatus(task.getStatus());
-                        dto.setLevel(task.getLevel());
-                        dto.setUpdateTimestamp(task.getUpdateTimestamp());
-                        item = dto;
-                    } else {
-                        // 以新item为基础
-                        item.setChannelContentId(midChannelContentId);
-                        item.setCreateTimestamp(item.getUpdateTimestamp());
+            try {
+                // 判断文章是否被抓回来,如果没有抓回来,不进行处理 临时方案
+                CrawlerContent crawlerContent = aigcBaseMapper.getCrawlerContentByChannelContentId(task.getChannelContentId());
+                if (Objects.isNull(crawlerContent)) {
+                    continue;
+                }
+                // 溯源
+                Article article = articleRepository.getByWxSn(task.getWxSn());
+                if (Objects.isNull(article)) {
+                    task.setDeleted(StatusEnum.ONE.getCode());
+                    articlePoolPromotionSourceRepository.save(task);
+                    continue;
+                }
+                PublishAccount publishAccount = publishAccountRepository.getByGhId(article.getGhId());
+                if (Objects.isNull(publishAccount)) {
+                    continue;
+                }
+                long publishTimestamp = article.getPublishTimestamp() > 0 ? article.getPublishTimestamp() * 1000 : article.getUpdateTime() * 1000;
+                List<PublishContent> publishContentList = aigcBaseMapper.getNearestPublishContent(publishAccount.getId(), publishTimestamp, 100);
+                PublishContent publishContent = findPublishContent(publishContentList, task.getTitle(), publishTimestamp);
+                if (Objects.isNull(publishContent)) {
+                    publishContentList = aigcBaseMapper.getLateNearestPublishContent(publishAccount.getId(), publishTimestamp);
+                    publishContent = findPublishContent(publishContentList, task.getTitle(), publishTimestamp);
+                    if (Objects.isNull(publishContent)) {
+                        task.setDeleted(StatusEnum.ONE.getCode());
+                        articlePoolPromotionSourceRepository.save(task);
+                        continue;
                     }
-                    item.setDeleted(StatusEnum.ZERO.getCode());
-                    articlePoolPromotionSourceRepository.save(item);
                 }
-                longArticleBaseMapper.updateRootProduceContentLevel(task.getRootProduceContentId(), task.getLevel());
-            } else {
-                task.setDeleted(StatusEnum.ONE.getCode());
-                articlePoolPromotionSourceRepository.save(task);
+                RootPublishContentVO source = getRootPublishContent(publishContent.getCrawlerChannelContentId(), null, publishContent.getId(), publishContent.getSourceId(), 0);
+                // 更新
+                if (StringUtils.hasText(source.getRootProduceContentId())) {
+                    task.setStatus(ArticlePoolPromotionSourceStatusEnum.FINISH.getCode());
+                    task.setSourcePublishContentId(source.getSourcePublishContentId());
+                    task.setRootProduceContentId(source.getRootProduceContentId());
+                    task.setRootPublishContentId(source.getRootPublishContentId());
+                    task.setUpdateTimestamp(now);
+                    articlePoolPromotionSourceRepository.save(task);
+                    // 保存中间环节 晋级溯源
+                    for (String midChannelContentId : source.getMidChannelContentIds()) {
+                        ArticlePoolPromotionSource item = new ArticlePoolPromotionSource();
+                        BeanUtils.copyProperties(task, item);
+                        ArticlePoolPromotionSource dto = articlePoolPromotionSourceRepository.getByChannelContentId(midChannelContentId);
+                        if (Objects.nonNull(dto)) {
+                            // 以dto为基础
+                            dto.setRootProduceContentId(task.getRootProduceContentId());
+                            dto.setRootPublishContentId(task.getRootPublishContentId());
+                            dto.setStatus(task.getStatus());
+                            dto.setLevel(task.getLevel());
+                            dto.setUpdateTimestamp(task.getUpdateTimestamp());
+                            item = dto;
+                        } else {
+                            // 以新item为基础
+                            item.setChannelContentId(midChannelContentId);
+                            item.setCreateTimestamp(item.getUpdateTimestamp());
+                        }
+                        item.setDeleted(StatusEnum.ZERO.getCode());
+                        articlePoolPromotionSourceRepository.save(item);
+                    }
+                    longArticleBaseMapper.updateRootProduceContentLevel(task.getRootProduceContentId(), task.getLevel());
+                } else {
+                    task.setDeleted(StatusEnum.ONE.getCode());
+                    articlePoolPromotionSourceRepository.save(task);
+                }
+            } catch (Exception e) {
+                log.error("articlePromotionTraceability error channelContentId:{}", task.getChannelContentId(), e);
             }
         }
     }
@@ -424,7 +453,7 @@ public class ArticleService {
         List<ProducePlanExeRecord> produceContentList = aigcBaseMapper.getAllByProducePlanId(producePlanIds);
         List<String> channelContentIds = produceContentList.stream().map(ProducePlanExeRecord::getChannelContentId).distinct().collect(Collectors.toList());
         List<ArticleCategory> articleCategoryList = articleCategoryRepository.getAllByChannelContentIdIn(channelContentIds);
-        List<String>  articleCategoryIds = articleCategoryList.stream().map(ArticleCategory::getChannelContentId).collect(Collectors.toList());
+        List<String> articleCategoryIds = articleCategoryList.stream().map(ArticleCategory::getChannelContentId).collect(Collectors.toList());
         List<ProduceContentCrawlerVO> list = produceContentList.stream().filter(o -> !articleCategoryIds.contains(o.getChannelContentId())).map(o -> {
             ProduceContentCrawlerVO item = new ProduceContentCrawlerVO();
             item.setChannelContentId(o.getChannelContentId());
@@ -507,6 +536,12 @@ public class ArticleService {
         PublishContent publishContent = findPublishContent(publishContentList, article.getTitle(), publishTimestamp);
         if (Objects.nonNull(publishContent)) {
             return publishContent.getId();
+        } else {
+            publishContentList = aigcBaseMapper.getLateNearestPublishContent(publishAccount.getId(), publishTimestamp);
+            publishContent = findPublishContent(publishContentList, article.getTitle(), publishTimestamp);
+            if (Objects.nonNull(publishContent)) {
+                return publishContent.getId();
+            }
         }
         return null;
     }

+ 13 - 0
long-article-recommend-service/src/main/resources/mapper/aigc/AigcBaseMapper.xml

@@ -160,6 +160,19 @@
         </if>
     </select>
 
+    <select id="getLateNearestPublishContent"
+            resultType="com.tzld.longarticle.recommend.server.model.entity.aigc.PublishContent">
+        select *
+        from publish_content
+        where publish_account_id = #{publishAccountId}
+        and channel = 5
+        and status = 2
+        <if test="publishTimestamp != null">
+            and publish_timestamp > (#{publishTimestamp})
+        </if>
+        order by publish_timestamp
+    </select>
+
     <select id="getCrawlerContentByChannelContentId"
             resultType="com.tzld.longarticle.recommend.server.model.dto.CrawlerContent">
         select cc.channel_content_id, ca.wx_gh as ghId, cc.title, cc.publish_timestamp