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 85e7a26..40187ee 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.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailUtil; @@ -23,7 +24,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.io.File; -import java.util.Objects; +import java.util.List; /** * 邮件发送处理 @@ -56,9 +57,9 @@ public class EmailHandler extends BaseHandler implements Handler { EmailContentModel emailContentModel = (EmailContentModel) taskInfo.getContentModel(); MailAccount account = getAccountConfig(taskInfo.getSendAccount()); try { - File file = StrUtil.isNotBlank(emailContentModel.getUrl()) ? AustinFileUtils.getRemoteUrl2File(dataPath, emailContentModel.getUrl()) : null; - String result = Objects.isNull(file) ? MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true) : - MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true, file); + List files = StrUtil.isNotBlank(emailContentModel.getUrl()) ? AustinFileUtils.getRemoteUrl2File(dataPath, StrUtil.split(emailContentModel.getUrl(), StrUtil.COMMA)) : null; + String result = CollUtil.isEmpty(files) ? MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true) : + MailUtil.send(account, taskInfo.getReceiver(), emailContentModel.getTitle(), emailContentModel.getContent(), true, files.toArray(new File[files.size()])); } 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 index 859f238..3c6873d 100644 --- 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 @@ -7,6 +7,9 @@ import lombok.extern.slf4j.Slf4j; import java.io.File; import java.io.FileOutputStream; import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; /** * @author 3y @@ -37,4 +40,22 @@ public class AustinFileUtils { return null; } + /** + * 读取 远程链接集合 返回有效的File对象集合 + * + * @param path 文件路径 + * @param remoteUrls cdn/oss文件访问链接集合 + * @return + */ + public static List getRemoteUrl2File(String path, Collection remoteUrls) { + List files = new ArrayList<>(); + remoteUrls.forEach(remoteUrl -> { + File file = getRemoteUrl2File(path, remoteUrl); + if (file != null) { + files.add(file); + } + }); + return files; + } + }