|
|
@ -122,57 +122,55 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
public Result<UserTokenResultDTO> loginByWxCode(GovWxmpFormDTO formDTO) { |
|
|
|
//1、解析微信用户
|
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult = loginService.getWxMaUser(formDTO.getApp(), formDTO.getWxCode()); |
|
|
|
Result<LatestStaffWechatLoginResultDTO> latestStaffWechat = epmetUserFeignClient.getLatestStaffWechatLoginRecord(wxMaJscode2SessionResult.getOpenid()); |
|
|
|
Result<StaffLatestAgencyResultDTO> latestStaffWechat = epmetUserFeignClient.getLatestStaffWechatLoginRecord(wxMaJscode2SessionResult.getOpenid()); |
|
|
|
if (!latestStaffWechat.success() || null == latestStaffWechat.getData()) { |
|
|
|
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()); |
|
|
|
} |
|
|
|
LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO = latestStaffWechat.getData(); |
|
|
|
StaffLatestAgencyResultDTO staffLatestAgencyResultDTO = latestStaffWechat.getData(); |
|
|
|
//2、记录staff_wechat
|
|
|
|
this.savestaffwechat(latestStaffWechatLoginDTO.getStaffId(), wxMaJscode2SessionResult.getOpenid()); |
|
|
|
this.savestaffwechat(staffLatestAgencyResultDTO.getStaffId(), wxMaJscode2SessionResult.getOpenid()); |
|
|
|
//3、记录登录日志
|
|
|
|
this.saveStaffLoginRecord(latestStaffWechatLoginDTO); |
|
|
|
this.saveStaffLoginRecord(staffLatestAgencyResultDTO); |
|
|
|
//4、获取用户token
|
|
|
|
String token = this.generateGovWxmpToken(latestStaffWechatLoginDTO.getStaffId()); |
|
|
|
String token = this.generateGovWxmpToken(staffLatestAgencyResultDTO.getStaffId()); |
|
|
|
//5、保存到redis
|
|
|
|
this.saveLatestGovTokenDto(latestStaffWechatLoginDTO, wxMaJscode2SessionResult, token); |
|
|
|
this.saveLatestGovTokenDto(staffLatestAgencyResultDTO, wxMaJscode2SessionResult, token); |
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
|
} |
|
|
|
|
|
|
|
//保存tokenDto到redis
|
|
|
|
private void saveLatestGovTokenDto(LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO, |
|
|
|
private void saveLatestGovTokenDto(StaffLatestAgencyResultDTO staffLatestAgency, |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult, |
|
|
|
String token) { |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
GovTokenDto govTokenDto = new GovTokenDto(); |
|
|
|
govTokenDto.setApp(LoginConstant.APP_GOV); |
|
|
|
govTokenDto.setClient(LoginConstant.CLIENT_WXMP); |
|
|
|
govTokenDto.setStaffId(latestStaffWechatLoginDTO.getStaffId()); |
|
|
|
govTokenDto.setStaffId(staffLatestAgency.getStaffId()); |
|
|
|
govTokenDto.setOpenId(wxMaJscode2SessionResult.getOpenid()); |
|
|
|
govTokenDto.setSessionKey(wxMaJscode2SessionResult.getSessionKey()); |
|
|
|
govTokenDto.setUnionId(wxMaJscode2SessionResult.getUnionid()); |
|
|
|
govTokenDto.setToken(token); |
|
|
|
govTokenDto.setUpdateTime(System.currentTimeMillis()); |
|
|
|
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
|
govTokenDto.setOrgId(latestStaffWechatLoginDTO.getOrgId()); |
|
|
|
govTokenDto.setGridId(latestStaffWechatLoginDTO.getGridId()); |
|
|
|
govTokenDto.setCustomerId(latestStaffWechatLoginDTO.getCustomerId()); |
|
|
|
govTokenDto.setOrgId(staffLatestAgency.getOrgId()); |
|
|
|
govTokenDto.setCustomerId(staffLatestAgency.getCustomerId()); |
|
|
|
cpUserDetailRedis.set(govTokenDto, expire); |
|
|
|
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
} |
|
|
|
|
|
|
|
//保存登录日志
|
|
|
|
private Result saveStaffLoginRecord(LatestStaffWechatLoginResultDTO latestStaffWechatLoginDTO) { |
|
|
|
StaffLoginHistoryFormDTO staffLoginHistoryFormDTO = new StaffLoginHistoryFormDTO(); |
|
|
|
staffLoginHistoryFormDTO.setCustomerId(latestStaffWechatLoginDTO.getCustomerId()); |
|
|
|
staffLoginHistoryFormDTO.setStaffId(latestStaffWechatLoginDTO.getStaffId()); |
|
|
|
staffLoginHistoryFormDTO.setWxOpenId(latestStaffWechatLoginDTO.getWxOpenId()); |
|
|
|
staffLoginHistoryFormDTO.setMobile(latestStaffWechatLoginDTO.getMobile()); |
|
|
|
staffLoginHistoryFormDTO.setOrgId(latestStaffWechatLoginDTO.getOrgId()); |
|
|
|
staffLoginHistoryFormDTO.setGridId(latestStaffWechatLoginDTO.getGridId()); |
|
|
|
Result staffLoginRecordResult = epmetUserFeignClient.saveStaffLoginRecord(staffLoginHistoryFormDTO); |
|
|
|
private Result saveStaffLoginRecord(StaffLatestAgencyResultDTO latestStaffWechatLoginDTO) { |
|
|
|
StaffLoginAgencyRecordFormDTO staffLoginAgencyRecordFormDTO = new StaffLoginAgencyRecordFormDTO(); |
|
|
|
staffLoginAgencyRecordFormDTO.setCustomerId(latestStaffWechatLoginDTO.getCustomerId()); |
|
|
|
staffLoginAgencyRecordFormDTO.setStaffId(latestStaffWechatLoginDTO.getStaffId()); |
|
|
|
staffLoginAgencyRecordFormDTO.setWxOpenId(latestStaffWechatLoginDTO.getWxOpenId()); |
|
|
|
staffLoginAgencyRecordFormDTO.setMobile(latestStaffWechatLoginDTO.getMobile()); |
|
|
|
staffLoginAgencyRecordFormDTO.setOrgId(latestStaffWechatLoginDTO.getOrgId()); |
|
|
|
Result staffLoginRecordResult = epmetUserFeignClient.saveStaffLoginRecord(staffLoginAgencyRecordFormDTO); |
|
|
|
return staffLoginRecordResult; |
|
|
|
} |
|
|
|
|
|
|
@ -199,7 +197,7 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
//1、获取用户token
|
|
|
|
String token = this.generateGovWxmpToken(customerStaff.getUserId()); |
|
|
|
//2、保存到redis
|
|
|
|
this.saveGovTokenDto(formDTO.getOrgId(), formDTO.getCustomerId(), latestGridInfo.getGridId(), customerStaff.getUserId(), wxMaJscode2SessionResult, token); |
|
|
|
this.saveGovTokenDto(formDTO.getOrgId(), formDTO.getCustomerId(), customerStaff.getUserId(), wxMaJscode2SessionResult, token); |
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
userTokenResultDTO.setToken(token); |
|
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
@ -220,14 +218,14 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
|
|
|
|
//保存登录日志
|
|
|
|
private Result saveStaffLoginRecord(GovWxmpEnteOrgFormDTO formDTO, String staffId, String openId, String grid) { |
|
|
|
StaffLoginHistoryFormDTO staffLoginHistoryFormDTO = new StaffLoginHistoryFormDTO(); |
|
|
|
staffLoginHistoryFormDTO.setCustomerId(formDTO.getCustomerId()); |
|
|
|
staffLoginHistoryFormDTO.setStaffId(staffId); |
|
|
|
staffLoginHistoryFormDTO.setWxOpenId(openId); |
|
|
|
staffLoginHistoryFormDTO.setMobile(formDTO.getMobile()); |
|
|
|
staffLoginHistoryFormDTO.setOrgId(formDTO.getOrgId()); |
|
|
|
staffLoginHistoryFormDTO.setGridId(grid); |
|
|
|
Result staffLoginRecordResult = epmetUserFeignClient.saveStaffLoginRecord(staffLoginHistoryFormDTO); |
|
|
|
StaffLoginAgencyRecordFormDTO staffLoginAgencyRecordFormDTO = new StaffLoginAgencyRecordFormDTO(); |
|
|
|
staffLoginAgencyRecordFormDTO.setCustomerId(formDTO.getCustomerId()); |
|
|
|
staffLoginAgencyRecordFormDTO.setStaffId(staffId); |
|
|
|
staffLoginAgencyRecordFormDTO.setWxOpenId(openId); |
|
|
|
staffLoginAgencyRecordFormDTO.setMobile(formDTO.getMobile()); |
|
|
|
staffLoginAgencyRecordFormDTO.setOrgId(formDTO.getOrgId()); |
|
|
|
staffLoginAgencyRecordFormDTO.setGridId(grid); |
|
|
|
Result staffLoginRecordResult = epmetUserFeignClient.saveStaffLoginRecord(staffLoginAgencyRecordFormDTO); |
|
|
|
return staffLoginRecordResult; |
|
|
|
} |
|
|
|
|
|
|
@ -267,7 +265,6 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
**/ |
|
|
|
private void saveGovTokenDto(String orgId, |
|
|
|
String customerId, |
|
|
|
String gridId, |
|
|
|
String staffId, |
|
|
|
WxMaJscode2SessionResult wxMaJscode2SessionResult, |
|
|
|
String token) { |
|
|
@ -283,7 +280,6 @@ public class GovLoginServiceImpl implements GovLoginService { |
|
|
|
govTokenDto.setUpdateTime(System.currentTimeMillis()); |
|
|
|
govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
|
govTokenDto.setOrgId(orgId); |
|
|
|
govTokenDto.setGridId(gridId); |
|
|
|
govTokenDto.setCustomerId(customerId); |
|
|
|
cpUserDetailRedis.set(govTokenDto, expire); |
|
|
|
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
|
|
|