123
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.ruoyi.cai.manager;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.ruoyi.cai.constant.RedisConstant;
|
||||
import com.ruoyi.cai.constant.RedisHttpConstant;
|
||||
import com.ruoyi.cai.enums.CodeEnum;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -20,7 +20,7 @@ public class CodeManager {
|
||||
private SystemConfigManager systemConfigManager;
|
||||
|
||||
public String getKey(CodeEnum codeEnum,String phone){
|
||||
return String.format(RedisConstant.CODE_REDIS,codeEnum.name(),phone);
|
||||
return String.format(RedisHttpConstant.CODE_REDIS,codeEnum.name(),phone);
|
||||
}
|
||||
|
||||
public void put(CodeEnum codeEnum,String phone,String code){
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.ruoyi.cai.manager;
|
||||
|
||||
import com.ruoyi.cai.constant.RedisConstant;
|
||||
import com.ruoyi.cai.constant.RedisHttpConstant;
|
||||
import com.ruoyi.cai.domain.UserForbid;
|
||||
import com.ruoyi.cai.enums.ForbidTypeEnum;
|
||||
import com.ruoyi.cai.ws.util.MapGetUtil;
|
||||
@@ -16,7 +16,7 @@ public class ForbidCache {
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
private String getKey(Integer type){
|
||||
return String.format(RedisConstant.FORBID_CACHE_REDIS,type);
|
||||
return String.format(RedisHttpConstant.FORBID_CACHE_REDIS,type);
|
||||
}
|
||||
|
||||
public void addForbid(UserForbid userForbid){
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.ruoyi.cai.manager;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.cai.constant.RedisHttpConstant;
|
||||
import com.ruoyi.cai.dto.app.query.index.AnchorListQuery;
|
||||
import com.ruoyi.cai.dto.app.vo.AnchorListVo;
|
||||
import com.ruoyi.cai.enums.home.AnchorListQueryTypeEnum;
|
||||
import com.ruoyi.cai.service.AnchorService;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 首页主播随机推荐
|
||||
*/
|
||||
@Component
|
||||
public class HomeManager {
|
||||
|
||||
@Autowired
|
||||
private AnchorService anchorService;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public void refreshHomeRecommendCache(){
|
||||
PageQuery pageQuery = new PageQuery();
|
||||
pageQuery.setPageSize(200);
|
||||
pageQuery.setPageNum(1);
|
||||
AnchorListQuery query = new AnchorListQuery();
|
||||
// 0-默认查询 1-活跃查询 2-新人查询 3-同城查询
|
||||
query.setType(0);
|
||||
Page<AnchorListVo> app = anchorService.pageApp(pageQuery, query);
|
||||
List<AnchorListVo> records = app.getRecords();
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_RECOMMEND_REDIS);
|
||||
bucket.set(records);
|
||||
}
|
||||
|
||||
public void refreshHomeNewCache(){
|
||||
PageQuery pageQuery = new PageQuery();
|
||||
pageQuery.setPageSize(200);
|
||||
pageQuery.setPageNum(1);
|
||||
AnchorListQuery query = new AnchorListQuery();
|
||||
// 0-默认查询 1-活跃查询 2-新人查询 3-同城查询
|
||||
query.setType(1);
|
||||
Page<AnchorListVo> app = anchorService.pageApp(pageQuery, query);
|
||||
List<AnchorListVo> records = app.getRecords();
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_NEW_REDIS);
|
||||
bucket.set(records);
|
||||
}
|
||||
|
||||
public void refreshHomeActiveCache(){
|
||||
PageQuery pageQuery = new PageQuery();
|
||||
pageQuery.setPageSize(200);
|
||||
pageQuery.setPageNum(1);
|
||||
AnchorListQuery query = new AnchorListQuery();
|
||||
// 0-默认查询 1-活跃查询 2-新人查询 3-同城查询
|
||||
query.setType(2);
|
||||
Page<AnchorListVo> app = anchorService.pageApp(pageQuery, query);
|
||||
List<AnchorListVo> records = app.getRecords();
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_ACTIVE_REDIS);
|
||||
bucket.set(records);
|
||||
}
|
||||
|
||||
|
||||
public List<AnchorListVo> getHomeCache(PageQuery pageQuery,AnchorListQuery query){
|
||||
AnchorListQueryTypeEnum anchorListQueryTypeEnum = AnchorListQueryTypeEnum.getByCode(query.getType());
|
||||
List<AnchorListVo> vos;
|
||||
if(anchorListQueryTypeEnum == AnchorListQueryTypeEnum.DEFAULT){ // 默认
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_RECOMMEND_REDIS);
|
||||
vos = bucket.get();
|
||||
}else if(anchorListQueryTypeEnum == AnchorListQueryTypeEnum.ACTIVE){
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_ACTIVE_REDIS);
|
||||
vos = bucket.get();
|
||||
}else if(anchorListQueryTypeEnum == AnchorListQueryTypeEnum.NEW){
|
||||
RBucket<List<AnchorListVo>> bucket = redissonClient.getBucket(RedisHttpConstant.HOME_NEW_REDIS);
|
||||
vos = bucket.get();
|
||||
} else {
|
||||
if(query.getCityId() == null){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return anchorService.pageApp(pageQuery, query).getRecords();
|
||||
}
|
||||
Collections.shuffle(vos);
|
||||
Integer pageNum = pageQuery.getPageNum();
|
||||
int startIndex = (pageNum - 1) * pageQuery.getPageSize();
|
||||
int endIndex = Math.min(startIndex+pageQuery.getPageSize(), vos.size());
|
||||
return vos.subList(startIndex, endIndex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.ruoyi.cai.manager;
|
||||
|
||||
import com.ruoyi.cai.constant.RedisConstant;
|
||||
import com.ruoyi.cai.constant.RedisHttpConstant;
|
||||
|
||||
public class LockManager {
|
||||
|
||||
public static final String LOCK_REGISTER_REDIS = RedisConstant.REDIS_P + "lock:register:%s";
|
||||
public static final String LOCK_DEAL_INVITE_REDIS = RedisConstant.REDIS_P + "lock:dealInvite:%s";
|
||||
public static final String LOCK_ADD_USER_GREET_REDIS = RedisConstant.REDIS_P + "lock:addUserGreet:%s";
|
||||
public static final String LOCK_SEND_GREET_REDIS = RedisConstant.REDIS_P + "lock:sendGreet:%s";
|
||||
public static final String LOCK_SEND_GUARD_REDIS = RedisConstant.REDIS_P + "lock:sendGuard:%s";
|
||||
public static final String LOCK_SEND_GIFT_REDIS = RedisConstant.REDIS_P + "lock:sendGift:%s";
|
||||
public static final String LOCK_VIDEO_SETTLE_REDIS = RedisConstant.REDIS_P + "lock:videoSettle:%s";
|
||||
public static final String LOCK_REGISTER_REDIS = RedisHttpConstant.REDIS_P + "lock:register:%s";
|
||||
public static final String LOCK_DEAL_INVITE_REDIS = RedisHttpConstant.REDIS_P + "lock:dealInvite:%s";
|
||||
public static final String LOCK_ADD_USER_GREET_REDIS = RedisHttpConstant.REDIS_P + "lock:addUserGreet:%s";
|
||||
public static final String LOCK_SEND_GREET_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGreet:%s";
|
||||
public static final String LOCK_SEND_GUARD_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGuard:%s";
|
||||
public static final String LOCK_SEND_GIFT_REDIS = RedisHttpConstant.REDIS_P + "lock:sendGift:%s";
|
||||
public static final String LOCK_VIDEO_SETTLE_REDIS = RedisHttpConstant.REDIS_P + "lock:videoSettle:%s";
|
||||
|
||||
public static String getRegisterLockKey(String mobile){
|
||||
return String.format(LOCK_REGISTER_REDIS,mobile);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.ruoyi.cai.manager;
|
||||
|
||||
import com.ruoyi.cai.constant.RedisConstant;
|
||||
import com.ruoyi.cai.constant.RedisHttpConstant;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.enums.systemconfig.SystemCheckResp;
|
||||
import com.ruoyi.common.core.service.SensitiveService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.availability.AvailabilityChangeEvent;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -93,7 +92,7 @@ public class SystemConfigManager {
|
||||
* @return
|
||||
*/
|
||||
public String getSystemConfig(SystemConfigEnum systemConfig){
|
||||
String value = (String) redisTemplate.opsForHash().get(RedisConstant.SYSTEM_CONFIG, systemConfig.name());
|
||||
String value = (String) redisTemplate.opsForHash().get(RedisHttpConstant.SYSTEM_CONFIG, systemConfig.name());
|
||||
if(StringUtils.isBlank(value)){
|
||||
return systemConfig.getDefaultValue();
|
||||
}
|
||||
@@ -124,7 +123,7 @@ public class SystemConfigManager {
|
||||
*/
|
||||
public Map<String,String> getAllSystemConfig(){
|
||||
HashOperations<String, String, String> stringObjectObjectHashOperations = redisTemplate.opsForHash();
|
||||
return stringObjectObjectHashOperations.entries(RedisConstant.SYSTEM_CONFIG);
|
||||
return stringObjectObjectHashOperations.entries(RedisHttpConstant.SYSTEM_CONFIG);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +142,6 @@ public class SystemConfigManager {
|
||||
if(key.equals(SystemConfigEnum.SENSITIVE_ENABLE.getKey())){
|
||||
sensitiveService.setSensitive(value.equals("1"));
|
||||
}
|
||||
redisTemplate.opsForHash().put(RedisConstant.SYSTEM_CONFIG, key,value);
|
||||
redisTemplate.opsForHash().put(RedisHttpConstant.SYSTEM_CONFIG, key,value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user