|
|
|
/**
|
|
|
|
* Copyright 2018 人人开源 https://www.renren.io
|
|
|
|
* <p>
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
* <p>
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* <p>
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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.Result;
|
|
|
|
import com.epmet.constant.UserRedisKeys;
|
|
|
|
import com.epmet.dao.GridLatestDao;
|
|
|
|
import com.epmet.dao.RegisterRelationDao;
|
|
|
|
import com.epmet.dao.UserBaseInfoDao;
|
|
|
|
import com.epmet.dto.form.BelongGridNameFormDTO;
|
|
|
|
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.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.util.Map;
|
|
|
|
|
|
|
|
import static com.epmet.commons.tools.redis.RedisUtils.NOT_EXPIRE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户基础信息
|
|
|
|
*
|
|
|
|
* @author generator generator@elink-cn.com
|
|
|
|
* @since v1.0.0 2020-07-19
|
|
|
|
*/
|
|
|
|
@Component
|
|
|
|
public class UserBaseInfoRedis {
|
|
|
|
@Autowired
|
|
|
|
private RedisUtils redisUtils;
|
|
|
|
@Autowired
|
|
|
|
private UserBaseInfoDao userBaseInfoDao;
|
|
|
|
@Autowired
|
|
|
|
private RegisterRelationDao registerRelationDao;
|
|
|
|
@Autowired
|
|
|
|
private GovOrgOpenFeignClient govOrgOpenFeignClient;
|
|
|
|
@Autowired
|
|
|
|
private GridLatestDao gridLatestDao;
|
|
|
|
|
|
|
|
public void delete(Object[] ids) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description 将用户基本信息放入缓存
|
|
|
|
* @param baseInfo
|
|
|
|
* @return
|
|
|
|
* @author wangc
|
|
|
|
* @date 2020.07.23 14:43
|
|
|
|
**/
|
|
|
|
public void set(UserBaseInfoResultDTO baseInfo){
|
|
|
|
if(StringUtils.isBlank(baseInfo.getUserId())) return;
|
|
|
|
String key = UserRedisKeys.getResiUserKey(baseInfo.getUserId());
|
|
|
|
//bean to map
|
|
|
|
Map<String, Object> map = BeanUtil.beanToMap(baseInfo, false, true);
|
|
|
|
redisUtils.hMSet(key, map,NOT_EXPIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String get(String id){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description 缓存中获取用户基本信息
|
|
|
|
* @param userId
|
|
|
|
* @return
|
|
|
|
* @author wangc
|
|
|
|
* @date 2020.07.23 14:58
|
|
|
|
**/
|
|
|
|
public UserBaseInfoResultDTO getUserInfo(String userId){
|
|
|
|
if(StringUtils.isNotBlank(userId)){
|
|
|
|
//获取居民缓存key
|
|
|
|
Map<String,Object> map = redisUtils.hGetAll(UserRedisKeys.getResiUserKey(userId));
|
|
|
|
if(null != map && !map.isEmpty()) {
|
|
|
|
//缓存中有数据,直接返回
|
|
|
|
return BeanUtil.mapToBean(map, UserBaseInfoResultDTO.class, true);
|
|
|
|
}
|
|
|
|
//缓存中没有数据,先查数据库,放入缓存后再返回
|
|
|
|
UserBaseInfoResultDTO baseInfo = userBaseInfoDao.selectListByUserIdList(userId);
|
|
|
|
if(null != baseInfo && StringUtils.isNotBlank(baseInfo.getId())){
|
|
|
|
RegisterRelationEntity relation = registerRelationDao.selectRegisteredGridIdByUserId(userId);
|
|
|
|
//如果没有首次注册网格,则没有网格名称(xx机关-xx网格)、显示昵称(xx网格-x先生/女士)
|
|
|
|
if(null != relation && StringUtils.isNotBlank(relation.getGridId())){
|
|
|
|
baseInfo.setCustomerId(relation.getCustomerId());
|
|
|
|
BelongGridNameFormDTO gridParam = new BelongGridNameFormDTO();
|
|
|
|
gridParam.setGridId(relation.getGridId());
|
|
|
|
baseInfo.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();
|
|
|
|
baseInfo.setRegisteredGridName(gridFullName);
|
|
|
|
StringBuffer buffer = new StringBuffer(gridFullName.split(ModuleConstant.DASH)[NumConstant.ONE]).append(ModuleConstant.DASH).append(baseInfo.getSurname());
|
|
|
|
switch (baseInfo.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);
|
|
|
|
}
|
|
|
|
baseInfo.setShowName(buffer.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//如果没有居民注册记录,说明当前用户是陌生人,需要从陌生人网格访问列表中查询所属的客户Id
|
|
|
|
LatestGridInfoResultDTO gridLatest =
|
|
|
|
gridLatestDao.selectLatestGridInfoByUserId(userId);
|
|
|
|
if(null != gridLatest){
|
|
|
|
baseInfo.setCustomerId(gridLatest.getCustomerId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set(baseInfo);
|
|
|
|
return baseInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|