|
@@ -4,6 +4,8 @@ package com.tzld.longarticle.recommend.server.service.recommend.rank;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+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.recommend.RankStrategyEnum;
|
|
|
import com.tzld.longarticle.recommend.server.model.dto.Content;
|
|
|
import com.tzld.longarticle.recommend.server.service.ServiceBeanFactory;
|
|
@@ -12,11 +14,13 @@ import com.tzld.longarticle.recommend.server.service.recommend.score.AccountInde
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.tzld.longarticle.recommend.server.common.constant.SceneConstants.FWH_COLD_START;
|
|
|
|
|
@@ -25,7 +29,30 @@ import static com.tzld.longarticle.recommend.server.common.constant.SceneConstan
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class RankService {
|
|
|
+public class RankService implements InitializingBean {
|
|
|
+
|
|
|
+ private static Map<String, Map<Integer, Integer>> staticAccountPoolSourceTypeMap;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${accountPoolSourceTypeConfig:{}}")
|
|
|
+ private Map<String, Map<Integer, Integer>> accountPoolSourceTypeMap;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() throws Exception {
|
|
|
+ RankService.staticAccountPoolSourceTypeMap = accountPoolSourceTypeMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Integer getAccountPoolSourceType(String ghId, Integer index) {
|
|
|
+ Integer sourceType = 0;
|
|
|
+ Map<Integer, Integer> indexSourceTypeMap = staticAccountPoolSourceTypeMap.get(ghId);
|
|
|
+ if (Objects.nonNull(indexSourceTypeMap)) {
|
|
|
+ sourceType = indexSourceTypeMap.get(index);
|
|
|
+ }
|
|
|
+ return sourceType;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<Integer, Integer> getAccountPoolSourceType(String ghId) {
|
|
|
+ return staticAccountPoolSourceTypeMap.get(ghId);
|
|
|
+ }
|
|
|
|
|
|
public RankResult rank(RankParam param) {
|
|
|
RankStrategy strategy = getRankStrategy(param);
|
|
@@ -60,11 +87,16 @@ public class RankService {
|
|
|
log.info("{} 账号名称 {} {}评分结果 {}", strategy, accountName, position, JSONObject.toJSONString(jsonArray));
|
|
|
}
|
|
|
|
|
|
- public static void commonAddSecondContent(List<Content> result,
|
|
|
+ public static void commonAddSecondContent(RankParam param, List<Content> result,
|
|
|
String[] publishPool, String[] contentPools,
|
|
|
Map<String, List<Content>> contentMap,
|
|
|
Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap) {
|
|
|
List<Content> pool = contentMap.get(contentPools[1]);
|
|
|
+ if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
+ Integer sourceType = getAccountPoolSourceType(param.getGhId(), 2);
|
|
|
+ Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
|
|
|
+ pool = contentSourceTypeFilter(videoSourceType, pool, sourceType);
|
|
|
+ }
|
|
|
if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
int i = RandomUtils.nextInt(0, Math.min(pool.size(), 5));
|
|
|
int j = RandomUtils.nextInt(0, Math.min(pool.size(), 5));
|
|
@@ -82,20 +114,40 @@ public class RankService {
|
|
|
}
|
|
|
} else {
|
|
|
// 替补 根据设置替补内容池查找内容进行替补
|
|
|
- AccountIndexReplacePoolConfig replacePoolConfig = indexReplacePoolConfigMap.get(2);
|
|
|
- if (Objects.nonNull(replacePoolConfig)) {
|
|
|
- List<Content> poolReplace = contentMap.get(replacePoolConfig.getContentPool());
|
|
|
- if (CollectionUtils.isNotEmpty(poolReplace)) {
|
|
|
- publishPool[1] = replacePoolConfig.getContentPool();
|
|
|
- result.add(poolReplace.get(0));
|
|
|
- }
|
|
|
+ findReplacePoolContent(result, publishPool, contentMap, indexReplacePoolConfigMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void findReplacePoolContent(List<Content> result, String[] publishPool,
|
|
|
+ Map<String, List<Content>> contentMap,
|
|
|
+ Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap) {
|
|
|
+ AccountIndexReplacePoolConfig replacePoolConfig = indexReplacePoolConfigMap.get(2);
|
|
|
+ if (Objects.nonNull(replacePoolConfig)) {
|
|
|
+ List<Content> poolReplace = contentMap.get(replacePoolConfig.getContentPool());
|
|
|
+ if (CollectionUtils.isNotEmpty(poolReplace)) {
|
|
|
+ publishPool[1] = replacePoolConfig.getContentPool();
|
|
|
+ result.add(poolReplace.get(0));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static List<Content> contentSourceTypeFilter(Integer videoSourceType, List<Content> pool, Integer sourceType) {
|
|
|
+ if (Objects.nonNull(sourceType) && sourceType.equals(videoSourceType)) {
|
|
|
+ pool = pool.stream().filter(o -> Objects.equals(o.getSourceType(), videoSourceType)).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ pool = pool.stream().filter(o -> !Objects.equals(o.getSourceType(), videoSourceType)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return pool;
|
|
|
+ }
|
|
|
+
|
|
|
public static void commonAdd38Content(RankParam param, List<Content> result, String[] contentPools,
|
|
|
Map<String, List<Content>> contentMap, String strategy) {
|
|
|
List<Content> pool = contentMap.get(contentPools[2]);
|
|
|
+ if (CollectionUtils.isNotEmpty(pool)) {
|
|
|
+ Integer sourceType = getAccountPoolSourceType(param.getGhId(), 3);
|
|
|
+ Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
|
|
|
+ pool = contentSourceTypeFilter(videoSourceType, pool, sourceType);
|
|
|
+ }
|
|
|
if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
|
|
|
RankService.printSortLog(strategy, param.getAccountName(), "3-8", pool.subList(0, Math.min(pool.size(), 200)));
|
|
|
result.addAll(pool.subList(0, Math.min(pool.size(), param.getSize() - result.size())));
|