| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -18,26 +18,34 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					package com.epmet.service.impl; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.alibaba.fastjson.JSON; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.common.token.constant.LoginConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.constant.MqConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.constant.NumConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.dto.form.mq.MqBaseMsgDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.dto.form.mq.eventmsg.BasePointEventMsg; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.enums.EventEnum; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.exception.EpmetErrorCode; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.exception.RenException; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.redis.RedisKeys; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.redis.RedisUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.security.dto.TokenDto; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.ConvertUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.Result; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.SendMqMsgUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.constant.SmsTemplateConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dao.VolunteerInfoDao; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.HeartUserInfoDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.VolunteerInfoDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.SendVerificationCodeFormDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.resi.ResiSendSmsCodeFormDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.form.resi.ResiVolunteerAuthenticateFormDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.result.ResiUserBaseInfoResultDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.result.SendVerificationCodeResultDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.dto.result.resi.ResiVolunteerInfoResultDTO; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.entity.VolunteerInfoEntity; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.feign.EpmetMessageOpenFeignClient; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.feign.EpmetUserOpenFeignClient; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.redis.VolunteerInfoRedis; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.service.HeartUserInfoService; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.service.VolunteerInfoService; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.apache.logging.log4j.LogManager; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -58,9 +66,12 @@ import java.util.List; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					@Service | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					public class VolunteerInfoServiceImpl extends BaseServiceImpl<VolunteerInfoDao, VolunteerInfoEntity> implements VolunteerInfoService { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private Logger logger = LogManager.getLogger(VolunteerInfoServiceImpl.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private static final String SEND_SMS_CODE_ERROR = "发送短信验证码异常,手机号[%s],code[%s],msg[%s]"; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private VolunteerInfoRedis volunteerInfoRedis; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * redis 验证码 过期时长为30分钟,单位:秒 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private final static long MINUTE_THIRTY_EXPIRE = 60 * 30 * 1L; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -68,9 +79,24 @@ public class VolunteerInfoServiceImpl extends BaseServiceImpl<VolunteerInfoDao, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private HeartUserInfoService heartUserInfoService; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private RedisUtils redisUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Autowired | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Override | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Transactional(rollbackFor = Exception.class) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public Result authenticate(TokenDto tokenDto, ResiVolunteerAuthenticateFormDTO formDTO) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // 验证码校验
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (null != formDTO.getSmsCode()){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String smsCodeKey = RedisKeys.getLoginSmsCodeKey(LoginConstant.APP_RESI, LoginConstant.CLIENT_WXMP, formDTO.getMobile()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            String rightSmsCode = (String) redisUtils.get(smsCodeKey); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (!formDTO.getSmsCode().equals(rightSmsCode)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                logger.error(String.format("验证码错误code[%s],msg[%s]", EpmetErrorCode.MOBILE_CODE_ERROR.getCode(), EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                throw new RenException(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        formDTO.setUserId(tokenDto.getUserId()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // 检查是否是志愿者
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        Integer volunteerFlag = baseDao.queryVolunteerFlagByUserId(tokenDto.getUserId()); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -138,4 +164,36 @@ public class VolunteerInfoServiceImpl extends BaseServiceImpl<VolunteerInfoDao, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return new Result<ResiVolunteerInfoResultDTO>().ok(resultDTO); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    @Override | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void sendSmsCode(ResiSendSmsCodeFormDTO formDTO) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //1、发送短信验证码
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        SendVerificationCodeFormDTO sendVerificationCodeFormDTO=new SendVerificationCodeFormDTO(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        sendVerificationCodeFormDTO.setMobile(formDTO.getMobile()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        sendVerificationCodeFormDTO.setAliyunTemplateCode(SmsTemplateConstant.USER_REGISTER); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        Result<SendVerificationCodeResultDTO> smsCodeResult=epmetMessageOpenFeignClient.sendVerificationCode(sendVerificationCodeFormDTO); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (!smsCodeResult.success()) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getMobile(), smsCodeResult.getCode(), smsCodeResult.getMsg())); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            throw new RenException(smsCodeResult.getCode()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //2、保存短信验证码(删除现有短信验证码、将新的短信验证码存入Redis)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.saveSmsCode(formDTO, smsCodeResult.getData().getCode()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        logger.info(String.format("发送短信验证码成功,手机号[%s]", formDTO.getMobile())); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * 保存短信验证码(删除现有短信验证码、将新的短信验证码存入Redis) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * 过期时长为30分钟 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param sendSmsCodeFormDTO app、client、phone | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param smsCode            验证码 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @return void | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @Author zhangyong | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @Date 09:43 2020-08-10 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     **/ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void saveSmsCode(ResiSendSmsCodeFormDTO sendSmsCodeFormDTO, String smsCode) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        String smsCodeKey = RedisKeys.getLoginSmsCodeKey(LoginConstant.APP_RESI, LoginConstant.CLIENT_WXMP, sendSmsCodeFormDTO.getMobile()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        logger.info(String.format("短信验证码key=%s", smsCodeKey)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        redisUtils.set(smsCodeKey, smsCode, MINUTE_THIRTY_EXPIRE); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |