Bladeren bron

Update ArticleService: clean code and add some comments

StrayWarrior 10 maanden geleden
bovenliggende
commit
2800740e4d

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

@@ -202,6 +202,7 @@ public class ArticleService {
         if (times > 20) {
             return result;
         }
+        // NOTE: channelContentId 为爬虫生成,不一定存在于AIGC系统中
         CrawlerContent crawlerContent = aigcBaseMapper.getCrawlerContentByChannelContentId(channelContentId);
         if (Objects.isNull(crawlerContent) || !StringUtils.hasText(crawlerContent.getGhId())) {
             return result;
@@ -247,6 +248,7 @@ public class ArticleService {
                 }
             }
         }
+        // channelContentId未被修改,说明未找到
         if (channelContentId.equals(crawlerContent.getChannelContentId())) {
             return result;
         } else {
@@ -273,6 +275,7 @@ public class ArticleService {
             RootPublishContentVO source = getRootPublishContent(task.getChannelContentId(), null, null, null, 0);
             // 更新
             if (StringUtils.hasText(source.getRootProduceContentId())) {
+                // TODO(11-06): enum
                 task.setStatus(1);
                 task.setSourcePublishContentId(source.getSourcePublishContentId());
                 task.setRootProduceContentId(source.getRootProduceContentId());
@@ -285,21 +288,23 @@ public class ArticleService {
                     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);
-                    if (Objects.isNull(item.getCreateTimestamp())) {
+                        // 以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());
                     }
                     articlePoolPromotionSourceRepository.save(item);
                 }
                 longArticleBaseMapper.updateRootProduceContentLevel(task.getRootProduceContentId(), task.getLevel());
             } else {
+                // TODO(11-06): 要修改
                 task.setDeleted(1);
                 articlePoolPromotionSourceRepository.save(task);
             }