|
@@ -4,6 +4,8 @@ package com.tzld.longarticle.recommend.server.service.recommend.rank;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.ctrip.framework.apollo.model.ConfigChangeEvent;
|
|
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
|
|
import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
|
|
|
import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
|
|
import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
|
|
@@ -31,27 +33,35 @@ import static com.tzld.longarticle.recommend.server.common.constant.SceneConstan
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class RankService implements InitializingBean {
|
|
public class RankService implements InitializingBean {
|
|
|
|
|
|
|
|
- private static Map<String, Map<Integer, Integer>> staticAccountPoolSourceTypeMap;
|
|
|
|
|
|
|
+ private static Map<String, Map<String, Integer>> staticStrategyPoolSourceTypeMap;
|
|
|
|
|
|
|
|
- @ApolloJsonValue("${accountPoolSourceTypeConfig:{}}")
|
|
|
|
|
- private Map<String, Map<Integer, Integer>> accountPoolSourceTypeMap;
|
|
|
|
|
|
|
+ @ApolloJsonValue("${strategyPoolSourceTypeConfig:{}}")
|
|
|
|
|
+ private Map<String, Map<String, Integer>> strategyPoolSourceTypeMap;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
- RankService.staticAccountPoolSourceTypeMap = accountPoolSourceTypeMap;
|
|
|
|
|
|
|
+ RankService.staticStrategyPoolSourceTypeMap = strategyPoolSourceTypeMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static Integer getAccountPoolSourceType(String ghId, Integer index) {
|
|
|
|
|
|
|
+ @ApolloConfigChangeListener(interestedKeys = {"strategyPoolSourceTypeConfig"})
|
|
|
|
|
+ public void configChange(ConfigChangeEvent changeEvent) {
|
|
|
|
|
+ RankService.staticStrategyPoolSourceTypeMap = JSONObject.parseObject(changeEvent.getChange(
|
|
|
|
|
+ "strategyPoolSourceTypeConfig").getNewValue(), Map.class);
|
|
|
|
|
+ log.info("strategyPoolSourceTypeConfig change updateStaticValue success newValue:{}",
|
|
|
|
|
+ JSONObject.toJSONString(staticStrategyPoolSourceTypeMap));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static Integer getStrategyPoolSourceType(String strategy, Integer index) {
|
|
|
Integer sourceType = 0;
|
|
Integer sourceType = 0;
|
|
|
- Map<Integer, Integer> indexSourceTypeMap = staticAccountPoolSourceTypeMap.get(ghId);
|
|
|
|
|
|
|
+ Map<String, Integer> indexSourceTypeMap = staticStrategyPoolSourceTypeMap.get(strategy);
|
|
|
if (Objects.nonNull(indexSourceTypeMap)) {
|
|
if (Objects.nonNull(indexSourceTypeMap)) {
|
|
|
- sourceType = indexSourceTypeMap.get(index);
|
|
|
|
|
|
|
+ sourceType = indexSourceTypeMap.get(String.valueOf(index));
|
|
|
}
|
|
}
|
|
|
return sourceType;
|
|
return sourceType;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static Map<Integer, Integer> getAccountPoolSourceType(String ghId) {
|
|
|
|
|
- return staticAccountPoolSourceTypeMap.get(ghId);
|
|
|
|
|
|
|
+ public static Map<String, Integer> getStrategyPoolSourceType(String strategy) {
|
|
|
|
|
+ return staticStrategyPoolSourceTypeMap.get(strategy);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public RankResult rank(RankParam param) {
|
|
public RankResult rank(RankParam param) {
|
|
@@ -93,9 +103,7 @@ public class RankService implements InitializingBean {
|
|
|
Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap) {
|
|
Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap) {
|
|
|
List<Content> pool = contentMap.get(contentPools[1]);
|
|
List<Content> pool = contentMap.get(contentPools[1]);
|
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
- Integer sourceType = getAccountPoolSourceType(param.getGhId(), 2);
|
|
|
|
|
- Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
|
|
|
|
|
- pool = contentSourceTypeFilter(videoSourceType, pool, sourceType);
|
|
|
|
|
|
|
+ pool = contentSourceTypeFilter(param.getStrategy(), pool, 2);
|
|
|
}
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
int i = RandomUtils.nextInt(0, Math.min(pool.size(), 5));
|
|
int i = RandomUtils.nextInt(0, Math.min(pool.size(), 5));
|
|
@@ -131,7 +139,12 @@ public class RankService implements InitializingBean {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static List<Content> contentSourceTypeFilter(Integer videoSourceType, List<Content> pool, Integer sourceType) {
|
|
|
|
|
|
|
+ public static List<Content> contentSourceTypeFilter(String strategy, List<Content> pool, Integer index) {
|
|
|
|
|
+ if (!staticStrategyPoolSourceTypeMap.containsKey(strategy)) {
|
|
|
|
|
+ return pool;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer sourceType = getStrategyPoolSourceType(strategy, index);
|
|
|
|
|
+ Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
|
|
|
if (Objects.nonNull(sourceType) && sourceType.equals(videoSourceType)) {
|
|
if (Objects.nonNull(sourceType) && sourceType.equals(videoSourceType)) {
|
|
|
pool = pool.stream().filter(o -> Objects.equals(o.getSourceType(), videoSourceType)).collect(Collectors.toList());
|
|
pool = pool.stream().filter(o -> Objects.equals(o.getSourceType(), videoSourceType)).collect(Collectors.toList());
|
|
|
} else {
|
|
} else {
|
|
@@ -144,9 +157,7 @@ public class RankService implements InitializingBean {
|
|
|
Map<String, List<Content>> contentMap, String strategy) {
|
|
Map<String, List<Content>> contentMap, String strategy) {
|
|
|
List<Content> pool = contentMap.get(contentPools[2]);
|
|
List<Content> pool = contentMap.get(contentPools[2]);
|
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
- Integer sourceType = getAccountPoolSourceType(param.getGhId(), 3);
|
|
|
|
|
- Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
|
|
|
|
|
- pool = contentSourceTypeFilter(videoSourceType, pool, sourceType);
|
|
|
|
|
|
|
+ pool = contentSourceTypeFilter(param.getStrategy(), pool, 3);
|
|
|
}
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
|
|
if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
|
|
|
RankService.printSortLog(strategy, param.getAccountName(), "3-8", pool.subList(0, Math.min(pool.size(), 200)));
|
|
RankService.printSortLog(strategy, param.getAccountName(), "3-8", pool.subList(0, Math.min(pool.size(), 200)));
|