|
|
@@ -31,10 +31,12 @@ import cn.reghao.tnb.user.api.iface.UserService;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.security.SecureRandom;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -55,6 +57,7 @@ public class VideoPostQueryImpl implements VideoPostQuery {
|
|
|
private final VideoTagMapper videoTagMapper;
|
|
|
private final ContentPermission contentPermission;
|
|
|
private final CategoryService categoryService;
|
|
|
+ private final Random random = new SecureRandom();
|
|
|
|
|
|
public VideoPostQueryImpl(VideoPostMapper videoPostMapper, VideoTagMapper videoTagMapper,
|
|
|
VideoStatisticMapper videoStatisticMapper, VideoCategoryPostMapper videoCategoryPostMapper,
|
|
|
@@ -103,10 +106,12 @@ public class VideoPostQueryImpl implements VideoPostQuery {
|
|
|
}
|
|
|
|
|
|
public VideoDetail getShortVideo() {
|
|
|
- long loginUser = UserContext.getUser();
|
|
|
- List<Integer> userScopes = contentPermission.getUserScopes(loginUser);
|
|
|
- VideoPost videoPost = videoPostMapper.findShortVideo(userScopes);
|
|
|
- String videoId = videoPost.getVideoId();
|
|
|
+ String videoId = getRandomVideoId();
|
|
|
+ if (videoId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ VideoPost videoPost = videoPostMapper.findByVideoId(videoId);
|
|
|
VideoStatistic videoStatistic = videoStatisticMapper.findByVideoId(videoId);
|
|
|
VideoDetail videoDetail = new VideoDetail(videoPost, videoStatistic);
|
|
|
List<String> tags = videoTagMapper.findVideoTags(videoId);
|
|
|
@@ -114,6 +119,20 @@ public class VideoPostQueryImpl implements VideoPostQuery {
|
|
|
return videoDetail;
|
|
|
}
|
|
|
|
|
|
+ private String getRandomVideoId() {
|
|
|
+ long loginUser = UserContext.getUser();
|
|
|
+ List<Integer> userScopes = contentPermission.getUserScopes(loginUser);
|
|
|
+ List<String> videoIds = videoPostMapper.findShortVideo(userScopes);
|
|
|
+ if (videoIds.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ int min = 0;
|
|
|
+ int size = videoIds.size();
|
|
|
+ int randomIdx = min + random.nextInt(size-1 - min);
|
|
|
+ return videoIds.get(randomIdx);
|
|
|
+ }
|
|
|
+
|
|
|
private PageList<VideoCard> getVideoCardsByUserGroup(VideoQuery videoQuery, int pageNumber) {
|
|
|
// int total = videoPostMapper.countByCriteriaAndUserGroup(videoQuery).size();
|
|
|
int total = videoCategoryPostMapper.countByCriteria(videoQuery);
|