fix notifications

This commit is contained in:
Anton Romanov 2019-01-04 17:41:48 +04:00
parent cec13bb677
commit eab71c1210
2 changed files with 11 additions and 9 deletions

View File

@ -30,14 +30,14 @@ public class PaperNotificationService {
private boolean needToSendDeadlineNotification(Paper paper, Date compareDate, boolean isDeadlineBeforeWeek) { private boolean needToSendDeadlineNotification(Paper paper, Date compareDate, boolean isDeadlineBeforeWeek) {
return (paper.getNextDeadline().isPresent()) 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()); && paper.getNextDeadline().get().getDate().after(new Date());
} }
private void sendMessageDeadline(Paper paper) { private void sendMessageDeadline(Paper paper) {
paper.getAuthors().forEach(user -> { paper.getAuthors().forEach(user -> {
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи", mailService.sendEmail(user.getEmail(), "Приближается дедлайн статьи",
"Срок сдачи статьи " + paper.getTitle() + " " + paper.getNextDeadline().get().getDate().toString()); "Срок сдачи статьи " + paper.getTitle() + " " + paper.getNextDeadline().get().getDate().toString());
}); });
} }

View File

@ -5,9 +5,11 @@ import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.TimeZone;
@Service @Service
public class PaperScheduler { 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); 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() { public void checkDeadlineBeforeWeek() {
log.debug("PaperScheduler.checkDeadlineBeforeWeek started"); 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"); log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
} }
@Scheduled(cron = "0 0 8 * * ?") @Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
public void checkDeadlineAfterWeek() { public void checkDeadlineAfterWeek() {
log.debug("PaperScheduler.checkDeadlineAfterWeek started"); 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"); log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
} }
@Scheduled(cron = "0 0 6 * * ?") @Scheduled(cron = "0 0 6 * * ?", zone = "Europe/Samara")
public void closeFailedPapers() { public void closeFailedPapers() {
log.debug("PaperScheduler.closeFailedPapers started"); log.debug("PaperScheduler.closeFailedPapers started");
paperService.closeFailedPapers(); paperService.closeFailedPapers();