Bladeren bron

阅读均值表查询修改

wangyunpeng 10 maanden geleden
bovenliggende
commit
a984536eda

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

@@ -64,4 +64,24 @@ public class AccountIndexAvgViewCountService {
         return info == null ? 1.0 : info.getReadAvg();
     }
 
+    public double getAvgReadCountByDB(List<AccountAvgInfo> accountAvgInfoListParam, String ghId, Integer index) {
+        if (CollectionUtils.isEmpty(accountAvgInfoListParam)) {
+            return 1.0;
+        }
+        Map<String, List<AccountAvgInfo>> accountAvgInfoAccountMap = accountAvgInfoListParam.stream().collect(Collectors.groupingBy(AccountAvgInfo::getGhId));
+        List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoAccountMap.get(ghId);
+        if (CollectionUtils.isEmpty(accountAvgInfoList)) {
+            return 1.0;
+        }
+        Map<String, AccountAvgInfo> accountAvgInfoMap = accountAvgInfoList.stream().collect(Collectors.toMap(AccountAvgInfo::getPosition, Function.identity()));
+        AccountAvgInfo info = accountAvgInfoMap.get(index + "");
+        if (Objects.isNull(info)) {
+            info =  accountAvgInfoMap.get("4");
+            if (Objects.isNull(info)) {
+                info =  accountAvgInfoMap.get("1");
+            }
+        }
+        return info == null ? 1.0 : info.getReadAvg();
+    }
+
 }

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

@@ -3,8 +3,10 @@ package com.tzld.longarticle.recommend.server.service;
 import com.alibaba.fastjson.JSONObject;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.model.*;
+import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.PublishContentSortLogRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.PublishSortLogRepository;
+import com.tzld.longarticle.recommend.server.repository.entity.crawler.AccountAvgInfo;
 import com.tzld.longarticle.recommend.server.repository.entity.crawler.PublishContentSortLog;
 import com.tzld.longarticle.recommend.server.repository.entity.crawler.PublishSortLog;
 import com.tzld.longarticle.recommend.server.repository.mapper.crawler.ArticleUserGroupMapper;
@@ -52,6 +54,8 @@ public class RecommendService {
     @Autowired
     AccountIndexAvgViewCountService accountIndexAvgViewCountService;
     @Autowired
+    AccountAvgInfoRepository accountAvgInfoRepository;
+    @Autowired
     private ArticleUserGroupMapper articleUserGroupMapper;
 
     @ApolloJsonValue("${accountStrategyConfig:{}}")
@@ -241,6 +245,7 @@ public class RecommendService {
 
         }
         List<PublishSortLog> publishSortLogSaveList = new ArrayList<>();
+        List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
         for (int i = 1; i < rankResult.getContents().size() + 1; i++) {
             Content content = rankResult.getContents().get(i - 1);
 
@@ -251,7 +256,7 @@ public class RecommendService {
             sortLog.setCrawlerChannelContentId(content.getCrawlerChannelContentId());
             sortLog.setTitle(content.getTitle());
             sortLog.setIndex(i);
-            sortLog.setIndexAvgCount(accountIndexAvgViewCountService.getAvgReadCountByDB(param.getGhId(), i));
+            sortLog.setIndexAvgCount(accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), i));
             sortLog.setCategory(JSONObject.toJSONString(content.getCategory()));
             sortLog.setStrategy(param.getStrategy());
             sortLog.setCreateTimestamp(System.currentTimeMillis());

+ 2 - 12
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/ViewCountRateStrategy.java

@@ -16,9 +16,7 @@ import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.Objects;
-import java.util.stream.Collectors;
 
 @Component
 @Slf4j
@@ -37,21 +35,13 @@ public class ViewCountRateStrategy implements ScoreStrategy {
         List<Score> scores = new ArrayList<>();
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
-        Map<Integer, Double> avgInfoMap = avgInfoList.stream().collect(Collectors.toMap(o -> Integer.valueOf(o.getPosition()), AccountAvgInfo::getReadAvg));
-        double avgViewCountFirst = avgInfoMap.get(1);
+        double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 1);
         for (Content content : param.getContents()) {
             for (int i = 0; i < contentPools.length; i++) {
                 if (!contentPools[i].equals(content.getContentPoolType())) {
                     continue;
                 }
-                double avgViewCountPos;
-                if (avgInfoMap.containsKey(i + 1)) {
-                    avgViewCountPos = avgInfoMap.get(i + 1);
-                } else if (avgInfoMap.containsKey(4)) {
-                    avgViewCountPos = avgInfoMap.get(4);
-                } else {
-                    avgViewCountPos = avgInfoMap.get(1);
-                }
+                double avgViewCountPos = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), i + 1);
                 double showViewCountSum = 0D;
                 double avgViewCountSum = 0D;
                 double showViewCountSumFirst = 0D;

+ 6 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/ViewMultiplierStrategy.java

@@ -3,8 +3,10 @@ package com.tzld.longarticle.recommend.server.service.score.strategy;
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.repository.adplatform.ChangwenArticleDatastatRepository;
 import com.tzld.longarticle.recommend.server.repository.adplatform.ChangwenArticleRepository;
+import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.entity.adplatform.ChangwenArticle;
 import com.tzld.longarticle.recommend.server.repository.entity.adplatform.ChangwenArticleDatastat;
+import com.tzld.longarticle.recommend.server.repository.entity.crawler.AccountAvgInfo;
 import com.tzld.longarticle.recommend.server.service.AccountIndexAvgViewCountService;
 import com.tzld.longarticle.recommend.server.service.score.Score;
 import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
@@ -32,6 +34,8 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
     ChangwenArticleDatastatRepository changwenArticleDatastatRepository;
     @Autowired
     AccountIndexAvgViewCountService accountIndexAvgViewCountService;
+    @Autowired
+    AccountAvgInfoRepository accountAvgInfoRepository;
 
     @Override
     public List<Score> score(ScoreParam param) {
@@ -44,6 +48,7 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
         Map<String, ChangwenArticle> changwenArticleDTOMap = getContentIndex(channelContentIds);
         Map<String, ChangwenArticleDatastat> changwenArticleDatastatDTOMap = getContentViewCount(channelContentIds);
 
+        List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByStatusEquals(1);
         List<Score> scores = CommonCollectionUtils.toList(param.getContents(), c -> {
             Score score = new Score();
             score.setContentId(c.getId());
@@ -51,7 +56,7 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
             ChangwenArticleDatastat datastat = changwenArticleDatastatDTOMap.get(c.getCrawlerChannelContentId());
 
             if (Objects.nonNull(article) && Objects.nonNull(datastat)) {
-                double avgReadCount = accountIndexAvgViewCountService.getAvgReadCountByDB(article.getAccountId(), article.getItemIndex());
+                double avgReadCount = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, article.getAccountId(), article.getItemIndex());
                 Integer readCount = datastat.getReadCount();
                 score.setScore(NormalizationUtils.min(Math.max(readCount, 0) / avgReadCount - 1));
             } else {