|
@@ -5,13 +5,15 @@ import com.tzld.piaoquan.recommend.server.model.Video;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterService;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConfigService;
|
|
|
import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
|
|
|
import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
|
|
|
-import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
|
|
|
import com.tzld.piaoquan.recommend.server.util.RecallUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -23,7 +25,7 @@ import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
-public class DouHotFlowPoolRecallStrategy implements RecallStrategy {
|
|
|
+public class DouHotFlowPoolRecallStrategy extends AbstractFlowPoolWithLevelRecallStrategy {
|
|
|
|
|
|
@Autowired
|
|
|
@Qualifier("redisTemplate")
|
|
@@ -32,18 +34,60 @@ public class DouHotFlowPoolRecallStrategy implements RecallStrategy {
|
|
|
@Autowired
|
|
|
private FilterService filterService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FlowPoolConfigService flowPoolConfigService;
|
|
|
+
|
|
|
@Value("${dou.hot.recall.video.count:20}")
|
|
|
private Integer douHotRecallVideoCnt;
|
|
|
|
|
|
public static final String PUSH_FROM = "recall_strategy_hotspot";
|
|
|
|
|
|
+ @Override
|
|
|
+ Pair<String, String> flowPoolKeyAndLevel(RecallParam param) {
|
|
|
+
|
|
|
+ Map<String, Double> douHotFLowPoolWithLevel = flowPoolConfigService.getDouHotFLowPoolWithLevel();
|
|
|
+ if (MapUtils.isEmpty(douHotFLowPoolWithLevel)) {
|
|
|
+ return Pair.of("", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ double totalWeight = 0;
|
|
|
+ NavigableMap<Double, String> levelMap = new TreeMap<>();
|
|
|
+ for (Map.Entry<String, Double> entry : douHotFLowPoolWithLevel.entrySet()) {
|
|
|
+ String redisKey = String.format(RedisKeyConstants.DouHot.ITEM_REDIS_KEY_FORMAT, RecallUtils.douHotProvinceConvert(param.getProvince()), entry.getKey());
|
|
|
+ if (redisTemplate.hasKey(redisKey)) {
|
|
|
+ totalWeight += entry.getValue();
|
|
|
+ levelMap.put(totalWeight, entry.getKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (MapUtils.isEmpty(levelMap)) {
|
|
|
+ return Pair.of("", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ double randomValue = Math.random() * totalWeight;
|
|
|
+ Map.Entry<Double, String> chooseEntry = levelMap.higherEntry(randomValue);
|
|
|
+ if (Objects.isNull(chooseEntry)) {
|
|
|
+ return Pair.of("", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ String redisKey = String.format(RedisKeyConstants.DouHot.ITEM_REDIS_KEY_FORMAT, RecallUtils.douHotProvinceConvert(param.getProvince()), chooseEntry.getValue());
|
|
|
+
|
|
|
+ return Pair.of(redisKey, chooseEntry.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Video> recall(RecallParam param) {
|
|
|
if (StringUtils.isBlank(param.getProvince())) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
- String redisKey = String.format(RedisKeyConstants.DouHot.ITEM_REDIS_KEY_FORMAT, RecallUtils.douHotProvinceConvert(param.getProvince()), "1");
|
|
|
+ Pair<String, String> weightPair = this.flowPoolKeyAndLevel(param);
|
|
|
+ if (Objects.isNull(weightPair)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ String redisKey = weightPair.getLeft();
|
|
|
+ String level = weightPair.getRight();
|
|
|
// log.info("[DouHot recall redisKey] {}", redisKey);
|
|
|
Set<ZSetOperations.TypedTuple<String>> redisValues = redisTemplate.opsForZSet().rangeWithScores(redisKey, 0, 10000000);
|
|
|
|
|
@@ -82,8 +126,7 @@ public class DouHotFlowPoolRecallStrategy implements RecallStrategy {
|
|
|
video.setVideoId(videoId);
|
|
|
video.setFlowPool(videoIdAndFlowPoolMap.get(videoId));
|
|
|
video.setPushFrom(pushFrom());
|
|
|
- // 热点宝供给目前只有一层,所以写死
|
|
|
- video.setLevel("1");
|
|
|
+ video.setLevel(level);
|
|
|
videos.add(video);
|
|
|
}
|
|
|
|