|
@@ -1,6 +1,9 @@
|
|
|
package com.tzld.piaoquan.recommend.server.service.filter.strategy;
|
|
|
|
|
|
+import com.google.common.base.Stopwatch;
|
|
|
import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
|
|
|
+import com.tzld.piaoquan.recommend.server.repository.VideoAppTypeStatus;
|
|
|
+import com.tzld.piaoquan.recommend.server.repository.VideoAppTypeStatusRepository;
|
|
|
import com.tzld.piaoquan.recommend.server.repository.WxVideoStatus;
|
|
|
import com.tzld.piaoquan.recommend.server.repository.WxVideoStatusRepository;
|
|
|
import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
|
|
@@ -33,10 +36,19 @@ public class RecommendStatusStrategy implements FilterStrategy {
|
|
|
@Qualifier("redisTemplate")
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("videoRedisTemplate")
|
|
|
+ private RedisTemplate<String, String> videoRedisTemplate;
|
|
|
+
|
|
|
@Autowired
|
|
|
private WxVideoStatusRepository wxVideoStatusRepository;
|
|
|
|
|
|
- private String keyFormat = "video:recommend:status:%s";
|
|
|
+ @Autowired
|
|
|
+ private VideoAppTypeStatusRepository videoAppTypeStatusRepository;
|
|
|
+
|
|
|
+ private final String keyFormat = "video:recommend:status:%s";
|
|
|
+
|
|
|
+ private final String videoAppTypeStatusKeyFormat = "video:active:status:%s:%s";
|
|
|
|
|
|
private static final int RECOMMEND_STATUS = -6;
|
|
|
|
|
@@ -90,9 +102,61 @@ public class RecommendStatusStrategy implements FilterStrategy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return param.getVideoIds().stream()
|
|
|
+ List<Long> filterAfterRecommendStatus = param.getVideoIds().stream()
|
|
|
.filter(id -> recommendStatusMap.containsKey(id) && recommendStatusMap.get(id) == RECOMMEND_STATUS)
|
|
|
.collect(Collectors.toList());
|
|
|
+
|
|
|
+ filterActiveStatusVideoId(filterAfterRecommendStatus, param.getAppType());
|
|
|
+
|
|
|
+ return filterAfterRecommendStatus;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 过滤上下架状态
|
|
|
+ * <p>
|
|
|
+ * 紧急需求上线
|
|
|
+ * 性能待优化
|
|
|
+ *
|
|
|
+ * @param idList videoId列表
|
|
|
+ * @param appType appType
|
|
|
+ */
|
|
|
+ private void filterActiveStatusVideoId(List<Long> idList, Integer appType) {
|
|
|
+ Stopwatch stopwatch = Stopwatch.createStarted();
|
|
|
+ if (CollectionUtils.isEmpty(idList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Iterator<Long> iterator = idList.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Long videoId = iterator.next();
|
|
|
+ if (Objects.isNull(videoId)) {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String activeStatus = videoRedisTemplate.opsForValue().get(String.format(videoAppTypeStatusKeyFormat, appType, videoId));
|
|
|
+ if (Objects.isNull(activeStatus)) {
|
|
|
+ //查库
|
|
|
+ List<VideoAppTypeStatus> videoAppTypeVideoStatusList =
|
|
|
+ videoAppTypeStatusRepository.findAllByVideoIdAndAppType(videoId, appType);
|
|
|
+ if (Objects.isNull(videoAppTypeVideoStatusList) || videoAppTypeVideoStatusList.isEmpty()) {
|
|
|
+ //无数据 刷1 进redis
|
|
|
+ videoRedisTemplate.opsForValue().set(String.format(videoAppTypeStatusKeyFormat, appType, videoId), "1"
|
|
|
+ , 15, TimeUnit.DAYS);
|
|
|
+ activeStatus = "1";
|
|
|
+ } else {
|
|
|
+ VideoAppTypeStatus videoAppTypeStatus = videoAppTypeVideoStatusList.get(0);
|
|
|
+ if (Objects.nonNull(videoAppTypeStatus) && Objects.nonNull(videoAppTypeStatus.getVideoStatus())) {
|
|
|
+ String videoStatus = videoAppTypeStatus.getVideoStatus().toString();
|
|
|
+ videoRedisTemplate.opsForValue().set(String.format(videoAppTypeStatusKeyFormat, appType, videoId), videoStatus
|
|
|
+ , 15, TimeUnit.DAYS);
|
|
|
+ activeStatus = videoStatus;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Objects.equals("0", activeStatus)) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|