fix notifications

This commit is contained in:
Anton Romanov 2019-01-05 08:01:07 +04:00
parent eab71c1210
commit ffb3c65118
3 changed files with 26 additions and 18 deletions

View File

@ -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<String, Object> variables = ImmutableMap.of("paper", paper);
sendForAllAuhtors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE);
}
public void sendCreateNotification(Paper paper) {
Map<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> variables, Paper paper, String template, String title) {
paper.getAuthors().forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
}
}

View File

@ -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);

View File

@ -10,10 +10,14 @@
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
</p>
<p>
Приближается срок сдачи статьи "<span th:text="${paper.title}">Title</span>".
Приближается дедлайн статьи <b>"<span th:text="${paper.title}">Title</span>"</b>.
</p>
<p>
Срок исполнения: <span th:text="${#dates.format(paper.nextDeadline.get().date, 'dd.MM.yyyy HH:mm')}"></span>.
Срок исполнения: <b><span th:text="${#dates.format(paper.nextDeadline.get().date, 'dd.MM.yyyy')}"></span></b>.
</p>
<p>
Примечание: <b><span th:text="${paper.nextDeadline.get().description}"></span></b>.
</p>
<p>
Regards,