From c14c7750eb3b48545273b9fa30fd53ab6cbc26a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E4=BD=B3?= Date: Wed, 15 Sep 2021 15:04:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?email=5Fsend=5Frecords=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executor/service/email/EmailService.java | 56 ++++++++++--------- .../dao/mapper/EmailSendRecordsMapper.java | 2 + .../notification/EmailJobsService.java | 2 +- .../notification/EmailSendRecordsService.java | 2 +- .../impl/EmailJobsServiceImpl.java | 2 +- .../impl/EmailSendRecordsServiceImpl.java | 10 +--- .../notification/EmailSendRecordsMapper.xml | 25 +++++++++ .../notification/EmailServiceTest.java | 6 +- 8 files changed, 66 insertions(+), 39 deletions(-) diff --git a/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java b/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java index 2924fb8..0229508 100644 --- a/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java +++ b/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java @@ -25,14 +25,13 @@ public class EmailService { private EmailSendRecordsService emailSendRecordsService; /** - * @Description: 处理邮件发送任务,根据emails添加到邮件发送记录表中。 - * - * @Param platform 平台编码 - * @Param dispatchNumber 待处理发送任务列表数量 - * @return: void - * @Author: wanjia - * @Date: 2021/9/15 - */ + * @Description: 处理邮件发送任务,根据emails添加到邮件发送记录表中。 + * @Param platform 平台编码 + * @Param dispatchNumber 待处理发送任务列表数量 + * @return: void + * @Author: wanjia + * @Date: 2021/9/15 + */ public void DispatchEmailJobs(String platform, Integer dispatchNumber) { //获取指定数量待处理列表 List emailJobList = new ArrayList<>(); @@ -52,7 +51,7 @@ public class EmailService { } //EmailJob分配成功,更新状态 try { - emailJobsService.markEmailJobAs(platform, emailJob.getId(), new Date(), flag ? 1 : 2); + emailJobsService.markEmailJobsAs(platform, emailJob.getId(), new Date(), flag ? 1 : 2); } catch (Exception e) { logger.error("更新EmailJob状态失败,email_job_id: " + emailJob.getId() + "\n" + e); } @@ -60,15 +59,14 @@ public class EmailService { } /** - * @Description: 发送邮件 - * - * @Param platform 平台编码 - * @Param sentNumber 一次发送数量 - * @return: void - * @Author: wanjia - * @Date: 2021/9/15 - */ - public void sendEmail(String platform, Integer sentNumber){ + * @Description: 发送邮件 + * @Param platform 平台编码 + * @Param sentNumber 一次发送数量 + * @return: void + * @Author: wanjia + * @Date: 2021/9/15 + */ + public void sendEmail(String platform, Integer sentNumber) { List emailSendRecordList = new ArrayList<>(); try { emailSendRecordList = emailSendRecordsService.getRecordsByStatus(platform, -1, sentNumber); @@ -77,17 +75,23 @@ public class EmailService { } Boolean flag = null; - for (EmailSendRecord emailSendRecord : emailSendRecordList){ + List updateEmailSendRecordList = new ArrayList<>(); + EmailSendRecord sentEmailSendRecord = new EmailSendRecord(); + for (EmailSendRecord unSentEmailSendRecord : emailSendRecordList) { //todo 发邮件 // 取到一条 emailSendRecord 调用发邮件的Util,返回发送结果赋值给flag - //更新emailSendRecord状态 - try { - emailSendRecordsService.markEmailSendRecordAs(platform, emailSendRecord.getId(), new Date(), flag ? 1 : 2); - } catch (Exception e){ - logger.error("更新EmailSendRecord状态失败,email_send_record_id: " + emailSendRecord.getId() + "\n" + e); - } - + sentEmailSendRecord.setId(unSentEmailSendRecord.getId()); + sentEmailSendRecord.setSentAt(new Date()); + sentEmailSendRecord.setStatus(flag ? 1 : 2); + updateEmailSendRecordList.add(sentEmailSendRecord); } + //更新emailSendRecord状态 + try { + emailSendRecordsService.markEmailSendRecordsAs(platform, updateEmailSendRecordList); + } catch (Exception e) { + logger.error(e); + } + } } diff --git a/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/EmailSendRecordsMapper.java b/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/EmailSendRecordsMapper.java index be0ca2e..d4d5e8e 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/EmailSendRecordsMapper.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/EmailSendRecordsMapper.java @@ -23,4 +23,6 @@ public interface EmailSendRecordsMapper extends BaseMapper { int insertEmailSendRecordBatch(@Param("platform") String platform,@Param("list") List emailSendRecordList); List getRecordsByStatus(@Param("platform") String platform, @Param("status") Integer status, @Param("size") Integer sentNumber); + + int updateEmailSendRecordsBatch(@Param("platform") String platform, @Param("list") List emailSendRecordList); } diff --git a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailJobsService.java b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailJobsService.java index 1d0c271..a984385 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailJobsService.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailJobsService.java @@ -42,6 +42,6 @@ public interface EmailJobsService extends IService { * @Author: wanjia * @Date: 2021/9/13 */ - int markEmailJobAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception; + int markEmailJobsAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception; } diff --git a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailSendRecordsService.java b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailSendRecordsService.java index 052de44..fa272bd 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailSendRecordsService.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/EmailSendRecordsService.java @@ -42,6 +42,6 @@ public interface EmailSendRecordsService extends IService { * @Author: wanjia * @Date: 2021/9/13 */ - int markEmailSendRecordAs(String platform, Integer emailSendRecordId, Date sentAt, Integer status) throws Exception; + int markEmailSendRecordsAs(String platform, List emailSendRecordList) throws Exception; } diff --git a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailJobsServiceImpl.java b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailJobsServiceImpl.java index e0c74a3..9098115 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailJobsServiceImpl.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailJobsServiceImpl.java @@ -31,7 +31,7 @@ public class EmailJobsServiceImpl extends ServiceImpl } @Override - public int markEmailJobAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception { + public int markEmailJobsAs(String platform, Integer emailJobId, Date dispatchedAt, Integer dispatchedStatus) throws Exception { EmailJob emailJob = new EmailJob(); emailJob.setId(emailJobId); emailJob.setDispatchedAt(dispatchedAt); diff --git a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailSendRecordsServiceImpl.java b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailSendRecordsServiceImpl.java index 7c9434f..11bd55b 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailSendRecordsServiceImpl.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/EmailSendRecordsServiceImpl.java @@ -31,16 +31,12 @@ public class EmailSendRecordsServiceImpl extends ServiceImpl emailSendRecordList){ + return baseMapper.updateEmailSendRecordsBatch(platform, emailSendRecordList); } @Override - public List getRecordsByStatus(String platform, Integer status, Integer sentNumber) throws Exception { + public List getRecordsByStatus(String platform, Integer status, Integer sentNumber){ return baseMapper.getRecordsByStatus(platform, status, sentNumber); } } diff --git a/model/src/main/resources/mapper/notification/EmailSendRecordsMapper.xml b/model/src/main/resources/mapper/notification/EmailSendRecordsMapper.xml index 37946d3..9200882 100644 --- a/model/src/main/resources/mapper/notification/EmailSendRecordsMapper.xml +++ b/model/src/main/resources/mapper/notification/EmailSendRecordsMapper.xml @@ -121,4 +121,29 @@ select * from ${platform}_email_send_records where status = #{status} limit #{size} + + + + update ${platform}_email_send_records + + + + + when id=#{i.id} then #{i.sentAt} + + + + + + + when id=#{i.id} then #{i.status} + + + + + where + + id=#{i.id} + + \ No newline at end of file diff --git a/model/src/test/java/cn/org/gitlink/notification/model/service/notification/EmailServiceTest.java b/model/src/test/java/cn/org/gitlink/notification/model/service/notification/EmailServiceTest.java index 29bb94e..39e41f9 100644 --- a/model/src/test/java/cn/org/gitlink/notification/model/service/notification/EmailServiceTest.java +++ b/model/src/test/java/cn/org/gitlink/notification/model/service/notification/EmailServiceTest.java @@ -52,13 +52,13 @@ public class EmailServiceTest { emailSendRecordsService.newEmailSendRecords("gitlink", emailJob.getEmails(), emailJob.getId()); } //发送邮件成功后,更新邮件发送记录 - int count = emailSendRecordsService.markEmailSendRecordAs("gitlink", 1, new Date(), 1); - Assert.isTrue(count > 0, "update email_send_record status success"); +// int count = emailSendRecordsService.markEmailSendRecordsAs("gitlink", 1, new Date(), 1); +// Assert.isTrue(count > 0, "update email_send_record status success"); } catch (Exception e){ e.printStackTrace(); } try { - int count = emailJobsService.markEmailJobAs("gitlink", 1, new Date(), 1); + int count = emailJobsService.markEmailJobsAs("gitlink", 1, new Date(), 1); Assert.isTrue(count > 0, "update status success"); } catch (Exception e) { e.printStackTrace(); From 2903ac29c76fcb43e62f1dad365f2e5c2c9ffb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E4=BD=B3?= Date: Wed, 15 Sep 2021 16:16:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?EmailJobsListener=E6=B3=A8=E9=87=8AKafkaLis?= =?UTF-8?q?tener=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executor/service/jobhandler/EmailJobsListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/src/main/java/cn/org/gitlink/notification/executor/service/jobhandler/EmailJobsListener.java b/executor/src/main/java/cn/org/gitlink/notification/executor/service/jobhandler/EmailJobsListener.java index 24e0e2f..c9eda84 100644 --- a/executor/src/main/java/cn/org/gitlink/notification/executor/service/jobhandler/EmailJobsListener.java +++ b/executor/src/main/java/cn/org/gitlink/notification/executor/service/jobhandler/EmailJobsListener.java @@ -14,7 +14,7 @@ import org.springframework.stereotype.Component; @Component @Configuration //todo 邮件的topics和groupId待处理 -@KafkaListener(topics = "${spring.kafka.consumer.topic}", groupId = "${spring.kafka.consumer.group_id}") +//@KafkaListener(topics = "${spring.kafka.consumer.topic}", groupId = "${spring.kafka.consumer.group_id}") public class EmailJobsListener { private Logger logger = LogManager.getLogger(EmailJobsListener.class);