/**
* 游戏视频列表
* @Author: yjw 2022-12-12
* @return:
*/
public List<VideoEntity> videoList(Vo vo){
Integer count = videoDao.listVideoTotal(vo);
//视频总数超过分页时获取随机分页起始index
if (count > vo.getPageSize){
Random r = new Random();
int random = r.nextInt(count - vo.getPageSize);
vo.setStart(random);
}
List<VideoEntity> videos1 = videoDao.listVideo(vo); //随机分页集合
if (count > vo.getPageSize && vo.getPage == 1){
List<VideoEntity> videos2 = videoDao.listVideo2(vo); //关注喜好作者集合
//首次获取视频若有关注喜好作者,提升关注作者作品比例,并去重
if (videos2 != null && videos2.size() > 0){
videos2.addAll(videos1);
Map<String, VideoEntity> m = new HashMap<>();
videos2.stream()
.forEach(v -> {
VideoEntity ve = m.get(v.getId().toString());
if (ve == null && m.size() < vo.getPageSize){
m.put(v.getId().toString(), v);
}
});
videos1 = m.values().stream().collect(Collectors.toList());
}
}
//list乱序
Collections.shuffle(videos1);
return videos1;
}
简易首屏随机视频插入一定比例用户关注喜好推荐视频并去重
于 2022-12-13 18:13:39 首次发布