From 179d1f45307430004a7e68bc7dc7d000857e6706 Mon Sep 17 00:00:00 2001 From: wangchao Date: Fri, 7 Aug 2020 16:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/redis/UserBaseInfoRedis.java | 62 +++++++++++-------- .../epmet/service/impl/UserServiceImpl.java | 36 ++++++++++- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBaseInfoRedis.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBaseInfoRedis.java index a2439d4dcd..918daf7435 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBaseInfoRedis.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/redis/UserBaseInfoRedis.java @@ -87,8 +87,17 @@ public class UserBaseInfoRedis { redisUtils.hMSet(key, map,RedisUtils.DEFAULT_EXPIRE * NumConstant.SEVEN); } - public String get(String id){ - return null; + public UserBaseInfoResultDTO get(String userId){ + + if(StringUtils.isNotBlank(userId)) { + Map map = redisUtils.hGetAll(UserRedisKeys.getResiUserKey(userId)); + if (null != map && !map.isEmpty()) { + //缓存中有数据,直接返回 + return BeanUtil.mapToBean(map, UserBaseInfoResultDTO.class, true); + } + } + return null; + } /** @@ -193,6 +202,14 @@ public class UserBaseInfoRedis { UserBaseInfoResultDTO currentCache = ConvertUtils.sourceToTarget(entity,UserBaseInfoResultDTO.class); + UserBaseInfoResultDTO orientCache = get(entity.getUserId()); + if(null != orientCache && StringUtils.isNotBlank(orientCache.getUserId())){ + //将要更改的信息赋值到原缓存中 + mergeObject(currentCache,orientCache); + //将原来的缓存对象赋值给要更新的缓存对象 + //此时orientCache中包概括要更新的属性以及之前有切不更新的属性 + currentCache = orientCache; + } RegisterRelationEntity relation = registerRelationDao.selectRegisteredGridIdByUserId(entity.getUserId()); //如果没有首次注册网格,则没有网格名称(xx机关-xx网格)、显示昵称(xx网格-x先生/女士) if(null != relation && StringUtils.isNotBlank(relation.getGridId())){ @@ -203,22 +220,24 @@ public class UserBaseInfoRedis { Result gridResult = govOrgOpenFeignClient.getGridNameByGridId(gridParam); if(gridResult.success() && null != gridResult.getData() - && StringUtils.isNotBlank(gridResult.getData().getBelongsGridName())){ + && StringUtils.isNotBlank(gridResult.getData().getBelongsGridName())) { String gridFullName = gridResult.getData().getBelongsGridName(); currentCache.setRegisteredGridName(gridFullName); - if(StringUtils.isBlank(currentCache.getGender()))currentCache.setGender(NumConstant.ZERO_STR); - StringBuffer buffer = new StringBuffer(gridFullName.split(ModuleConstant.DASH)[NumConstant.ONE]).append(ModuleConstant.DASH).append(currentCache.getSurname()); - switch (currentCache.getGender()) { - case NumConstant.ONE_STR: - buffer.append(ModuleConstant.RESI_USER_NICKNAME_SUFFIX_MALE); - break; - case NumConstant.TWO_STR: - buffer.append(ModuleConstant.RESI_USER_NICKNAME_SUFFIX_FEMALE); - break; - default: - buffer.append(ModuleConstant.RESI_USER_NICKNAME_SUFFIX_GENDER_UNKNOWN); + if (StringUtils.isBlank(currentCache.getGender())) currentCache.setGender(NumConstant.ZERO_STR); + if (StringUtils.isNotBlank(currentCache.getNickname())) { + StringBuffer buffer = new StringBuffer(gridFullName.split(ModuleConstant.DASH)[NumConstant.ONE]).append(ModuleConstant.DASH).append(currentCache.getSurname()); + switch (currentCache.getGender()) { + case NumConstant.ONE_STR: + buffer.append(ModuleConstant.RESI_USER_NICKNAME_SUFFIX_MALE); + break; + case NumConstant.TWO_STR: + buffer.append(ModuleConstant.RESI_USER_NICKNAME_SUFFIX_FEMALE); + break; + default: + buffer.append(ModuleConstant.RESI_USER_NICKNAME_SUFFIX_GENDER_UNKNOWN); + } + currentCache.setShowName(buffer.toString()); } - currentCache.setShowName(buffer.toString()); } }else{ //如果没有居民注册记录,说明当前用户是陌生人,需要从陌生人网格访问列表中查询所属的客户Id @@ -240,18 +259,7 @@ public class UserBaseInfoRedis { // } //} - Map map = redisUtils.hGetAll(UserRedisKeys.getResiUserKey(entity.getUserId())); - if(null != map && !map.isEmpty()) { - //缓存中有数据,直接返回 - UserBaseInfoResultDTO orientCache = BeanUtil.mapToBean(map, UserBaseInfoResultDTO.class, true); - mergeObject(currentCache , orientCache); - set(orientCache); - }else{ - //缓存中没有该数据 - set(currentCache); - } - - + set(currentCache); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java index 88ad2d8ce0..f90ef05032 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserServiceImpl.java @@ -8,11 +8,10 @@ import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.CpUserDetailRedis; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.UserConstant; -import com.epmet.dao.UserDao; -import com.epmet.dao.UserRoleDao; -import com.epmet.dao.UserWechatDao; +import com.epmet.dao.*; import com.epmet.dto.CustomerGridDTO; import com.epmet.dto.UserDTO; +import com.epmet.dto.UserResiInfoDTO; import com.epmet.dto.UserWechatDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; @@ -21,6 +20,7 @@ import com.epmet.entity.UserEntity; import com.epmet.entity.UserWechatEntity; import com.epmet.feign.EpmetPointOpenFeignClient; import com.epmet.feign.GovOrgFeignClient; +import com.epmet.redis.UserBaseInfoRedis; import com.epmet.service.UserBaseInfoService; import com.epmet.service.UserService; import com.epmet.util.ModuleConstant; @@ -53,6 +53,12 @@ public class UserServiceImpl extends BaseServiceImpl implem private UserBaseInfoService userBaseInfoService; @Autowired private EpmetPointOpenFeignClient epmetPointOpenFeignClient; + @Autowired + private UserBaseInfoRedis userBaseInfoRedis; + @Autowired + private UserResiInfoDao userResiInfoDao; + @Autowired + private UserBaseInfoDao userBaseInfoDao; private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class); @@ -130,7 +136,31 @@ public class UserServiceImpl extends BaseServiceImpl implem userWechatDTO.setUpdatedTime(new Date()); userWechatDTO.setUpdatedBy(wxUserInfoFormDTO.getUserId()); userWechatDao.updateByUserId(userWechatDTO); + UserBaseInfoEntity baseInfo = new UserBaseInfoEntity(); + UserBaseInfoResultDTO cache = userBaseInfoRedis.get(wxUserInfoFormDTO.getUserId()); + if(null == cache || StringUtils.isBlank(cache.getId())){ + //没有缓存 + cache = + userBaseInfoDao.selectListByUserIdList(wxUserInfoFormDTO.getUserId()); + if(null == cache || StringUtils.isBlank(cache.getId()) || StringUtils.isBlank(cache.getMobile()) ||StringUtils.isBlank(cache.getSurname())){ + //没有baseInfo + UserResiInfoDTO resiInfo = + userResiInfoDao.selectByUserId(wxUserInfoFormDTO.getUserId()); + if(null == resiInfo || StringUtils.isBlank(resiInfo.getId())){ + //没有resiInfo + return new Result(); + }else{ + baseInfo.setSurname(resiInfo.getSurname()); + baseInfo.setName(resiInfo.getName()); + baseInfo.setStreet(resiInfo.getStreet()); + baseInfo.setDistrict(resiInfo.getDistrict()); + baseInfo.setBuildingAddress(resiInfo.getBuildingAddress()); + baseInfo.setMobile(resiInfo.getRegMobile()); + } + } + } + baseInfo.setUserId(wxUserInfoFormDTO.getUserId()); baseInfo.setNickname(wxUserInfoFormDTO.getNickName()); baseInfo.setHeadImgUrl(wxUserInfoFormDTO.getAvatarUrl());