#70 added new column to event

This commit is contained in:
Nightblade73 2019-04-26 09:28:20 +04:00
parent 34925b81ff
commit 51877023d1
6 changed files with 47 additions and 12 deletions

View File

@ -146,13 +146,4 @@ public class Conference extends BaseEntity {
.filter(d -> d.getDate().after(new Date())) .filter(d -> d.getDate().after(new Date()))
.findFirst(); .findFirst();
} }
public boolean lastDeadlineFailed() {
return !deadlines
.stream()
.filter(deadline -> deadline.getDate() != null)
.filter(d -> d.getDate().after(new Date()))
.findAny()
.isPresent();
}
} }

View File

@ -21,14 +21,14 @@ public class ConferenceScheduler {
} }
@Scheduled(cron = "0 0 21-22 * * *", zone = "Europe/Samara") @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara")
public void checkDeadlineBeforeWeek() { public void checkDeadlineBeforeWeek() {
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started");
conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished");
} }
@Scheduled(cron = "0 0 21-22 * * ?", zone = "Europe/Samara") @Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
public void checkDeadlineAfterWeek() { public void checkDeadlineAfterWeek() {
log.debug("ConferenceScheduler.checkDeadlineAfterWeek started"); log.debug("ConferenceScheduler.checkDeadlineAfterWeek started");
conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);

View File

@ -15,6 +15,7 @@ import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import ru.ulstu.ping.service.PingService; import ru.ulstu.ping.service.PingService;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
@ -39,6 +40,7 @@ public class ConferenceService {
private final UserService userService; private final UserService userService;
private final PingService pingService; private final PingService pingService;
private final ConferenceNotificationService conferenceNotificationService; private final ConferenceNotificationService conferenceNotificationService;
private final EventService eventService;
public ConferenceService(ConferenceRepository conferenceRepository, public ConferenceService(ConferenceRepository conferenceRepository,
ConferenceUserService conferenceUserService, ConferenceUserService conferenceUserService,
@ -46,7 +48,8 @@ public class ConferenceService {
PaperService paperService, PaperService paperService,
UserService userService, UserService userService,
PingService pingService, PingService pingService,
ConferenceNotificationService conferenceNotificationService) { ConferenceNotificationService conferenceNotificationService,
EventService eventService) {
this.conferenceRepository = conferenceRepository; this.conferenceRepository = conferenceRepository;
this.conferenceUserService = conferenceUserService; this.conferenceUserService = conferenceUserService;
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
@ -54,6 +57,7 @@ public class ConferenceService {
this.userService = userService; this.userService = userService;
this.pingService = pingService; this.pingService = pingService;
this.conferenceNotificationService = conferenceNotificationService; this.conferenceNotificationService = conferenceNotificationService;
this.eventService = eventService;
} }
public ConferenceDto getExistConferenceById(Integer id) { public ConferenceDto getExistConferenceById(Integer id) {
@ -97,6 +101,7 @@ public class ConferenceService {
Conference newConference = copyFromDto(new Conference(), conferenceDto); Conference newConference = copyFromDto(new Conference(), conferenceDto);
newConference = conferenceRepository.save(newConference); newConference = conferenceRepository.save(newConference);
conferenceNotificationService.sendCreateNotification(newConference); conferenceNotificationService.sendCreateNotification(newConference);
eventService.createFromConference(newConference);
return newConference.getId(); return newConference.getId();
} }

View File

@ -4,6 +4,7 @@ import org.apache.commons.lang3.time.DateUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.conference.model.Conference;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
@ -140,4 +141,28 @@ public class EventService {
public List<EventDto> findAllFutureDto() { public List<EventDto> findAllFutureDto() {
return convert(findAllFuture(), EventDto::new); return convert(findAllFuture(), EventDto::new);
} }
public void createFromConference(Conference newConference) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newConference.getDeadlines()
.stream()
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
.collect(Collectors.toList())) {
Event newEvent = new Event();
newEvent.setTitle("Дедлайн статьи");
newEvent.setStatus(Event.EventStatus.NEW);
newEvent.setExecuteDate(deadline.getDate());
newEvent.setCreateDate(new Date());
newEvent.setUpdateDate(new Date());
// newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'");
// newEvent.setRecipients(new ArrayList(newPaper.getAuthors()));
// newEvent.setConference(newConference);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
}
} }

View 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="vova" id="20190426_000000-1">
<addColumn tableName="event">
<column name="conference_id" type="integer"></column>
</addColumn>
<addForeignKeyConstraint baseTableName="event" baseColumnNames="conference_id"
constraintName="fk_event_conference_id" referencedTableName="conference"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

View File

@ -34,4 +34,5 @@
<include file="db/changelog-20190421_000000-schema.xml"/> <include file="db/changelog-20190421_000000-schema.xml"/>
<include file="db/changelog-20190422_000000-schema.xml"/> <include file="db/changelog-20190422_000000-schema.xml"/>
<include file="db/changelog-20190424_000000-schema.xml"/> <include file="db/changelog-20190424_000000-schema.xml"/>
<include file="db/changelog-20190426_000000-schema.xml"/>
</databaseChangeLog> </databaseChangeLog>