Showing
18 changed files
with
555 additions
and
31 deletions
| ... | @@ -204,6 +204,22 @@ | ... | @@ -204,6 +204,22 @@ |
| 204 | </dependency> | 204 | </dependency> |
| 205 | 205 | ||
| 206 | <dependency> | 206 | <dependency> |
| 207 | + <groupId>org.apache.logging.log4j</groupId> | ||
| 208 | + <artifactId>log4j-spring-boot</artifactId> | ||
| 209 | + <version>2.17.1</version> | ||
| 210 | + <exclusions> | ||
| 211 | + <exclusion> | ||
| 212 | + <artifactId>log4j-api</artifactId> | ||
| 213 | + <groupId>org.apache.logging.log4j</groupId> | ||
| 214 | + </exclusion> | ||
| 215 | + <exclusion> | ||
| 216 | + <artifactId>log4j-core</artifactId> | ||
| 217 | + <groupId>org.apache.logging.log4j</groupId> | ||
| 218 | + </exclusion> | ||
| 219 | + </exclusions> | ||
| 220 | + </dependency> | ||
| 221 | + | ||
| 222 | + <dependency> | ||
| 207 | <groupId>io.jsonwebtoken</groupId> | 223 | <groupId>io.jsonwebtoken</groupId> |
| 208 | <artifactId>jjwt-impl</artifactId> | 224 | <artifactId>jjwt-impl</artifactId> |
| 209 | <version>0.10.6</version> | 225 | <version>0.10.6</version> | ... | ... |
| ... | @@ -61,7 +61,7 @@ public class Email implements Serializable { | ... | @@ -61,7 +61,7 @@ public class Email implements Serializable { |
| 61 | /** | 61 | /** |
| 62 | * 发送次数(0-3次) | 62 | * 发送次数(0-3次) |
| 63 | */ | 63 | */ |
| 64 | - private Long sendNum; | 64 | + private int sendNum; |
| 65 | 65 | ||
| 66 | /** | 66 | /** |
| 67 | * 邮件发送时间 | 67 | * 邮件发送时间 |
| ... | @@ -190,11 +190,11 @@ public class Email implements Serializable { | ... | @@ -190,11 +190,11 @@ public class Email implements Serializable { |
| 190 | this.statusName = statusName == null ? null : statusName.trim(); | 190 | this.statusName = statusName == null ? null : statusName.trim(); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | - public Long getSendNum() { | 193 | + public int getSendNum() { |
| 194 | return sendNum; | 194 | return sendNum; |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | - public void setSendNum(Long sendNum) { | 197 | + public void setSendNum(int sendNum) { |
| 198 | this.sendNum = sendNum; | 198 | this.sendNum = sendNum; |
| 199 | } | 199 | } |
| 200 | 200 | ... | ... |
| ... | @@ -11,7 +11,7 @@ public class ClearanceEmailTemplate implements EmailTemplate { | ... | @@ -11,7 +11,7 @@ public class ClearanceEmailTemplate implements EmailTemplate { |
| 11 | */ | 11 | */ |
| 12 | @Override | 12 | @Override |
| 13 | public String getTitle(Object ... arguments) { | 13 | public String getTitle(Object ... arguments) { |
| 14 | - return MessageFormat.format(CE_EMAIL_TITLE.TITLE,arguments); | 14 | + return MessageFormat.format(CLEARANCE_TITLE.TITLE,arguments); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| ... | @@ -19,6 +19,14 @@ public class ClearanceEmailTemplate implements EmailTemplate { | ... | @@ -19,6 +19,14 @@ public class ClearanceEmailTemplate implements EmailTemplate { |
| 19 | */ | 19 | */ |
| 20 | @Override | 20 | @Override |
| 21 | public String getBody(Object ... arguments) { | 21 | public String getBody(Object ... arguments) { |
| 22 | - return CE_EMAIL_BODY.BODY; | 22 | + return CLEARANCE_BODY.BODY; |
| 23 | + } | ||
| 24 | + | ||
| 25 | + interface CLEARANCE_TITLE{ | ||
| 26 | + String TITLE = ""; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + interface CLEARANCE_BODY{ | ||
| 30 | + String BODY = ""; | ||
| 23 | } | 31 | } |
| 24 | } | 32 | } | ... | ... |
| 1 | +package com.fedex.connect.task.data.bo; | ||
| 2 | + | ||
| 3 | +import java.io.File; | ||
| 4 | + | ||
| 5 | +public class MailAttachmentBo { | ||
| 6 | + | ||
| 7 | + private File file; | ||
| 8 | + private String fileName; | ||
| 9 | + private String fileType; | ||
| 10 | + | ||
| 11 | + public File getFile() { | ||
| 12 | + return file; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public void setFile(File file) { | ||
| 16 | + this.file = file; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public String getFileName() { | ||
| 20 | + return fileName; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void setFileName(String fileName) { | ||
| 24 | + this.fileName = fileName; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public String getFileType() { | ||
| 28 | + return fileType; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setFileType(String fileType) { | ||
| 32 | + this.fileType = fileType; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public MailAttachmentBo() { | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + public MailAttachmentBo(File file, String fileName) { | ||
| 39 | + this.file = file; | ||
| 40 | + this.fileName = fileName; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public MailAttachmentBo(File file, String fileName, String fileType) { | ||
| 44 | + this.file = file; | ||
| 45 | + this.fileName = fileName; | ||
| 46 | + this.fileType = fileType; | ||
| 47 | + } | ||
| 48 | +} |
| 1 | +package com.fedex.connect.task.data.dto; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.task.data.bo.MailAttachmentBo; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import java.io.Serializable; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 定义发送邮件内容对象 | ||
| 11 | + * @author Administrator | ||
| 12 | + */ | ||
| 13 | +@Data | ||
| 14 | +public class MailConfigDto implements Serializable { | ||
| 15 | + | ||
| 16 | + private static final long serialVersionUID = -8262893648898431866L; | ||
| 17 | + | ||
| 18 | + private String host; | ||
| 19 | + | ||
| 20 | + private String port; | ||
| 21 | + | ||
| 22 | + private String auth; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 业务名称 | ||
| 26 | + */ | ||
| 27 | + private String bizName; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 发件人 | ||
| 31 | + */ | ||
| 32 | + private String from; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 发件人密码 | ||
| 36 | + */ | ||
| 37 | + private String password; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 收件人 | ||
| 41 | + */ | ||
| 42 | + private String to; | ||
| 43 | + /** | ||
| 44 | + * 抄送 | ||
| 45 | + */ | ||
| 46 | + private String cc; | ||
| 47 | + /** | ||
| 48 | + * 邮件主题 | ||
| 49 | + */ | ||
| 50 | + private String subject; | ||
| 51 | + /** | ||
| 52 | + * 邮件内容 | ||
| 53 | + */ | ||
| 54 | + private String content; | ||
| 55 | + | ||
| 56 | + private String senderAccount; | ||
| 57 | + private String senderPassword; | ||
| 58 | + private String receiveAccount; | ||
| 59 | + private String ccAccount; | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + private List<Object> dataList; | ||
| 63 | + | ||
| 64 | + private List<MailAttachmentBo> fileList; | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * 是否启用代理(uat,prod 在外网,需要使用代理) | ||
| 68 | + */ | ||
| 69 | + private String proxyStartFlag; | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 代理服务器地址 | ||
| 73 | + */ | ||
| 74 | + private String proxyHost; | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 代理服务器端口 | ||
| 78 | + */ | ||
| 79 | + private String proxyPort; | ||
| 80 | + | ||
| 81 | + private String mailAccountFlag; | ||
| 82 | + | ||
| 83 | + | ||
| 84 | + @Override | ||
| 85 | + public String toString() { | ||
| 86 | + return "MailMessageReq{" + | ||
| 87 | + "host='" + host + '\'' + | ||
| 88 | + ", port='" + port + '\'' + | ||
| 89 | + ", auth='" + auth + '\'' + | ||
| 90 | + ", bizName='" + bizName + '\'' + | ||
| 91 | + ", from='" + from + '\'' + | ||
| 92 | + ", to='" + to + '\'' + | ||
| 93 | + ", cc='" + cc + '\'' + | ||
| 94 | + ", subject='" + subject + '\'' + | ||
| 95 | + ", content='" + content + '\'' + | ||
| 96 | + ", proxyStartFlag='" + proxyStartFlag + '\'' + | ||
| 97 | + ", proxyHost='" + proxyHost + '\'' + | ||
| 98 | + ", proxyPort='" + proxyPort + '\'' + | ||
| 99 | + '}'; | ||
| 100 | + } | ||
| 101 | +} | ||
| 102 | + |
server/task-schedule/src/main/java/com/fedex/connect/task/repository/base/AbstractDaoRepository.java
| 1 | package com.fedex.connect.task.repository.base; | 1 | package com.fedex.connect.task.repository.base; |
| 2 | 2 | ||
| 3 | +import com.fedex.connect.common.dao.biz.EmailMapper; | ||
| 4 | +import com.fedex.connect.common.dao.log.EmailHistoryMapper; | ||
| 3 | import com.fedex.connect.common.dao.sys.KafkaStorageHistoryMapper; | 5 | import com.fedex.connect.common.dao.sys.KafkaStorageHistoryMapper; |
| 4 | import com.fedex.connect.common.dao.sys.KafkaTemporaryStorageMapper; | 6 | import com.fedex.connect.common.dao.sys.KafkaTemporaryStorageMapper; |
| 5 | import com.fedex.connect.task.repository.dao.*; | 7 | import com.fedex.connect.task.repository.dao.*; |
| ... | @@ -20,4 +22,8 @@ public class AbstractDaoRepository { | ... | @@ -20,4 +22,8 @@ public class AbstractDaoRepository { |
| 20 | protected AttachmentExtMapper attachmentExtMapper; | 22 | protected AttachmentExtMapper attachmentExtMapper; |
| 21 | @Autowired | 23 | @Autowired |
| 22 | protected PortclearEmailMappingExtMapper portclearEmailMappingExtMapper; | 24 | protected PortclearEmailMappingExtMapper portclearEmailMappingExtMapper; |
| 25 | + @Autowired | ||
| 26 | + protected EmailMapper emailMapper; | ||
| 27 | + @Autowired | ||
| 28 | + protected EmailHistoryMapper emailHistoryMapper; | ||
| 23 | } | 29 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | package com.fedex.connect.task.repository.dao; | 1 | package com.fedex.connect.task.repository.dao; |
| 2 | 2 | ||
| 3 | import com.fedex.connect.common.model.biz.Email; | 3 | import com.fedex.connect.common.model.biz.Email; |
| 4 | +import org.apache.ibatis.annotations.Delete; | ||
| 4 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | +import org.apache.ibatis.annotations.Param; | ||
| 5 | 7 | ||
| 6 | import java.util.List; | 8 | import java.util.List; |
| 7 | 9 | ||
| 8 | @Mapper | 10 | @Mapper |
| 9 | public interface EmailExtMapper { | 11 | public interface EmailExtMapper { |
| 10 | List<Email> findConPushEmails(String typeCode,String statusCode); | 12 | List<Email> findConPushEmails(String typeCode,String statusCode); |
| 13 | + | ||
| 14 | + @Delete("DELETE FROM T_BIZ_EMAIL WHERE ID = #{id}") | ||
| 15 | + void deleteById(@Param("id") Long id); | ||
| 11 | } | 16 | } | ... | ... |
| ... | @@ -5,7 +5,7 @@ import org.apache.ibatis.annotations.Param; | ... | @@ -5,7 +5,7 @@ import org.apache.ibatis.annotations.Param; |
| 5 | 5 | ||
| 6 | import java.util.List; | 6 | import java.util.List; |
| 7 | 7 | ||
| 8 | -public interface IAttachmentExtRepository { | 8 | +public interface IAttachmentRepository { |
| 9 | 9 | ||
| 10 | List<PushZipEmailDto> findAttachmentDetailsByBizId(@Param("bizId") Long bizId); | 10 | List<PushZipEmailDto> findAttachmentDetailsByBizId(@Param("bizId") Long bizId); |
| 11 | } | 11 | } | ... | ... |
| ... | @@ -4,6 +4,10 @@ import com.fedex.connect.common.model.biz.Email; | ... | @@ -4,6 +4,10 @@ import com.fedex.connect.common.model.biz.Email; |
| 4 | 4 | ||
| 5 | import java.util.List; | 5 | import java.util.List; |
| 6 | 6 | ||
| 7 | -public interface IEmailExtRepository { | 7 | +public interface IEmailRepository { |
| 8 | List<Email> findConPushEmails(String typeCode,String statusCode); | 8 | List<Email> findConPushEmails(String typeCode,String statusCode); |
| 9 | + | ||
| 10 | + void deleteById(Long id); | ||
| 11 | + | ||
| 12 | + void save(Email entity); | ||
| 9 | } | 13 | } | ... | ... |
| ... | @@ -2,13 +2,13 @@ package com.fedex.connect.task.repository.repo.biz.impl; | ... | @@ -2,13 +2,13 @@ package com.fedex.connect.task.repository.repo.biz.impl; |
| 2 | 2 | ||
| 3 | import com.fedex.connect.task.data.dto.PushZipEmailDto; | 3 | import com.fedex.connect.task.data.dto.PushZipEmailDto; |
| 4 | import com.fedex.connect.task.repository.base.AbstractDaoRepository; | 4 | import com.fedex.connect.task.repository.base.AbstractDaoRepository; |
| 5 | -import com.fedex.connect.task.repository.repo.biz.IAttachmentExtRepository; | 5 | +import com.fedex.connect.task.repository.repo.biz.IAttachmentRepository; |
| 6 | import org.springframework.stereotype.Repository; | 6 | import org.springframework.stereotype.Repository; |
| 7 | 7 | ||
| 8 | import java.util.List; | 8 | import java.util.List; |
| 9 | 9 | ||
| 10 | @Repository | 10 | @Repository |
| 11 | -public class AttachmentExtRepositoryImpl extends AbstractDaoRepository implements IAttachmentExtRepository { | 11 | +public class AttachmentRepositoryImpl extends AbstractDaoRepository implements IAttachmentRepository { |
| 12 | 12 | ||
| 13 | @Override | 13 | @Override |
| 14 | public List<PushZipEmailDto> findAttachmentDetailsByBizId(Long bizId) { | 14 | public List<PushZipEmailDto> findAttachmentDetailsByBizId(Long bizId) { | ... | ... |
| ... | @@ -2,15 +2,30 @@ package com.fedex.connect.task.repository.repo.biz.impl; | ... | @@ -2,15 +2,30 @@ package com.fedex.connect.task.repository.repo.biz.impl; |
| 2 | 2 | ||
| 3 | import com.fedex.connect.common.model.biz.Email; | 3 | import com.fedex.connect.common.model.biz.Email; |
| 4 | import com.fedex.connect.task.repository.base.AbstractDaoRepository; | 4 | import com.fedex.connect.task.repository.base.AbstractDaoRepository; |
| 5 | -import com.fedex.connect.task.repository.repo.biz.IEmailExtRepository; | 5 | +import com.fedex.connect.task.repository.repo.biz.IEmailRepository; |
| 6 | import org.springframework.stereotype.Repository; | 6 | import org.springframework.stereotype.Repository; |
| 7 | 7 | ||
| 8 | import java.util.List; | 8 | import java.util.List; |
| 9 | 9 | ||
| 10 | @Repository | 10 | @Repository |
| 11 | -public class EmailExtRepositoryImpl extends AbstractDaoRepository implements IEmailExtRepository { | 11 | +public class EmailRepositoryImpl extends AbstractDaoRepository implements IEmailRepository { |
| 12 | public List<Email> findConPushEmails(String typeCode,String statusCode){ | 12 | public List<Email> findConPushEmails(String typeCode,String statusCode){ |
| 13 | return emailExtMapper.findConPushEmails(typeCode,statusCode); | 13 | return emailExtMapper.findConPushEmails(typeCode,statusCode); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | + @Override | ||
| 17 | + public void deleteById(Long id) { | ||
| 18 | + emailExtMapper.deleteById(id); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void save(Email entity){ | ||
| 22 | + if(entity != null) { | ||
| 23 | + if (entity.getId() == null || entity.getId() <= 0) { | ||
| 24 | + emailMapper.insertSelective(entity); | ||
| 25 | + } else if (entity.getId() != null && entity.getId() > 0){ | ||
| 26 | + emailMapper.updateByPrimaryKeySelective(entity); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + | ||
| 16 | } | 31 | } | ... | ... |
| 1 | +package com.fedex.connect.task.repository.repo.log.impl; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.model.log.EmailHistory; | ||
| 4 | +import com.fedex.connect.task.repository.base.AbstractDaoRepository; | ||
| 5 | +import com.fedex.connect.task.repository.repo.log.IEmailHistoryRepository; | ||
| 6 | +import org.springframework.stereotype.Repository; | ||
| 7 | + | ||
| 8 | +@Repository | ||
| 9 | +public class EmailHistoryRepositoryImpl extends AbstractDaoRepository implements IEmailHistoryRepository { | ||
| 10 | + | ||
| 11 | + @Override | ||
| 12 | + public void save(EmailHistory entity) { | ||
| 13 | + if(entity != null) { | ||
| 14 | + if (entity.getId() == null || entity.getId() <= 0) { | ||
| 15 | + emailHistoryMapper.insertSelective(entity); | ||
| 16 | + } else if (entity.getId() != null && entity.getId() > 0){ | ||
| 17 | + emailHistoryMapper.updateByPrimaryKeySelective(entity); | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | +} |
| 1 | package com.fedex.connect.task.service.base; | 1 | package com.fedex.connect.task.service.base; |
| 2 | 2 | ||
| 3 | import com.fedex.connect.common.dependencies.repository.repo.sys.IRedisSlabRepository; | 3 | import com.fedex.connect.common.dependencies.repository.repo.sys.IRedisSlabRepository; |
| 4 | -import com.fedex.connect.task.repository.repo.biz.IAttachmentExtRepository; | 4 | +import com.fedex.connect.task.repository.repo.biz.IAttachmentRepository; |
| 5 | -import com.fedex.connect.task.repository.repo.biz.IEmailExtRepository; | 5 | +import com.fedex.connect.task.repository.repo.biz.IEmailRepository; |
| 6 | import com.fedex.connect.task.repository.repo.sys.IKafkaStorageHistoryRepository; | 6 | import com.fedex.connect.task.repository.repo.sys.IKafkaStorageHistoryRepository; |
| 7 | import com.fedex.connect.task.repository.repo.sys.IKafkaTemporaryStorageRepository; | 7 | import com.fedex.connect.task.repository.repo.sys.IKafkaTemporaryStorageRepository; |
| 8 | import com.fedex.connect.task.repository.repo.sys.IRedisSlabExtRepository; | 8 | import com.fedex.connect.task.repository.repo.sys.IRedisSlabExtRepository; |
| ... | @@ -23,7 +23,7 @@ public class BaseService { | ... | @@ -23,7 +23,7 @@ public class BaseService { |
| 23 | @Autowired | 23 | @Autowired |
| 24 | protected IRedisSlabExtRepository redisRepository; | 24 | protected IRedisSlabExtRepository redisRepository; |
| 25 | @Autowired | 25 | @Autowired |
| 26 | - protected IEmailExtRepository iEmailExtRepository; | 26 | + protected IEmailRepository iEmailExtRepository; |
| 27 | @Autowired | 27 | @Autowired |
| 28 | - protected IAttachmentExtRepository attachmentExtRepository; | 28 | + protected IAttachmentRepository attachmentExtRepository; |
| 29 | } | 29 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -3,13 +3,16 @@ package com.fedex.connect.task.service.biz.impl; | ... | @@ -3,13 +3,16 @@ package com.fedex.connect.task.service.biz.impl; |
| 3 | import com.fedex.connect.common.dependencies.cache.CacheSystem; | 3 | import com.fedex.connect.common.dependencies.cache.CacheSystem; |
| 4 | import com.fedex.connect.common.dependencies.enums.biz.EmailStatusEnum; | 4 | import com.fedex.connect.common.dependencies.enums.biz.EmailStatusEnum; |
| 5 | import com.fedex.connect.common.dependencies.enums.biz.EmailTypeEnum; | 5 | import com.fedex.connect.common.dependencies.enums.biz.EmailTypeEnum; |
| 6 | +import com.fedex.connect.common.dependencies.util.NIOFileUtils; | ||
| 6 | import com.fedex.connect.common.dependencies.util.ZipUtils; | 7 | import com.fedex.connect.common.dependencies.util.ZipUtils; |
| 7 | import com.fedex.connect.common.model.biz.Email; | 8 | import com.fedex.connect.common.model.biz.Email; |
| 9 | +import com.fedex.connect.task.data.dto.MailConfigDto; | ||
| 8 | import com.fedex.connect.task.data.dto.PortFileDto; | 10 | import com.fedex.connect.task.data.dto.PortFileDto; |
| 9 | import com.fedex.connect.task.data.dto.PushZipEmailDto; | 11 | import com.fedex.connect.task.data.dto.PushZipEmailDto; |
| 10 | import com.fedex.connect.task.service.base.BaseService; | 12 | import com.fedex.connect.task.service.base.BaseService; |
| 11 | import com.fedex.connect.task.service.biz.IPushConsignmentFileService; | 13 | import com.fedex.connect.task.service.biz.IPushConsignmentFileService; |
| 12 | import com.fedex.connect.task.utils.sys.ConFileEmailUtil; | 14 | import com.fedex.connect.task.utils.sys.ConFileEmailUtil; |
| 15 | +import com.fedex.connect.task.utils.sys.EmailUtil; | ||
| 13 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
| ... | @@ -34,6 +37,12 @@ public class PushConsignmentFileServiceImpl extends BaseService implements IPush | ... | @@ -34,6 +37,12 @@ public class PushConsignmentFileServiceImpl extends BaseService implements IPush |
| 34 | @Autowired | 37 | @Autowired |
| 35 | private ConFileEmailUtil conFileEmailUtil; | 38 | private ConFileEmailUtil conFileEmailUtil; |
| 36 | 39 | ||
| 40 | + @Autowired | ||
| 41 | + private EmailUtil emailUtil; | ||
| 42 | + | ||
| 43 | + @Autowired | ||
| 44 | + private NIOFileUtils nioFileUtils; | ||
| 45 | + | ||
| 37 | /** | 46 | /** |
| 38 | * @Author Szl | 47 | * @Author Szl |
| 39 | * @Description 功能说明 推送清关文件 | 48 | * @Description 功能说明 推送清关文件 |
| ... | @@ -46,17 +55,22 @@ public class PushConsignmentFileServiceImpl extends BaseService implements IPush | ... | @@ -46,17 +55,22 @@ public class PushConsignmentFileServiceImpl extends BaseService implements IPush |
| 46 | String tempPath = ""; | 55 | String tempPath = ""; |
| 47 | String finalPath = ""; | 56 | String finalPath = ""; |
| 48 | //查询需要发送的数据 | 57 | //查询需要发送的数据 |
| 49 | - List<Email> conPushEmails = iEmailExtRepository.findConPushEmails(cacheSystem.getDicEmailType(EmailTypeEnum.PENDING.getEnMsg()).getCode(), | 58 | + List<Email> conPushEmails = iEmailExtRepository.findConPushEmails(cacheSystem.getDicEmailType(EmailTypeEnum.PUSH_CON_FILE.getEnMsg()).getCode(), |
| 50 | cacheSystem.getDicEmailStatus(EmailStatusEnum.PENDING.getEnMsg()).getCode()); | 59 | cacheSystem.getDicEmailStatus(EmailStatusEnum.PENDING.getEnMsg()).getCode()); |
| 51 | 60 | ||
| 52 | for (Email conPushEmail : conPushEmails) { | 61 | for (Email conPushEmail : conPushEmails) { |
| 53 | //获取待发送的文件并打zip包 | 62 | //获取待发送的文件并打zip包 |
| 54 | - List<PushZipEmailDto> attachmentDetailsByBizId = attachmentExtRepository.findAttachmentDetailsByBizId(conPushEmail.getBizId()); | ||
| 55 | PortFileDto portFileDto = new PortFileDto(); | 63 | PortFileDto portFileDto = new PortFileDto(); |
| 64 | + List<PushZipEmailDto> attachmentDetailsByBizId = attachmentExtRepository.findAttachmentDetailsByBizId(conPushEmail.getBizId()); | ||
| 56 | portFileDto = conFileEmailUtil.getPortZipMap(portFileDto, attachmentDetailsByBizId, tempPath, finalPath, zipUtils); | 65 | portFileDto = conFileEmailUtil.getPortZipMap(portFileDto, attachmentDetailsByBizId, tempPath, finalPath, zipUtils); |
| 57 | - | 66 | + //发送邮件 |
| 58 | - //记录到发送邮件表中 | 67 | + MailConfigDto mailMessageReqDto = new MailConfigDto(); |
| 59 | - | 68 | + boolean result = conFileEmailUtil.sendEmail(portFileDto, emailUtil,mailMessageReqDto); |
| 69 | + //根据是否成功发送邮件对文件进行备份 | ||
| 70 | + String filePath = conFileEmailUtil.backFile(portFileDto.getZipPath(), nioFileUtils,result); | ||
| 71 | + //更新邮件记录表 | ||
| 72 | + conFileEmailUtil.createEmail(cacheSystem,conPushEmail,mailMessageReqDto,result,filePath); | ||
| 73 | + //保存入库 | ||
| 60 | 74 | ||
| 61 | } | 75 | } |
| 62 | 76 | ... | ... |
| 1 | package com.fedex.connect.task.utils.sys; | 1 | package com.fedex.connect.task.utils.sys; |
| 2 | 2 | ||
| 3 | +import com.fedex.connect.common.dependencies.cache.CacheSystem; | ||
| 3 | import com.fedex.connect.common.dependencies.contants.BaseConstants; | 4 | import com.fedex.connect.common.dependencies.contants.BaseConstants; |
| 4 | import com.fedex.connect.common.dependencies.contants.BaseSeparatorConstants; | 5 | import com.fedex.connect.common.dependencies.contants.BaseSeparatorConstants; |
| 5 | -import com.fedex.connect.common.dependencies.enums.biz.AttachmentBizTypeEnum; | 6 | +import com.fedex.connect.common.dependencies.enums.biz.EmailStatusEnum; |
| 7 | +import com.fedex.connect.common.dependencies.template.clearanceEmail.ClearanceEmailTemplate; | ||
| 6 | import com.fedex.connect.common.dependencies.util.DateUtil; | 8 | import com.fedex.connect.common.dependencies.util.DateUtil; |
| 9 | +import com.fedex.connect.common.dependencies.util.NIOFileUtils; | ||
| 7 | import com.fedex.connect.common.dependencies.util.ZipUtils; | 10 | import com.fedex.connect.common.dependencies.util.ZipUtils; |
| 11 | +import com.fedex.connect.common.model.bi.DictionaryEntries; | ||
| 8 | import com.fedex.connect.common.model.biz.Email; | 12 | import com.fedex.connect.common.model.biz.Email; |
| 13 | +import com.fedex.connect.common.model.log.EmailHistory; | ||
| 14 | +import com.fedex.connect.task.data.bo.MailAttachmentBo; | ||
| 15 | +import com.fedex.connect.task.data.dto.MailConfigDto; | ||
| 9 | import com.fedex.connect.task.data.dto.PortFileDto; | 16 | import com.fedex.connect.task.data.dto.PortFileDto; |
| 10 | import com.fedex.connect.task.data.dto.PushZipEmailDto; | 17 | import com.fedex.connect.task.data.dto.PushZipEmailDto; |
| 11 | import com.fedex.connect.task.repository.repo.bi.IPortclearEmailMappingExtRepository; | 18 | import com.fedex.connect.task.repository.repo.bi.IPortclearEmailMappingExtRepository; |
| 19 | +import com.fedex.connect.task.repository.repo.biz.IEmailRepository; | ||
| 20 | +import com.fedex.connect.task.repository.repo.log.IEmailHistoryRepository; | ||
| 12 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
| 13 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
| 23 | +import org.springframework.beans.BeanUtils; | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 24 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | import org.springframework.stereotype.Component; | 25 | import org.springframework.stereotype.Component; |
| 26 | +import org.springframework.transaction.annotation.Transactional; | ||
| 16 | 27 | ||
| 17 | import java.io.File; | 28 | import java.io.File; |
| 18 | import java.io.FileOutputStream; | 29 | import java.io.FileOutputStream; |
| 19 | import java.io.IOException; | 30 | import java.io.IOException; |
| 31 | +import java.nio.file.Paths; | ||
| 32 | +import java.text.SimpleDateFormat; | ||
| 20 | import java.util.ArrayList; | 33 | import java.util.ArrayList; |
| 21 | import java.util.Date; | 34 | import java.util.Date; |
| 22 | import java.util.List; | 35 | import java.util.List; |
| ... | @@ -33,9 +46,18 @@ public class ConFileEmailUtil { | ... | @@ -33,9 +46,18 @@ public class ConFileEmailUtil { |
| 33 | @Autowired | 46 | @Autowired |
| 34 | private IPortclearEmailMappingExtRepository portclearEmailMappingExtRepository; | 47 | private IPortclearEmailMappingExtRepository portclearEmailMappingExtRepository; |
| 35 | 48 | ||
| 49 | + @Autowired | ||
| 50 | + private IEmailRepository emailRepository; | ||
| 51 | + | ||
| 52 | + @Autowired | ||
| 53 | + private ClearanceEmailTemplate clearanceEmailTemplate; | ||
| 54 | + | ||
| 55 | + @Autowired | ||
| 56 | + private IEmailHistoryRepository emailHistoryRepository; | ||
| 57 | + | ||
| 36 | /** | 58 | /** |
| 37 | * @Author Szl | 59 | * @Author Szl |
| 38 | - * @Description 功能说明 根据口岸打包,每个口岸的文件打成一个zip包 | 60 | + * @Description 功能说明 根据运单打包,一票一个zip包 |
| 39 | * @Date 2024/11/14 | 61 | * @Date 2024/11/14 |
| 40 | * @param tempPath | 62 | * @param tempPath |
| 41 | * @param finalPath | 63 | * @param finalPath |
| ... | @@ -55,7 +77,7 @@ public class ConFileEmailUtil { | ... | @@ -55,7 +77,7 @@ public class ConFileEmailUtil { |
| 55 | filesList.add(file); | 77 | filesList.add(file); |
| 56 | } | 78 | } |
| 57 | } | 79 | } |
| 58 | - String date = DateUtil.formatTimeWithoutSlash(new Date()); | 80 | + String date = DateUtil.yyyyMMddHHmmss(new Date()); |
| 59 | String fileName = date + BaseSeparatorConstants.SEPARATOR_UNDERLINE + portCode + BaseConstants.FILE_SUFFIX_KEYS.ZIP; | 81 | String fileName = date + BaseSeparatorConstants.SEPARATOR_UNDERLINE + portCode + BaseConstants.FILE_SUFFIX_KEYS.ZIP; |
| 60 | String fileNameTemp = date + BaseSeparatorConstants.SEPARATOR_UNDERLINE + portCode + BaseConstants.FILE_SUFFIX_KEYS.ZIP + BaseConstants.FILE_SUFFIX_KEYS.TEMP; | 82 | String fileNameTemp = date + BaseSeparatorConstants.SEPARATOR_UNDERLINE + portCode + BaseConstants.FILE_SUFFIX_KEYS.ZIP + BaseConstants.FILE_SUFFIX_KEYS.TEMP; |
| 61 | FileOutputStream fos = null; | 83 | FileOutputStream fos = null; |
| ... | @@ -90,20 +112,183 @@ public class ConFileEmailUtil { | ... | @@ -90,20 +112,183 @@ public class ConFileEmailUtil { |
| 90 | return portFileDto; | 112 | return portFileDto; |
| 91 | } | 113 | } |
| 92 | 114 | ||
| 115 | + /** | ||
| 116 | + * @Author Szl | ||
| 117 | + * @Description 功能说明 发送邮件 | ||
| 118 | + * @Date 2024/11/18 | ||
| 119 | + * @param portFileDto | ||
| 120 | + * @return void | ||
| 121 | + */ | ||
| 122 | + public boolean sendEmail(PortFileDto portFileDto,EmailUtil emailUtil,MailConfigDto mailMessageReqDto){ | ||
| 123 | + /** | ||
| 124 | + * 获取邮件地址 | ||
| 125 | + */ | ||
| 126 | + String emailAddress = this.getEmailAddress(portFileDto); | ||
| 127 | + /** | ||
| 128 | + * 构建发送邮件对象 | ||
| 129 | + */ | ||
| 130 | + this.createMailMessageReqDto(emailAddress, portFileDto,mailMessageReqDto); | ||
| 131 | + /** | ||
| 132 | + * 发送邮件 | ||
| 133 | + */ | ||
| 134 | + boolean result = emailUtil.sendMail(mailMessageReqDto); | ||
| 135 | + | ||
| 136 | + return result; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * @Author Szl | ||
| 141 | + * @Description 功能说明 构建发送邮件dto | ||
| 142 | + * @Date 2024/11/18 | ||
| 143 | + * @param emailAddress | ||
| 144 | + * @param portFileDto | ||
| 145 | + * @return com.fedex.connect.task.data.dto.MailMessageReqDto | ||
| 146 | + */ | ||
| 147 | + private MailConfigDto createMailMessageReqDto(String emailAddress, PortFileDto portFileDto,MailConfigDto mailConfigDto){ | ||
| 148 | + mailConfigDto.setHost(""); | ||
| 149 | + mailConfigDto.setPort(""); | ||
| 150 | + mailConfigDto.setAuth(""); | ||
| 151 | + //设置代理 | ||
| 152 | + mailConfigDto.setProxyStartFlag(""); | ||
| 153 | + mailConfigDto.setProxyHost(""); | ||
| 154 | + mailConfigDto.setProxyPort(""); | ||
| 155 | + //发件人 | ||
| 156 | + mailConfigDto.setFrom(""); | ||
| 157 | + //发件人密码 | ||
| 158 | + mailConfigDto.setPassword(""); | ||
| 159 | + //ce接收人 | ||
| 160 | + mailConfigDto.setTo(emailAddress); | ||
| 161 | + //设置邮件标题 | ||
| 162 | + mailConfigDto.setSubject(clearanceEmailTemplate.getTitle()); | ||
| 163 | + //设置邮件内容 | ||
| 164 | + mailConfigDto.setContent(clearanceEmailTemplate.getBody()); | ||
| 165 | + //放入文件列表 | ||
| 166 | + List<MailAttachmentBo> srcFiles = new ArrayList<>(); | ||
| 167 | + File file = new File(portFileDto.getZipPath()); | ||
| 168 | + srcFiles.add(new MailAttachmentBo(file, "")); | ||
| 169 | + mailConfigDto.setFileList(srcFiles); | ||
| 170 | + return mailConfigDto; | ||
| 171 | + } | ||
| 93 | 172 | ||
| 94 | - public void saveEmail(Email conPushEmail,PortFileDto portFileDto){ | 173 | + /** |
| 95 | - //获取邮箱地址 | 174 | + * @Author Szl |
| 175 | + * @Description 功能说明 根据口岸获取邮件地址 | ||
| 176 | + * @Date 2024/11/18 | ||
| 177 | + * @param portFileDto | ||
| 178 | + * @return java.lang.String | ||
| 179 | + */ | ||
| 180 | + private String getEmailAddress(PortFileDto portFileDto){ | ||
| 96 | if (BaseConstants.CONSIGNMENT_TABLE_COLUMN_KEYS.DEST_IATA_CODE.equals(portFileDto.getDestIataCode())){ | 181 | if (BaseConstants.CONSIGNMENT_TABLE_COLUMN_KEYS.DEST_IATA_CODE.equals(portFileDto.getDestIataCode())){ |
| 97 | - portFileDto.setDestIataCode(AttachmentBizTypeEnum.OTH.getEnMsg()); | 182 | + portFileDto.setDestIataCode("OTHER"); |
| 98 | } | 183 | } |
| 99 | String emailByPortCode = portclearEmailMappingExtRepository.findEmailByPortCode(portFileDto.getDestIataCode()); | 184 | String emailByPortCode = portclearEmailMappingExtRepository.findEmailByPortCode(portFileDto.getDestIataCode()); |
| 100 | if (StringUtils.isEmpty(emailByPortCode)){ | 185 | if (StringUtils.isEmpty(emailByPortCode)){ |
| 186 | + emailByPortCode = portclearEmailMappingExtRepository.findEmailByPortCode("OTHER"); | ||
| 187 | + } | ||
| 188 | + return emailByPortCode; | ||
| 189 | + } | ||
| 101 | 190 | ||
| 191 | + /** | ||
| 192 | + * @Author Szl | ||
| 193 | + * @Description 功能说明 创建邮件记录 | ||
| 194 | + * @Date 2024/11/18 | ||
| 195 | + * @param cacheSystem | ||
| 196 | + * @param conPushEmail | ||
| 197 | + * @param mailMessageReqDto | ||
| 198 | + * @param result | ||
| 199 | + * @return void | ||
| 200 | + */ | ||
| 201 | + public void createEmail(CacheSystem cacheSystem, Email conPushEmail, MailConfigDto mailMessageReqDto, boolean result,String filePath){ | ||
| 202 | + DictionaryEntries pending = cacheSystem.getDicEmailStatus(EmailStatusEnum.PENDING.getEnMsg()); | ||
| 203 | + DictionaryEntries success = cacheSystem.getDicEmailStatus(EmailStatusEnum.SUCCESS.getEnMsg()); | ||
| 204 | + DictionaryEntries failed = cacheSystem.getDicEmailStatus(EmailStatusEnum.FAILED.getEnMsg()); | ||
| 205 | + conPushEmail.setToAddress(mailMessageReqDto.getTo()); | ||
| 206 | + conPushEmail.setCcAddress(mailMessageReqDto.getCc()); | ||
| 207 | + conPushEmail.setSubject(mailMessageReqDto.getSubject()); | ||
| 208 | + conPushEmail.setBody(mailMessageReqDto.getContent()); | ||
| 209 | + conPushEmail.setSendTime(new Date()); | ||
| 210 | + conPushEmail.setFilePath(filePath); | ||
| 211 | + //如果失败次数小于三则更新为待处理,继续处理 | ||
| 212 | + if (result){ | ||
| 213 | + conPushEmail.setTypeCode(success.getCode()); | ||
| 214 | + conPushEmail.setTypeName(success.getEnglishName()); | ||
| 215 | + }else { | ||
| 216 | + if (conPushEmail.getSendNum()<3){ | ||
| 217 | + conPushEmail.setTypeCode(pending.getCode()); | ||
| 218 | + conPushEmail.setTypeName(pending.getEnglishName()); | ||
| 219 | + conPushEmail.setSendNum(conPushEmail.getSendNum()+1); | ||
| 220 | + }else { | ||
| 221 | + conPushEmail.setTypeCode(failed.getCode()); | ||
| 222 | + conPushEmail.setTypeName(failed.getEnglishName()); | ||
| 223 | + } | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + /** | ||
| 228 | + * @Author Szl | ||
| 229 | + * @Description 功能说明 备份文件 | ||
| 230 | + * @Date 2024/11/18 | ||
| 231 | + * @param filePath | ||
| 232 | + * @param nioFileUtils | ||
| 233 | + * @param result | ||
| 234 | + * @return java.lang.String | ||
| 235 | + */ | ||
| 236 | + public String backFile(String filePath, NIOFileUtils nioFileUtils,boolean result){ | ||
| 237 | + File file = new File(filePath); | ||
| 238 | + String targetDirPath = null; | ||
| 239 | + try { | ||
| 240 | + // 获取文件的扩展名 | ||
| 241 | + String extension = filePath.substring(filePath.lastIndexOf(".")); | ||
| 242 | + | ||
| 243 | + // 生成新的文件名 | ||
| 244 | + String fileName = String.format("%s%s%s%s", | ||
| 245 | + "", | ||
| 246 | + "", | ||
| 247 | + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()), | ||
| 248 | + extension | ||
| 249 | + ); | ||
| 250 | + String basePath = ""; | ||
| 251 | + // 构建目标文件路径 | ||
| 252 | + targetDirPath = String.join(File.separator, | ||
| 253 | + basePath, | ||
| 254 | + fileName | ||
| 255 | + ); | ||
| 256 | + // 复制文件 | ||
| 257 | + nioFileUtils.copyFile(file, targetDirPath); | ||
| 258 | + nioFileUtils.deleteTempFile(Paths.get(filePath)); | ||
| 259 | + } catch (Exception e) { | ||
| 260 | + String errorMsg = String.format("文件复制失败:%s,portId:%s,fileName:%s", e.getMessage()); | ||
| 261 | + // 错误处理 | ||
| 262 | + log.error(errorMsg, e); | ||
| 263 | + } | ||
| 264 | + return targetDirPath; | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /** | ||
| 268 | + * @Author Szl | ||
| 269 | + * @Description 功能说明 保存数据 | ||
| 270 | + * @Date 2024/11/18 | ||
| 271 | + * @param conPushEmail | ||
| 272 | + * @param result | ||
| 273 | + * @return void | ||
| 274 | + */ | ||
| 275 | + @Transactional | ||
| 276 | + private void saveEmail(Email conPushEmail,boolean result){ | ||
| 277 | + EmailHistory emailHistory = new EmailHistory(); | ||
| 278 | + BeanUtils.copyProperties(conPushEmail, emailHistory); | ||
| 279 | + if (result){ | ||
| 280 | + //成功后需要将业务表数据删除,保存至历史表 | ||
| 281 | + emailRepository.deleteById(conPushEmail.getId()); | ||
| 282 | + emailHistoryRepository.save(emailHistory); | ||
| 283 | + }else { | ||
| 284 | + //失败则根据是否第三次,如果是第三次失败则删除,保存到历史表 | ||
| 285 | + if (conPushEmail.getSendNum() == 3){ | ||
| 286 | + emailRepository.deleteById(conPushEmail.getId()); | ||
| 287 | + emailHistoryRepository.save(emailHistory); | ||
| 288 | + }else { | ||
| 289 | + emailRepository.save(conPushEmail); | ||
| 290 | + } | ||
| 102 | } | 291 | } |
| 103 | - conPushEmail.setToAddress(emailByPortCode); | ||
| 104 | - conPushEmail.setSubject(); | ||
| 105 | - conPushEmail.setBody(); | ||
| 106 | - conPushEmail.setFilePath(portFileDto.getZipPath()); | ||
| 107 | 292 | ||
| 108 | } | 293 | } |
| 109 | 294 | ... | ... |
| 1 | +package com.fedex.connect.task.utils.sys; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.task.data.bo.MailAttachmentBo; | ||
| 4 | +import com.fedex.connect.task.data.dto.MailConfigDto; | ||
| 5 | +import lombok.extern.slf4j.Slf4j; | ||
| 6 | +import org.apache.commons.lang3.StringUtils; | ||
| 7 | +import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
| 8 | +import org.springframework.mail.javamail.MimeMessageHelper; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | + | ||
| 11 | +import javax.mail.internet.InternetAddress; | ||
| 12 | +import javax.mail.internet.MimeMessage; | ||
| 13 | +import java.util.List; | ||
| 14 | +import java.util.Objects; | ||
| 15 | +import java.util.Optional; | ||
| 16 | +import java.util.Properties; | ||
| 17 | + | ||
| 18 | +@Slf4j | ||
| 19 | +@Component | ||
| 20 | +public class EmailUtil { | ||
| 21 | + public static boolean sendMail(MailConfigDto mailConfig) { | ||
| 22 | + System.setProperty("mail.mime.splitlongparameters","false"); | ||
| 23 | + try { | ||
| 24 | + | ||
| 25 | + JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); | ||
| 26 | + senderImpl.setHost(mailConfig.getHost()); | ||
| 27 | + senderImpl.setPort(Integer.parseInt(Optional.ofNullable(mailConfig.getPort()).orElse("25"))); | ||
| 28 | + if ("true".equalsIgnoreCase(mailConfig.getMailAccountFlag())){ | ||
| 29 | + log.info("set user and pwd"); | ||
| 30 | + senderImpl.setUsername(mailConfig.getSenderAccount()); | ||
| 31 | + senderImpl.setPassword(mailConfig.getSenderPassword()); | ||
| 32 | + } | ||
| 33 | + Properties prop = new Properties(); | ||
| 34 | + prop.put("mail.smtp.timeout", "60000"); | ||
| 35 | + senderImpl.setJavaMailProperties(prop); | ||
| 36 | + | ||
| 37 | + MimeMessage mailMessage = senderImpl.createMimeMessage(); | ||
| 38 | + MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8"); | ||
| 39 | + | ||
| 40 | + InternetAddress[] addressesTo = null; | ||
| 41 | + String receiveAccount = mailConfig.getReceiveAccount(); | ||
| 42 | + if (!StringUtils.isBlank(receiveAccount)&& receiveAccount.trim().length() > 0) { | ||
| 43 | + receiveAccount = receiveAccount.trim(); | ||
| 44 | + String[] receiveList = receiveAccount.split(","); | ||
| 45 | + int receiveCount = receiveList.length; | ||
| 46 | + if (receiveCount > 0) { | ||
| 47 | + addressesTo = new InternetAddress[receiveCount]; | ||
| 48 | + for (int i = 0; i < receiveCount; i++) { | ||
| 49 | + addressesTo[i] = new InternetAddress(receiveList[i]); | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + messageHelper.setTo(addressesTo); | ||
| 54 | + | ||
| 55 | + // 4,抄送人 | ||
| 56 | + InternetAddress[] addressesCc = null; | ||
| 57 | + String chaoSongCount = mailConfig.getCcAccount(); | ||
| 58 | + if (StringUtils.isNotBlank(chaoSongCount) && StringUtils.trimToEmpty(chaoSongCount).length() > 0) { | ||
| 59 | + String[] copyList = chaoSongCount.split(","); | ||
| 60 | + int copyCount = copyList.length; | ||
| 61 | + if (copyCount > 0) { | ||
| 62 | + addressesCc = new InternetAddress[copyCount]; | ||
| 63 | + for (int i = 0; i < copyCount; i++) { | ||
| 64 | + addressesCc[i] = new InternetAddress(copyList[i]); | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + messageHelper.setCc(addressesCc); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + messageHelper.setFrom(mailConfig.getSenderAccount(), mailConfig.getBizName()); | ||
| 71 | + messageHelper.setSubject(mailConfig.getSubject()); | ||
| 72 | + messageHelper.setText(mailConfig.getContent(), true); | ||
| 73 | + List<MailAttachmentBo> fileList = mailConfig.getFileList(); | ||
| 74 | + if(Objects.nonNull(fileList)){ | ||
| 75 | + for (int i = 0, maxi = fileList.size(); i < maxi; i++) { | ||
| 76 | + MailAttachmentBo bo = fileList.get(i); | ||
| 77 | + if (bo != null){ | ||
| 78 | + messageHelper.addAttachment(bo.getFileName(), bo.getFile()); | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + senderImpl.send(mailMessage); | ||
| 84 | + | ||
| 85 | + return true; | ||
| 86 | + } catch (Exception e) { | ||
| 87 | + e.printStackTrace(); | ||
| 88 | + log.error("发送邮件失败...........",e); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + return false; | ||
| 92 | + } | ||
| 93 | +} |
-
Please register or login to post a comment