|
|
|
@ -13,12 +13,10 @@ import com.elink.esua.epdc.dto.*; |
|
|
|
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.EpdcUserRegisterInfoResultDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.EpdcLeaderGridResultDTO; |
|
|
|
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.*; |
|
|
|
@ -590,4 +588,127 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|
return this.dealWithUserRegisterState(userResult.getData(), openId, unionId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 针对不同用户注册状态进行处理 |
|
|
|
* |
|
|
|
* @params [checkUserResult, unionId] |
|
|
|
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.result.EpdcAppAuthorizationDTO> |
|
|
|
* @author liuchuang |
|
|
|
* @since 2019/10/25 12:49 |
|
|
|
*/ |
|
|
|
private Result<EpdcAppAuthorizationDTO> dealWithUserRegisterState(EpdcUserRegisterInfoResultDTO userResult, |
|
|
|
String openId, String unionId) { |
|
|
|
EpdcUserRegisterBindGridFormDTO registerBindGridFormDto = new EpdcUserRegisterBindGridFormDTO(); |
|
|
|
// 未注册
|
|
|
|
if (NumConstant.ZERO == userResult.getRegisterState()) { |
|
|
|
// 组装用户注册信息
|
|
|
|
registerBindGridFormDto.setRegisterState(NumConstant.ZERO); |
|
|
|
registerBindGridFormDto.setUserDTO(this.packageUserInfo(openId, unionId)); |
|
|
|
} |
|
|
|
// 已注册未绑定当前网格
|
|
|
|
else if (NumConstant.ONE == userResult.getRegisterState()) { |
|
|
|
registerBindGridFormDto.setRegisterState(NumConstant.ONE); |
|
|
|
registerBindGridFormDto.setUserDTO(userResult.getUserDTO()); |
|
|
|
} |
|
|
|
|
|
|
|
// 用户注册或绑定网格
|
|
|
|
if (NumConstant.TWO != userResult.getRegisterState()) { |
|
|
|
// 组装用户关联网格信息
|
|
|
|
registerBindGridFormDto.setGridRelationDTO(this.packageUserGridRelationInfo(userResult.getGridId())); |
|
|
|
// 用户并绑定网格
|
|
|
|
Result<EpdcUserRegisterInfoResultDTO> registerBindGridResultDto = userFeignClient.registerOrBindGrid(registerBindGridFormDto); |
|
|
|
if (!registerBindGridResultDto.success()) { |
|
|
|
return new Result<EpdcAppAuthorizationDTO>().error(registerBindGridResultDto.getMsg()); |
|
|
|
} |
|
|
|
userResult = registerBindGridResultDto.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
// 已注册已绑定当前网格
|
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(userResult.getUserDTO(), TokenDto.class); |
|
|
|
tokenDto.setUserId(userResult.getUserDTO().getId()); |
|
|
|
EpdcAppAuthorizationDTO authorization = this.packageEpdcAppAuthorization(tokenDto, userResult.getGrid(), userResult.getUserDTO().getState()); |
|
|
|
authorization.setUserState(userResult.getUserDTO().getState()); |
|
|
|
|
|
|
|
return new Result<EpdcAppAuthorizationDTO>().ok(authorization); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 组装用户注册信息 |
|
|
|
* |
|
|
|
* @params [openId, unionId, completeDept] |
|
|
|
* @return com.elink.esua.epdc.dto.UserDTO |
|
|
|
* @author liuchuang |
|
|
|
* @since 2019/10/24 18:16 |
|
|
|
*/ |
|
|
|
private UserDTO packageUserInfo(String openId, String unionId) { |
|
|
|
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()); |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
userDto.setRegisterTime(now); |
|
|
|
userDto.setLastLoginTime(now); |
|
|
|
userDto.setRegisterWay(AppUserRegisterWayEnum.WX.value()); |
|
|
|
userDto.setRegisterSource(AppUserRegisterSourceEnum.WP.value()); |
|
|
|
|
|
|
|
// IP地址
|
|
|
|
HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); |
|
|
|
userDto.setLastLoginIp(IpUtils.getIpAddr(request)); |
|
|
|
|
|
|
|
return userDto; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 组装用户关联网格信息 |
|
|
|
* |
|
|
|
* @params [gridId] |
|
|
|
* @return com.elink.esua.epdc.dto.UserGridRelationDTO |
|
|
|
* @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 gridRelationDTO = new UserGridRelationDTO(); |
|
|
|
gridRelationDTO.setDistrictId(completeDept.getDistrictId()); |
|
|
|
gridRelationDTO.setDistrict(completeDept.getDistrict()); |
|
|
|
gridRelationDTO.setStreet(completeDept.getStreet()); |
|
|
|
gridRelationDTO.setStreetId(completeDept.getStreetId()); |
|
|
|
gridRelationDTO.setCommunity(completeDept.getCommunity()); |
|
|
|
gridRelationDTO.setCommunityId(completeDept.getCommunityId()); |
|
|
|
gridRelationDTO.setGrid(completeDept.getGrid()); |
|
|
|
gridRelationDTO.setGridId(completeDept.getGridId()); |
|
|
|
gridRelationDTO.setSwitchedTime(new Date()); |
|
|
|
|
|
|
|
return gridRelationDTO; |
|
|
|
} |
|
|
|
} |
|
|
|
|