From 50fb58286ed3b718c39a97e0987ee7561a295651 Mon Sep 17 00:00:00 2001 From: k94314517 <8417338+k94314517@user.noreply.gitee.com> Date: 星期五, 04 七月 2025 17:56:41 +0800 Subject: [PATCH] git ch --- server/service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java | 68 +++++++++++++++++++++++++++++++++- 1 files changed, 66 insertions(+), 2 deletions(-) diff --git a/server/service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java index 0679e4b..f5a2de4 100644 --- a/server/service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java +++ b/server/service/src/main/java/com/doumee/service/business/impl/SmsEmailServiceImpl.java @@ -3,19 +3,24 @@ 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.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +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; @@ -23,6 +28,7 @@ import java.util.Date; import java.util.List; +import java.util.Objects; /** * 鐭俊閭欢淇℃伅琛⊿ervice瀹炵幇 @@ -38,6 +44,10 @@ private SystemDictDataBiz systemDictDataBiz; @Autowired 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() @@ -52,7 +62,8 @@ 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); @@ -69,21 +80,74 @@ return smsEmail.getId(); } @Override + public Integer sendEmail(SmsEmail smsEmail) { + if(StringUtils.isBlank(smsEmail.getEmail())){ + throw new BusinessException(ResponseStatus.BAD_REQUEST); + } + boolean result= emailService.sendEmail(smsEmail.getEmail(),smsEmail.getTitle(),smsEmail.getContent(),smsEmail.getFileList()); + smsEmail.setRemark("閭欢鍙戠敓鎴愬姛"); + if(!result){ + smsEmail.setRemark("閭欢鍙戠敓澶辫触"); + } + smsEmail.setIsdeleted(Constants.ZERO); + smsEmail.setCreateDate(new Date()); + smsEmail.setStatus(Constants.ONE); + smsEmail.setType(Constants.TWO); + smsEmailMapper.insert(smsEmail); + + return smsEmail.getId(); + } + @Override public Integer sendSms(SmsEmail smsEmail) { 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(); + + 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 -- Gitblit v1.9.3