|
|
|
@ -2,31 +2,28 @@ package com.elink.esua.epdc.service.impl; |
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; |
|
|
|
import com.elink.esua.epdc.common.token.dto.TokenDto; |
|
|
|
import com.elink.esua.epdc.common.token.util.CpUserDetailRedis; |
|
|
|
import com.elink.esua.epdc.common.token.util.TokenUtil; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.enums.YesOrNoEnum; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.*; |
|
|
|
import com.elink.esua.epdc.dto.CompleteDeptDTO; |
|
|
|
import com.elink.esua.epdc.dto.UserDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcUserRegistFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcUserUpdateAvatarFromDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcUserUpdateMobileFromDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcUserSaveWxFormIdFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.*; |
|
|
|
import com.elink.esua.epdc.dto.epdc.EpdcCompleteAppUserDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.EpdcGridLeaderRegisterDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcGridLeaderRegisterFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.GridLeaderRegisterDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.*; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.EpdcUserGridResultDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.EpdcUserRegisterInfoResultDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.EpdcUserInfoResultDTO; |
|
|
|
import com.elink.esua.epdc.dto.form.EpdcAppUserMaTokenFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.form.EpdcAppUserTokenFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.form.EpdcAppSaveWxFormIdFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.form.EpdcCheckRegisterFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.form.*; |
|
|
|
import com.elink.esua.epdc.dto.result.EpdcAppRegisterCallbackDTO; |
|
|
|
import com.elink.esua.epdc.dto.result.EpdcAppAuthorizationDTO; |
|
|
|
import com.elink.esua.epdc.enums.AppUserAuditStateEnum; |
|
|
|
import com.elink.esua.epdc.enums.AppUserRegisterSourceEnum; |
|
|
|
import com.elink.esua.epdc.enums.AppUserRegisterWayEnum; |
|
|
|
import com.elink.esua.epdc.enums.AppUserStateEnum; |
|
|
|
import com.elink.esua.epdc.dto.result.EpdcCompleteUserInfoDTO; |
|
|
|
import com.elink.esua.epdc.enums.*; |
|
|
|
import com.elink.esua.epdc.feign.AdminFeignClient; |
|
|
|
import com.elink.esua.epdc.feign.UserFeignClient; |
|
|
|
import com.elink.esua.epdc.jwt.JwtTokenProperties; |
|
|
|
@ -44,6 +41,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -73,9 +71,6 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
@Autowired |
|
|
|
private UserFeignClient userFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TokenUtil tokenUtil; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private JwtTokenProperties jwtTokenProperties; |
|
|
|
|
|
|
|
@ -86,6 +81,9 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
|
|
|
|
private static String USER_FACE = "https://epdc.elinkchina.com.cn/esua-epdc/static/default/default_user_face.png"; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> getMpToken(EpdcAppUserTokenFormDTO formDto) { |
|
|
|
return this.getTokenByOpenId(this.getWxMpUser(formDto.getWxCode()).getOpenId()); |
|
|
|
@ -111,23 +109,6 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
return this.userFeignClient.saveWxFormId(saveFormId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据unionId登录 |
|
|
|
* |
|
|
|
* @param unionId |
|
|
|
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.result.EpdcAppAuthorizationDTO> |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/9/19 19:16 |
|
|
|
*/ |
|
|
|
private Result<EpdcAppAuthorizationDTO> getTokenByUnionId(String unionId) { |
|
|
|
// 查询当前微信是否已注册用户
|
|
|
|
Result<UserDTO> userInfoResult = userFeignClient.getUserForLoginByOpenId(unionId); |
|
|
|
if (!userInfoResult.success()) { |
|
|
|
return new Result().error(userInfoResult.getMsg()); |
|
|
|
} |
|
|
|
return this.getTokenByUserDto(userInfoResult.getData()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据openId登录 |
|
|
|
* |
|
|
|
@ -158,51 +139,21 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
EpdcAppAuthorizationDTO authorization = new EpdcAppAuthorizationDTO(); |
|
|
|
// 用户未注册
|
|
|
|
if (null == userDto) { |
|
|
|
authorization.setUserState(AppUserStateEnum.UNREGISTERED.value()); |
|
|
|
authorization.setUserState(AppUserStatesEnum.STATE_NOT_REGISTERED.value()); |
|
|
|
return new Result().ok(authorization); |
|
|
|
} |
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(userDto, TokenDto.class); |
|
|
|
tokenDto.setUserId(userDto.getId()); |
|
|
|
|
|
|
|
String state = userDto.getState(); |
|
|
|
// 用户注册审核失败
|
|
|
|
if (AppUserAuditStateEnum.AUDIT_FAILURE.value().equals(state)) { |
|
|
|
authorization.setUserState(AppUserStateEnum.AUDIT_FAILURE.value()); |
|
|
|
Result result = new Result().ok(authorization); |
|
|
|
authorization = this.packageEpdcAppAuthorization(tokenDto, userDto.getGrid(), userDto.getState()); |
|
|
|
|
|
|
|
Result result = new Result().ok(authorization); |
|
|
|
// 已注册,未完善信息
|
|
|
|
if (AppUserStatesEnum.STATE_INFORMATION_NOT_PASSED.value().equals(state)) { |
|
|
|
result.setMsg(userDto.getRemark()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
// 用户提交注册、正在等待审核
|
|
|
|
else if (AppUserAuditStateEnum.UNDER_AUDIT.value().equals(state)) { |
|
|
|
authorization.setUserState(AppUserStateEnum.UNDER_AUDIT.value()); |
|
|
|
return new Result().ok(authorization); |
|
|
|
} |
|
|
|
// 用户已注册且审核通过,正常登录系统
|
|
|
|
else if (AppUserAuditStateEnum.AUDIT_SUCCESS.value().equals(state)) { |
|
|
|
String userId = userDto.getId(); |
|
|
|
TokenDto tokenInfo = tokenUtil.getTokenInfo(userId); |
|
|
|
// 生成token
|
|
|
|
String token = jwtTokenUtils.generateToken(userId); |
|
|
|
Long expire; |
|
|
|
// 用户已登录过,且用户缓存信息未超时
|
|
|
|
if (null != tokenInfo) { |
|
|
|
tokenUtil.delayToken(userId); |
|
|
|
expire = tokenUtil.getExpire(userId); |
|
|
|
} else { |
|
|
|
expire = (long) jwtTokenProperties.getExpire(); |
|
|
|
} |
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(userDto, TokenDto.class); |
|
|
|
tokenDto.setUserId(userId); |
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
// 暂用,部署生产环境时删除
|
|
|
|
redisUtils.set("epdc:sys:security:cpuser:token:" + userId, token); |
|
|
|
|
|
|
|
authorization.setUserState(AppUserStateEnum.REGISTERED.value()); |
|
|
|
authorization.setToken(token); |
|
|
|
authorization.setUserId(userId); |
|
|
|
authorization.setExpire(expire); |
|
|
|
authorization.setGrid(userDto.getGrid()); |
|
|
|
return new Result().ok(authorization); |
|
|
|
} else { |
|
|
|
return new Result().error("Login failed"); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -219,6 +170,93 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
return getRegisterResult(userDto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> maGridLeaderRegister(EpdcGridLeaderRegisterSubmitFormDTO formDto) { |
|
|
|
|
|
|
|
String mobile = formDto.getMobile(); |
|
|
|
|
|
|
|
// 校验手机号是否已被注册为小程序用户
|
|
|
|
EpdcUserRegistFormDTO verifyAppUser = new EpdcUserRegistFormDTO(); |
|
|
|
verifyAppUser.setMobile(mobile); |
|
|
|
// 在获取信息时就进行校验,不消耗wxCode,用户可以重复提交
|
|
|
|
Result verifyUserRegisterData = userFeignClient.verifyUserRegisterData(verifyAppUser); |
|
|
|
if (!verifyUserRegisterData.success()) { |
|
|
|
return new Result().error(verifyUserRegisterData.getMsg()); |
|
|
|
} |
|
|
|
// 校验手机验证码
|
|
|
|
this.checkSmsCode(mobile, formDto.getSmsCode()); |
|
|
|
|
|
|
|
Result<GridLeaderRegisterDTO> adminResult = adminFeignClient.listGridWhileLeaderRegister(mobile); |
|
|
|
if (!adminResult.success()) { |
|
|
|
return new Result().error(adminResult.getMsg()); |
|
|
|
} |
|
|
|
GridLeaderRegisterDTO leaderRegisterDto = adminResult.getData(); |
|
|
|
|
|
|
|
// 组装用户注册信息
|
|
|
|
EpdcGridLeaderRegisterDTO gridLeaderRegister = this.packageGridLeaderWhileRegister(leaderRegisterDto.getSysUser(), formDto.getWxCode()); |
|
|
|
List<UserGridRelationDTO> userGridList = ConvertUtils.sourceToTarget(leaderRegisterDto.getLeaderGridList(), UserGridRelationDTO.class); |
|
|
|
|
|
|
|
EpdcGridLeaderRegisterFormDTO registerDto = new EpdcGridLeaderRegisterFormDTO(); |
|
|
|
registerDto.setGridLeader(gridLeaderRegister); |
|
|
|
registerDto.setUserGridList(userGridList); |
|
|
|
|
|
|
|
Result<UserDTO> appUserResult = userFeignClient.gridLeaderRegister(registerDto); |
|
|
|
if (!appUserResult.success()) { |
|
|
|
return new Result().error(adminResult.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
UserDTO newAppUser = appUserResult.getData(); |
|
|
|
|
|
|
|
// 用户已注册且审核通过,正常登录系统
|
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(newAppUser, TokenDto.class); |
|
|
|
tokenDto.setUserId(newAppUser.getId()); |
|
|
|
|
|
|
|
EpdcAppAuthorizationDTO authorization = this.packageEpdcAppAuthorization(tokenDto, newAppUser.getGrid(), AppUserStatesEnum.STATE_REGISTERED.value()); |
|
|
|
|
|
|
|
return new Result().ok(authorization); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装网格长注册的用户信息 |
|
|
|
* |
|
|
|
* @param sysUser 后台管理端管理员账号 |
|
|
|
* @param wxCode |
|
|
|
* @return com.elink.esua.epdc.dto.UserDTO |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/10/23 10:01 |
|
|
|
*/ |
|
|
|
private EpdcGridLeaderRegisterDTO packageGridLeaderWhileRegister(SysUserDTO sysUser, String wxCode) { |
|
|
|
|
|
|
|
WxMaJscode2SessionResult wxMaUser = this.getWxMaUser(wxCode); |
|
|
|
Date now = new Date(); |
|
|
|
String mobile = sysUser.getMobile(); |
|
|
|
|
|
|
|
EpdcGridLeaderRegisterDTO gridLeaderRegister = new EpdcGridLeaderRegisterDTO(); |
|
|
|
gridLeaderRegister.setFaceImg(USER_FACE); |
|
|
|
gridLeaderRegister.setWxUnionId(wxMaUser.getUnionid()); |
|
|
|
gridLeaderRegister.setWxOpenId(wxMaUser.getOpenid()); |
|
|
|
gridLeaderRegister.setRegisterTime(now); |
|
|
|
gridLeaderRegister.setState(AppUserStatesEnum.STATE_INFORMATION_PASSED.value()); |
|
|
|
gridLeaderRegister.setRegisterSource(AppUserRegisterSourceEnum.MA.value()); |
|
|
|
gridLeaderRegister.setRegisterWay(AppUserRegisterWayEnum.WX.value()); |
|
|
|
gridLeaderRegister.setMobile(mobile); |
|
|
|
gridLeaderRegister.setNickname("网格长-" |
|
|
|
+ sysUser.getRealName().substring(NumConstant.ZERO, NumConstant.ONE) |
|
|
|
+ (sysUser.getGender() == NumConstant.ZERO ? "女士" : "先生")); |
|
|
|
gridLeaderRegister.setSex(String.valueOf(sysUser.getGender())); |
|
|
|
gridLeaderRegister.setRealName(sysUser.getRealName()); |
|
|
|
gridLeaderRegister.setEmail(sysUser.getEmail()); |
|
|
|
gridLeaderRegister.setPartyFlag(YesOrNoEnum.NO.value()); |
|
|
|
|
|
|
|
PhoneDto phoneDto = PhoneUtil.getPhoneDto(mobile); |
|
|
|
if (phoneDto != null) { |
|
|
|
gridLeaderRegister.setMobileProvince(phoneDto.getProvinceName()); |
|
|
|
gridLeaderRegister.setMobileCity(phoneDto.getCityName()); |
|
|
|
gridLeaderRegister.setMobileCarrier(phoneDto.getCarrier()); |
|
|
|
} |
|
|
|
|
|
|
|
return gridLeaderRegister; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppRegisterCallbackDTO> mpUserRegister(EpdcUserRegistFormDTO formDto) { |
|
|
|
@ -242,6 +280,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/9/25 17:26 |
|
|
|
*/ |
|
|
|
@Deprecated |
|
|
|
private Result<EpdcAppRegisterCallbackDTO> getRegisterResult(UserDTO userDto) { |
|
|
|
Result result = userFeignClient.userRegist(userDto); |
|
|
|
EpdcAppRegisterCallbackDTO dto = new EpdcAppRegisterCallbackDTO(); |
|
|
|
@ -258,6 +297,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/9/20 14:40 |
|
|
|
*/ |
|
|
|
@Deprecated |
|
|
|
private void verifyUserRegisterData(EpdcUserRegistFormDTO formDto) { |
|
|
|
// 校验身份证号码格式
|
|
|
|
String verification = IdentityNoUtils.IdentityNoVerification(formDto.getIdentityNo()); |
|
|
|
@ -299,6 +339,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
* @author yujintao |
|
|
|
* @date 2019/9/10 21:09 |
|
|
|
*/ |
|
|
|
@Deprecated |
|
|
|
private UserDTO packageUserDto(EpdcUserRegistFormDTO formDto, WxMpUser wxMpUser, WxMaJscode2SessionResult wxMaUser) { |
|
|
|
String unionId = null; |
|
|
|
String openId = null; |
|
|
|
@ -383,7 +424,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
user.setPartyFlag(YesOrNoEnum.NO.value()); |
|
|
|
user.setRegisterWay(AppUserRegisterWayEnum.WX.value()); |
|
|
|
user.setRegisterSource(AppUserRegisterSourceEnum.WP.value()); |
|
|
|
user.setFaceImg("https://epdc.elinkchina.com.cn/esua-epdc/static/default/default_user_face.png"); |
|
|
|
user.setFaceImg(USER_FACE); |
|
|
|
return user; |
|
|
|
} |
|
|
|
|
|
|
|
@ -464,4 +505,338 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
} |
|
|
|
return userFeignClient.updateMobileOrAvatar(userDto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> userSwitchGrid(TokenDto userDetail, String gridId) { |
|
|
|
|
|
|
|
String userId = userDetail.getUserId(); |
|
|
|
|
|
|
|
EpdcLeaderSwitchGridFormDTO switchGrid = new EpdcLeaderSwitchGridFormDTO(); |
|
|
|
switchGrid.setAppUserId(userId); |
|
|
|
switchGrid.setGridId(gridId); |
|
|
|
// 更新用户-网格关系表,更新将要切换的网格的 SWITCHED_TIME 字段
|
|
|
|
Result<UserGridRelationDTO> appUserResult = userFeignClient.userSwitchGrid(switchGrid); |
|
|
|
if (!appUserResult.success()) { |
|
|
|
return new Result().error(appUserResult.getMsg()); |
|
|
|
} |
|
|
|
UserGridRelationDTO userGridRelation = appUserResult.getData(); |
|
|
|
|
|
|
|
userDetail.setGridId(Long.parseLong(gridId)); |
|
|
|
EpdcAppAuthorizationDTO authorization = this.packageEpdcAppAuthorization(userDetail, userGridRelation.getGrid(), AppUserStatesEnum.STATE_REGISTERED.value()); |
|
|
|
|
|
|
|
return new Result().ok(authorization); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<List<EpdcUserGridResultDTO>> listUserGrid(String userId) { |
|
|
|
return userFeignClient.listUserGrid(userId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装成功登录的数据 |
|
|
|
* |
|
|
|
* @param tokenDto 缓存的用户数据 |
|
|
|
* @param grid 网格名称 |
|
|
|
* @param userState AppUserStatesEnum |
|
|
|
* @return com.elink.esua.epdc.dto.result.EpdcAppAuthorizationDTO |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/10/23 13:57 |
|
|
|
*/ |
|
|
|
private EpdcAppAuthorizationDTO packageEpdcAppAuthorization(TokenDto tokenDto, String grid, String userState) { |
|
|
|
String userId = tokenDto.getUserId(); |
|
|
|
// 生成token
|
|
|
|
String token = jwtTokenUtils.generateToken(userId); |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
|
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
|
|
|
|
EpdcAppAuthorizationDTO authorization = new EpdcAppAuthorizationDTO(); |
|
|
|
authorization.setUserState(userState); |
|
|
|
authorization.setToken(token); |
|
|
|
authorization.setUserId(userId); |
|
|
|
authorization.setExpire((long) expire); |
|
|
|
authorization.setGrid(grid); |
|
|
|
|
|
|
|
// 暂用,部署生产环境时删除
|
|
|
|
redisUtils.set("epdc:sys:security:cpuser:token:" + userId, token); |
|
|
|
|
|
|
|
return authorization; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> getMaV2Token(EpdcAppUserRegisterFormDTO formDto) { |
|
|
|
WxMaJscode2SessionResult wxMaResult = this.getWxMaUser(formDto.getWxCode()); |
|
|
|
String openId = wxMaResult.getOpenid(); |
|
|
|
String unionId = wxMaResult.getUnionid(); |
|
|
|
// 查询当前微信注册状态
|
|
|
|
EpdcCheckUserRegisterFromDTO checkFromDto = new EpdcCheckUserRegisterFromDTO(); |
|
|
|
checkFromDto.setOpenId(openId); |
|
|
|
checkFromDto.setGridId(formDto.getGridId()); |
|
|
|
Result<EpdcUserRegisterInfoResultDTO> userResult = userFeignClient.getUserRegisterState(checkFromDto); |
|
|
|
if (!userResult.success()) { |
|
|
|
return new Result<EpdcAppAuthorizationDTO>().error(userResult.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
// IP地址
|
|
|
|
HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); |
|
|
|
|
|
|
|
return this.dealWithUserRegisterState(userResult.getData(), openId, unionId, IpUtils.getIpAddr(request)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 针对不同用户注册状态进行处理 |
|
|
|
* |
|
|
|
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.result.EpdcAppAuthorizationDTO> |
|
|
|
* @params [checkUserResult, unionId] |
|
|
|
* @author liuchuang |
|
|
|
* @since 2019/10/25 12:49 |
|
|
|
*/ |
|
|
|
private Result<EpdcAppAuthorizationDTO> dealWithUserRegisterState(EpdcUserRegisterInfoResultDTO userResult, String openId, String unionId, String ipAddress) { |
|
|
|
EpdcUserRegisterBindGridFormDTO registerBindGridFormDto = new EpdcUserRegisterBindGridFormDTO(); |
|
|
|
// 用户注册状态 0-未注册未绑定网格,1-已注册未绑定当前网格,2-已注册已绑定当前网格
|
|
|
|
Integer registerState = userResult.getRegisterState(); |
|
|
|
UserDTO registeredUser = userResult.getUserDTO(); |
|
|
|
Long gridId = userResult.getGridId(); |
|
|
|
// 未注册
|
|
|
|
if (NumConstant.ZERO == registerState) { |
|
|
|
// 组装用户注册信息
|
|
|
|
registerBindGridFormDto.setRegisterState(NumConstant.ZERO); |
|
|
|
registeredUser = this.packageUserInfo(openId, unionId, ipAddress); |
|
|
|
registerBindGridFormDto.setUserDTO(registeredUser); |
|
|
|
} |
|
|
|
// 已注册未绑定当前网格
|
|
|
|
else if (NumConstant.ONE == registerState) { |
|
|
|
registerBindGridFormDto.setRegisterState(NumConstant.ONE); |
|
|
|
registerBindGridFormDto.setUserDTO(registeredUser); |
|
|
|
} |
|
|
|
// 用户注册或绑定网格
|
|
|
|
if (NumConstant.TWO != registerState) { |
|
|
|
// 组装用户关联网格信息
|
|
|
|
registerBindGridFormDto.setGridRelationDTO(this.packageUserGridRelationInfo(gridId)); |
|
|
|
// 用户并绑定网格
|
|
|
|
Result<EpdcUserRegisterInfoResultDTO> registerBindGridResultDto = userFeignClient.registerOrBindGrid(registerBindGridFormDto); |
|
|
|
if (!registerBindGridResultDto.success()) { |
|
|
|
return new Result<EpdcAppAuthorizationDTO>().error(registerBindGridResultDto.getMsg()); |
|
|
|
} |
|
|
|
userResult = registerBindGridResultDto.getData(); |
|
|
|
registeredUser = userResult.getUserDTO(); |
|
|
|
} |
|
|
|
|
|
|
|
// 已注册已绑定当前网格
|
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(registeredUser, TokenDto.class); |
|
|
|
tokenDto.setUserId(registeredUser.getId()); |
|
|
|
tokenDto.setGridId(gridId); |
|
|
|
EpdcAppAuthorizationDTO authorization = this.packageEpdcAppAuthorization(tokenDto, userResult.getGrid(), registeredUser.getState()); |
|
|
|
|
|
|
|
return new Result<EpdcAppAuthorizationDTO>().ok(authorization); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装用户注册信息 |
|
|
|
* |
|
|
|
* @return com.elink.esua.epdc.dto.UserDTO |
|
|
|
* @params [openId, unionId, completeDept] |
|
|
|
* @author liuchuang |
|
|
|
* @since 2019/10/24 18:16 |
|
|
|
*/ |
|
|
|
private UserDTO packageUserInfo(String openId, String unionId, String ipAddress) { |
|
|
|
UserDTO userDto = new UserDTO(); |
|
|
|
userDto.setWxOpenId(openId); |
|
|
|
userDto.setWxUnionId(unionId); |
|
|
|
userDto.setNickname("用户" + RandomUtil.getNewRandomCode(4)); |
|
|
|
userDto.setFaceImg(USER_FACE); |
|
|
|
userDto.setState(AppUserStatesEnum.STATE_REGISTERED.value()); |
|
|
|
userDto.setPartyFlag(YesOrNoEnum.NO.value()); |
|
|
|
userDto.setLastLoginIp(ipAddress); |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
userDto.setRegisterTime(now); |
|
|
|
userDto.setLastLoginTime(now); |
|
|
|
userDto.setRegisterWay(AppUserRegisterWayEnum.WX.value()); |
|
|
|
userDto.setRegisterSource(AppUserRegisterSourceEnum.MA.value()); |
|
|
|
|
|
|
|
return userDto; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> completeUserInfo(TokenDto tokenDto, EpdcCompleteUserInfoFormDTO infoDto) { |
|
|
|
|
|
|
|
UserDTO userDto = ConvertUtils.sourceToTarget(infoDto, UserDTO.class); |
|
|
|
userDto.setId(tokenDto.getUserId()); |
|
|
|
|
|
|
|
// 党员提交,验证身份证号
|
|
|
|
if (YesOrNoEnum.YES.value().equals(userDto.getPartyFlag())) { |
|
|
|
String identityNo = userDto.getIdentityNo(); |
|
|
|
if (StringUtils.isBlank(identityNo)) { |
|
|
|
return new Result().error("身份证号不能为空"); |
|
|
|
} else { |
|
|
|
String verification = IdentityNoUtils.IdentityNoVerification(identityNo); |
|
|
|
if (StringUtils.isNotBlank(verification)) { |
|
|
|
return new Result().error(verification); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 验证手机号
|
|
|
|
this.checkSmsCode(userDto.getMobile(), infoDto.getSmsCode()); |
|
|
|
// 验证用户提交的信息
|
|
|
|
Result<String> verifyResult = userFeignClient.verifyUserCompleteData(userDto); |
|
|
|
if (!verifyResult.success()) { |
|
|
|
return new Result().error(verifyResult.getMsg()); |
|
|
|
} |
|
|
|
String userState = verifyResult.getData(); |
|
|
|
|
|
|
|
UserGridRelationDTO userGrid = this.packageUserGridRelationInfo(tokenDto.getGridId()); |
|
|
|
EpdcCompleteAppUserDTO completeAppUserDto = ConvertUtils.sourceToTarget(userDto, EpdcCompleteAppUserDTO.class); |
|
|
|
completeAppUserDto = this.packageUserCompleteInfo(completeAppUserDto, userState); |
|
|
|
// 组装对象,准备保存用户信息
|
|
|
|
EpdcAppUserCompleteInfoFormDTO dto = new EpdcAppUserCompleteInfoFormDTO(); |
|
|
|
dto.setCompleteAppUser(completeAppUserDto); |
|
|
|
dto.setUserGridRelation(userGrid); |
|
|
|
|
|
|
|
Result<UserDTO> completeResult = userFeignClient.completeUserInfo(dto); |
|
|
|
if (!completeResult.success()) { |
|
|
|
return new Result().error(completeResult.getMsg()); |
|
|
|
} |
|
|
|
UserDTO user = completeResult.getData(); |
|
|
|
tokenDto.setRealName(user.getRealName()); |
|
|
|
tokenDto.setNickname(user.getNickname()); |
|
|
|
tokenDto.setMobile(user.getMobile()); |
|
|
|
tokenDto.setPartyFlag(user.getPartyFlag()); |
|
|
|
EpdcAppAuthorizationDTO authorizationDto = this.packageEpdcAppAuthorization(tokenDto, userGrid.getGrid(), userDto.getState()); |
|
|
|
|
|
|
|
return new Result().ok(authorizationDto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcCompleteUserInfoDTO> prepareCompleteUserInfo(TokenDto tokenDto) { |
|
|
|
|
|
|
|
Result<UserDTO> result = userFeignClient.getUserInfoById(tokenDto.getUserId()); |
|
|
|
if (result.success() && null != result.getData()) { |
|
|
|
EpdcCompleteUserInfoDTO dto = ConvertUtils.sourceToTarget(result.getData(), EpdcCompleteUserInfoDTO.class); |
|
|
|
dto.setGridId(tokenDto.getGridId()); |
|
|
|
return new Result<EpdcCompleteUserInfoDTO>().ok(dto); |
|
|
|
} |
|
|
|
return new Result().error("获取用户信息失败"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装个人完善信息对象 |
|
|
|
* |
|
|
|
* @param dto 已知数据 |
|
|
|
* @param userState 用户当前状态,用户状态不为0时,表明用户操作为二次修改 |
|
|
|
* @return com.elink.esua.epdc.dto.epdc.EpdcCompleteAppUserDTO |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/10/29 17:54 |
|
|
|
*/ |
|
|
|
private EpdcCompleteAppUserDTO packageUserCompleteInfo(EpdcCompleteAppUserDTO dto, String userState) { |
|
|
|
|
|
|
|
String road = dto.getRoad(); |
|
|
|
String villageName = dto.getVillageName(); |
|
|
|
String dwellingPlace = dto.getDwellingPlace(); |
|
|
|
String identityNo = dto.getIdentityNo(); |
|
|
|
|
|
|
|
if (YesOrNoEnum.YES.value().equals(dto.getPartyFlag())) { |
|
|
|
dto.setState(AppUserStatesEnum.STATE_INFORMATION_PASSED.value()); |
|
|
|
dto.setSex(IdentityNoUtils.getSex(identityNo)); |
|
|
|
dto.setNickname( |
|
|
|
road.concat("-").concat(dto.getRealName().substring(NumConstant.ZERO, NumConstant.ONE)) |
|
|
|
.concat(NumConstant.ZERO_STR.equals(dto.getSex()) ? "女士" : "先生")); |
|
|
|
dto.setBirthday(DateUtils.parse(IdentityNoUtils.getBirthday(identityNo), DateUtils.DATE_PATTERN)); |
|
|
|
} else { |
|
|
|
dto.setState(AppUserStatesEnum.STATE_COMPLETED_INFORMATION_PENDING_REVIEW.value()); |
|
|
|
} |
|
|
|
// 用户不是第一次完善信息,保持现在的用户状态不变
|
|
|
|
if (!AppUserStatesEnum.STATE_REGISTERED.value().equals(userState)) { |
|
|
|
dto.setState(userState); |
|
|
|
} |
|
|
|
|
|
|
|
String address = road |
|
|
|
.concat(StringUtils.isNotBlank(villageName) ? villageName : "") |
|
|
|
.concat(StringUtils.isNotBlank(dwellingPlace) ? dwellingPlace : ""); |
|
|
|
dto.setAddress(address); |
|
|
|
|
|
|
|
PhoneDto phoneDto = PhoneUtil.getPhoneDto(dto.getMobile()); |
|
|
|
if (phoneDto != null) { |
|
|
|
dto.setMobileCarrier(phoneDto.getCarrier()); |
|
|
|
dto.setMobileCity(phoneDto.getCityName()); |
|
|
|
dto.setMobileProvince(phoneDto.getProvinceName()); |
|
|
|
} |
|
|
|
|
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装用户关联网格信息 |
|
|
|
* |
|
|
|
* @return com.elink.esua.epdc.dto.UserGridRelationDTO |
|
|
|
* @params [gridId] |
|
|
|
* @author liuchuang |
|
|
|
* @since 2019/10/25 13:53 |
|
|
|
*/ |
|
|
|
private UserGridRelationDTO packageUserGridRelationInfo(Long gridId) { |
|
|
|
// 获取网格机构详情
|
|
|
|
Result<CompleteDeptDTO> adminDeptResult = adminFeignClient.getCompleteDept(gridId); |
|
|
|
if (!adminDeptResult.success() || null == adminDeptResult.getData()) { |
|
|
|
throw new RenException("查询网格信息失败"); |
|
|
|
} |
|
|
|
CompleteDeptDTO completeDept = adminDeptResult.getData(); |
|
|
|
UserGridRelationDTO gridRelation = ConvertUtils.sourceToTarget(completeDept, UserGridRelationDTO.class); |
|
|
|
gridRelation.setSwitchedTime(new Date()); |
|
|
|
gridRelation.setLeaderFlag(YesOrNoEnum.NO.value()); |
|
|
|
|
|
|
|
return gridRelation; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result updateWxInfo(TokenDto userDetail, EpdcAppUserMaInfoFormDTO formDto) { |
|
|
|
if (null == userDetail || StringUtils.isEmpty(userDetail.getUserId())) { |
|
|
|
return new Result().error("获取用户信息失败"); |
|
|
|
} |
|
|
|
String sessionKey = this.getUserSessionKey(formDto.getWxCode()); |
|
|
|
WxMaUserInfo wxMaUserInfo = wxMaService.getUserService().getUserInfo(sessionKey, formDto.getEncryptedData(), formDto.getIv()); |
|
|
|
UserDTO userDTO = new UserDTO(); |
|
|
|
userDTO.setId(userDetail.getUserId()); |
|
|
|
userDTO.setNickname(wxMaUserInfo.getNickName()); |
|
|
|
userDTO.setFaceImg(wxMaUserInfo.getAvatarUrl()); |
|
|
|
userDTO.setSex(wxMaUserInfo.getGender()); |
|
|
|
Result updateWxInfoResult = userFeignClient.updateWxInfo(userDTO); |
|
|
|
if (!updateWxInfoResult.success()) { |
|
|
|
return new Result().error("更新用户信息失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新用户缓存信息
|
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(userDTO, TokenDto.class); |
|
|
|
tokenDto.setUserId(userDetail.getUserId()); |
|
|
|
tokenDto.setGridId(userDetail.getGridId()); |
|
|
|
tokenDto.setMobile(userDetail.getMobile()); |
|
|
|
tokenDto.setPartyFlag(userDetail.getPartyFlag()); |
|
|
|
tokenDto.setRealName(userDetail.getRealName()); |
|
|
|
long expire = cpUserDetailRedis.getExpire(userDetail.getUserId()); |
|
|
|
cpUserDetailRedis.logout(userDetail.getUserId()); |
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据微信code获取session_key |
|
|
|
* |
|
|
|
* @return java.lang.String |
|
|
|
* @params [code] |
|
|
|
* @author liuchuang |
|
|
|
* @since 2019/10/25 16:31 |
|
|
|
*/ |
|
|
|
private String getUserSessionKey(String code) { |
|
|
|
try { |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult = wxMaService.jsCode2SessionInfo(code); |
|
|
|
if (wxMaJscode2SessionResult != null) { |
|
|
|
return wxMaJscode2SessionResult.getSessionKey(); |
|
|
|
} |
|
|
|
} catch (WxErrorException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw new RenException(e.getError().getErrorMsg()); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|