123
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.cai.manager;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.cai.constant.RedisHttpConstant;
|
||||
import com.ruoyi.cai.dto.admin.vo.AnchorTopAdminVo;
|
||||
import com.ruoyi.cai.dto.app.query.index.AnchorListQuery;
|
||||
import com.ruoyi.cai.dto.app.vo.AnchorListVo;
|
||||
import com.ruoyi.cai.dto.app.vo.setting.AppHomeConfig;
|
||||
@@ -10,9 +11,11 @@ import com.ruoyi.cai.enums.home.AnchorListQueryTypeEnum;
|
||||
import com.ruoyi.cai.mq.AmqpProducer;
|
||||
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
||||
import com.ruoyi.cai.service.AnchorService;
|
||||
import com.ruoyi.cai.service.AnchorTopService;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -21,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 首页主播随机推荐
|
||||
@@ -31,8 +35,16 @@ public class HomeManager {
|
||||
@Autowired
|
||||
private AnchorService anchorService;
|
||||
@Autowired
|
||||
private AnchorTopService anchorTopService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public void refreshHomeAnchorTopCache(){
|
||||
List<AnchorListVo> anchorTop = anchorTopService.anchorTop(4);
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_RECOMMEND_TOP_REDIS);
|
||||
bucket.set(anchorTop);
|
||||
}
|
||||
|
||||
public void refreshHomeRecommendCache(){
|
||||
PageQuery pageQuery = new PageQuery();
|
||||
pageQuery.setPageSize(200);
|
||||
@@ -86,7 +98,7 @@ public class HomeManager {
|
||||
}else if(anchorListQueryTypeEnum == AnchorListQueryTypeEnum.NEW){
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_NEW_REDIS);
|
||||
vos = bucket.get();
|
||||
} else {
|
||||
} else { // 同城查询
|
||||
if(query.getCityId() == null){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -95,11 +107,22 @@ public class HomeManager {
|
||||
Collections.shuffle(vos);
|
||||
Integer pageNum = pageQuery.getPageNum();
|
||||
int startIndex = (pageNum - 1) * pageQuery.getPageSize();
|
||||
if(startIndex > vos.size()){
|
||||
if(startIndex > vos.size()){ // 超出范围
|
||||
return Collections.emptyList();
|
||||
}
|
||||
int endIndex = Math.min(startIndex+pageQuery.getPageSize(), vos.size());
|
||||
return vos.subList(startIndex, endIndex);
|
||||
List<AnchorListVo> result = vos.subList(startIndex, endIndex);
|
||||
if(anchorListQueryTypeEnum == AnchorListQueryTypeEnum.DEFAULT && pageNum == 1){
|
||||
List<AnchorListVo> list = getAnchorTopList();
|
||||
result.addAll(0, list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<AnchorListVo> getAnchorTopList(){
|
||||
RBucket<List<AnchorListVo>> bucketTop = redissonClient.getBucket(RedisHttpConstant.HOME_RECOMMEND_TOP_REDIS);
|
||||
List<AnchorListVo> anchorListVos = bucketTop.get();
|
||||
return anchorListVos == null ? Collections.emptyList() : anchorListVos;
|
||||
}
|
||||
|
||||
public List<AnchorListVo> recommendFollows(Integer limit) {
|
||||
|
||||
Reference in New Issue
Block a user