|  |  | @ -1,5 +1,6 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.common.token.constant.LoginConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.ExceptionUtils; | 
			
		
	
	
		
			
				
					|  |  | @ -10,10 +11,7 @@ import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.CpUserDetailRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.DateUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.CustomerAgencyDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.GovStaffRoleDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.UserDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.UserWechatDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.DepartmentListResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.GridByStaffResultDTO; | 
			
		
	
	
		
			
				
					|  |  | @ -347,4 +345,100 @@ public class ThirdLoginServiceImpl implements ThirdLoginService { | 
			
		
	
		
			
				
					|  |  |  |         return null; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @param formDTO | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 单客户-选择组织,进入首页 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public UserTokenResultDTO enterOrg(ThirdWxmpEnteOrgFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //1、需要校验要登录的客户,是否被禁用
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffFormDTO customerStaffFormDTO = new CustomerStaffFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |         customerStaffFormDTO.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         customerStaffFormDTO.setMobile(formDTO.getMobile()); | 
			
		
	
		
			
				
					|  |  |  |         Result<CustomerStaffDTO> customerStaffDTOResult = epmetUserOpenFeignClient.getCustomerStaffInfo(customerStaffFormDTO); | 
			
		
	
		
			
				
					|  |  |  |         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())); | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(customerStaffDTOResult.getCode()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffDTO customerStaff = customerStaffDTOResult.getData(); | 
			
		
	
		
			
				
					|  |  |  |         //2020.7.24 获取微信信息接口调整,改调用微信api的方式  sun  start
 | 
			
		
	
		
			
				
					|  |  |  |         //2.调用epmet_third服务,校验appId是否有效以及是否授权,校验通过的调用微信API获取用户基本信息
 | 
			
		
	
		
			
				
					|  |  |  |         WxLoginFormDTO resiLoginFormDTO = new WxLoginFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |         resiLoginFormDTO.setAppId(formDTO.getAppId()); | 
			
		
	
		
			
				
					|  |  |  |         resiLoginFormDTO.setWxCode(formDTO.getWxCode()); | 
			
		
	
		
			
				
					|  |  |  |         Result<UserWechatDTO> result = epmetThirdFeignClient.resiAndWorkLogin(resiLoginFormDTO); | 
			
		
	
		
			
				
					|  |  |  |         if (!result.success()) { | 
			
		
	
		
			
				
					|  |  |  |             logger.error("工作端小程序登陆,调用epmet_third服务获取数据失败"); | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(result.getCode()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         UserWechatDTO userWechatDTO = result.getData(); | 
			
		
	
		
			
				
					|  |  |  |         WxMaJscode2SessionResult wxMaJscode2SessionResult = new WxMaJscode2SessionResult(); | 
			
		
	
		
			
				
					|  |  |  |         wxMaJscode2SessionResult.setOpenid(userWechatDTO.getWxOpenId()); | 
			
		
	
		
			
				
					|  |  |  |         wxMaJscode2SessionResult.setSessionKey(userWechatDTO.getSessionKey()); | 
			
		
	
		
			
				
					|  |  |  |         wxMaJscode2SessionResult.setUnionid(""); | 
			
		
	
		
			
				
					|  |  |  |         // end
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //3、记录staff_wechat,并记录用户激活状态,激活时间
 | 
			
		
	
		
			
				
					|  |  |  |         this.savestaffwechat(customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid()); | 
			
		
	
		
			
				
					|  |  |  |         //4、记录登录日志
 | 
			
		
	
		
			
				
					|  |  |  |         this.saveGovStaffLoginRecord(formDTO, customerStaff.getUserId(), wxMaJscode2SessionResult.getOpenid()); | 
			
		
	
		
			
				
					|  |  |  |         //5.1、获取用户token
 | 
			
		
	
		
			
				
					|  |  |  |         String token = this.generateGovWxmpToken(customerStaff.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         //5.2、保存到redis
 | 
			
		
	
		
			
				
					|  |  |  |         this.saveGovTokenDto(formDTO.getRootAgencyId(), formDTO.getCustomerId(), customerStaff.getUserId(), wxMaJscode2SessionResult, token); | 
			
		
	
		
			
				
					|  |  |  |         UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); | 
			
		
	
		
			
				
					|  |  |  |         userTokenResultDTO.setToken(token); | 
			
		
	
		
			
				
					|  |  |  |         return userTokenResultDTO; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     //保存登录日志
 | 
			
		
	
		
			
				
					|  |  |  |     private Result saveGovStaffLoginRecord(ThirdWxmpEnteOrgFormDTO formDTO, String staffId, String openId) { | 
			
		
	
		
			
				
					|  |  |  |         StaffLoginAgencyRecordFormDTO staffLoginAgencyRecordFormDTO = new StaffLoginAgencyRecordFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |         staffLoginAgencyRecordFormDTO.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         staffLoginAgencyRecordFormDTO.setStaffId(staffId); | 
			
		
	
		
			
				
					|  |  |  |         staffLoginAgencyRecordFormDTO.setWxOpenId(openId); | 
			
		
	
		
			
				
					|  |  |  |         staffLoginAgencyRecordFormDTO.setMobile(formDTO.getMobile()); | 
			
		
	
		
			
				
					|  |  |  |         staffLoginAgencyRecordFormDTO.setAgencyId(formDTO.getRootAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         Result staffLoginRecordResult = epmetUserOpenFeignClient.saveStaffLoginRecord(staffLoginAgencyRecordFormDTO); | 
			
		
	
		
			
				
					|  |  |  |         return staffLoginRecordResult; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Description 生成token | 
			
		
	
		
			
				
					|  |  |  |      * @Date 2020/4/18 23:04 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     private void saveGovTokenDto(String orgId, | 
			
		
	
		
			
				
					|  |  |  |                                  String customerId, | 
			
		
	
		
			
				
					|  |  |  |                                  String staffId, | 
			
		
	
		
			
				
					|  |  |  |                                  WxMaJscode2SessionResult wxMaJscode2SessionResult, | 
			
		
	
		
			
				
					|  |  |  |                                  String token) { | 
			
		
	
		
			
				
					|  |  |  |         int expire = jwtTokenProperties.getExpire(); | 
			
		
	
		
			
				
					|  |  |  |         GovTokenDto govTokenDto = new GovTokenDto(); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setApp(LoginConstant.APP_GOV); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setClient(LoginConstant.CLIENT_WXMP); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setUserId(staffId); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setOpenId(wxMaJscode2SessionResult.getOpenid()); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setSessionKey(wxMaJscode2SessionResult.getSessionKey()); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setUnionId(null == wxMaJscode2SessionResult.getUnionid() ? "" : wxMaJscode2SessionResult.getUnionid()); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setToken(token); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setUpdateTime(System.currentTimeMillis()); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setRootAgencyId(orgId); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //设置部门,网格,角色列表
 | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setDeptIdList(getDeptartmentIdList(staffId)); | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setGridIdList(getGridIdList(staffId)); | 
			
		
	
		
			
				
					|  |  |  |         CustomerAgencyDTO agency = getAgencyByStaffId(staffId); | 
			
		
	
		
			
				
					|  |  |  |         if (agency != null) { | 
			
		
	
		
			
				
					|  |  |  |             govTokenDto.setAgencyId(agency.getId()); | 
			
		
	
		
			
				
					|  |  |  |             govTokenDto.setRoleList(queryGovStaffRoles(staffId, agency.getId())); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         govTokenDto.setOrgIdPath(getOrgIdPath(staffId)); | 
			
		
	
		
			
				
					|  |  |  |         cpUserDetailRedis.set(govTokenDto, expire); | 
			
		
	
		
			
				
					|  |  |  |         logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |