|
@ -2,6 +2,7 @@ package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
|
|
import com.epmet.common.token.constant.LoginConstant; |
|
|
import com.epmet.common.token.constant.LoginConstant; |
|
|
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
@ -67,28 +68,27 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
* @Date 2020/4/18 10:59 |
|
|
* @Date 2020/4/18 10:59 |
|
|
**/ |
|
|
**/ |
|
|
@Override |
|
|
@Override |
|
|
public Result sendSmsCode(SendSmsCodeFormDTO formDTO) { |
|
|
public void sendSmsCode(SendSmsCodeFormDTO formDTO) { |
|
|
//1、校验手机号是否符合规范
|
|
|
//1、校验手机号是否符合规范
|
|
|
if (!PhoneValidatorUtils.isMobile(formDTO.getMobile())) { |
|
|
if (!PhoneValidatorUtils.isMobile(formDTO.getMobile())) { |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), EpmetErrorCode.ERROR_PHONE.getCode(), EpmetErrorCode.ERROR_PHONE.getMsg())); |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), EpmetErrorCode.ERROR_PHONE.getCode(), EpmetErrorCode.ERROR_PHONE.getMsg())); |
|
|
return new Result().error(EpmetErrorCode.ERROR_PHONE.getCode()); |
|
|
throw new RenException(EpmetErrorCode.ERROR_PHONE.getCode()); |
|
|
} |
|
|
} |
|
|
//2、根据手机号校验用户是否存在
|
|
|
//2、根据手机号校验用户是否存在
|
|
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserFeignClient.checkCustomerStaff(formDTO.getMobile()); |
|
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserFeignClient.checkCustomerStaff(formDTO.getMobile()); |
|
|
if (!customerStaffResult.success()) { |
|
|
if (!customerStaffResult.success()) { |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
|
|
return new Result().error(customerStaffResult.getCode()); |
|
|
throw new RenException(customerStaffResult.getCode()); |
|
|
} |
|
|
} |
|
|
//3、发送短信验证码
|
|
|
//3、发送短信验证码
|
|
|
Result<Map<String, String>> smsCodeResult = messageFeignClient.sendSmsCaptcha(formDTO.getMobile()); |
|
|
Result<Map<String, String>> smsCodeResult = messageFeignClient.sendSmsCaptcha(formDTO.getMobile()); |
|
|
if (!smsCodeResult.success()) { |
|
|
if (!smsCodeResult.success()) { |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), smsCodeResult.getCode(), smsCodeResult.getMsg())); |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), smsCodeResult.getCode(), smsCodeResult.getMsg())); |
|
|
return new Result().error(smsCodeResult.getCode()); |
|
|
throw new RenException(smsCodeResult.getCode()); |
|
|
} |
|
|
} |
|
|
//4、保存短信验证码(删除现有短信验证码、将新的短信验证码存入Redis)
|
|
|
//4、保存短信验证码(删除现有短信验证码、将新的短信验证码存入Redis)
|
|
|
captchaRedis.saveSmsCode(formDTO, smsCodeResult.getData().get("code")); |
|
|
captchaRedis.saveSmsCode(formDTO, smsCodeResult.getData().get("code")); |
|
|
logger.info(String.format("发送短信验证码成功,手机号[%s]", formDTO.getMobile())); |
|
|
logger.info(String.format("发送短信验证码成功,手机号[%s]", formDTO.getMobile())); |
|
|
return new Result(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -99,18 +99,18 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
* @Date 2020/4/18 21:11 |
|
|
* @Date 2020/4/18 21:11 |
|
|
**/ |
|
|
**/ |
|
|
@Override |
|
|
@Override |
|
|
public Result<List<StaffOrgsResultDTO>> getMyOrg(StaffOrgsFormDTO formDTO) { |
|
|
public List<StaffOrgsResultDTO> getMyOrg(StaffOrgsFormDTO formDTO) { |
|
|
//1、根据手机号查询到用户信息
|
|
|
//1、根据手机号查询到用户信息
|
|
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserFeignClient.checkCustomerStaff(formDTO.getMobile()); |
|
|
Result<List<CustomerStaffDTO>> customerStaffResult = epmetUserFeignClient.checkCustomerStaff(formDTO.getMobile()); |
|
|
if (!customerStaffResult.success()) { |
|
|
if (!customerStaffResult.success()) { |
|
|
logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
|
|
logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getMobile(), customerStaffResult.getCode(), customerStaffResult.getMsg())); |
|
|
return new Result().error(customerStaffResult.getCode()); |
|
|
throw new RenException(customerStaffResult.getCode()); |
|
|
} |
|
|
} |
|
|
//2、验证码是否正确
|
|
|
//2、验证码是否正确
|
|
|
String rightSmsCode = captchaRedis.getSmsCode(formDTO.getMobile()); |
|
|
String rightSmsCode = captchaRedis.getSmsCode(formDTO.getMobile()); |
|
|
if (!formDTO.getSmsCode().equals(rightSmsCode)) { |
|
|
if (!formDTO.getSmsCode().equals(rightSmsCode)) { |
|
|
logger.error(String.format("验证码错误code[%s],msg[%s]",EpmetErrorCode.MOBILE_CODE_ERROR.getCode(),EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); |
|
|
logger.error(String.format("验证码错误code[%s],msg[%s]",EpmetErrorCode.MOBILE_CODE_ERROR.getCode(),EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); |
|
|
return new Result<List<StaffOrgsResultDTO>>().error(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
|
|
throw new RenException(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
|
|
} |
|
|
} |
|
|
//3、查询用户所有的组织信息
|
|
|
//3、查询用户所有的组织信息
|
|
|
List<String> customerIdList = new ArrayList<>(); |
|
|
List<String> customerIdList = new ArrayList<>(); |
|
@ -120,11 +120,15 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); |
|
|
StaffOrgFormDTO staffOrgFormDTO = new StaffOrgFormDTO(); |
|
|
staffOrgFormDTO.setCustomerIdList(customerIdList); |
|
|
staffOrgFormDTO.setCustomerIdList(customerIdList); |
|
|
Result<List<StaffOrgsResultDTO>> result = govOrgFeignClient.getStaffOrgList(staffOrgFormDTO); |
|
|
Result<List<StaffOrgsResultDTO>> result = govOrgFeignClient.getStaffOrgList(staffOrgFormDTO); |
|
|
return result; |
|
|
if(result.success()&&null!=result.getData()){ |
|
|
|
|
|
return result.getData(); |
|
|
|
|
|
} |
|
|
|
|
|
logger.error(String .format("手机验证码获取组织,调用%s服务失败,入参手机号%s,验证码%s,返回错误码%s,错误提示信息%s", ServiceConstant.GOV_ORG_SERVER,formDTO.getMobile(),formDTO.getSmsCode(),result.getCode(),result.getMsg())); |
|
|
|
|
|
return new ArrayList<>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Result<UserTokenResultDTO> loginByWxCode(GovWxmpFormDTO formDTO) { |
|
|
public UserTokenResultDTO loginByWxCode(GovWxmpFormDTO formDTO) { |
|
|
//1、解析微信用户
|
|
|
//1、解析微信用户
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(formDTO.getApp(), formDTO.getWxCode()); |
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(formDTO.getApp(), formDTO.getWxCode()); |
|
|
if(null!=wxMaJscode2SessionResult){ |
|
|
if(null!=wxMaJscode2SessionResult){ |
|
@ -133,7 +137,7 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
Result<StaffLatestAgencyResultDTO> latestStaffWechat = epmetUserFeignClient.getLatestStaffWechatLoginRecord(wxMaJscode2SessionResult.getOpenid()); |
|
|
Result<StaffLatestAgencyResultDTO> latestStaffWechat = epmetUserFeignClient.getLatestStaffWechatLoginRecord(wxMaJscode2SessionResult.getOpenid()); |
|
|
if (!latestStaffWechat.success() || null == latestStaffWechat.getData()) { |
|
|
if (!latestStaffWechat.success() || null == latestStaffWechat.getData()) { |
|
|
logger.error(String.format("没有获取到用户最近一次登录账户信息,code[%s],msg[%s]", EpmetErrorCode.PLEASE_LOGIN.getCode(), EpmetErrorCode.PLEASE_LOGIN.getMsg())); |
|
|
logger.error(String.format("没有获取到用户最近一次登录账户信息,code[%s],msg[%s]", EpmetErrorCode.PLEASE_LOGIN.getCode(), EpmetErrorCode.PLEASE_LOGIN.getMsg())); |
|
|
return new Result<UserTokenResultDTO>().error(EpmetErrorCode.PLEASE_LOGIN.getCode()); |
|
|
throw new RenException(EpmetErrorCode.PLEASE_LOGIN.getCode()); |
|
|
} |
|
|
} |
|
|
StaffLatestAgencyResultDTO staffLatestAgencyResultDTO = latestStaffWechat.getData(); |
|
|
StaffLatestAgencyResultDTO staffLatestAgencyResultDTO = latestStaffWechat.getData(); |
|
|
//2、记录staff_wechat
|
|
|
//2、记录staff_wechat
|
|
@ -146,7 +150,7 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
this.saveLatestGovTokenDto(staffLatestAgencyResultDTO, wxMaJscode2SessionResult, token); |
|
|
this.saveLatestGovTokenDto(staffLatestAgencyResultDTO, wxMaJscode2SessionResult, token); |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
userTokenResultDTO.setToken(token); |
|
|
userTokenResultDTO.setToken(token); |
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
return userTokenResultDTO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//保存tokenDto到redis
|
|
|
//保存tokenDto到redis
|
|
@ -244,7 +248,7 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Result<UserTokenResultDTO> enterOrg(GovWxmpEnteOrgFormDTO formDTO) { |
|
|
public UserTokenResultDTO enterOrg(GovWxmpEnteOrgFormDTO formDTO) { |
|
|
//1、需要校验要登录的客户,是否被禁用
|
|
|
//1、需要校验要登录的客户,是否被禁用
|
|
|
CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); |
|
|
CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); |
|
|
customerStaffFormDTO.setCustomerId(formDTO.getCustomerId()); |
|
|
customerStaffFormDTO.setCustomerId(formDTO.getCustomerId()); |
|
@ -252,7 +256,7 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
Result<CustomerStaffDTO> customerStaffDTOResult = epmetUserFeignClient.getCustomerStaffInfo(customerStaffFormDTO); |
|
|
Result<CustomerStaffDTO> customerStaffDTOResult = epmetUserFeignClient.getCustomerStaffInfo(customerStaffFormDTO); |
|
|
if (!customerStaffDTOResult.success() || null == customerStaffDTOResult.getData()) { |
|
|
if (!customerStaffDTOResult.success() || null == customerStaffDTOResult.getData()) { |
|
|
logger.error(String.format("获取工作人员信息失败,手机号[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getMobile(), formDTO.getCustomerId(), customerStaffDTOResult.getCode(), customerStaffDTOResult.getMsg())); |
|
|
logger.error(String.format("获取工作人员信息失败,手机号[%s],客户id:[%s],code[%s],msg[%s]", formDTO.getMobile(), formDTO.getCustomerId(), customerStaffDTOResult.getCode(), customerStaffDTOResult.getMsg())); |
|
|
return new Result().error(customerStaffDTOResult.getCode()); |
|
|
throw new RenException(customerStaffDTOResult.getCode()); |
|
|
} |
|
|
} |
|
|
CustomerStaffDTO customerStaff = customerStaffDTOResult.getData(); |
|
|
CustomerStaffDTO customerStaff = customerStaffDTOResult.getData(); |
|
|
//2、解析微信用户
|
|
|
//2、解析微信用户
|
|
@ -267,17 +271,16 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
this.saveGovTokenDto(formDTO.getRootAgencyId(), formDTO.getCustomerId(), customerStaff.getUserId(), wxMaJscode2SessionResult, token); |
|
|
this.saveGovTokenDto(formDTO.getRootAgencyId(), formDTO.getCustomerId(), customerStaff.getUserId(), wxMaJscode2SessionResult, token); |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
userTokenResultDTO.setToken(token); |
|
|
userTokenResultDTO.setToken(token); |
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
return userTokenResultDTO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Result loginOut(TokenDto tokenDto) { |
|
|
public void loginOut(TokenDto tokenDto) { |
|
|
if(null == tokenDto){ |
|
|
if(null == tokenDto){ |
|
|
logger.error("token解析失败,直接跳转重新登录即可"); |
|
|
logger.error("token解析失败,直接跳转重新登录即可"); |
|
|
throw new RenException("当前用户信息获取失败"); |
|
|
throw new RenException("当前用户信息获取失败"); |
|
|
} |
|
|
} |
|
|
cpUserDetailRedis.logout(tokenDto.getApp() , tokenDto.getClient() , tokenDto.getUserId()); |
|
|
cpUserDetailRedis.logout(tokenDto.getApp() , tokenDto.getClient() , tokenDto.getUserId()); |
|
|
return new Result(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//保存登录日志
|
|
|
//保存登录日志
|
|
|