redis缓存开关
This commit is contained in:
parent
f43edc38a5
commit
7a269dcbbb
|
|
@ -16,6 +16,7 @@ import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.common.redis.service.RedisService;
|
import com.bonus.common.redis.service.RedisService;
|
||||||
import com.bonus.common.security.utils.SecurityUtils;
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
@ -43,6 +44,9 @@ public class TbBdRecordServiceImpl implements TbBdRecordService {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@Value("${isRedisCache}")
|
||||||
|
private Boolean isRedisCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public AjaxResult deleteByPrimaryKey(Long id) {
|
public AjaxResult deleteByPrimaryKey(Long id) {
|
||||||
|
|
@ -222,16 +226,26 @@ public class TbBdRecordServiceImpl implements TbBdRecordService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResultVo<TbBdRecord> getAll(TbBdRecord record){
|
public PageResultVo<TbBdRecord> getAll(TbBdRecord record){
|
||||||
List<TbBdRecord> list = redisService.getCacheObject(Constants.TB_BD_RECORD_REDIS_KEY);
|
List<TbBdRecord> list;
|
||||||
|
if (isRedisCache) {
|
||||||
|
list = redisService.getCacheObject(Constants.TB_BD_RECORD_REDIS_KEY);
|
||||||
if (list == null || list.isEmpty()) {
|
if (list == null || list.isEmpty()) {
|
||||||
// 从数据库获取数据并缓存
|
// 从数据库获取数据并缓存
|
||||||
list = tbBdRecordMapper.getAll(record);
|
list = tbBdRecordMapper.getAll(record);
|
||||||
redisService.setCacheObject(Constants.TB_BD_RECORD_REDIS_KEY, list, 10L, TimeUnit.MINUTES);
|
if (list != null && !list.isEmpty()) {
|
||||||
|
// 设置缓存并定义有效时间,避免重复加载数据
|
||||||
|
redisService.setCacheObject(Constants.TB_BD_RECORD_REDIS_KEY, list, 600L, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list = tbBdRecordMapper.getAll(record);
|
||||||
}
|
}
|
||||||
// 处理手机号解密
|
// 处理手机号解密
|
||||||
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
list.stream()
|
list.stream()
|
||||||
.filter(tbBdRecord -> tbBdRecord.getDepartName() != null)
|
.filter(tbBdRecord -> tbBdRecord.getDepartName() != null)
|
||||||
.forEach(tbBdRecord -> tbBdRecord.setRelPhone(Sm4Utils.decode(tbBdRecord.getRelPhone())));
|
.forEach(tbBdRecord -> tbBdRecord.setRelPhone(Sm4Utils.decode(tbBdRecord.getRelPhone())));
|
||||||
|
}
|
||||||
// 手动计算分页信息
|
// 手动计算分页信息
|
||||||
// 默认为第1页
|
// 默认为第1页
|
||||||
int pageNum = Math.max(record.getPageNum(), 1);
|
int pageNum = Math.max(record.getPageNum(), 1);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import com.bonus.base.basic.config.Constants;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.common.redis.service.RedisService;
|
import com.bonus.common.redis.service.RedisService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -33,6 +34,9 @@ public class TbDevAttributeServiceImpl implements TbDevAttributeService {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@Value("${isRedisCache}")
|
||||||
|
private Boolean isRedisCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int deleteByPrimaryKey(Long id) {
|
public int deleteByPrimaryKey(Long id) {
|
||||||
return tbDevAttributeMapper.deleteByPrimaryKey(id);
|
return tbDevAttributeMapper.deleteByPrimaryKey(id);
|
||||||
|
|
@ -68,14 +72,26 @@ public class TbDevAttributeServiceImpl implements TbDevAttributeService {
|
||||||
return tbDevAttributeMapper.updateBatch(list);
|
return tbDevAttributeMapper.updateBatch(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备监测信息管理数据
|
||||||
|
* @param record
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResultVo<TbDevAttributeVo> queryAll(TbDevAttribute record) {
|
public PageResultVo<TbDevAttributeVo> queryAll(TbDevAttribute record) {
|
||||||
|
List<TbDevAttributeVo> list;
|
||||||
|
if (isRedisCache) {
|
||||||
//先从缓存中查询
|
//先从缓存中查询
|
||||||
List<TbDevAttributeVo> list = redisService.getCacheObject(Constants.TB_DEV_ATTRIBUTE_REDIS_KEY);
|
list = redisService.getCacheObject(Constants.TB_DEV_ATTRIBUTE_REDIS_KEY);
|
||||||
if (list == null || list.isEmpty()) {
|
if (list == null || list.isEmpty()) {
|
||||||
// 从数据库获取数据并缓存
|
// 从数据库获取数据并缓存
|
||||||
list = tbDevAttributeMapper.queryAll(record);
|
list = tbDevAttributeMapper.queryAll(record);
|
||||||
redisService.setCacheObject(Constants.TB_DEV_ATTRIBUTE_REDIS_KEY, list, 10L, TimeUnit.MINUTES);
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
|
redisService.setCacheObject(Constants.TB_DEV_ATTRIBUTE_REDIS_KEY, list, 600L, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list = tbDevAttributeMapper.queryAll(record);
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
list.forEach(attribute -> {
|
list.forEach(attribute -> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue