- make scheduler as a service
- reformat code - fix cyrillic letter
This commit is contained in:
parent
7388b2cb27
commit
afd854e0cb
@ -3,32 +3,25 @@ package ru.ulstu.paper.service;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import ru.ulstu.core.util.DateUtils;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
import ru.ulstu.paper.repository.PaperRepository;
|
||||
import ru.ulstu.paper.service.PaperService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.repository.PaperRepository;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
import ru.ulstu.user.repository.UserRepository;
|
||||
import ru.ulstu.user.scheduler.UserScheduler;
|
||||
import ru.ulstu.user.service.MailService;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
public class DeadlineSсheduler {
|
||||
@Service
|
||||
public class DeadlineScheduler {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(UserScheduler.class);
|
||||
|
||||
private final PaperRepository paperRepository;
|
||||
private final MailService mailService;
|
||||
|
||||
public DeadlineSсheduler(PaperRepository paperRepository, MailService mailService) {
|
||||
public DeadlineScheduler(PaperRepository paperRepository, MailService mailService) {
|
||||
this.paperRepository = paperRepository;
|
||||
this.mailService = mailService;
|
||||
}
|
||||
@ -37,31 +30,32 @@ public class DeadlineSсheduler {
|
||||
public void sendMessageDeadlineBeforeWeek() {
|
||||
log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek started");
|
||||
List<Paper> allPapers = paperRepository.findAll();
|
||||
for (Paper element: allPapers) {
|
||||
for (Paper element : allPapers) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.add(Calendar.DAY_OF_YEAR, 7);
|
||||
if(c.getTime().compareTo(element.getDeadlineDate()) < 0 ) {
|
||||
if (c.getTime().compareTo(element.getDeadlineDate()) < 0) {
|
||||
List<User> users = element.getAuthors();
|
||||
for (User user : users) {
|
||||
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
||||
"Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString());
|
||||
"Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek finished");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 8 * * ?")
|
||||
public void sendMessageDeadlineAfterWeek() {
|
||||
log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek started");
|
||||
List<Paper> allPapers = paperRepository.findAll();
|
||||
for (Paper element: allPapers) {
|
||||
for (Paper element : allPapers) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.add(Calendar.DAY_OF_YEAR, 7);
|
||||
if(c.getTime().compareTo(element.getDeadlineDate()) >= 0 ) {
|
||||
if (c.getTime().compareTo(element.getDeadlineDate()) >= 0) {
|
||||
List<User> users = element.getAuthors();
|
||||
for (User user : users) {
|
||||
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
||||
"Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString());
|
||||
"Срок сдачи статьи " + element.getTitle() + " " + element.getDeadlineDate().toString());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user