|
|
|
|
@@ -1,6 +1,10 @@
|
|
|
|
|
package org.agt.module.system.service.mail;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import lombok.Setter;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.agt.framework.common.enums.CommonStatusEnum;
|
|
|
|
|
import org.agt.framework.common.enums.UserTypeEnum;
|
|
|
|
|
import org.agt.module.system.dal.dataobject.mail.MailAccountDO;
|
|
|
|
|
@@ -10,17 +14,19 @@ import org.agt.module.system.mq.message.mail.MailSendMessage;
|
|
|
|
|
import org.agt.module.system.mq.producer.mail.MailProducer;
|
|
|
|
|
import org.agt.module.system.service.member.MemberService;
|
|
|
|
|
import org.agt.module.system.service.user.AdminUserService;
|
|
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.dromara.hutool.extra.mail.*;
|
|
|
|
|
import org.dromara.hutool.extra.mail.MailAccount;
|
|
|
|
|
import org.dromara.hutool.extra.mail.MailUtil;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static org.agt.module.system.enums.ErrorCodeConstants.*;
|
|
|
|
|
import static org.agt.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_NOT_EXISTS;
|
|
|
|
|
import static org.agt.module.system.enums.ErrorCodeConstants.MAIL_SEND_MAIL_NOT_EXISTS;
|
|
|
|
|
import static org.agt.module.system.enums.ErrorCodeConstants.MAIL_SEND_TEMPLATE_PARAM_MISS;
|
|
|
|
|
import static org.agt.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 邮箱发送 Service 实现类
|
|
|
|
|
@@ -48,6 +54,13 @@ public class MailSendServiceImpl implements MailSendService {
|
|
|
|
|
@Resource
|
|
|
|
|
private MailProducer mailProducer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 邮件的开关,默认为 true
|
|
|
|
|
*/
|
|
|
|
|
@Value("${agt.mail.enable:true}")
|
|
|
|
|
@Setter // 为了开发环境关闭邮件发送
|
|
|
|
|
private Boolean mailEnable;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Long sendSingleMailToAdmin(String mail, Long userId,
|
|
|
|
|
String templateCode, Map<String, Object> templateParams) {
|
|
|
|
|
@@ -92,7 +105,7 @@ public class MailSendServiceImpl implements MailSendService {
|
|
|
|
|
Long sendLogId = mailLogService.createMailLog(userId, userType, mail,
|
|
|
|
|
account, template, content, templateParams, isSend);
|
|
|
|
|
// 发送 MQ 消息,异步执行发送短信
|
|
|
|
|
if (isSend) {
|
|
|
|
|
if (isSend && mailEnable) {
|
|
|
|
|
mailProducer.sendMailSendMessage(sendLogId, mail, account.getId(),
|
|
|
|
|
template.getNickname(), title, content);
|
|
|
|
|
}
|
|
|
|
|
|