|
@@ -0,0 +1,67 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.score.strategy;
|
|
|
+
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.aigc.CrawlerMetaArticleRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.AccountCategoryWeightConfig;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.Score;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
|
|
|
+import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
|
|
|
+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.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class CategoryStrategy implements ScoreStrategy {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CrawlerMetaArticleRepository crawlerMetaArticleRepository;
|
|
|
+ @Autowired
|
|
|
+ AccountContentPoolConfigService accountContentPoolConfigService;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${accountCategoryWeightConfig:{}}")
|
|
|
+ private Map<String, AccountCategoryWeightConfig[]> accountCategoryWeightConfigMap;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Score> score(ScoreParam param) {
|
|
|
+ List<Score> scores = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isEmpty(param.getContents())) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ AccountCategoryWeightConfig[] categoryWeightConfigList = accountCategoryWeightConfigMap.get(param.getAccountName());
|
|
|
+ if (Objects.isNull(categoryWeightConfigList) || categoryWeightConfigList.length == 0) {
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+ Map<Integer, AccountCategoryWeightConfig> categoryWeightConfigMap = Arrays.stream(categoryWeightConfigList).collect(Collectors.toMap(AccountCategoryWeightConfig::getIndex, o -> o));
|
|
|
+ String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
|
|
|
+ for (Content content : param.getContents()) {
|
|
|
+ Score score = new Score();
|
|
|
+ score.setStrategy(this);
|
|
|
+ score.setContentId(content.getId());
|
|
|
+ for (int i = 0; i < contentPools.length; i++) {
|
|
|
+ if (contentPools[i].equals(content.getContentPoolType())) {
|
|
|
+ AccountCategoryWeightConfig categoryWeightConfig = categoryWeightConfigMap.get(i+1);
|
|
|
+ if (Objects.nonNull(categoryWeightConfig)) {
|
|
|
+ List<AccountCategoryWeightConfig.CategoryWeight> categoryWeightList = categoryWeightConfig.getCategoryWeightList();
|
|
|
+ for (AccountCategoryWeightConfig.CategoryWeight categoryWeight : categoryWeightList) {
|
|
|
+ if (categoryWeight.getCategory().equals(content.getCategory())) {
|
|
|
+ score.setScore(categoryWeight.getWeight());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ scores.add(score);
|
|
|
+ }
|
|
|
+
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|