|
@@ -6,8 +6,10 @@ import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -15,6 +17,7 @@ import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
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.*;
|
|
|
|
|
|
|
|
@@ -35,6 +38,10 @@ public class FlowPoolService {
|
|
|
|
|
|
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) {
|
|
|
if (CollectionUtils.isEmpty(videos)) {
|
|
|
return;
|
|
@@ -46,6 +53,15 @@ public class FlowPoolService {
|
|
|
}
|
|
|
|
|
|
private void asyncDelDistributeCountWithLevel(Map<Long, String> videoFlowPoolMap) {
|
|
|
+ asyncDelDistributeCountV2(videoFlowPoolMap, (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);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
asyncDelDistributeCountV2(videoFlowPoolMap, (appType, level, values) -> {
|
|
|
redisTemplate.opsForSet().remove(String.format(KEY_WITH_LEVEL_FORMAT_V2, appType, level), values);
|
|
|
});
|
|
@@ -64,6 +80,34 @@ public class FlowPoolService {
|
|
|
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());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (String level : levelWeight.keySet()) {
|
|
|
+ for (int appType : appTypes) {
|
|
|
+ flowPoolRemoveConsumer.accept(appType, level, values);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void asyncDelDistributeCountV2(Map<Long, String> videoFlowPoolMap,
|
|
|
TripleConsumer<Integer, String, String[]> flowPoolRemoveConsumer) {
|
|
|
if (MapUtils.isEmpty(videoFlowPoolMap)) {
|
|
@@ -88,3 +132,4 @@ public class FlowPoolService {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+
|