|
@@ -0,0 +1,60 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.recommend.score.strategy;
|
|
|
+
|
|
|
+import com.tzld.longarticle.recommend.server.model.dto.Content;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
|
|
|
+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.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 抓取时间超过60天的文章,分数减少
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class CrawlerDaysDecreaseStrategy implements ScoreStrategy {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccountContentPoolConfigService accountContentPoolConfigService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Score> score(ScoreParam param) {
|
|
|
+ List<Score> scores = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isEmpty(param.getContents())) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ long now = DateUtils.getTodayStart();
|
|
|
+ for (Content content : param.getContents()) {
|
|
|
+ String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
|
|
|
+ if (!contentPools[2].equals(content.getContentPoolType())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Score score = new Score();
|
|
|
+ score.setStrategy(this);
|
|
|
+ score.setContentId(content.getId());
|
|
|
+ score.setScore(getContentScore(content, now));
|
|
|
+ scores.add(score);
|
|
|
+ }
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getContentScore(Content content, long now) {
|
|
|
+ double maxReleaseScore = -0.15;
|
|
|
+ double minScoreDays = 7;
|
|
|
+ double maxScoreDays = 60.0;
|
|
|
+ int days = (int) ((now - content.getCrawlerTimestamp()) / 86400000);
|
|
|
+ if (days < minScoreDays) {
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ double scoreDays = Math.min(maxScoreDays, Math.max(minScoreDays, days));
|
|
|
+ return maxReleaseScore * ((scoreDays - minScoreDays) / maxScoreDays);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|