From 929d7a077916df5f2a4ae58b155b9df66c6c0204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E2=99=82=E5=9C=A3=E7=BF=94?= Date: Mon, 7 May 2018 16:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ibase4j/model/SysEmailConfig.java | 151 ++++++++---------- .../service/impl/SysEmailServiceImpl.java | 29 ++++ 2 files changed, 94 insertions(+), 86 deletions(-) diff --git a/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysEmailConfig.java b/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysEmailConfig.java index ed95a5bd..5768939f 100644 --- a/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysEmailConfig.java +++ b/iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysEmailConfig.java @@ -1,7 +1,5 @@ package org.ibase4j.model; -import java.io.Serializable; - import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableName; @@ -19,88 +17,69 @@ @TableName("sys_email_config") public class SysEmailConfig extends BaseModel { - /** - * SMTP服务器 - */ - @TableField(value="smtp_host") - private String smtpHost; - /** - * SMTP服务器端口 - */ - @TableField(value="smtp_port") - private String smtpPort; - /** - * 发送方式 - */ - @TableField(value="send_method") - private String sendMethod; - /** - * 名称 - */ - @TableField(value="sender_name") - private String senderName; - /** - * 发邮件邮箱账号 - */ - @TableField(value="sender_account") - private String senderAccount; - /** - * 发邮件邮箱密码 - */ - @TableField(value="sender_password") - private String senderPassword; - - - public String getSmtpHost() { - return smtpHost; - } - - public void setSmtpHost(String smtpHost) { - this.smtpHost = smtpHost; - } - - public String getSmtpPort() { - return smtpPort; - } - - public void setSmtpPort(String smtpPort) { - this.smtpPort = smtpPort; - } - - public String getSendMethod() { - return sendMethod; - } - - public void setSendMethod(String sendMethod) { - this.sendMethod = sendMethod; - } - - public String getSenderName() { - return senderName; - } - - public void setSenderName(String senderName) { - this.senderName = senderName; - } - - public String getSenderAccount() { - return senderAccount; - } - - public void setSenderAccount(String senderAccount) { - this.senderAccount = senderAccount; - } - - public String getSenderPassword() { - return senderPassword; - } - - public void setSenderPassword(String senderPassword) { - this.senderPassword = senderPassword; - } - - protected Serializable pkVal() { - return getId(); - } - + /** + * SMTP服务器 + */ + @TableField(value="smtp_host") + private String smtpHost; + /** + * 名称 + */ + @TableField(value="sender_name") + private String senderName; + /** + * 发邮件邮箱账号 + */ + @TableField(value="sender_account") + private String senderAccount; + /** + * 发邮件邮箱密码 + */ + @TableField(value="sender_password") + private String senderPassword; + /** + * 发送邮箱鉴权 + */ + @TableField(value = "sender_password_auth") + private String senderPasswordAuth; + + public String getSmtpHost() { + return smtpHost; + } + + public void setSmtpHost(String smtpHost) { + this.smtpHost = smtpHost; + } + + public String getSenderName() { + return senderName; + } + + public void setSenderName(String senderName) { + this.senderName = senderName; + } + + public String getSenderAccount() { + return senderAccount; + } + + public void setSenderAccount(String senderAccount) { + this.senderAccount = senderAccount; + } + + public String getSenderPassword() { + return senderPassword; + } + + public void setSenderPassword(String senderPassword) { + this.senderPassword = senderPassword; + } + + public String getSenderPasswordAuth() { + return senderPasswordAuth; + } + + public void setSenderPasswordAuth(String senderPasswordAuth) { + this.senderPasswordAuth = senderPasswordAuth; + } } diff --git a/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/impl/SysEmailServiceImpl.java b/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/impl/SysEmailServiceImpl.java index 264fc5b1..44a0cfa7 100644 --- a/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/impl/SysEmailServiceImpl.java +++ b/iBase4J-SYS-Service/src/main/java/org/ibase4j/service/impl/SysEmailServiceImpl.java @@ -1,14 +1,24 @@ package org.ibase4j.service.impl; +import java.util.List; + import org.ibase4j.mapper.SysEmailMapper; import org.ibase4j.model.SysEmail; +import org.ibase4j.model.SysEmailConfig; +import org.ibase4j.service.ISysEmailConfigService; import org.ibase4j.service.ISysEmailService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.transaction.annotation.Transactional; import com.alibaba.dubbo.config.annotation.Service; import com.weibo.api.motan.config.springsupport.annotation.MotanService; import top.ibase4j.core.base.BaseService; +import top.ibase4j.core.support.email.Email; +import top.ibase4j.core.util.DataUtil; +import top.ibase4j.core.util.EmailUtil; +import top.ibase4j.core.util.InstanceUtil; /** * @author ShenHuaJie @@ -18,5 +28,24 @@ @Service(interfaceClass = ISysEmailService.class) @MotanService(interfaceClass = ISysEmailService.class) public class SysEmailServiceImpl extends BaseService implements ISysEmailService { + @Autowired + private ISysEmailConfigService emailConfigService; + @Transactional + public void sendEmail(SysEmail record) { + Email email = new Email(record.getSender(), record.getEmailTitle(), record.getEmailContent()); + List emailConfigs = emailConfigService.queryList(InstanceUtil.newHashMap()); + if (DataUtil.isEmpty(emailConfigs)) { + logger.warn("缺少邮件配置, 使用配置文件默认配置"); + } else { + SysEmailConfig emailConfig = emailConfigs.get(0); + email.setHost(emailConfig.getSmtpHost()); + email.setName(emailConfig.getSenderName()); + email.setFrom(emailConfig.getSenderName() + "," + emailConfig.getSenderAccount()); + email.setPassword(emailConfig.getSenderPassword()); + email.setKey(emailConfig.getSenderPasswordAuth()); + } + EmailUtil.sendEmail(email); + update(record); + } }