From 450cb92d012b0d10325a8d660aef7c38fc071577 Mon Sep 17 00:00:00 2001 From: Alyona Date: Sun, 28 Oct 2018 00:15:42 +0400 Subject: [PATCH] fix --- .../paper/service/DeadlineScheduler.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java index 45260cc..63b1fa0 100644 --- a/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java @@ -25,33 +25,32 @@ public class DeadlineScheduler { this.paperRepository = paperRepository; this.mailService = mailService; } + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; @Scheduled(cron = "0 0 8 * 1 ?") public void checkDeadlineBeforeWeek() { log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started"); - List allPapers = paperRepository.findAll(); - for (Paper paper : allPapers) { - Calendar c = Calendar.getInstance(); - c.add(Calendar.DAY_OF_YEAR, 7); - if (c.getTime().compareTo(paper.getDeadlineDate()) < 0) { - sendMessageDeadline(paper); - } - } + sendNotifications(IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished"); } @Scheduled(cron = "0 0 8 * * ?") public void checkDeadlineAfterWeek() { log.debug("DeadlineScheduler.checkDeadlineAfterWeek started"); + sendNotifications(!IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished"); + } + + private void sendNotifications(boolean isDeadlineBeforeWeek) { List allPapers = paperRepository.findAll(); for (Paper paper : allPapers) { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, 7); - if (c.getTime().compareTo(paper.getDeadlineDate()) >= 0) { - sendMessageDeadline(paper); + if (((c.getTime().compareTo(paper.getDeadlineDate()) < 0) && isDeadlineBeforeWeek) || + (c.getTime().compareTo(paper.getDeadlineDate()) >= 0) && !isDeadlineBeforeWeek) { + sendMessageDeadline(paper); } } - log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished"); } private void sendMessageDeadline(Paper paper){