|
@@ -2,6 +2,8 @@ package com.tzld.longarticle.recommend.server.service.score.strategy;
|
|
|
|
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
import com.tzld.longarticle.recommend.server.model.ContentHisPublishArticle;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.entity.crawler.AccountAvgInfo;
|
|
|
import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
|
|
|
import com.tzld.longarticle.recommend.server.service.AccountIndexAvgViewCountService;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.Score;
|
|
@@ -12,7 +14,11 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
|
@Slf4j
|
|
@@ -21,19 +27,31 @@ public class ViewCountRateStrategy implements ScoreStrategy {
|
|
|
@Autowired
|
|
|
AccountIndexAvgViewCountService accountIndexAvgViewCountService;
|
|
|
@Autowired
|
|
|
- private AccountContentPoolConfigService accountContentPoolConfigService;
|
|
|
+ AccountContentPoolConfigService accountContentPoolConfigService;
|
|
|
+ @Autowired
|
|
|
+ AccountAvgInfoRepository accountAvgInfoRepository;
|
|
|
|
|
|
@Override
|
|
|
public List<Score> score(ScoreParam param) {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
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);
|
|
|
for (Content content : param.getContents()) {
|
|
|
- String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
|
|
|
for (int i = 0; i < contentPools.length; i++) {
|
|
|
if (!contentPools[i].equals(content.getContentPoolType())) {
|
|
|
continue;
|
|
|
}
|
|
|
- double avgViewCountPos = accountIndexAvgViewCountService.getAvgReadCountByDB(param.getGhId(), i + 1);
|
|
|
- double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCountByDB(param.getGhId(), 1);
|
|
|
+ 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 showViewCountSum = 0D;
|
|
|
double avgViewCountSum = 0D;
|
|
|
double showViewCountSumFirst = 0D;
|
|
@@ -88,6 +106,7 @@ public class ViewCountRateStrategy implements ScoreStrategy {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ log.info("ViewCountRateStrategy cost:{}", System.currentTimeMillis() - start);
|
|
|
return scores;
|
|
|
}
|
|
|
}
|