|
@@ -3,7 +3,10 @@ package com.tzld.longarticle.recommend.server.service.score.strategy;
|
|
|
import cn.hutool.core.io.resource.ResourceUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
-import com.tzld.longarticle.recommend.server.repository.mapper.adplatform.AdplatformBaseMapper;
|
|
|
+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.entity.adplatform.ChangwenArticle;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.entity.adplatform.ChangwenArticleDatastat;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.*;
|
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
|
import com.tzld.longarticle.recommend.server.util.NormalizationUtils;
|
|
@@ -22,7 +25,9 @@ import java.util.stream.Collectors;
|
|
|
public class ViewMultiplierStrategy implements ScoreStrategy {
|
|
|
|
|
|
@Autowired
|
|
|
- AdplatformBaseMapper adplatformBaseMapper;
|
|
|
+ ChangwenArticleRepository changwenArticleRepository;
|
|
|
+ @Autowired
|
|
|
+ ChangwenArticleDatastatRepository changwenArticleDatastatRepository;
|
|
|
|
|
|
private JSONObject jsonObject;
|
|
|
|
|
@@ -39,18 +44,18 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
List<String> channelContentIds = param.getContents().stream().map(Content::getCrawlerChannelContentId).collect(Collectors.toList());
|
|
|
- Map<String, ChangwenArticleDTO> changwenArticleDTOMap = getContentIndex(channelContentIds);
|
|
|
- Map<String, ChangwenArticleDatastatDTO> changwenArticleDatastatDTOMap = getContentViewCount(channelContentIds);
|
|
|
+ Map<String, ChangwenArticle> changwenArticleDTOMap = getContentIndex(channelContentIds);
|
|
|
+ Map<String, ChangwenArticleDatastat> changwenArticleDatastatDTOMap = getContentViewCount(channelContentIds);
|
|
|
|
|
|
List<Score> scores = CommonCollectionUtils.toList(param.getContents(), c -> {
|
|
|
Score score = new Score();
|
|
|
score.setContentId(c.getId());
|
|
|
- ChangwenArticleDTO articleDTO = changwenArticleDTOMap.get(c.getCrawlerChannelContentId());
|
|
|
- ChangwenArticleDatastatDTO datastatDTO = changwenArticleDatastatDTOMap.get(c.getCrawlerChannelContentId());
|
|
|
+ ChangwenArticle article = changwenArticleDTOMap.get(c.getCrawlerChannelContentId());
|
|
|
+ ChangwenArticleDatastat datastat = changwenArticleDatastatDTOMap.get(c.getCrawlerChannelContentId());
|
|
|
|
|
|
- if (Objects.nonNull(articleDTO) && Objects.nonNull(datastatDTO)) {
|
|
|
- double avgReadCount = getAvgReadCount(articleDTO.getAccountId(), articleDTO.getItemIndex());
|
|
|
- Integer readCount = datastatDTO.getReadCount();
|
|
|
+ if (Objects.nonNull(article) && Objects.nonNull(datastat)) {
|
|
|
+ double avgReadCount = getAvgReadCount(article.getAccountId(), article.getItemIndex());
|
|
|
+ Integer readCount = datastat.getReadCount();
|
|
|
score.setScore(NormalizationUtils.min(Math.max(readCount, 0) / avgReadCount - 1));
|
|
|
} else {
|
|
|
score.setScore(-1.0);
|
|
@@ -61,26 +66,26 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
|
|
|
return scores;
|
|
|
}
|
|
|
|
|
|
- private Map<String, ChangwenArticleDTO> getContentIndex(List<String> channelContentIds) {
|
|
|
+ private Map<String, ChangwenArticle> getContentIndex(List<String> channelContentIds) {
|
|
|
if (CollectionUtils.isEmpty(channelContentIds)) {
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
- List<ChangwenArticleDTO> result = adplatformBaseMapper.getChangwenArticles(channelContentIds);
|
|
|
+ List<ChangwenArticle> result = changwenArticleRepository.findAllById(channelContentIds);
|
|
|
if (CollectionUtils.isEmpty(result)) {
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
- return result.stream().collect(Collectors.toMap(ChangwenArticleDTO::getId, o -> o));
|
|
|
+ return result.stream().collect(Collectors.toMap(ChangwenArticle::getId, o -> o));
|
|
|
}
|
|
|
|
|
|
- private Map<String, ChangwenArticleDatastatDTO> getContentViewCount(List<String> channelContentIds) {
|
|
|
+ private Map<String, ChangwenArticleDatastat> getContentViewCount(List<String> channelContentIds) {
|
|
|
if (CollectionUtils.isEmpty(channelContentIds)) {
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
- List<ChangwenArticleDatastatDTO> result = adplatformBaseMapper.getChangwenArticleDatastats(channelContentIds);
|
|
|
+ List<ChangwenArticleDatastat> result = changwenArticleDatastatRepository.findAllById(channelContentIds);
|
|
|
if (CollectionUtils.isEmpty(result)) {
|
|
|
return new HashMap<>();
|
|
|
}
|
|
|
- return result.stream().collect(Collectors.toMap(ChangwenArticleDatastatDTO::getArticleId, o -> o));
|
|
|
+ return result.stream().collect(Collectors.toMap(ChangwenArticleDatastat::getArticleId, o -> o));
|
|
|
}
|
|
|
|
|
|
private double getAvgReadCount(String ghId, Integer index) {
|