close failed papers

pull/148/head
Anton Romanov 6 years ago
parent 4e3e882f76
commit 29586c9313

@ -23,7 +23,11 @@ import java.util.Set;
@Entity
public class Paper extends BaseEntity implements UserContainer {
public enum PaperStatus {
ATTENTION("Обратить внимание"), ON_PREPARATION("На подготовке"), DRAFT("Черновик"), COMPLETED("Завершена");
ATTENTION("Обратить внимание"),
ON_PREPARATION("На подготовке"),
DRAFT("Черновик"),
COMPLETED("Завершена"),
FAILED("Провалены сроки");
private String name;

@ -55,4 +55,11 @@ public class PaperNotificationService {
mailService.sendEmailFromTemplate(variables, author, "paperStatusChangeNotification", "Изменился статус статьи");
});
}
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", "Статья провалена");
});
}
}

@ -6,16 +6,16 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class DeadlineScheduler {
public class PaperScheduler {
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
private final Logger log = LoggerFactory.getLogger(DeadlineScheduler.class);
private final Logger log = LoggerFactory.getLogger(PaperScheduler.class);
private final PaperNotificationService paperNotificationService;
private final PaperService paperService;
public DeadlineScheduler(PaperNotificationService paperNotificationService,
PaperService paperService) {
public PaperScheduler(PaperNotificationService paperNotificationService,
PaperService paperService) {
this.paperNotificationService = paperNotificationService;
this.paperService = paperService;
}
@ -23,15 +23,22 @@ public class DeadlineScheduler {
@Scheduled(cron = "0 0 8 * 1 ?")
public void checkDeadlineBeforeWeek() {
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started");
log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished");
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
}
@Scheduled(cron = "0 0 8 * * ?")
public void checkDeadlineAfterWeek() {
log.debug("DeadlineScheduler.checkDeadlineAfterWeek started");
log.debug("PaperScheduler.checkDeadlineAfterWeek started");
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished");
log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
}
@Scheduled(cron = "0 0 6 * * ?")
public void closeFailedPapers() {
log.debug("PaperScheduler.closeFailedPapers started");
paperService.closeFailedPapers();
log.debug("PaperScheduler.closeFailedPapers finished");
}
}

@ -18,6 +18,9 @@ import java.util.List;
import java.util.stream.Collectors;
import static ru.ulstu.core.util.StreamApiUtils.convert;
import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION;
import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT;
import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION;
@Service
public class PaperService {
@ -65,7 +68,7 @@ public class PaperService {
paper.setComment(paperDto.getComment());
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
paper.setLocked(paperDto.getLocked());
paper.setStatus(paperDto.getStatus() == null ? Paper.PaperStatus.DRAFT : paperDto.getStatus());
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
paper.setTitle(paperDto.getTitle());
paper.setUpdateDate(new Date());
paper.setDeadlineDate(paperDto.getDeadlineDate());
@ -115,7 +118,7 @@ public class PaperService {
paper.setDeadlineDate(deadlineDate);
paper.setCreateDate(new Date());
paper.setUpdateDate(new Date());
paper.setStatus(Paper.PaperStatus.DRAFT);
paper.setStatus(DRAFT);
paper = paperRepository.save(paper);
paperNotificationService.sendCreateNotification(paper);
@ -126,4 +129,21 @@ public class PaperService {
public List<PaperDto> filter(PaperFilterDto filterDto) {
return convert(paperRepository.filter(userService.findById(filterDto.getAuthorId()), filterDto.getYear()), PaperDto::new);
}
public void closeFailedPapers() {
List<Paper> papers = paperRepository.findAll()
.stream()
.filter(paper -> paper.getDeadlineDate() != null
&& (paper.getStatus() == ON_PREPARATION
|| paper.getStatus() == DRAFT
|| paper.getStatus() == ATTENTION)
&& paper.getDeadlineDate().before(new Date()))
.collect(Collectors.toList());
papers.forEach(paper -> {
Paper.PaperStatus oldStatus = paper.getStatus();
paper.setStatus(Paper.PaperStatus.FAILED);
paperRepository.save(paper);
paperNotificationService.sendFailedNotification(paper, oldStatus);
});
}
}

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Уведомление о провале статьи</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
</head>
<body>
<p>
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
</p>
<p>
Статья "<span th:text="${paper.title}">Title</span>" провалена.
Предыдущий статус - "<span th:text="${oldStatus.name}">oldStatus</span>".
</p>
<p>
Regards,
<br/>
<em>NG-tracker.</em>
</p>
</body>
</html>
Loading…
Cancel
Save