|  |  | @ -24,20 +24,27 @@ 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 +65,7 @@ import java.util.List; | 
			
		
	
		
			
				
					|  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  | public class VolunteerInfoServiceImpl extends BaseServiceImpl<VolunteerInfoDao, VolunteerInfoEntity> implements VolunteerInfoService { | 
			
		
	
		
			
				
					|  |  |  |     private Logger logger = LogManager.getLogger(VolunteerInfoServiceImpl.class); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private VolunteerInfoRedis volunteerInfoRedis; | 
			
		
	
		
			
				
					|  |  |  |     private static final String SEND_SMS_CODE_ERROR = "发送短信验证码异常,手机号[%s],code[%s],msg[%s]"; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
			
		
	
	
		
			
				
					|  |  | @ -68,9 +73,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.getVolunteerSmsCodeKey(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 +158,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 phone | 
			
		
	
		
			
				
					|  |  |  |      * @param smsCode            验证码 | 
			
		
	
		
			
				
					|  |  |  |      * @return void | 
			
		
	
		
			
				
					|  |  |  |      * @Author zhangyong | 
			
		
	
		
			
				
					|  |  |  |      * @Date 09:43 2020-08-10 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     public void saveSmsCode(ResiSendSmsCodeFormDTO sendSmsCodeFormDTO, String smsCode) { | 
			
		
	
		
			
				
					|  |  |  |         String smsCodeKey = RedisKeys.getVolunteerSmsCodeKey(sendSmsCodeFormDTO.getMobile()); | 
			
		
	
		
			
				
					|  |  |  |         logger.info(String.format("短信验证码key=%s", smsCodeKey)); | 
			
		
	
		
			
				
					|  |  |  |         redisUtils.set(smsCodeKey, smsCode, RedisUtils.MINUTE_THIRTY_EXPIRE); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |