同步充电桩数据到JCPP

This commit is contained in:
Guoqs
2026-01-06 10:12:49 +08:00
parent 30ec68abb1
commit 8f9cbc6cf8
6 changed files with 258 additions and 26 deletions

View File

@@ -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);
}