代码完善

This commit is contained in:
万佳 2021-09-17 13:35:28 +08:00
parent c485627592
commit 935b2cdb5a
1 changed files with 8 additions and 2 deletions

View File

@ -24,10 +24,16 @@ public class EmailService {
private Logger logger = LogManager.getLogger(EmailService.class);
//邮件任务处理状态
private static final Integer EMAIL_JOB_NOT_DISPATCHED = -1; //处理成功
private static final Integer EMAIL_JOB_DISPATCHED_SUCCESS = 1; //处理成功
private static final Integer EMAIL_JOB_DISPATCHED_FAIL = 2; //处理失败
//邮件发送记录状态
private static final Integer EMAIL_UNSENT_RECORD = -1; //处理成功
private static final Integer EMAIL_SENT_SUCCESS = 1; //处理成功
private static final Integer EMAIL_SENT_FAIL = 2; //处理失败
@Autowired
private EmailJobsService emailJobsService;
@ -85,7 +91,7 @@ public class EmailService {
//获取待发送列表
List<EmailSendRecord> emailSendRecordList = new ArrayList<>();
try {
emailSendRecordList = emailSendRecordsService.getRecordsByStatus(platform, -1, sentNumber);
emailSendRecordList = emailSendRecordsService.getRecordsByStatus(platform, EMAIL_UNSENT_RECORD, sentNumber);
} catch (Exception e) {
logger.error("获取未发送邮件列表失败:\n" + e);
}
@ -98,7 +104,7 @@ public class EmailService {
emailUtils.sendMail(unSentEmailSendRecord.getSubject(), unSentEmailSendRecord.getEmail(), unSentEmailSendRecord.getContent());
flag = true;
unSentEmailSendRecord.setSentAt(new Date());
unSentEmailSendRecord.setStatus(flag ? 1 : 2);
unSentEmailSendRecord.setStatus(flag ? EMAIL_SENT_SUCCESS : EMAIL_SENT_FAIL);
} catch (MessagingException e) {
logger.error("发送邮件失败email: " + unSentEmailSendRecord.getEmail() + "\n" + e);
}