Browse Source

dingResiLogin

feature/evaluate
yinzuomei 3 years ago
parent
commit
3ee0a5b718
  1. 117
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserBaseInfoServiceImpl.java

117
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/UserBaseInfoServiceImpl.java

@ -26,6 +26,7 @@ import com.epmet.commons.tools.constant.AppClientConstant;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.distributedlock.DistributedLock;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.RenException;
@ -61,6 +62,7 @@ import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -68,6 +70,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 用户基础信息
@ -102,6 +105,8 @@ public class UserBaseInfoServiceImpl extends BaseServiceImpl<UserBaseInfoDao, Us
private RegisterRelationDao registerRelationDao;
@Resource
private UserDao userDao;
@Autowired
private DistributedLock distributedLock;
@Override
public PageData<UserBaseInfoDTO> page(Map<String, Object> params) {
@ -550,66 +555,72 @@ public class UserBaseInfoServiceImpl extends BaseServiceImpl<UserBaseInfoDao, Us
result.setGridId(StrConstant.EPMETY_STR);
result.setGridName(StrConstant.EPMETY_STR);
result.setAgencyId(StrConstant.EPMETY_STR);
//根据手机号从baseinfo查对应的信息,如果有则返回,没有则注册
UserBaseInfoEntity baseInfo = baseDao.selectUserByMobile(formDTO.getCustomerId(),formDTO.getMobile());
if (null == baseInfo) {
//注册
UserEntity userEntity = new UserEntity();
userEntity.setFromApp(AppClientConstant.APP_RESI);
userEntity.setFromClient(AppClientConstant.MINI_DING);
userEntity.setCustomerId(formDTO.getCustomerId());
userDao.insert(userEntity);
//信息存入baseinfo
baseInfo = new UserBaseInfoEntity();
baseInfo.setCustomerId(formDTO.getCustomerId());
baseInfo.setUserId(userEntity.getId());
baseInfo.setMobile(formDTO.getMobile());
baseInfo.setRealName(formDTO.getNick());
baseInfo.setSurname(NameUtils.getSurNameComplex(formDTO.getNick()));
baseInfo.setName(NameUtils.getNameComplex(formDTO.getNick()));
baseInfo.setNickname(formDTO.getNick());
baseInfo.setHeadImgUrl(formDTO.getAvatarUrl());
baseInfo.setGender(NumConstant.ZERO_STR);
baseDao.insert(baseInfo);
result.setEpmetUserId(userEntity.getId());
result.setRegFlag(false);
} else {
// 更新下user_Base_info信息
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getRealName())) {
RLock lock = null;
try {
lock = distributedLock.getLock(String.format("epmet:lock:dingResiLogin:%s",formDTO.getMobile()), 120L, 3L, TimeUnit.SECONDS);
//根据手机号从baseinfo查对应的信息,如果有则返回,没有则注册
UserBaseInfoEntity baseInfo = baseDao.selectUserByMobile(formDTO.getCustomerId(),formDTO.getMobile());
if (null == baseInfo) {
//注册
UserEntity userEntity = new UserEntity();
userEntity.setFromApp(AppClientConstant.APP_RESI);
userEntity.setFromClient(AppClientConstant.MINI_DING);
userEntity.setCustomerId(formDTO.getCustomerId());
userDao.insert(userEntity);
//信息存入baseinfo
baseInfo = new UserBaseInfoEntity();
baseInfo.setCustomerId(formDTO.getCustomerId());
baseInfo.setUserId(userEntity.getId());
baseInfo.setMobile(formDTO.getMobile());
baseInfo.setRealName(formDTO.getNick());
}
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getSurname())) {
baseInfo.setSurname(NameUtils.getSurNameComplex(formDTO.getNick()));
}
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getName())) {
baseInfo.setName(NameUtils.getNameComplex(formDTO.getNick()));
}
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getNickname())) {
baseInfo.setNickname(formDTO.getNick());
}
if (StringUtils.isNotBlank(formDTO.getAvatarUrl()) && StringUtils.isBlank(baseInfo.getHeadImgUrl())) {
baseInfo.setHeadImgUrl(formDTO.getAvatarUrl());
}
baseDao.updateById(baseInfo);
result.setEpmetUserId(baseInfo.getUserId());
LambdaQueryWrapper<RegisterRelationEntity> registerWrapper = new LambdaQueryWrapper<>();
registerWrapper.eq(RegisterRelationEntity::getCustomerId, formDTO.getCustomerId());
registerWrapper.eq(RegisterRelationEntity::getUserId, baseInfo.getUserId());
registerWrapper.eq(RegisterRelationEntity::getFirstRegister, NumConstant.ONE_STR);
RegisterRelationEntity registerRelation = registerRelationDao.selectOne(registerWrapper);
if (null != registerRelation) {
result.setAgencyId(registerRelation.getAgencyId());
result.setGridId(registerRelation.getGridId());
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(registerRelation.getGridId());
if (null == gridInfo) {
logger.error(String.format("获取用户注册网格信息为空,userId:%s,gridId:%s", baseInfo.getUserId(), registerRelation.getGridId()));
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取网格信息为空", "获取小程序注册网格信息失败");
baseInfo.setGender(NumConstant.ZERO_STR);
baseDao.insert(baseInfo);
result.setEpmetUserId(userEntity.getId());
result.setRegFlag(false);
} else {
// 更新下user_Base_info信息
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getRealName())) {
baseInfo.setRealName(formDTO.getNick());
}
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getSurname())) {
baseInfo.setSurname(NameUtils.getSurNameComplex(formDTO.getNick()));
}
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getName())) {
baseInfo.setName(NameUtils.getNameComplex(formDTO.getNick()));
}
if (StringUtils.isNotBlank(formDTO.getNick()) && StringUtils.isBlank(baseInfo.getNickname())) {
baseInfo.setNickname(formDTO.getNick());
}
if (StringUtils.isNotBlank(formDTO.getAvatarUrl()) && StringUtils.isBlank(baseInfo.getHeadImgUrl())) {
baseInfo.setHeadImgUrl(formDTO.getAvatarUrl());
}
baseDao.updateById(baseInfo);
result.setEpmetUserId(baseInfo.getUserId());
LambdaQueryWrapper<RegisterRelationEntity> registerWrapper = new LambdaQueryWrapper<>();
registerWrapper.eq(RegisterRelationEntity::getCustomerId, formDTO.getCustomerId());
registerWrapper.eq(RegisterRelationEntity::getUserId, baseInfo.getUserId());
registerWrapper.eq(RegisterRelationEntity::getFirstRegister, NumConstant.ONE_STR);
RegisterRelationEntity registerRelation = registerRelationDao.selectOne(registerWrapper);
if (null != registerRelation) {
result.setAgencyId(registerRelation.getAgencyId());
result.setGridId(registerRelation.getGridId());
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(registerRelation.getGridId());
if (null == gridInfo) {
logger.error(String.format("获取用户注册网格信息为空,userId:%s,gridId:%s", baseInfo.getUserId(), registerRelation.getGridId()));
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取网格信息为空", "获取小程序注册网格信息失败");
}
result.setGridName(gridInfo.getGridNamePath());
result.setRegFlag(true);
}
result.setGridName(gridInfo.getGridNamePath());
result.setRegFlag(true);
}
} finally {
distributedLock.unLock(lock);
}
return result;
}

Loading…
Cancel
Save