|
@@ -1,5 +1,7 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.recall;
|
|
|
|
|
|
+import cn.hutool.core.io.resource.ResourceUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
|
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
import com.tzld.longarticle.recommend.server.model.ContentHisPublishArticle;
|
|
@@ -9,6 +11,7 @@ import com.tzld.longarticle.recommend.server.repository.entity.aigc.CrawlerMetaA
|
|
|
import com.tzld.longarticle.recommend.server.repository.entity.crawler.Article;
|
|
|
import com.tzld.longarticle.recommend.server.service.recall.strategy.ColdStartBackupRecallStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.service.recall.strategy.DefaultRecallStrategy;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.AvgReadDTO;
|
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
|
import com.tzld.longarticle.recommend.server.util.JSONUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -126,19 +129,18 @@ public class RecallService implements ApplicationContextAware {
|
|
|
|
|
|
public void setTitleAvgViewCount(List<Content> contentList) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
+ String cardJSON = ResourceUtil.readUtf8Str("file/AccountInfo.json");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(cardJSON);
|
|
|
List<String> titleList = contentList.stream().map(Content::getTitle).collect(Collectors.toList());
|
|
|
List<Article> hisArticleList = articleRepository.getByTitleIn(titleList);
|
|
|
Map<String, Map<Integer, List<Article>>> map = hisArticleList.stream()
|
|
|
.collect(Collectors.groupingBy(Article::getTitle, Collectors.groupingBy(Article::getItemIndex)));
|
|
|
for (Content content : contentList) {
|
|
|
List<Article> hisArticles = new ArrayList<>();
|
|
|
- Map<Integer, Integer> indexAvgMap = new HashMap<>();
|
|
|
Map<Integer, List<Article>> indexArticleMap = map.get(content.getTitle());
|
|
|
if (Objects.nonNull(indexArticleMap) && !indexArticleMap.isEmpty()) {
|
|
|
for (Map.Entry<Integer, List<Article>> indexArticleEntry : indexArticleMap.entrySet()) {
|
|
|
List<Article> indexArticleList = indexArticleEntry.getValue();
|
|
|
- int sumViewCount = indexArticleList.stream().mapToInt(Article::getShowViewCount).sum();
|
|
|
- indexAvgMap.put(indexArticleEntry.getKey(), sumViewCount/ indexArticleList.size());
|
|
|
hisArticles.addAll(indexArticleList);
|
|
|
}
|
|
|
}
|
|
@@ -146,7 +148,13 @@ public class RecallService implements ApplicationContextAware {
|
|
|
for (Article hisArticle : hisArticles) {
|
|
|
ContentHisPublishArticle article = new ContentHisPublishArticle();
|
|
|
BeanUtils.copyProperties(hisArticle, article);
|
|
|
- article.setAvgViewCount(indexAvgMap.get(article.getItemIndex()));
|
|
|
+ AvgReadDTO dto = jsonObject.getObject(hisArticle.getGhId() + "_" + hisArticle.getItemIndex(), AvgReadDTO.class);
|
|
|
+ int avgViewCount = 0;
|
|
|
+ if (Objects.nonNull(dto)) {
|
|
|
+ article.setInnerAccount(true);
|
|
|
+ avgViewCount = (int) dto.getReadAvg();
|
|
|
+ }
|
|
|
+ article.setAvgViewCount(avgViewCount);
|
|
|
if (Objects.nonNull(article.getAvgViewCount()) && article.getAvgViewCount() > 0) {
|
|
|
article.setViewCountRate((article.getShowViewCount() * 1.0) / article.getAvgViewCount());
|
|
|
}
|