## 去掉不需要邮件发送等逻辑;
This commit is contained in:
parent
670900d1d3
commit
794587a0be
|
@ -1,23 +0,0 @@
|
||||||
package com.hzs.third.email;
|
|
||||||
|
|
||||||
import com.hzs.common.core.domain.R;
|
|
||||||
import com.hzs.third.email.dto.EmailServiceDTO;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件发送dubbo服务
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 9:41
|
|
||||||
* @Classname: IEmailServiceApi
|
|
||||||
* @PackageName: com.hzs.third.email
|
|
||||||
*/
|
|
||||||
public interface IEmailServiceApi {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送邮件
|
|
||||||
*
|
|
||||||
* @param emailDTO 邮件发送DTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
R<?> sendMail(EmailServiceDTO emailDTO);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package com.hzs.third.email.dto;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件发送DTO
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 9:43
|
|
||||||
* @Classname: EmailServiceDTO
|
|
||||||
* @PackageName: com.hzs.third.email.dto
|
|
||||||
*/
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Data
|
|
||||||
public class EmailServiceDTO implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 接收人
|
|
||||||
*/
|
|
||||||
private String recipient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标题
|
|
||||||
*/
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 内容
|
|
||||||
*/
|
|
||||||
private String content;
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,11 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 短信处理控制器
|
* 短信处理控制器
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2023/3/8 15:54
|
|
||||||
* @Classname: SmsController
|
|
||||||
* @PackageName: com.hzs.member.sms.controller
|
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/api/sms")
|
@RequestMapping("/api/sms")
|
||||||
@RestController
|
@RestController
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package com.hzs.member.sms.service;
|
package com.hzs.member.sms.service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 验证码服务
|
* 验证码服务
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 15:43
|
|
||||||
* @Classname: IApiCodeService
|
|
||||||
* @PackageName: com.hzs.member.sms.service
|
|
||||||
*/
|
*/
|
||||||
public interface IApiCodeService {
|
public interface IApiCodeService {
|
||||||
|
|
||||||
|
@ -29,23 +25,6 @@ public interface IApiCodeService {
|
||||||
*/
|
*/
|
||||||
String checkCode(String phone, String smsCode, String checkKey);
|
String checkCode(String phone, String smsCode, String checkKey);
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 登录发送验证码
|
|
||||||
// *
|
|
||||||
// * @param phone 联系方式
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// String sendLoginCode(String phone);
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 校验登录验证码
|
|
||||||
// *
|
|
||||||
// * @param phone 联系方式
|
|
||||||
// * @param smsCode 短信验证码
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// String checkLoginCode(String phone, String smsCode);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册发送验证码
|
* 注册发送验证码
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
package com.hzs.member.sms.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件处理服务
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 15:28
|
|
||||||
* @Classname: IApiEmailService
|
|
||||||
* @PackageName: com.hzs.member.email.service
|
|
||||||
*/
|
|
||||||
public interface IApiEmailService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 短信验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @param checkKey 验证码KEY -- 为空使用默认
|
|
||||||
* @param sendTimKey 验证码重复发送间隔KEY -- 为空使用默认
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String sendCode(String email, String checkKey, String sendTimKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验短信验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @param smsCode 短信验证码
|
|
||||||
* @param checkKey 验证码KEY -- 为空使用默认
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String checkCode(String email, String smsCode, String checkKey);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 登录发送验证码
|
|
||||||
// *
|
|
||||||
// * @param email 邮箱
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// String sendLoginCode(String email);
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 校验登录验证码
|
|
||||||
// *
|
|
||||||
// * @param email 邮箱
|
|
||||||
// * @param smsCode 短信验证码
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// String checkLoginCode(String email, String smsCode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册发送验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String sendRegisterCode(String email);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验注册验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @param smsCode 短信验证码
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String checkRegisterCode(String email, String smsCode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 找回密码发送验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String sendRecoverCode(String email);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验找回密码验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @param smsCode 短信验证码
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String checkRecoverCode(String email, String smsCode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重置支付密码发送验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String resetPayPasswordCode(String email);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验重置支付密码验证码
|
|
||||||
*
|
|
||||||
* @param email 邮箱
|
|
||||||
* @param smsCode 短信验证码
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String checkPayPasswordCode(String email, String smsCode);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,143 +1,59 @@
|
||||||
package com.hzs.member.sms.service.impl;
|
package com.hzs.member.sms.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Validator;
|
|
||||||
import com.hzs.member.sms.service.IApiAliSmsService;
|
import com.hzs.member.sms.service.IApiAliSmsService;
|
||||||
import com.hzs.member.sms.service.IApiCodeService;
|
import com.hzs.member.sms.service.IApiCodeService;
|
||||||
import com.hzs.member.sms.service.IApiEmailService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 验证码服务
|
* 验证码服务
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 15:43
|
|
||||||
* @Classname: ApiCodeServiceImpl
|
|
||||||
* @PackageName: com.hzs.member.sms.service.impl
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class ApiCodeServiceImpl implements IApiCodeService {
|
public class ApiCodeServiceImpl implements IApiCodeService {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IApiEmailService iApiEmailService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IApiAliSmsService iApiAliSmsService;
|
private IApiAliSmsService iApiAliSmsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sendCode(String phone, String checkKey, String sendTimKey) {
|
public String sendCode(String phone, String checkKey, String sendTimKey) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.sendCode(phone, checkKey, sendTimKey);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.sendCode(phone, checkKey, sendTimKey);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.sendCode(phone, checkKey, sendTimKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String checkCode(String phone, String smsCode, String checkKey) {
|
public String checkCode(String phone, String smsCode, String checkKey) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.checkCode(phone, smsCode, checkKey);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.checkCode(phone, smsCode, checkKey);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.checkCode(phone, smsCode, checkKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public String sendLoginCode(String phone) {
|
|
||||||
// if (Validator.isEmail(phone)) {
|
|
||||||
// // 邮箱
|
|
||||||
// return iApiEmailService.sendLoginCode(phone);
|
|
||||||
// } else {
|
|
||||||
// // 非邮箱,按手机号码处理
|
|
||||||
// return iApiAliSmsService.sendLoginCode(phone);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String checkLoginCode(String phone, String smsCode) {
|
|
||||||
// String str;
|
|
||||||
// if (Validator.isEmail(phone)) {
|
|
||||||
// // 邮箱
|
|
||||||
// str = iApiEmailService.checkLoginCode(phone, smsCode);
|
|
||||||
// } else {
|
|
||||||
// // 非邮箱,按手机号码处理
|
|
||||||
// str = iApiAliSmsService.checkLoginCode(phone, smsCode);
|
|
||||||
// }
|
|
||||||
// if (null == str) {
|
|
||||||
// // 删除验证码间隔时间缓存
|
|
||||||
// redisService.deleteObject(CacheConstants.LOGIN_SEND_TIME + phone);
|
|
||||||
// }
|
|
||||||
// return str;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sendRegisterCode(String phone) {
|
public String sendRegisterCode(String phone) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.sendRegisterCode(phone);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.sendRegisterCode(phone);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.sendRegisterCode(phone);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String checkRegisterCode(String phone, String smsCode) {
|
public String checkRegisterCode(String phone, String smsCode) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.checkRegisterCode(phone, smsCode);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.checkRegisterCode(phone, smsCode);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.checkRegisterCode(phone, smsCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sendRecoverCode(String phone) {
|
public String sendRecoverCode(String phone) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.sendRecoverCode(phone);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.sendRecoverCode(phone);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.sendRecoverCode(phone);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String checkRecoverCode(String phone, String smsCode) {
|
public String checkRecoverCode(String phone, String smsCode) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.checkRecoverCode(phone, smsCode);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.checkRecoverCode(phone, smsCode);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.checkRecoverCode(phone, smsCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resetPayPasswordCode(String phone) {
|
public String resetPayPasswordCode(String phone) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.resetPayPasswordCode(phone);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.resetPayPasswordCode(phone);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.resetPayPasswordCode(phone);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String checkPayPasswordCode(String phone, String smsCode) {
|
public String checkPayPasswordCode(String phone, String smsCode) {
|
||||||
if (Validator.isEmail(phone)) {
|
return iApiAliSmsService.checkPayPasswordCode(phone, smsCode);
|
||||||
// 邮箱
|
|
||||||
return iApiEmailService.checkPayPasswordCode(phone, smsCode);
|
|
||||||
} else {
|
|
||||||
// 非邮箱,按手机号码处理
|
|
||||||
return iApiAliSmsService.checkPayPasswordCode(phone, smsCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,159 +0,0 @@
|
||||||
package com.hzs.member.sms.service.impl;
|
|
||||||
|
|
||||||
import com.hzs.common.core.config.HzsConfig;
|
|
||||||
import com.hzs.common.core.constant.CacheConstants;
|
|
||||||
import com.hzs.common.core.domain.R;
|
|
||||||
import com.hzs.common.core.enums.EEnv;
|
|
||||||
import com.hzs.common.core.service.RedisService;
|
|
||||||
import com.hzs.common.core.utils.VerificationCodeUtil;
|
|
||||||
import com.hzs.member.sms.service.IApiEmailService;
|
|
||||||
import com.hzs.third.email.IEmailServiceApi;
|
|
||||||
import com.hzs.third.email.dto.EmailServiceDTO;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件处理服务
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 15:28
|
|
||||||
* @Classname: ApiEmailServiceImpl
|
|
||||||
* @PackageName: com.hzs.member.email.service.impl
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class ApiEmailServiceImpl implements IApiEmailService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
@DubboReference
|
|
||||||
IEmailServiceApi iEmailServiceApi;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String sendCode(String email, String checkKey, String sendTimKey) {
|
|
||||||
if (null == checkKey) {
|
|
||||||
// 如果为空,使用默认发送短信key
|
|
||||||
checkKey = CacheConstants.DEFAULT_CHECK;
|
|
||||||
}
|
|
||||||
if (null == sendTimKey) {
|
|
||||||
// 如果为空,使用默认发送短信key间隔时间
|
|
||||||
sendTimKey = CacheConstants.DEFAULT_SEND_TIME;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (redisService.hasKey(sendTimKey + email)) {
|
|
||||||
return "获取验证码过于频繁,请稍后再试";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成4位验证码
|
|
||||||
String code = VerificationCodeUtil.createCode();
|
|
||||||
log.info("发送邮件验证码,email: {}, code: {}", email, code);
|
|
||||||
|
|
||||||
R<?> sendResult = iEmailServiceApi.sendMail(EmailServiceDTO.builder()
|
|
||||||
.recipient(email)
|
|
||||||
.title("青岛海之圣邮箱验证码")
|
|
||||||
.content("【青岛海之圣生物工程】尊敬的会员,您的验证码为 " + code + ",该验证码5分钟内有效。")
|
|
||||||
.build());
|
|
||||||
if (sendResult.isSuccess()) {
|
|
||||||
// 返回成功,验证码放入缓存
|
|
||||||
// 验证码缓存有效期5分钟
|
|
||||||
redisService.setCacheObject(checkKey + email, code, 5L, TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
// 验证码发送间隔不能低于1分钟
|
|
||||||
redisService.setCacheObject(sendTimKey + email, "", 1L, TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
log.error("发送邮件失败:{}", sendResult.getMsg());
|
|
||||||
return "获取验证码失败,请稍候重试";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String checkCode(String email, String smsCode, String checkKey) {
|
|
||||||
if (EEnv.TEST.getValue().equals(HzsConfig.getEnv()) && "ASDF".equals(smsCode)) {
|
|
||||||
// 测试环境暂时不发放短信
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null == checkKey) {
|
|
||||||
// 如果为空,使用默认发送短信key
|
|
||||||
checkKey = CacheConstants.DEFAULT_CHECK;
|
|
||||||
}
|
|
||||||
|
|
||||||
String cacheSmsCode = redisService.getCacheObject(checkKey + email);
|
|
||||||
if (null == cacheSmsCode) {
|
|
||||||
return "验证码已失效";
|
|
||||||
}
|
|
||||||
if (!cacheSmsCode.equals(smsCode)) {
|
|
||||||
// TODO 验证码错误,需不需要清除缓存验证码??会不会存在暴力破解情况??
|
|
||||||
return "验证码错误";
|
|
||||||
}
|
|
||||||
// 校验通过,删除验证码缓存
|
|
||||||
redisService.deleteObject(checkKey + email);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public String sendLoginCode(String email) {
|
|
||||||
// return this.sendCode(email, CacheConstants.LOGIN_CHECK, CacheConstants.LOGIN_SEND_TIME);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String checkLoginCode(String email, String smsCode) {
|
|
||||||
// String str = this.checkCode(email, smsCode, CacheConstants.LOGIN_CHECK);
|
|
||||||
// if (null == str) {
|
|
||||||
// // 删除验证码间隔时间缓存
|
|
||||||
// redisService.deleteObject(CacheConstants.LOGIN_SEND_TIME + email);
|
|
||||||
// }
|
|
||||||
// return str;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String sendRegisterCode(String email) {
|
|
||||||
return this.sendCode(email, CacheConstants.REGISTER_CHECK, CacheConstants.REGISTER_SEND_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String checkRegisterCode(String email, String smsCode) {
|
|
||||||
String str = this.checkCode(email, smsCode, CacheConstants.REGISTER_CHECK);
|
|
||||||
if (null == str) {
|
|
||||||
// 删除验证码间隔时间缓存
|
|
||||||
redisService.deleteObject(CacheConstants.REGISTER_SEND_TIME + email);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String sendRecoverCode(String email) {
|
|
||||||
return this.sendCode(email, CacheConstants.RECOVER_CHECK, CacheConstants.RECOVER_SEND_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String checkRecoverCode(String email, String smsCode) {
|
|
||||||
String str = this.checkCode(email, smsCode, CacheConstants.RECOVER_CHECK);
|
|
||||||
if (null == str) {
|
|
||||||
// 删除验证码间隔时间缓存
|
|
||||||
redisService.deleteObject(CacheConstants.RECOVER_SEND_TIME + email);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String resetPayPasswordCode(String email) {
|
|
||||||
return this.sendCode(email, CacheConstants.RESET_CHECK, CacheConstants.RESET_SEND_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String checkPayPasswordCode(String email, String smsCode) {
|
|
||||||
String str = this.checkCode(email, smsCode, CacheConstants.RESET_CHECK);
|
|
||||||
if (null == str) {
|
|
||||||
// 删除验证码间隔时间缓存
|
|
||||||
redisService.deleteObject(CacheConstants.RESET_SEND_TIME + email);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package com.hzs.third.email.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件配置
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 9:38
|
|
||||||
* @Classname: EmailConfig
|
|
||||||
* @PackageName: com.hzs.third.email.config
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@ConfigurationProperties(prefix = "spring.mail")
|
|
||||||
@Component
|
|
||||||
public class EmailConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邮件发送人
|
|
||||||
*/
|
|
||||||
private String from;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.hzs.third.email.provider;
|
|
||||||
|
|
||||||
import com.hzs.common.core.domain.R;
|
|
||||||
import com.hzs.third.email.IEmailServiceApi;
|
|
||||||
import com.hzs.third.email.dto.EmailServiceDTO;
|
|
||||||
import com.hzs.third.email.service.IEmailService;
|
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件发送dubbo服务
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 9:41
|
|
||||||
* @Classname: EmailServiceProvider
|
|
||||||
* @PackageName: com.hzs.third.email.provider
|
|
||||||
*/
|
|
||||||
@DubboService
|
|
||||||
public class EmailServiceProvider implements IEmailServiceApi {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IEmailService iEmailService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public R<?> sendMail(EmailServiceDTO emailDTO) {
|
|
||||||
try {
|
|
||||||
iEmailService.sendMail(emailDTO.getRecipient(), emailDTO.getTitle(), emailDTO.getContent());
|
|
||||||
return R.ok();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return R.fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package com.hzs.third.email.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件服务
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 9:24
|
|
||||||
* @Classname: IEmailService
|
|
||||||
* @PackageName: com.hzs.third.email.service
|
|
||||||
*/
|
|
||||||
public interface IEmailService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送邮件
|
|
||||||
*
|
|
||||||
* @param recipient 接收账号
|
|
||||||
* @param title 邮件标题
|
|
||||||
* @param content 邮件内容
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
void sendMail(String recipient, String title, String content);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.hzs.third.email.service.impl;
|
|
||||||
|
|
||||||
import com.hzs.third.email.config.EmailConfig;
|
|
||||||
import com.hzs.third.email.service.IEmailService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 邮件服务
|
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2025/1/6 9:24
|
|
||||||
* @Classname: EmailServiceImpl
|
|
||||||
* @PackageName: com.hzs.third.email.service.impl
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class EmailServiceImpl implements IEmailService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmailConfig emailConfig;
|
|
||||||
@Autowired
|
|
||||||
private JavaMailSender mailSender;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMail(String recipient, String title, String content) {
|
|
||||||
// 创建一个邮件对象
|
|
||||||
SimpleMailMessage msg = new SimpleMailMessage();
|
|
||||||
msg.setFrom(emailConfig.getFrom());
|
|
||||||
msg.setTo(recipient);
|
|
||||||
msg.setSubject(title);
|
|
||||||
msg.setText(content);
|
|
||||||
mailSender.send(msg);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +1,14 @@
|
||||||
package com.hzs.third.job;
|
package com.hzs.third.job;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import com.hzs.common.core.constant.CountryConstants;
|
|
||||||
import com.hzs.common.core.enums.EOrderType;
|
|
||||||
import com.hzs.common.core.enums.EYesNo;
|
|
||||||
import com.hzs.common.core.utils.ComputeUtil;
|
|
||||||
import com.hzs.common.core.utils.DateUtils;
|
|
||||||
import com.hzs.common.domain.member.account.CuMemberRecharge;
|
|
||||||
import com.hzs.common.domain.sale.ext.SaOrderExt;
|
|
||||||
import com.hzs.member.account.IMemberJobServiceApi;
|
import com.hzs.member.account.IMemberJobServiceApi;
|
||||||
import com.hzs.sale.order.ISaOrderServiceApi;
|
import com.hzs.sale.order.ISaOrderServiceApi;
|
||||||
import com.hzs.system.base.ICurrencyServiceApi;
|
import com.hzs.system.base.ICurrencyServiceApi;
|
||||||
import com.hzs.system.base.dto.CurrencyDTO;
|
|
||||||
import com.hzs.third.sms.util.SmsUtil;
|
|
||||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: hzs_cloud
|
|
||||||
* @BelongsPackage: com.hzs.third.job
|
|
||||||
* @Author: sui qing
|
|
||||||
* @CreateTime: 2023-03-29 18:39
|
|
||||||
* @Description: 定时发送业绩短信
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ConditionalOnProperty(name = "xxl-job.start", havingValue = "true")
|
@ConditionalOnProperty(name = "xxl-job.start", havingValue = "true")
|
||||||
@Component
|
@Component
|
||||||
|
@ -39,109 +16,13 @@ public class OrderJob {
|
||||||
|
|
||||||
@DubboReference
|
@DubboReference
|
||||||
ISaOrderServiceApi orderServiceApi;
|
ISaOrderServiceApi orderServiceApi;
|
||||||
@DubboReference
|
|
||||||
ICurrencyServiceApi currencyServiceApi;
|
|
||||||
@DubboReference
|
|
||||||
IMemberJobServiceApi memberJobServiceApi;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时关单 订单三十分钟未支付自动关闭
|
* 定时关单 订单三十分钟未支付自动关闭
|
||||||
*/
|
*/
|
||||||
// TODO 设置定时任务 启动频率
|
|
||||||
@XxlJob("autoCloseOrder")
|
@XxlJob("autoCloseOrder")
|
||||||
public void timingCloseOrder() {
|
public void timingCloseOrder() {
|
||||||
orderServiceApi.closeOrder();
|
orderServiceApi.closeOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @description: 定时发送业绩短信
|
|
||||||
* @author: sui q
|
|
||||||
* @date: 2023/9/6 13:54
|
|
||||||
* @param: null null
|
|
||||||
**/
|
|
||||||
@XxlJob("sendOrderAchieve")
|
|
||||||
// @Scheduled(cron = "00 49 15 * * ?")
|
|
||||||
public void sendOrderAchieveMsg() {
|
|
||||||
Date startDate = DateUtils.currentDate();
|
|
||||||
Date endDate = DateUtils.afterDate(1, ChronoUnit.DAYS);
|
|
||||||
List<SaOrderExt> saOrderExtList = orderServiceApi.querySaOrderByDay(startDate, endDate).getData();
|
|
||||||
if (CollectionUtil.isNotEmpty(saOrderExtList)) {
|
|
||||||
BigDecimal registerAchieve = BigDecimal.ZERO;
|
|
||||||
BigDecimal updateAchieve = BigDecimal.ZERO;
|
|
||||||
BigDecimal repurchaseAchieve = BigDecimal.ZERO;
|
|
||||||
BigDecimal haiFunAchieve = BigDecimal.ZERO;
|
|
||||||
BigDecimal directSupplyAchieve = BigDecimal.ZERO;
|
|
||||||
Map<Integer, CurrencyDTO> currencyDtoMap = new HashMap<>();
|
|
||||||
for (SaOrderExt saOrderExt : saOrderExtList) {
|
|
||||||
if (EYesNo.NO.getIntValue() == saOrderExt.getDelFlag()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
BigDecimal orderAmount = saOrderExt.getOrderAmount();
|
|
||||||
if (!Objects.equals(CountryConstants.CHINA_COUNTRY, saOrderExt.getPkCountry())) {
|
|
||||||
BigDecimal outRate;
|
|
||||||
if (currencyDtoMap.containsKey(saOrderExt.getPkRate())) {
|
|
||||||
outRate = currencyDtoMap.get(saOrderExt.getPkRate()).getInExchangeRate();
|
|
||||||
} else {
|
|
||||||
CurrencyDTO currencyDTO = currencyServiceApi.getCurrencyByPkId(saOrderExt.getPkRate()).getData();
|
|
||||||
outRate = currencyDTO.getInExchangeRate();
|
|
||||||
currencyDtoMap.put(saOrderExt.getPkCountry(), currencyDTO);
|
|
||||||
}
|
|
||||||
orderAmount = ComputeUtil.computeMultiply(ComputeUtil.computeDivide(orderAmount, outRate), 6.4);
|
|
||||||
}
|
|
||||||
if (Objects.equals(EOrderType.REGISTER_ORDER.getValue(), saOrderExt.getOrderType()) ||
|
|
||||||
Objects.equals(EOrderType.SPECIAL_UPGRADE_ORDER.getValue(), saOrderExt.getOrderType())) {
|
|
||||||
registerAchieve = ComputeUtil.computeAdd(registerAchieve, orderAmount);
|
|
||||||
} else if (Objects.equals(EOrderType.UPGRADE_ORDER.getValue(), saOrderExt.getOrderType()) ||
|
|
||||||
Objects.equals(EOrderType.FICTITIOUS_ORDER.getValue(), saOrderExt.getOrderType()) ||
|
|
||||||
Objects.equals(EOrderType.SPECIAL_REGISTER_ORDER.getValue(), saOrderExt.getOrderType())) {
|
|
||||||
updateAchieve = ComputeUtil.computeAdd(updateAchieve, orderAmount);
|
|
||||||
} else if (Objects.equals(EOrderType.FANS_ORDER.getValue(), saOrderExt.getOrderType())) {
|
|
||||||
haiFunAchieve = ComputeUtil.computeAdd(haiFunAchieve, orderAmount);
|
|
||||||
} else {
|
|
||||||
if (Objects.equals(EOrderType.CONSUME_ORDER.getValue(), saOrderExt.getOrderType())) {
|
|
||||||
orderAmount = ComputeUtil.computeSubtract(orderAmount, saOrderExt.getConsumeAmount());
|
|
||||||
}
|
|
||||||
repurchaseAchieve = ComputeUtil.computeAdd(repurchaseAchieve, orderAmount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BigDecimal rechargeTotalAmount = selectRechargeTotalAmount(startDate, endDate);
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.append("尊敬的董事长您好!今日A=").append(calculateAchieve(registerAchieve))
|
|
||||||
.append(",B=").append(calculateAchieve(updateAchieve))
|
|
||||||
.append(",C=").append(calculateAchieve(repurchaseAchieve))
|
|
||||||
.append(",D=").append(calculateAchieve(haiFunAchieve))
|
|
||||||
// .append(",E=").append(calculateAchieve(directSupplyAchieve))
|
|
||||||
.append(",合计=").append(calculateAchieve(registerAchieve.add(updateAchieve)
|
|
||||||
.add(repurchaseAchieve).add(haiFunAchieve).add(directSupplyAchieve))).append(",Q=").append(calculateAchieve(rechargeTotalAmount)).append("。");
|
|
||||||
List<String> phoneList = new ArrayList<>();
|
|
||||||
phoneList.add("18454272386");
|
|
||||||
phoneList.add("18389196333");
|
|
||||||
phoneList.add("18561823095");
|
|
||||||
phoneList.forEach(phone -> {
|
|
||||||
String smsStr = SmsUtil.sendSms(phone, stringBuilder.toString());
|
|
||||||
log.info("发送短信{}", smsStr);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询充值现金币的总金额
|
|
||||||
*
|
|
||||||
* @param startDate 开始时间
|
|
||||||
* @param endDate 结束时间
|
|
||||||
* @return BigDecimal
|
|
||||||
*/
|
|
||||||
private BigDecimal selectRechargeTotalAmount(Date startDate, Date endDate) {
|
|
||||||
CuMemberRecharge cuMemberRecharge = memberJobServiceApi.selectRechargeTotalAmount(startDate, endDate).getData();
|
|
||||||
if (null != cuMemberRecharge) {
|
|
||||||
return cuMemberRecharge.getRechargeAmount();
|
|
||||||
} else {
|
|
||||||
return BigDecimal.ZERO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BigDecimal calculateAchieve(BigDecimal achieve) {
|
|
||||||
return ComputeUtil.computeDivide(achieve, BigDecimal.valueOf(10000)).setScale(2, RoundingMode.HALF_UP);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 定时任务测试控制器
|
* 定时任务测试控制器
|
||||||
* @Author: jiang chao
|
|
||||||
* @Time: 2024/2/23 14:20
|
|
||||||
* @Classname: JobController
|
|
||||||
* @PackageName: com.hzs.third.job.controller
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -31,10 +27,7 @@ import java.util.*;
|
||||||
public class JobTestController {
|
public class JobTestController {
|
||||||
|
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private IAreaServiceApi iAreaServiceApi;
|
IAreaServiceApi iAreaServiceApi;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private OrderJob orderJob;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试行政区划更新
|
* 测试行政区划更新
|
||||||
|
|
Loading…
Reference in New Issue