|
@@ -1,8 +1,12 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.recommend.score.strategy;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.StatusEnum;
|
|
|
import com.tzld.longarticle.recommend.server.model.dto.Content;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.AccountCategory;
|
|
|
import com.tzld.longarticle.recommend.server.repository.aigc.CrawlerMetaArticleRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.longArticle.AccountCategoryRepository;
|
|
|
import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
|
|
|
import com.tzld.longarticle.recommend.server.service.recommend.score.AccountCategoryWeightConfig;
|
|
|
import com.tzld.longarticle.recommend.server.service.recommend.score.Score;
|
|
@@ -12,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -24,6 +29,8 @@ public class CategoryStrategy implements ScoreStrategy {
|
|
|
CrawlerMetaArticleRepository crawlerMetaArticleRepository;
|
|
|
@Autowired
|
|
|
AccountContentPoolConfigService accountContentPoolConfigService;
|
|
|
+ @Autowired
|
|
|
+ AccountCategoryRepository accountCategoryRepository;
|
|
|
|
|
|
@ApolloJsonValue("${accountCategoryWeightConfig:{}}")
|
|
|
private Map<String, AccountCategoryWeightConfig[]> accountCategoryWeightConfigMap;
|
|
@@ -36,12 +43,11 @@ public class CategoryStrategy implements ScoreStrategy {
|
|
|
if (CollectionUtils.isEmpty(param.getContents())) {
|
|
|
return scores;
|
|
|
}
|
|
|
- AccountCategoryWeightConfig[] categoryWeightConfigList = accountCategoryWeightConfigMap.get(param.getAccountName());
|
|
|
- if (Objects.isNull(categoryWeightConfigList) || categoryWeightConfigList.length == 0) {
|
|
|
+ AccountCategory accountCategory = accountCategoryRepository.getByGhIdAndStatus(param.getGhId(), StatusEnum.ONE.getCode());
|
|
|
+ if (Objects.isNull(accountCategory) || StringUtils.hasText(accountCategory.getCategoryMap())) {
|
|
|
return scores;
|
|
|
}
|
|
|
- Map<Integer, AccountCategoryWeightConfig> categoryWeightConfigMap = Arrays.stream(categoryWeightConfigList).collect(Collectors.toMap(AccountCategoryWeightConfig::getIndex, o -> o));
|
|
|
- String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
|
|
|
+ Map<String, Double> categoryWeightMap = JSONObject.parseObject(accountCategory.getCategoryMap()).toJavaObject(HashMap.class);
|
|
|
for (Content content : param.getContents()) {
|
|
|
if (CollectionUtils.isEmpty(content.getCategory())) {
|
|
|
continue;
|
|
@@ -49,19 +55,14 @@ public class CategoryStrategy implements ScoreStrategy {
|
|
|
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 (content.getCategory().contains(categoryWeight.getCategory())) {
|
|
|
- score.setScore(Double.valueOf(categoryWeight.getWeight()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ double scoreValue = 0.0;
|
|
|
+ for (String category : content.getCategory()) {
|
|
|
+ if (!categoryWeightMap.containsKey(category)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ scoreValue += categoryWeightMap.get(category);
|
|
|
}
|
|
|
+ score.setScore(scoreValue);
|
|
|
scores.add(score);
|
|
|
}
|
|
|
log.info("CategoryStrategy cost:{}", System.currentTimeMillis() - start);
|