|
|
@@ -0,0 +1,106 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.recommend.score.strategy;
|
|
|
+
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ArticleCategoryStatusEnum;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
|
|
|
+import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.model.dto.Content;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishContent;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticleCategory;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.longArticle.ArticleCategoryRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recommend.score.Score;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreParam;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrategy;
|
|
|
+import com.tzld.longarticle.recommend.server.util.DateUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class DedupCategoryStrategy implements ScoreStrategy {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AigcBaseMapper aigcBaseMapper;
|
|
|
+ @Autowired
|
|
|
+ private CrawlerBaseMapper crawlerBaseMapper;
|
|
|
+ @Autowired
|
|
|
+ private ArticleCategoryRepository articleCategoryRepository;
|
|
|
+
|
|
|
+ @Value("${category.active.version:1}")
|
|
|
+ private Integer activeVersion;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${dedupCategoryList:[\"军事历史\",\"政治新闻\",\"国家大事\"]}")
|
|
|
+ private List<String> dedupCategoryList;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Score> score(ScoreParam param) {
|
|
|
+ List<Score> scores = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isEmpty(param.getContents())) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(dedupCategoryList)) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ // 查询昨日发布的头条内容
|
|
|
+ Long yesterdayStart = DateUtils.getBeforeDayStart(1) * 1000L;
|
|
|
+ List<PublishContent> publishContentList = aigcBaseMapper.getTodayPublishContentList(param.getAccountId(), yesterdayStart);
|
|
|
+ if (CollectionUtils.isEmpty(publishContentList)) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ String yesterdayStr = DateUtils.getBeforeDaysDateStr("yyyyMMdd", 1);
|
|
|
+ List<String> publishContentIds = publishContentList.stream().map(PublishContent::getId).collect(Collectors.toList());
|
|
|
+ List<String> sourceIds = crawlerBaseMapper.getFirstYesterdayContentSourceIds(yesterdayStr, param.getGhId(), publishContentIds);
|
|
|
+
|
|
|
+ Set<String> recentHeadCategories = new HashSet<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(sourceIds)) {
|
|
|
+ List<ArticleCategory> categoryList = articleCategoryRepository.getByProduceContentIdInAndVersionAndStatus(
|
|
|
+ sourceIds, activeVersion, ArticleCategoryStatusEnum.SUCCESS.getCode());
|
|
|
+ for (ArticleCategory ac : categoryList) {
|
|
|
+ if (StringUtils.hasText(ac.getCategory())) {
|
|
|
+ recentHeadCategories.add(ac.getCategory());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(recentHeadCategories)) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ // 若 recentHeadCategories 与 dedupCategoryList 无交集,直接返回
|
|
|
+ boolean hasIntersection = dedupCategoryList.stream().anyMatch(recentHeadCategories::contains);
|
|
|
+ if (!hasIntersection) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ // 品类与近昨日头条品类匹配且在配置降权品类中,则降权
|
|
|
+ for (Content content : param.getContents()) {
|
|
|
+ if (CollectionUtils.isEmpty(content.getCategory())
|
|
|
+ || !ContentPoolEnum.autoArticlePoolLevel1.getContentPool().equals(content.getContentPoolType())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Score score = new Score();
|
|
|
+ score.setStrategy(this);
|
|
|
+ score.setContentId(content.getId());
|
|
|
+ double scoreValue = 0.0;
|
|
|
+ for (String category : content.getCategory()) {
|
|
|
+ if (recentHeadCategories.contains(category) && dedupCategoryList.contains(category)) {
|
|
|
+ scoreValue -= 10;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ score.setScore(scoreValue);
|
|
|
+ if (scoreValue != 0.0) {
|
|
|
+ scores.add(score);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|