|
@@ -1,7 +1,9 @@
|
|
|
package com.tzld.piaoquan.recommend.server.service.flowpool;
|
|
|
|
|
|
+import com.tzld.piaoquan.recommend.server.model.Video;
|
|
|
import com.tzld.piaoquan.recommend.server.service.ThreadPoolFactory;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -105,8 +107,6 @@ public class FlowPoolService {
|
|
|
}
|
|
|
|
|
|
Map<Long, Integer> result = getDistributeCount(videoFlowPoolMap);
|
|
|
-
|
|
|
-
|
|
|
// 处理脏数据:分发数<0
|
|
|
Map<Long, String> dirties = videoFlowPoolMap.entrySet().stream()
|
|
|
.filter(e -> result.get(e.getKey()) <= 0)
|
|
@@ -146,10 +146,7 @@ public class FlowPoolService {
|
|
|
if (MapUtils.isEmpty(videoFlowPoolMap)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
-
|
|
|
Map<Long, Integer> result = getDistributeCount(videoFlowPoolMap);
|
|
|
-
|
|
|
-
|
|
|
// 处理脏数据:分发数<0
|
|
|
Map<Long, String> dirties = videoFlowPoolMap.entrySet().stream()
|
|
|
.filter(e -> result.get(e.getKey()) <= 0)
|
|
@@ -185,4 +182,43 @@ public class FlowPoolService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public void updateLocalDistributeCountWithLevel(List<Video> videos) {
|
|
|
+ if (CollectionUtils.isEmpty(videos)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, String> removeMap = updateDistributeCount(videos);
|
|
|
+
|
|
|
+ asyncDelLocalDistributeCountWithLevel(removeMap);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, String> updateDistributeCount(List<Video> videos) {
|
|
|
+ Map<Long, String> removeMap = new HashMap<>();
|
|
|
+ videos.stream().forEach(v -> {
|
|
|
+ String key = String.format(localDistributeCountFormat, v.getVideoId(), v.getFlowPool());
|
|
|
+ Long count = redisTemplate.opsForValue().decrement(key);
|
|
|
+ if (count <= 0) {
|
|
|
+ removeMap.put(v.getVideoId(), v.getFlowPool());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return removeMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateLocalDistributeCountWithLevelScore(List<Video> videos) {
|
|
|
+ if (CollectionUtils.isEmpty(videos)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, String> removeMap = updateDistributeCount(videos);
|
|
|
+
|
|
|
+ asyncDelLocalDistributeCountWithLevelScore(removeMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateLocalDistributeCount(List<Video> videos) {
|
|
|
+ if (CollectionUtils.isEmpty(videos)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, String> removeMap = updateDistributeCount(videos);
|
|
|
+
|
|
|
+ asyncDelLocalDistributeCountWithScore(removeMap);
|
|
|
+ }
|
|
|
}
|