diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/model/EmailContentModel.java b/austin-common/src/main/java/com/java3y/austin/common/dto/model/EmailContentModel.java index 4b81311..e7c5820 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/dto/model/EmailContentModel.java +++ b/austin-common/src/main/java/com/java3y/austin/common/dto/model/EmailContentModel.java @@ -27,5 +27,8 @@ public class EmailContentModel extends ContentModel { */ private String content; - + /** + * 邮件附件链接 + */ + private String url; } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java index 6442662..7c03943 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java @@ -1,6 +1,7 @@ package com.java3y.austin.handler.handler.impl; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; import com.google.common.base.Throwables; @@ -14,11 +15,15 @@ import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.Handler; import com.java3y.austin.support.domain.MessageTemplate; import com.java3y.austin.support.utils.AccountUtils; +import com.java3y.austin.support.utils.AustinFileUtils; import com.sun.mail.util.MailSSLSocketFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import java.io.File; + /** * 邮件发送处理 * @@ -31,6 +36,9 @@ public class EmailHandler extends BaseHandler implements Handler { @Autowired private AccountUtils accountUtils; + @Value("${austin.business.upload.crowd.path}") + private String dataPath; + public EmailHandler() { channelCode = ChannelType.EMAIL.getCode(); @@ -47,8 +55,8 @@ public class EmailHandler extends BaseHandler implements Handler { EmailContentModel emailContentModel = (EmailContentModel) taskInfo.getContentModel(); MailAccount account = getAccountConfig(taskInfo.getSendAccount()); try { - MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), - emailContentModel.getContent(), true, null); + File file = StrUtil.isNotBlank(emailContentModel.getUrl()) ? AustinFileUtils.getRemoteUrl2File(dataPath, emailContentModel.getUrl()) : null; + MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true, file); } catch (Exception e) { log.error("EmailHandler#handler fail!{},params:{}", Throwables.getStackTraceAsString(e), taskInfo); return false; diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/AustinFileUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/AustinFileUtils.java new file mode 100644 index 0000000..6d945de --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/AustinFileUtils.java @@ -0,0 +1,38 @@ +package com.java3y.austin.support.utils; + +import cn.hutool.core.io.IoUtil; +import com.google.common.base.Throwables; +import lombok.extern.slf4j.Slf4j; + +import java.io.File; +import java.io.FileOutputStream; +import java.net.URL; + +/** + * @author 3y + * @date 2023/2/14 + */ +@Slf4j +public class AustinFileUtils { + + /** + * 读取 远程链接 返回File对象 + * + * @param path 文件路径 + * @param remoteUrl cdn/oss文件访问链接 + * @return + */ + public static File getRemoteUrl2File(String path, String remoteUrl) { + try { + new File(path).mkdirs(); + URL url = new URL(remoteUrl); + File file = new File(path, url.getPath()); + IoUtil.copy(url.openStream(), new FileOutputStream(file)); + return file; + } catch (Exception e) { + log.error("AustinFileUtils#getRemoteUrl2File fail:{},remoteUrl:{}", Throwables.getStackTraceAsString(e), remoteUrl); + } + return null; + } + +} diff --git a/sql/austin.sql b/sql/austin.sql index 8fd7d3e..61569b1 100644 --- a/sql/austin.sql +++ b/sql/austin.sql @@ -17,12 +17,12 @@ CREATE TABLE `message_template` `cron_crowd_path` varchar(500) COMMENT '定时发送人群的文件路径', `expect_push_time` varchar(100) COLLATE utf8mb4_unicode_ci COMMENT '期望发送时间:0:立即发送 定时任务以及周期任务:cron表达式', `id_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '消息的发送ID类型:10. userId 20.did 30.手机号 40.openId 50.email 60.企业微信userId', - `send_channel` tinyint(4) NOT NULL DEFAULT '0' COMMENT '消息发送渠道:10.IM 20.Push 30.短信 40.Email 50.公众号 60.小程序 70.企业微信 80.钉钉机器人 90.钉钉工作通知 100.企业微信机器人 110.飞书机器人 110. 飞书应用消息 ', + `send_channel` int(10) NOT NULL DEFAULT '0' COMMENT '消息发送渠道:10.IM 20.Push 30.短信 40.Email 50.公众号 60.小程序 70.企业微信 80.钉钉机器人 90.钉钉工作通知 100.企业微信机器人 110.飞书机器人 110. 飞书应用消息 ', `template_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '10.运营类 20.技术类接口调用', `msg_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '10.通知类消息 20.营销类消息 30.验证码类消息', `shield_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '10.夜间不屏蔽 20.夜间屏蔽 30.夜间屏蔽(次日早上9点发送)', `msg_content` varchar(4096) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '消息内容 占位符用{$var}表示', - `send_account` tinyint(4) NOT NULL DEFAULT '0' COMMENT '发送账号 一个渠道下可存在多个账号', + `send_account` int(10) NOT NULL DEFAULT '0' COMMENT '发送账号 一个渠道下可存在多个账号', `creator` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '创建者', `updator` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '更新者', `auditor` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '审核人',