|
@@ -1,67 +1,78 @@
|
|
|
package com.tzld.piaoquan.recommend.server.service.filter.strategy;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.google.common.hash.Hashing;
|
|
|
import com.tzld.piaoquan.recommend.server.common.enums.AppTypeEnum;
|
|
|
-import com.tzld.piaoquan.recommend.server.service.PreViewedService;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterStrategy;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
* @author dyp
|
|
|
*/
|
|
|
@Component
|
|
|
+@Slf4j
|
|
|
public class AllowListStrategy implements FilterStrategy {
|
|
|
@Autowired
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
private static final String VIDEO_ALLOW_LIST_BITMAP_KEY_PREFIX = "movie:videoid:allowlist:";
|
|
|
private static final String VIDEO_ALLOW_LIST_BITMAP_KEY_SET_PREFIX = "movie:videoid:allowSet:";
|
|
|
+ private static final String VIDEO_ALLOW_LIST_BITMAP_KEY = "movie.store.mp.allowlist.videoid.bitmap";
|
|
|
+ private static final String RELIGION_VIDEO_ALLOW_LIST_BITMAP_KEY = "mp:religion:allowlist:videoid:bitmap";
|
|
|
+ @Value("${movie.videoid.allowlist.compatible:1}")
|
|
|
+ private Integer mvalCompatible;
|
|
|
|
|
|
@Override
|
|
|
+
|
|
|
public List<Long> filter(FilterParam param) {
|
|
|
|
|
|
if (param == null
|
|
|
- || CollectionUtils.isEmpty(param.getVideoIds()) {
|
|
|
+ || CollectionUtils.isEmpty(param.getVideoIds())) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
+ Set<Long> retainVideoIds = new LinkedHashSet<>();
|
|
|
if (param.getAppType() != AppTypeEnum.WAN_NENG_VIDEO.getCode()
|
|
|
&& param.getAppType() != AppTypeEnum.LAO_HAO_KAN_VIDEO.getCode()
|
|
|
&& param.getAppType() != AppTypeEnum.ZUI_JING_QI.getCode()
|
|
|
&& param.getAppType() != AppTypeEnum.H5.getCode()) {
|
|
|
|
|
|
- Iterator<Long> iterator = videoIds.iterator();
|
|
|
+ Iterator<Long> iterator = param.getVideoIds().iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
Long videoId = iterator.next();
|
|
|
-
|
|
|
- if (movieStoreMpService.isMemberOfAllowList(videoId)) {
|
|
|
- iterator.remove();
|
|
|
+
|
|
|
+ if (!isMemberOfVideoAllowList(videoId)) {
|
|
|
+ retainVideoIds.add(videoId);
|
|
|
}
|
|
|
}
|
|
|
- } else if (param.getAppType() != AppTypeEnum.WAN_NENG_VIDEO.getCode()
|
|
|
- && param.getAppType() != AppTypeEnum.LAO_HAO_KAN_VIDEO.getCode()
|
|
|
- && param.getAppType() != AppTypeEnum.ZUI_JING_QI.getCode()
|
|
|
- && param.getAppType() != AppTypeEnum.H5.getCode()) {
|
|
|
+ } else if (param.getAppType() == AppTypeEnum.WAN_NENG_VIDEO.getCode()
|
|
|
+ || param.getAppType() == AppTypeEnum.LAO_HAO_KAN_VIDEO.getCode()
|
|
|
+ || param.getAppType() == AppTypeEnum.ZUI_JING_QI.getCode()
|
|
|
+ || param.getAppType() == AppTypeEnum.H5.getCode()) {
|
|
|
+ Iterator<Long> iterator = param.getVideoIds().iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
Long videoId = iterator.next();
|
|
|
-
|
|
|
- if (movieStoreMpService.isMemberOfReligionVideoAllowList(videoId)) {
|
|
|
- iterator.remove();
|
|
|
+
|
|
|
+ if (!isMemberOfReligionVideoAllowList(videoId)) {
|
|
|
+ retainVideoIds.add(videoId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return videoIds;
|
|
|
+ if (CollectionUtils.isEmpty(retainVideoIds)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ return Lists.newArrayList(retainVideoIds);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private boolean isMemberOfVideoAllowList(Long videoId) {
|
|
|
if (Objects.isNull(videoId)) {
|
|
|
return false;
|
|
@@ -73,14 +84,26 @@ public class AllowListStrategy implements FilterStrategy {
|
|
|
|
|
|
if (Objects.equals(1, mvalCompatible) && !result) {
|
|
|
int idx = Math.abs(Hashing.murmur3_32().hashLong(videoId).asInt()) % 10;
|
|
|
- result = redisUtils.getBit(VIDEO_ALLOW_LIST_BITMAP_KEY_PREFIX + idx, videoId);
|
|
|
+ result = redisTemplate.opsForValue().getBit(VIDEO_ALLOW_LIST_BITMAP_KEY_PREFIX + idx, videoId);
|
|
|
}
|
|
|
if (Objects.equals(1, mvalCompatible) && !result) {
|
|
|
- result = redisUtils.getBit(VIDEO_ALLOW_LIST_BITMAP_KEY, videoId);
|
|
|
+ result = redisTemplate.opsForValue().getBit(VIDEO_ALLOW_LIST_BITMAP_KEY, videoId);
|
|
|
}
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
- LOGGER.error("isMemberOfVideoAllowList error {}", videoId, e);
|
|
|
+ log.error("isMemberOfVideoAllowList error {}", videoId, e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isMemberOfReligionVideoAllowList(Long videoId) {
|
|
|
+ if (Objects.isNull(videoId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return redisTemplate.opsForValue().getBit(RELIGION_VIDEO_ALLOW_LIST_BITMAP_KEY, videoId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("isMemberOfReligionVideoAllowList error {}", e, videoId);
|
|
|
}
|
|
|
return false;
|
|
|
}
|