diff --git a/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java b/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java index 93f7096..5628c46 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperNotificationService.java @@ -13,6 +13,16 @@ import java.util.Map; @Service public class PaperNotificationService { private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; + private final static String TEMPLATE_DEADLINE = "paperDeadlineNotification"; + private final static String TEMPLATE_CREATE = "paperCreateNotification"; + private final static String TEMPLATE_STATUS_CHANGED = "paperStatusChangeNotification"; + private final static String TEMPLATE_FAILED = "paperFailedNotification"; + + private final static String TITLE_DEADLINE = "Приближается дедлайн статьи"; + private final static String TITLE_CREATE = "Создана статья"; + private final static String TITLE_STATUS_CHANGED = "Изменился статус статьи"; + private final static String TITLE_FAILED = "Статья провалена"; + private final MailService mailService; @@ -36,30 +46,26 @@ public class PaperNotificationService { } private void sendMessageDeadline(Paper paper) { - paper.getAuthors().forEach(user -> { - mailService.sendEmail(user.getEmail(), "Приближается дедлайн статьи", - "Срок сдачи статьи " + paper.getTitle() + " " + paper.getNextDeadline().get().getDate().toString()); - }); + Map variables = ImmutableMap.of("paper", paper); + sendForAllAuhtors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE); } public void sendCreateNotification(Paper paper) { Map variables = ImmutableMap.of("paper", paper); - paper.getAuthors().forEach(author -> { - mailService.sendEmailFromTemplate(variables, author, "paperCreateNotification", "Создана статья"); - }); + sendForAllAuhtors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE); } public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); - paper.getAuthors().forEach(author -> { - mailService.sendEmailFromTemplate(variables, author, "paperStatusChangeNotification", "Изменился статус статьи"); - }); + sendForAllAuhtors(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED); } public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) { Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); - paper.getAuthors().forEach(author -> { - mailService.sendEmailFromTemplate(variables, author, "paperFailedNotification", "Статья провалена"); - }); + sendForAllAuhtors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED); + } + + private void sendForAllAuhtors(Map variables, Paper paper, String template, String title) { + paper.getAuthors().forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title)); } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperScheduler.java b/src/main/java/ru/ulstu/paper/service/PaperScheduler.java index deead88..a5acf63 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperScheduler.java +++ b/src/main/java/ru/ulstu/paper/service/PaperScheduler.java @@ -5,8 +5,6 @@ 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_BEFORE_WEEK = true; @@ -23,7 +21,7 @@ public class PaperScheduler { } - @Scheduled(cron = "0 0 8 * 1 ?", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") public void checkDeadlineBeforeWeek() { log.debug("PaperScheduler.checkDeadlineBeforeWeek started"); paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); diff --git a/src/main/resources/mail_templates/paperDeadlineNotification.html b/src/main/resources/mail_templates/paperDeadlineNotification.html index a239421..f81e904 100644 --- a/src/main/resources/mail_templates/paperDeadlineNotification.html +++ b/src/main/resources/mail_templates/paperDeadlineNotification.html @@ -10,10 +10,14 @@ Уважаемый(ая) Ivan Ivanov

- Приближается срок сдачи статьи "Title". + Приближается дедлайн статьи "Title".

- Срок исполнения: . + Срок исполнения: . +

+ +

+ Примечание: .

Regards,