Resolve "Список периодических событий" #129

Merged
romanov73 merged 57 commits from 4-show-time-line into master 2018-10-30 23:32:01 +04:00
Showing only changes of commit 450cb92d01 - Show all commits

View File

@ -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<Paper> 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<Paper> 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){