From eab71c12106fd088990f2a0f0e0adfff5ba843bc Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 4 Jan 2019 17:41:48 +0400 Subject: [PATCH] fix notifications --- .../paper/service/PaperNotificationService.java | 6 +++--- .../ru/ulstu/paper/service/PaperScheduler.java | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java b/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java index 697958b..93f7096 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java @@ -30,14 +30,14 @@ public class PaperNotificationService { private boolean needToSendDeadlineNotification(Paper paper, Date compareDate, boolean isDeadlineBeforeWeek) { return (paper.getNextDeadline().isPresent()) - && (compareDate.after(paper.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek - || compareDate.before(paper.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek) + && (compareDate.before(paper.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek + || compareDate.after(paper.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek) && paper.getNextDeadline().get().getDate().after(new Date()); } private void sendMessageDeadline(Paper paper) { paper.getAuthors().forEach(user -> { - mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", + mailService.sendEmail(user.getEmail(), "Приближается дедлайн статьи", "Срок сдачи статьи " + paper.getTitle() + " " + paper.getNextDeadline().get().getDate().toString()); }); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperScheduler.java b/src/main/java/ru/ulstu/paper/service/PaperScheduler.java index c7fcf0f..deead88 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/PaperScheduler.java @@ -5,9 +5,11 @@ import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.util.TimeZone; + @Service public class PaperScheduler { - private final static boolean IS_DEADLINE_NOTIFICATION_AFTER_WEEK = true; + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; private final Logger log = LoggerFactory.getLogger(PaperScheduler.class); @@ -21,21 +23,21 @@ public class PaperScheduler { } - @Scheduled(cron = "0 0 8 * 1 ?") + @Scheduled(cron = "0 0 8 * 1 ?", zone = "Europe/Samara") public void checkDeadlineBeforeWeek() { log.debug("PaperScheduler.checkDeadlineBeforeWeek started"); - paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_AFTER_WEEK); + paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("PaperScheduler.checkDeadlineBeforeWeek finished"); } - @Scheduled(cron = "0 0 8 * * ?") + @Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara") public void checkDeadlineAfterWeek() { log.debug("PaperScheduler.checkDeadlineAfterWeek started"); - paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_AFTER_WEEK); + paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("PaperScheduler.checkDeadlineAfterWeek finished"); } - @Scheduled(cron = "0 0 6 * * ?") + @Scheduled(cron = "0 0 6 * * ?", zone = "Europe/Samara") public void closeFailedPapers() { log.debug("PaperScheduler.closeFailedPapers started"); paperService.closeFailedPapers();