added period event

This commit is contained in:
Alyona 2018-11-09 14:51:19 +04:00
parent 25707db6cd
commit 392b2a9657

View File

@ -31,7 +31,7 @@ public class EventScheduler {
public void checkPeriodEvents() { public void checkPeriodEvents() {
log.debug("EventScheduler.checkPeriodEvents started"); log.debug("EventScheduler.checkPeriodEvents started");
for (Event event : eventRepository.findAll()) { for (Event event : eventRepository.findAll()) {
if(halfOfThePariodHasPassed(event)){ if(halfOfThePeriodHasPassed(event)){
event.setCreateDate(Date.from((LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant()))); event.setCreateDate(Date.from((LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant())));
event.setBeginDate(DateUtils.addDays(event.getBeginDate(), event.getPeriod().getPeriod().getDays())); event.setBeginDate(DateUtils.addDays(event.getBeginDate(), event.getPeriod().getPeriod().getDays()));
event.setUpdateDate(null); event.setUpdateDate(null);
@ -53,7 +53,7 @@ public class EventScheduler {
log.debug("EventScheduler.checkPeriodEvents finished"); log.debug("EventScheduler.checkPeriodEvents finished");
} }
private boolean halfOfThePariodHasPassed(Event event){ private boolean halfOfThePeriodHasPassed(Event event){
if (Period.between(event.getBeginDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), if (Period.between(event.getBeginDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(),
LocalDate.now()).getDays() <= event.getPeriod().getPeriod().getDays() / 2) { LocalDate.now()).getDays() <= event.getPeriod().getPeriod().getDays() / 2) {
return true; return true;