| | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.SmsEmailMapper; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.SmsEmail; |
| | | import com.doumee.service.business.SmsEmailService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import com.doumee.service.business.third.EmailService; |
| | | import com.doumee.service.business.third.EmayService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 短信邮件信息表Service实现 |
| | |
| | | private EmayService emayService; |
| | | @Autowired |
| | | private EmailService emailService; |
| | | @Value("${debug_model}") |
| | | private boolean debugModel; |
| | | |
| | | public static void isCaptcheValide(SmsEmailMapper smsEmailMapper, String phone, String captche) { |
| | | SmsEmail model = smsEmailMapper.selectOne(new QueryWrapper<SmsEmail>().lambda() |
| | |
| | | if(!Constants.equalsInteger(model.getStatus(),Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码已失效,请重新发送再试!"); |
| | | } |
| | | if(model.getCreateDate() !=null && System.currentTimeMillis() - model.getCreateDate().getTime() > 3*60*100){ |
| | | if(model.getCreateDate() !=null && |
| | | System.currentTimeMillis() - model.getCreateDate().getTime() > 3*60*1000){ |
| | | model.setStatus(Constants.ONE); |
| | | model.setEditDate(new Date()); |
| | | smsEmailMapper.updateById(model); |
| | |
| | | if(StringUtils.isBlank(smsEmail.getPhone())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | String nowDate = DateUtil.getFomartDate(new Date(),"yyyy-MM-dd HH:mm:ss"); |
| | | if(smsEmailMapper.selectCount(new QueryWrapper<SmsEmail>().lambda() |
| | | .eq(SmsEmail::getPhone,smsEmail.getPhone()) |
| | | .eq(SmsEmail::getType,Constants.ZERO) |
| | | .between(SmsEmail::getCreateDate, DateUtil.getFomartDate(DateUtil.afterMinutesDate(-5),"yyyy-MM-dd HH:mm:ss"),nowDate) |
| | | )>=3){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,超出发送次数,请稍后重试!"); |
| | | } |
| | | |
| | | String code = Constants.getRandom6Num(); |
| | | boolean result= emayService.sendSingleSms(smsEmail.getPhone(),code); |
| | | |
| | | String content = systemDictDataBiz.queryByCode(Constants.SMS,Constants.SMS_COMNAME).getCode()+"验证码为:"+code+",此验证码有效为3分钟。请勿泄露"; |
| | | |
| | | boolean result= emayService.sendSingleSms(smsEmail.getPhone(),content); |
| | | if(!result){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,短信验证码发送失败,请稍后重试!"); |
| | | } |
| | | |
| | | smsEmail.setRemark(code); |
| | | smsEmail.setIsdeleted(Constants.ZERO); |
| | | smsEmail.setCreateDate(new Date()); |
| | | smsEmail.setStatus(Constants.ZERO); |
| | | smsEmail.setType(Constants.ZERO); |
| | | smsEmail.setTitle("短信验证码"); |
| | | smsEmail.setContent(systemDictDataBiz.queryByCode(Constants.SMS,Constants.SMS_COMNAME).getCode()+"验证码为:"+code+",此验证码有效为3分钟。请勿泄露"); |
| | | smsEmail.setContent(content); |
| | | smsEmailMapper.insert(smsEmail); |
| | | |
| | | return smsEmail.getId(); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void validateCode(String code) { |
| | | if(StringUtils.isBlank(code)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(debugModel){ |
| | | return; |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(!(loginUserInfo.getType().equals(Constants.ONE)||loginUserInfo.getType().equals(Constants.TWO))){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户类别错误"); |
| | | }; |
| | | Company company = loginUserInfo.getCompany(); |
| | | SmsEmailServiceImpl.isCaptcheValide(smsEmailMapper,company.getPhone(),code); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | smsEmailMapper.deleteById(id); |