添加静态资源处理

This commit is contained in:
Administrator
2017-07-29 10:18:35 +08:00
committed by wangkang
parent 1534a69fd1
commit 8a533b2238
2 changed files with 93 additions and 1 deletions
@@ -0,0 +1,66 @@
/**
* MailException.java
* Created at 2016-03-01
* Created by wangkang
* Copyright (C) 2016 egridcloud.com, All rights reserved.
*/
package com.egridcloud.udf.mail;
/**
* <p>
* ClassName: MailException
* </p>
* <p>
* Description: 文件异常
* </p>
* <p>
* Author: wangkang
* </p>
* <p>
* Date: 2016年3月23日
* </p>
*/
public class MailException extends RuntimeException {
/**
* <p>
* Field serialVersionUID: 序列号
* </p>
*/
private static final long serialVersionUID = 1L;
/**
* <p>
* Description: 构造函数
* </p>
*
* @param message 异常信息
*/
public MailException(String message) {
super(message);
}
/**
* <p>
* Description: 构造函数
* </p>
*
* @param cause 堆栈
*/
public MailException(Throwable cause) {
super(cause);
}
/**
* <p>
* Description: 构造函数
* </p>
*
* @param message 异常信息
* @param cause 堆栈
*/
public MailException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -26,8 +26,10 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.egridcloud.udf.core.RestResponse;
import com.egridcloud.udf.mail.MailException;
import com.egridcloud.udf.mail.MailProperties;
import com.egridcloud.udf.mail.domain.AttachmentInfo;
import com.egridcloud.udf.mail.domain.InlineInfo;
import com.egridcloud.udf.mail.domain.MailInfo;
import com.egridcloud.udf.mail.vo.file.FileInfo;
import com.egridcloud.udf.rms.Rms;
@@ -66,7 +68,7 @@ public class MailService {
* @throws MessagingException 异常
*/
@Async
public void send(MailInfo mailInfo) throws MessagingException {
public void send(MailInfo mailInfo) throws MessagingException { //NOSONAR
//创建消息
MimeMessage message = mailSender.createMimeMessage();
//判断是否有附件
@@ -95,6 +97,30 @@ public class MailService {
if (StringUtils.isNotBlank(mailInfo.getReplyTo())) {
helper.setReplyTo(mailInfo.getReplyTo());
}
//处理静态资源
if (CollectionUtils.isNotEmpty(mailInfo.getInlines())) {
for (InlineInfo inlineInfo : mailInfo.getInlines()) {
//判空
if (StringUtils.isBlank(inlineInfo.getFileId())
|| StringUtils.isBlank(inlineInfo.getName())) {
throw new MailException("inlineInfo fileid and name are not be null");
}
//获得必要参数
String fileId = inlineInfo.getFileId();
String name = inlineInfo.getName();
//构造参数
Map<String, String> uriVariables = new HashMap<>();
uriVariables.put("fileId", fileId);
//获得文件
ResponseEntity<byte[]> file =
rms.call("FILE_3", null, null, new ParameterizedTypeReference<byte[]>() {
}, uriVariables);
//构造resource
ByteArrayResource bar = new ByteArrayResource(file.getBody());
//添加静态资源
helper.addInline(name, bar);
}
}
//处理附件
if (CollectionUtils.isNotEmpty(mailInfo.getAttachments())) {
for (AttachmentInfo attachment : mailInfo.getAttachments()) {