Kaynağa Gözat

不连续发时政内容降权

wangyunpeng 1 ay önce
ebeveyn
işleme
97c739b672

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/recommend/ScoreStrategyEnum.java

@@ -5,6 +5,7 @@ public enum ScoreStrategyEnum {
     CATEGORY("CategoryStrategy"),
     ACCOUNT_USER_CATEGORY("AccountUserCategoryStrategy"),
     CONTENT_POOL("ContentPoolStrategy"),
+    DEDUP_CATEGORY("DedupCategoryStrategy"),
     FLOW_CTL_DECREASE("FlowCtlDecreaseStrategy"),
     HIS_FISSION_AVG_READ_RATE_CORRELATION_RATE("HisFissionAvgReadRateCorrelationRateStrategy"),
     HIS_FISSION_AVG_READ_RATE_RATE("HisFissionAvgReadRateRateStrategy"),

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

@@ -52,4 +52,6 @@ public interface CrawlerBaseMapper {
     List<String> getNeedResetUserGroupGhIds();
 
     List<String> getNearDaysRootSourceIds(String rootSourceIdPrefix, Long publishTimestamp);
+
+    List<String> getFirstYesterdayContentSourceIds(String yesterdayStr, String ghId, List<String> publishContentIds);
 }

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

@@ -313,6 +313,7 @@ public class RecommendService {
         rankParam.setBackup(backup);
         rankParam.setStrategy(param.getStrategy());
         rankParam.setGhId(param.getGhId());
+        rankParam.setAccountId(param.getAccountId());
         rankParam.setAccountName(param.getAccountName());
         rankParam.setSize(param.getPublishNum());
         rankParam.setScene(param.getScene());

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/RankParam.java

@@ -11,6 +11,7 @@ import java.util.List;
 @Data
 public class RankParam {
     private String ghId;
+    private String accountId;
     private String accountName;
     private String planId;
     private List<Content> contents;

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/RankStrategy.java

@@ -63,6 +63,7 @@ public interface RankStrategy {
     public static ScoreParam convertToScoreParam(RankParam param) {
         ScoreParam scoreParam = new ScoreParam();
         scoreParam.setGhId(param.getGhId());
+        scoreParam.setAccountId(param.getAccountId());
         scoreParam.setAccountName(param.getAccountName());
         scoreParam.setContents(param.getContents());
         scoreParam.setStrategy(param.getStrategy());

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/ScoreParam.java

@@ -17,6 +17,7 @@ import java.util.List;
 @NoArgsConstructor
 public class ScoreParam {
     private String ghId;
+    private String accountId;
     private String accountName;
     private String planId;
     private List<Content> contents;

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/ScoreService.java

@@ -137,6 +137,7 @@ public class ScoreService implements ApplicationContextAware {
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV21.getStrategy())
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.INFINITE_STRATEGY.getStrategy())) {
             strategies.add(strategyMap.get(ScoreStrategyEnum.CATEGORY.value()));
+            //strategies.add(strategyMap.get(ScoreStrategyEnum.DEDUP_CATEGORY.value()));
             strategies.add(strategyMap.get(ScoreStrategyEnum.ACCOUNT_USER_CATEGORY.value()));
             //strategies.add(strategyMap.get(ScoreStrategyEnum.ACCOUNT_PRE_DISTRIBUTE.value()));
             strategies.add(strategyMap.get(ScoreStrategyEnum.FLOW_CTL_DECREASE.value()));

+ 106 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/strategy/DedupCategoryStrategy.java

@@ -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;
+    }
+
+}

+ 12 - 0
long-article-recommend-service/src/main/resources/mapper/crawler/CrawlerBaseMapper.xml

@@ -114,4 +114,16 @@
         and root_source_id_list like CONCAT('%', #{rootSourceIdPrefix}, '%')
     </select>
 
+    <select id="getFirstYesterdayContentSourceIds" resultType="java.lang.String">
+        select source_id
+        from publish_sort_log
+        where date_str = #{yesterdayStr}
+        and gh_id = #{ghId}
+        and `index` = 1
+        and publish_content_id in
+        <foreach collection="publishContentIds" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+    </select>
+
 </mapper>