mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-01 16:40:04 +08:00
同步充电桩数据到JCPP
This commit is contained in:
@@ -30,14 +30,32 @@ public class PileModelInfoServiceImpl implements PileModelInfoService {
|
||||
private RedisCache redisCache;
|
||||
|
||||
/**
|
||||
* 查询充电桩型号信息
|
||||
* 查询充电桩型号信息(带缓存)
|
||||
*
|
||||
* @param id 充电桩型号信息主键
|
||||
* @return 充电桩型号信息
|
||||
*/
|
||||
@Override
|
||||
public PileModelInfo selectPileModelInfoById(Long id) {
|
||||
return pileModelInfoMapper.selectPileModelInfoById(id);
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1. 尝试从缓存获取
|
||||
String redisKey = CacheConstants.PILE_MODEL_INFO_BY_ID + id;
|
||||
PileModelInfo modelInfo = redisCache.getCacheObject(redisKey);
|
||||
|
||||
// 2. 缓存未命中,从数据库查询
|
||||
if (modelInfo == null) {
|
||||
modelInfo = pileModelInfoMapper.selectPileModelInfoById(id);
|
||||
|
||||
// 3. 查询结果存入缓存(1天有效期)
|
||||
if (modelInfo != null) {
|
||||
redisCache.setCacheObject(redisKey, modelInfo, CacheConstants.cache_expire_time_1d);
|
||||
}
|
||||
}
|
||||
|
||||
return modelInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,10 +153,18 @@ public class PileModelInfoServiceImpl implements PileModelInfoService {
|
||||
return modelInfoVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
*
|
||||
* @param modelIds 型号ID数组
|
||||
*/
|
||||
private void cleanCache(Long[] modelIds) {
|
||||
List<String> redisKeyList = Lists.newArrayList();
|
||||
for (Long modelId : modelIds) {
|
||||
// 清除 getPileModelInfoByModelId 的缓存
|
||||
redisKeyList.add(CacheConstants.GET_PILE_MODEL_INFO_BY_MODEL_ID + modelId);
|
||||
// 清除 selectPileModelInfoById 的缓存
|
||||
redisKeyList.add(CacheConstants.PILE_MODEL_INFO_BY_ID + modelId);
|
||||
}
|
||||
redisCache.deleteObject(redisKeyList);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user