|
|
|
@ -106,6 +106,14 @@ public class DictUtil {
|
|
|
|
|
return defaultVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
|
|
|
|
|
cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_VALUE + typeCode,
|
|
|
|
|
dictValue, DictDetailModel.class);
|
|
|
|
|
if (cacheModel != null){
|
|
|
|
|
dictName = cacheModel.getDictName();
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(dictName)) return dictName;
|
|
|
|
|
|
|
|
|
|
// 查询数据库 并保存到缓存内
|
|
|
|
|
ResultVo<List<DictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode);
|
|
|
|
|
if(resultVo.isSuccess()){
|
|
|
|
@ -182,6 +190,14 @@ public class DictUtil {
|
|
|
|
|
return defaultVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
|
|
|
|
|
cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_NAME + typeCode,
|
|
|
|
|
dictName, DictDetailModel.class);
|
|
|
|
|
if (cacheModel != null){
|
|
|
|
|
dictValue = cacheModel.getDictValue();
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(dictValue)) return dictValue;
|
|
|
|
|
|
|
|
|
|
// 查询数据库 并保存到缓存内
|
|
|
|
|
ResultVo<List<DictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode);
|
|
|
|
|
if(resultVo.isSuccess()){
|
|
|
|
@ -250,8 +266,10 @@ public class DictUtil {
|
|
|
|
|
dictWrapperModel.setDictValue(model.getDictValue());
|
|
|
|
|
dictWrapperModels.add(dictWrapperModel);
|
|
|
|
|
}
|
|
|
|
|
if(!dictWrapperModels.isEmpty()){
|
|
|
|
|
return dictWrapperModels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(dictWrapperModels.isEmpty()){
|
|
|
|
|
// 防止缓存穿透判断
|
|
|
|
|
boolean hasNilFlag = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_LIST + typeCode);
|
|
|
|
|
if(hasNilFlag){
|
|
|
|
@ -272,6 +290,32 @@ public class DictUtil {
|
|
|
|
|
return dictWrapperModels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
|
|
|
|
|
key = CacheUtil.handleKey(CacheConstants.EDEN_HASH_DATA, DictConstants.CACHE_PREFIX_VALUE + typeCode);
|
|
|
|
|
dictMap = redisPlugin.hGetAll(key);
|
|
|
|
|
entries = dictMap.entrySet();
|
|
|
|
|
for (Map.Entry<Object, Object> entry : entries) {
|
|
|
|
|
// 赋值
|
|
|
|
|
JSONObject jsonObject = (JSONObject) entry.getValue();
|
|
|
|
|
if(jsonObject == null){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
JSONObject dataJson = jsonObject.getJSONObject(CacheUtil.JSON_KEY);
|
|
|
|
|
if(dataJson == null){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
DictDetailModel model = dataJson.toJavaObject(DictDetailModel.class);
|
|
|
|
|
DictWrapper dictWrapperModel = new DictWrapper();
|
|
|
|
|
dictWrapperModel.setTypeCode(typeCode);
|
|
|
|
|
dictWrapperModel.setDictName(model.getDictName());
|
|
|
|
|
dictWrapperModel.setDictValue(model.getDictValue());
|
|
|
|
|
dictWrapperModels.add(dictWrapperModel);
|
|
|
|
|
}
|
|
|
|
|
if(!dictWrapperModels.isEmpty()){
|
|
|
|
|
return dictWrapperModels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询数据库 并保存到缓存内
|
|
|
|
|
ResultVo<List<DictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode);
|
|
|
|
|
if(resultVo.isSuccess()){
|
|
|
|
@ -305,7 +349,6 @@ public class DictUtil {
|
|
|
|
|
CacheUtil.putNilFlag(DictConstants.CACHE_PREFIX_LIST + typeCode );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error(e.getMessage(),e);
|
|
|
|
|
dictWrapperModels = Lists.newArrayList();
|
|
|
|
|