|
@@ -15,6 +15,7 @@ import java.util.*;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+import static com.tzld.piaoquan.recommend.server.common.enums.AppTypeEnum.*;
|
|
import static com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants.*;
|
|
import static com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -35,6 +36,10 @@ public class FlowPoolService {
|
|
|
|
|
|
private ExecutorService pool = ThreadPoolFactory.defaultPool();
|
|
private ExecutorService pool = ThreadPoolFactory.defaultPool();
|
|
|
|
|
|
|
|
+ private int[] appTypes = {VLOG.getCode(), LOVE_MOVIE.getCode(), LOVE_LIVE.getCode(), LONG_VIDEO.getCode(),
|
|
|
|
+ SHORT_VIDEO.getCode(), H5.getCode(), APP_SPEED.getCode(), WAN_NENG_VIDEO.getCode(),
|
|
|
|
+ LAO_HAO_KAN_VIDEO.getCode(), ZUI_JING_QI.getCode(), PIAO_QUAN_VIDEO_PLUS.getCode(), JOURNEY.getCode()};
|
|
|
|
+
|
|
public void updateDistributeCountWithLevel(List<Video> videos) {
|
|
public void updateDistributeCountWithLevel(List<Video> videos) {
|
|
if (CollectionUtils.isEmpty(videos)) {
|
|
if (CollectionUtils.isEmpty(videos)) {
|
|
return;
|
|
return;
|
|
@@ -49,6 +54,10 @@ public class FlowPoolService {
|
|
asyncDelDistributeCountV2(videoFlowPoolMap, (appType, level, values) -> {
|
|
asyncDelDistributeCountV2(videoFlowPoolMap, (appType, level, values) -> {
|
|
redisTemplate.opsForSet().remove(String.format(KEY_WITH_LEVEL_FORMAT_V2, appType, level), values);
|
|
redisTemplate.opsForSet().remove(String.format(KEY_WITH_LEVEL_FORMAT_V2, appType, level), values);
|
|
});
|
|
});
|
|
|
|
+ asyncDelDistributeCount(videoFlowPoolMap, (appType, level, values) -> {
|
|
|
|
+ String key = String.format(KEY_WITH_LEVEL_FORMAT, appType, level);
|
|
|
|
+ Long count = redisTemplate.opsForSet().remove(key, values);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
private Map<Long, String> updateDistributeCount(List<Video> videos) {
|
|
private Map<Long, String> updateDistributeCount(List<Video> videos) {
|
|
@@ -64,6 +73,34 @@ public class FlowPoolService {
|
|
return removeMap;
|
|
return removeMap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void asyncDelDistributeCount(Map<Long, String> videoFlowPoolMap,
|
|
|
|
+ TripleConsumer<Integer, String, String[]> flowPoolRemoveConsumer) {
|
|
|
|
+ if (MapUtils.isEmpty(videoFlowPoolMap)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ pool.execute(() -> {
|
|
|
|
+ List<String> keys = videoFlowPoolMap.entrySet().stream()
|
|
|
|
+ .map(v -> String.format(localDistributeCountFormat, v.getKey(), v.getValue()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ redisTemplate.delete(keys);
|
|
|
|
+
|
|
|
|
+ Map<String, Double> levelWeight = flowPoolConfigService.getLevelWeight4FlowPoolWithLevel();
|
|
|
|
+ String[] values = new String[videoFlowPoolMap.size()];
|
|
|
|
+ int i = 0;
|
|
|
|
+ for (Map.Entry v : videoFlowPoolMap.entrySet()) {
|
|
|
|
+ values[i++] = String.format(valueFormat, v.getKey(), v.getValue());
|
|
|
|
+ }
|
|
|
|
+ // remove 每小程序每层的数据
|
|
|
|
+ // TODO 现在视频只会出现在一个层级,所以可以做个优化
|
|
|
|
+ for (String level : levelWeight.keySet()) {
|
|
|
|
+ for (int appType : appTypes) {
|
|
|
|
+ flowPoolRemoveConsumer.accept(appType, level, values);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private void asyncDelDistributeCountV2(Map<Long, String> videoFlowPoolMap,
|
|
private void asyncDelDistributeCountV2(Map<Long, String> videoFlowPoolMap,
|
|
TripleConsumer<Integer, String, String[]> flowPoolRemoveConsumer) {
|
|
TripleConsumer<Integer, String, String[]> flowPoolRemoveConsumer) {
|
|
if (MapUtils.isEmpty(videoFlowPoolMap)) {
|
|
if (MapUtils.isEmpty(videoFlowPoolMap)) {
|
|
@@ -88,3 +125,4 @@ public class FlowPoolService {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|