Resolve "Список периодических событий" #129
@ -25,33 +25,32 @@ public class DeadlineScheduler {
|
|||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
}
|
}
|
||||||
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8 * 1 ?")
|
@Scheduled(cron = "0 0 8 * 1 ?")
|
||||||
public void checkDeadlineBeforeWeek() {
|
public void checkDeadlineBeforeWeek() {
|
||||||
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started");
|
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started");
|
||||||
List<Paper> allPapers = paperRepository.findAll();
|
sendNotifications(IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
for (Paper paper : allPapers) {
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
c.add(Calendar.DAY_OF_YEAR, 7);
|
|
||||||
if (c.getTime().compareTo(paper.getDeadlineDate()) < 0) {
|
|
||||||
sendMessageDeadline(paper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished");
|
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8 * * ?")
|
@Scheduled(cron = "0 0 8 * * ?")
|
||||||
public void checkDeadlineAfterWeek() {
|
public void checkDeadlineAfterWeek() {
|
||||||
log.debug("DeadlineScheduler.checkDeadlineAfterWeek started");
|
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();
|
List<Paper> allPapers = paperRepository.findAll();
|
||||||
for (Paper paper : allPapers) {
|
for (Paper paper : allPapers) {
|
||||||
Calendar c = Calendar.getInstance();
|
Calendar c = Calendar.getInstance();
|
||||||
c.add(Calendar.DAY_OF_YEAR, 7);
|
c.add(Calendar.DAY_OF_YEAR, 7);
|
||||||
if (c.getTime().compareTo(paper.getDeadlineDate()) >= 0) {
|
if (((c.getTime().compareTo(paper.getDeadlineDate()) < 0) && isDeadlineBeforeWeek) ||
|
||||||
sendMessageDeadline(paper);
|
(c.getTime().compareTo(paper.getDeadlineDate()) >= 0) && !isDeadlineBeforeWeek) {
|
||||||
|
sendMessageDeadline(paper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessageDeadline(Paper paper){
|
private void sendMessageDeadline(Paper paper){
|
||||||
|
Loading…
Reference in New Issue
Block a user