|
@@ -13,10 +13,10 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
@@ -38,6 +38,12 @@ public class CategoryStrategy implements ScoreStrategy {
|
|
|
@Value("${category.active.version:1}")
|
|
|
private Integer activeVersion;
|
|
|
|
|
|
+ @ApolloJsonValue("${category.strategy.add.account.list:[]}")
|
|
|
+ private List<String> categoryAddAccountList;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${category.strategy.add.score:{}}")
|
|
|
+ private Map<String, Double> categoryAddScoreConfig;
|
|
|
+
|
|
|
@Override
|
|
|
public List<Score> score(ScoreParam param) {
|
|
|
long start = System.currentTimeMillis();
|
|
@@ -47,16 +53,12 @@ public class CategoryStrategy implements ScoreStrategy {
|
|
|
}
|
|
|
List<AccountCategory> accountCategoryList = accountCategoryRepository.getByGhIdAndStatusAndVersion(
|
|
|
param.getGhId(), StatusEnum.ONE.getCode(), activeVersion);
|
|
|
- if (CollectionUtils.isEmpty(accountCategoryList)) {
|
|
|
- return scores;
|
|
|
+ AccountCategory accountCategory = null;
|
|
|
+ if (CollectionUtils.isNotEmpty(accountCategoryList)) {
|
|
|
+ accountCategory = accountCategoryList.stream()
|
|
|
+ .sorted(Comparator.comparing(AccountCategory::getDt, Comparator.reverseOrder()))
|
|
|
+ .findFirst().get();
|
|
|
}
|
|
|
- AccountCategory accountCategory = accountCategoryList.stream()
|
|
|
- .sorted(Comparator.comparing(AccountCategory::getDt, Comparator.reverseOrder()))
|
|
|
- .findFirst().get();
|
|
|
- if (!StringUtils.hasText(accountCategory.getCategoryMap())) {
|
|
|
- return scores;
|
|
|
- }
|
|
|
- JSONObject categoryWeightMap = JSONObject.parseObject(accountCategory.getCategoryMap());
|
|
|
for (Content content : param.getContents()) {
|
|
|
if (CollectionUtils.isEmpty(content.getCategory())) {
|
|
|
continue;
|
|
@@ -65,11 +67,19 @@ public class CategoryStrategy implements ScoreStrategy {
|
|
|
score.setStrategy(this);
|
|
|
score.setContentId(content.getId());
|
|
|
double scoreValue = 0.0;
|
|
|
+ double categoryWeight = 0.0;
|
|
|
for (String category : content.getCategory()) {
|
|
|
- if (!categoryWeightMap.containsKey(category)) {
|
|
|
- continue;
|
|
|
+ if (Objects.nonNull(accountCategory) && StringUtils.hasText(accountCategory.getCategoryMap())) {
|
|
|
+ JSONObject categoryWeightMap = JSONObject.parseObject(accountCategory.getCategoryMap());
|
|
|
+ categoryWeight = categoryWeightMap.getDoubleValue(category);
|
|
|
+ scoreValue += categoryWeight;
|
|
|
+ }
|
|
|
+ if (categoryAddAccountList.contains(param.getAccountName()) && categoryWeight >= 0) {
|
|
|
+ Double addScore = categoryAddScoreConfig.get(category);
|
|
|
+ if (Objects.nonNull(addScore)) {
|
|
|
+ scoreValue += addScore;
|
|
|
+ }
|
|
|
}
|
|
|
- scoreValue += categoryWeightMap.getDoubleValue(category);
|
|
|
}
|
|
|
score.setScore(scoreValue);
|
|
|
scores.add(score);
|