Merge branch '11-Message-about-deadlines' into 'master'
Resolve "Реализовать уведомления о дедлайне статьи" Closes #11 See merge request romanov73/ng-tracker!12
This commit is contained in:
commit
5766bdadbc
@ -37,6 +37,9 @@ public class Paper extends BaseEntity {
|
|||||||
@Column(name = "update_date")
|
@Column(name = "update_date")
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
|
|
||||||
|
@Column(name = "deadline_date")
|
||||||
|
private Date deadlineDate;
|
||||||
|
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
private Boolean locked;
|
private Boolean locked;
|
||||||
@ -72,6 +75,14 @@ public class Paper extends BaseEntity {
|
|||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getDeadlineDate() {
|
||||||
|
return deadlineDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeadlineDate(Date deadlineDate) {
|
||||||
|
this.deadlineDate = deadlineDate;
|
||||||
|
}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ public class PaperDto {
|
|||||||
private final Paper.PaperStatus status;
|
private final Paper.PaperStatus status;
|
||||||
private final Date createDate;
|
private final Date createDate;
|
||||||
private final Date updateDate;
|
private final Date updateDate;
|
||||||
|
private final Date deadlineDate;
|
||||||
private final String comment;
|
private final String comment;
|
||||||
private final Boolean locked;
|
private final Boolean locked;
|
||||||
private final String tmpFileName;
|
private final String tmpFileName;
|
||||||
@ -29,6 +30,7 @@ public class PaperDto {
|
|||||||
@JsonProperty("status") Paper.PaperStatus status,
|
@JsonProperty("status") Paper.PaperStatus status,
|
||||||
@JsonProperty("createDate") Date createDate,
|
@JsonProperty("createDate") Date createDate,
|
||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
|
@JsonProperty("deadlineDate") Date deadlineDate,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@JsonProperty("tmpFileName") String tmpFileName,
|
@JsonProperty("tmpFileName") String tmpFileName,
|
||||||
@ -38,6 +40,7 @@ public class PaperDto {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
this.createDate = createDate;
|
this.createDate = createDate;
|
||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
|
this.deadlineDate = deadlineDate;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
this.tmpFileName = tmpFileName;
|
this.tmpFileName = tmpFileName;
|
||||||
@ -53,6 +56,7 @@ public class PaperDto {
|
|||||||
this.status = paper.getStatus();
|
this.status = paper.getStatus();
|
||||||
this.createDate = paper.getCreateDate();
|
this.createDate = paper.getCreateDate();
|
||||||
this.updateDate = paper.getUpdateDate();
|
this.updateDate = paper.getUpdateDate();
|
||||||
|
this.deadlineDate = paper.getDeadlineDate();
|
||||||
this.comment = paper.getComment();
|
this.comment = paper.getComment();
|
||||||
this.locked = paper.getLocked();
|
this.locked = paper.getLocked();
|
||||||
this.tmpFileName = null;
|
this.tmpFileName = null;
|
||||||
@ -82,6 +86,8 @@ public class PaperDto {
|
|||||||
return updateDate;
|
return updateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getDeadlineDate() {return deadlineDate;}
|
||||||
|
|
||||||
public String getComment() {
|
public String getComment() {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
65
src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java
Normal file
65
src/main/java/ru/ulstu/paper/service/DeadlineScheduler.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package ru.ulstu.paper.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
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.scheduler.UserScheduler;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeadlineScheduler {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(DeadlineScheduler.class);
|
||||||
|
|
||||||
|
private final PaperRepository paperRepository;
|
||||||
|
|
||||||
|
private final MailService mailService;
|
||||||
|
|
||||||
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
|
|
||||||
|
public DeadlineScheduler(PaperRepository paperRepository, MailService mailService) {
|
||||||
|
this.paperRepository = paperRepository;
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * 1 ?")
|
||||||
|
public void checkDeadlineBeforeWeek() {
|
||||||
|
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started");
|
||||||
|
sendNotifications(IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
|
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * ?")
|
||||||
|
public void checkDeadlineAfterWeek() {
|
||||||
|
log.debug("DeadlineScheduler.checkDeadlineAfterWeek started");
|
||||||
|
sendNotifications(!IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
|
log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNotifications(boolean isDeadlineBeforeWeek) {
|
||||||
|
List<Paper> allPapers = paperRepository.findAll();
|
||||||
|
for (Paper paper : allPapers) {
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.add(Calendar.DAY_OF_YEAR, 7);
|
||||||
|
if (((c.getTime().compareTo(paper.getDeadlineDate()) < 0) && isDeadlineBeforeWeek) ||
|
||||||
|
(c.getTime().compareTo(paper.getDeadlineDate()) >= 0) && !isDeadlineBeforeWeek) {
|
||||||
|
sendMessageDeadline(paper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageDeadline(Paper paper){
|
||||||
|
for (User user : paper.getAuthors()) {
|
||||||
|
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
|
||||||
|
"Срок сдачи статьи " + paper.getTitle() + " " + paper.getDeadlineDate().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
src/main/resources/db/changelog-20181027_000000-schema.xml
Normal file
13
src/main/resources/db/changelog-20181027_000000-schema.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="orion" id="20181027_000000-1">
|
||||||
|
<preConditions onFail="MARK_RAN">
|
||||||
|
<not><columnExists columnName="deadline_date" tableName="paper"/></not>
|
||||||
|
</preConditions>
|
||||||
|
<addColumn tableName="paper">
|
||||||
|
<column name="deadline_date" type="TIMESTAMP"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -11,4 +11,5 @@
|
|||||||
<include file="db/changelog-20180405_110000-schema.xml"/>
|
<include file="db/changelog-20180405_110000-schema.xml"/>
|
||||||
<include file="db/changelog-20180428_110000-schema.xml"/>
|
<include file="db/changelog-20180428_110000-schema.xml"/>
|
||||||
<include file="db/changelog-20180505_000000-schema.xml"/>
|
<include file="db/changelog-20180505_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20181027_000000-schema.xml"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
Loading…
x
Reference in New Issue
Block a user