- 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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
|
||||||
import ru.ulstu.paper.repository.PaperRepository;
|
|
||||||
import ru.ulstu.paper.service.PaperService;
|
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.paper.repository.PaperRepository;
|
||||||
import ru.ulstu.user.model.User;
|
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.scheduler.UserScheduler;
|
||||||
import ru.ulstu.user.service.MailService;
|
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.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeadlineSсheduler {
|
@Service
|
||||||
|
public class DeadlineScheduler {
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(UserScheduler.class);
|
private final Logger log = LoggerFactory.getLogger(UserScheduler.class);
|
||||||
|
|
||||||
private final PaperRepository paperRepository;
|
private final PaperRepository paperRepository;
|
||||||
private final MailService mailService;
|
private final MailService mailService;
|
||||||
|
|
||||||
public DeadlineSсheduler(PaperRepository paperRepository, MailService mailService) {
|
public DeadlineScheduler(PaperRepository paperRepository, MailService mailService) {
|
||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
}
|
}
|
||||||
@ -37,10 +30,10 @@ public class DeadlineSсheduler {
|
|||||||
public void sendMessageDeadlineBeforeWeek() {
|
public void sendMessageDeadlineBeforeWeek() {
|
||||||
log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek started");
|
log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek started");
|
||||||
List<Paper> allPapers = paperRepository.findAll();
|
List<Paper> allPapers = paperRepository.findAll();
|
||||||
for (Paper element: allPapers) {
|
for (Paper element : 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(element.getDeadlineDate()) < 0 ) {
|
if (c.getTime().compareTo(element.getDeadlineDate()) < 0) {
|
||||||
List<User> users = element.getAuthors();
|
List<User> users = element.getAuthors();
|
||||||
for (User user : users) {
|
for (User user : users) {
|
||||||
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
||||||
@ -50,14 +43,15 @@ public class DeadlineSсheduler {
|
|||||||
}
|
}
|
||||||
log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek finished");
|
log.debug("DeadlineSсheduler.sendMessageDeadlineBeforeWeek finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8 * * ?")
|
@Scheduled(cron = "0 0 8 * * ?")
|
||||||
public void sendMessageDeadlineAfterWeek() {
|
public void sendMessageDeadlineAfterWeek() {
|
||||||
log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek started");
|
log.debug("DeadlineSсheduler.sendMessageDeadlineAfterWeek started");
|
||||||
List<Paper> allPapers = paperRepository.findAll();
|
List<Paper> allPapers = paperRepository.findAll();
|
||||||
for (Paper element: allPapers) {
|
for (Paper element : 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(element.getDeadlineDate()) >= 0 ) {
|
if (c.getTime().compareTo(element.getDeadlineDate()) >= 0) {
|
||||||
List<User> users = element.getAuthors();
|
List<User> users = element.getAuthors();
|
||||||
for (User user : users) {
|
for (User user : users) {
|
||||||
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
Loading…
Reference in New Issue
Block a user