|
|
@ -20,6 +20,7 @@ package com.epmet.redis; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.UserRedisKeys; |
|
|
|
import com.epmet.dao.GridLatestDao; |
|
|
@ -30,12 +31,14 @@ import com.epmet.dto.result.BelongGridNameResultDTO; |
|
|
|
import com.epmet.dto.result.LatestGridInfoResultDTO; |
|
|
|
import com.epmet.dto.result.UserBaseInfoResultDTO; |
|
|
|
import com.epmet.entity.RegisterRelationEntity; |
|
|
|
import com.epmet.entity.UserBaseInfoEntity; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import com.epmet.util.ModuleConstant; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import static com.epmet.commons.tools.redis.RedisUtils.NOT_EXPIRE; |
|
|
@ -127,18 +130,115 @@ public class UserBaseInfoRedis { |
|
|
|
baseInfo.setShowName(buffer.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//如果没有居民注册记录,说明当前用户是陌生人,需要从陌生人网格访问列表中查询所属的客户Id
|
|
|
|
LatestGridInfoResultDTO gridLatest = |
|
|
|
gridLatestDao.selectLatestGridInfoByUserId(userId); |
|
|
|
if(null != gridLatest){ |
|
|
|
baseInfo.setCustomerId(gridLatest.getCustomerId()); |
|
|
|
else{ |
|
|
|
//如果没有居民注册记录,说明当前用户是陌生人,需要从陌生人网格访问列表中查询所属的客户Id
|
|
|
|
LatestGridInfoResultDTO gridLatest = |
|
|
|
gridLatestDao.selectLatestGridInfoByUserId(userId); |
|
|
|
if(null != gridLatest){ |
|
|
|
baseInfo.setCustomerId(gridLatest.getCustomerId()); |
|
|
|
} |
|
|
|
} |
|
|
|
set(baseInfo); |
|
|
|
return baseInfo; |
|
|
|
} |
|
|
|
set(baseInfo); |
|
|
|
return baseInfo; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 更新缓存 |
|
|
|
* @param entity |
|
|
|
* @return |
|
|
|
* @author wangc |
|
|
|
* @date 2020.07.30 14:07 |
|
|
|
**/ |
|
|
|
public void updateUserCache(UserBaseInfoEntity entity){ |
|
|
|
if(null == entity || StringUtils.isBlank(entity.getUserId())) return; |
|
|
|
|
|
|
|
UserBaseInfoResultDTO currentCache = ConvertUtils.sourceToTarget(entity,UserBaseInfoResultDTO.class); |
|
|
|
|
|
|
|
RegisterRelationEntity relation = registerRelationDao.selectRegisteredGridIdByUserId(entity.getUserId()); |
|
|
|
//如果没有首次注册网格,则没有网格名称(xx机关-xx网格)、显示昵称(xx网格-x先生/女士)
|
|
|
|
if(null != relation && StringUtils.isNotBlank(relation.getGridId())){ |
|
|
|
currentCache.setCustomerId(relation.getCustomerId()); |
|
|
|
BelongGridNameFormDTO gridParam = new BelongGridNameFormDTO(); |
|
|
|
gridParam.setGridId(relation.getGridId()); |
|
|
|
currentCache.setRegisteredGridId(relation.getGridId()); |
|
|
|
Result<BelongGridNameResultDTO> gridResult = |
|
|
|
govOrgOpenFeignClient.getGridNameByGridId(gridParam); |
|
|
|
if(gridResult.success() && null != gridResult.getData() |
|
|
|
&& StringUtils.isNotBlank(gridResult.getData().getBelongsGridName())){ |
|
|
|
String gridFullName = gridResult.getData().getBelongsGridName(); |
|
|
|
currentCache.setRegisteredGridName(gridFullName); |
|
|
|
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()); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//如果没有居民注册记录,说明当前用户是陌生人,需要从陌生人网格访问列表中查询所属的客户Id
|
|
|
|
LatestGridInfoResultDTO gridLatest = |
|
|
|
gridLatestDao.selectLatestGridInfoByUserId(entity.getUserId()); |
|
|
|
if(null != gridLatest){ |
|
|
|
currentCache.setCustomerId(gridLatest.getCustomerId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//更新缓存的入口只有1.更新微信信息,entity中一定携带微信信息,2.注册居民信息,在调用此方法之前,已经查询过微信信息并赋值到entity中
|
|
|
|
//因此以下代码不需执行
|
|
|
|
//if(StringUtils.isBlank(currentCache.getNickname()) || StringUtils.isBlank(currentCache.getHeadImgUrl())){
|
|
|
|
// UserBaseInfoResultDTO wechatInfo = userBaseInfoDao.selectListByUserIdList(entity.getUserId());
|
|
|
|
// if(null != wechatInfo){
|
|
|
|
// currentCache.setNickname(wechatInfo.getNickname());
|
|
|
|
// currentCache.setGender(wechatInfo.getGender());
|
|
|
|
// currentCache.setHeadImgUrl(wechatInfo.getHeadImgUrl());
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
Map<String,Object> 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); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public <T> void mergeObject(T origin, T destination) { |
|
|
|
if (origin == null || destination == null) |
|
|
|
return; |
|
|
|
if (!origin.getClass().equals(destination.getClass())) |
|
|
|
return; |
|
|
|
|
|
|
|
Field[] fields = origin.getClass().getDeclaredFields(); |
|
|
|
for (int i = 0; i < fields.length; i++) { |
|
|
|
try { |
|
|
|
fields[i].setAccessible(true); |
|
|
|
Object value = fields[i].get(origin); |
|
|
|
if (null != value) { |
|
|
|
fields[i].set(destination, value); |
|
|
|
} |
|
|
|
fields[i].setAccessible(false); |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |