|
@@ -2171,19 +2171,27 @@ public class QwExternalContactServiceImpl extends ServiceImpl<QwExternalContactM
|
|
|
|
|
|
@Override
|
|
|
public QwUser getQwUserByRedisForId(String qwUserId) {
|
|
|
- String key =(String)redisCache.getCacheObject("qwUserRdById:"+qwUserId);
|
|
|
- if (ObjectUtils.isNotEmpty(key)&& !StringUtil.strIsNullOrEmpty(key)){
|
|
|
- return JSON.parseObject(key, QwUser.class);
|
|
|
- }
|
|
|
- logger.error("qwUserId:{}",qwUserId);
|
|
|
- if (ObjectUtils.isEmpty(qwUserId)||qwUserId.equals("null")){
|
|
|
- return null;
|
|
|
+
|
|
|
+ String redisKey = "qwUserRdById:" + qwUserId;
|
|
|
+
|
|
|
+ // 直接从Redis获取JSON字符串
|
|
|
+ String cachedJson = (String) redisCache.getCacheObject(redisKey);
|
|
|
+ if (!StringUtil.strIsNullOrEmpty(cachedJson)) {
|
|
|
+ try {
|
|
|
+ return JSON.parseObject(cachedJson, QwUser.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 解析失败时删除缓存,重新查询
|
|
|
+ redisCache.deleteObject(redisKey);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
QwUser qwUser = qwUserMapper.selectQwUserById(Long.valueOf(qwUserId));
|
|
|
- if (qwUser==null){
|
|
|
+ if (qwUser == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- redisCache.setCacheObject("qwUserRdById:"+qwUser.getId() ,JSON.toJSONString(qwUser),1, TimeUnit.HOURS);
|
|
|
+
|
|
|
+ // 存储时确保是JSON字符串
|
|
|
+ redisCache.setCacheObject(redisKey, JSON.toJSONString(qwUser), 1, TimeUnit.HOURS);
|
|
|
return qwUser;
|
|
|
}
|
|
|
;
|