mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
加缓存
This commit is contained in:
@@ -54,6 +54,16 @@ public class CacheConstants {
|
||||
*/
|
||||
public static final String PILE_CONNECTOR_STATUS_KEY = "pile_connector_status:";
|
||||
|
||||
/**
|
||||
* 查询设备管理
|
||||
*/
|
||||
public static final String SELECT_PILE_BASIC_INFO_BY_SN = "select_pile_basic_info_by_sn:";
|
||||
|
||||
/**
|
||||
* 查询站点信息
|
||||
*/
|
||||
public static final String SELECT_PILE_STATION_INFO_BY_ID = "select_pile_station_info_by_id:";
|
||||
|
||||
/**
|
||||
* 充电桩sn生成 key
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,7 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -96,7 +97,16 @@ public class PileBasicInfoServiceImpl implements IPileBasicInfoService {
|
||||
@Override
|
||||
public PileBasicInfo selectPileBasicInfoBySN(String pileSn) {
|
||||
// 加缓存
|
||||
return pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn);
|
||||
String redisKey = CacheConstants.SELECT_PILE_BASIC_INFO_BY_SN + pileSn;
|
||||
PileBasicInfo pileBasicInfo = redisCache.getCacheObject(redisKey);
|
||||
if (pileBasicInfo == null) {
|
||||
// 查数据库
|
||||
pileBasicInfo = pileBasicInfoMapper.selectPileBasicInfoBySn(pileSn);
|
||||
if (pileBasicInfo != null) {
|
||||
redisCache.setCacheObject(redisKey, pileBasicInfo, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
return pileBasicInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,6 +142,9 @@ public class PileBasicInfoServiceImpl implements IPileBasicInfoService {
|
||||
@Override
|
||||
public int updatePileBasicInfo(PileBasicInfo pileBasicInfo) {
|
||||
// pileBasicInfo.setUpdateBy(SecurityUtils.getUsername());
|
||||
// 清缓存
|
||||
String redisKey = CacheConstants.SELECT_PILE_BASIC_INFO_BY_SN + pileBasicInfo.getSn();
|
||||
redisCache.deleteObject(redisKey);
|
||||
pileBasicInfo.setUpdateTime(DateUtils.getNowDate());
|
||||
return pileBasicInfoMapper.updatePileBasicInfo(pileBasicInfo);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.jsowell.pile.service.impl;
|
||||
|
||||
import cn.hutool.core.util.PageUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.entity.SysDept;
|
||||
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
|
||||
import com.jsowell.common.core.page.PageResponse;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.DistanceUtils;
|
||||
import com.jsowell.common.util.SecurityUtils;
|
||||
@@ -34,6 +36,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -63,6 +66,9 @@ public class PileStationInfoServiceImpl implements IPileStationInfoService {
|
||||
@Autowired
|
||||
private IPileBasicInfoService pileBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* 查询充电站信息
|
||||
*
|
||||
@@ -71,7 +77,15 @@ public class PileStationInfoServiceImpl implements IPileStationInfoService {
|
||||
*/
|
||||
@Override
|
||||
public PileStationInfo selectPileStationInfoById(Long id) {
|
||||
return pileStationInfoMapper.selectPileStationInfoById(id);
|
||||
// 加缓存
|
||||
String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + id;
|
||||
PileStationInfo pileStationInfo = redisCache.getCacheObject(redisKey);
|
||||
if (pileStationInfo == null) {
|
||||
// 查数据库
|
||||
pileStationInfo = pileStationInfoMapper.selectPileStationInfoById(id);
|
||||
redisCache.setCacheObject(redisKey, pileStationInfo, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
return pileStationInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,6 +239,9 @@ public class PileStationInfoServiceImpl implements IPileStationInfoService {
|
||||
*/
|
||||
@Override
|
||||
public int updatePileStationInfo(PileStationInfo pileStationInfo) {
|
||||
// 清缓存
|
||||
String redisKey = CacheConstants.SELECT_PILE_STATION_INFO_BY_ID + pileStationInfo.getId();
|
||||
redisCache.deleteObject(redisKey);
|
||||
pileStationInfo.setUpdateBy(SecurityUtils.getUsername());
|
||||
pileStationInfo.setUpdateTime(DateUtils.getNowDate());
|
||||
return pileStationInfoMapper.updatePileStationInfo(pileStationInfo);
|
||||
|
||||
Reference in New Issue
Block a user