2020-12-21 17:12:10 +01:00
|
|
|
package com.plannaplan.services;
|
|
|
|
|
2021-01-04 18:10:14 +01:00
|
|
|
import java.sql.Date;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
|
|
import com.plannaplan.entities.AppConfig;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2021-01-03 18:06:25 +01:00
|
|
|
import org.springframework.context.annotation.Bean;
|
2021-01-04 18:10:14 +01:00
|
|
|
import org.springframework.scheduling.TaskScheduler;
|
2020-12-23 11:51:17 +01:00
|
|
|
// import org.springframework.beans.factory.annotation.Autowired;
|
2020-12-21 17:12:10 +01:00
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
2021-01-04 18:10:14 +01:00
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
|
import org.springframework.scheduling.support.CronTrigger;
|
2020-12-21 17:12:10 +01:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class EventService {
|
|
|
|
|
2021-01-04 18:10:14 +01:00
|
|
|
public static final int FIRST_TOUR_SCHEDULE = 0;
|
|
|
|
public static final int SECOND_TOUR_SCHEDULE = 1;
|
|
|
|
|
2020-12-23 11:51:17 +01:00
|
|
|
// @Autowired
|
|
|
|
// private EmailService emailService;
|
2020-12-21 17:12:10 +01:00
|
|
|
|
2021-01-04 18:10:14 +01:00
|
|
|
private ThreadPoolTaskScheduler scheduler;
|
|
|
|
private Map<Integer, ScheduledFuture<?>> jobsMap = new HashMap<>();
|
|
|
|
|
|
|
|
// @Autowired
|
|
|
|
// private ConfiguratorService configService;
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 24 17 * * *")
|
2020-12-21 17:12:10 +01:00
|
|
|
public void collectGroupLosses() {
|
|
|
|
System.out.println("Checking for groups");
|
|
|
|
}
|
2021-01-03 18:06:25 +01:00
|
|
|
|
2021-01-04 18:10:14 +01:00
|
|
|
// @Scheduled(cron = "#{eventService.getFirstTourValue()}")
|
|
|
|
// public void performAcceptAction() {
|
|
|
|
// System.out.println("Checking for hahaha");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// new CronTrigger("0 0 0 * * ?",
|
|
|
|
// TimeZone.getTimeZone(TimeZone.getDefault().getID()))
|
|
|
|
|
|
|
|
public void scheduleTask(int taskId, Runnable task, CronTrigger cronTrigger) {
|
|
|
|
ScheduledFuture<?> scheduledTask = jobsMap.get(taskId);
|
|
|
|
if (scheduledTask != null) {
|
|
|
|
scheduledTask.cancel(true);
|
|
|
|
jobsMap.put(taskId, null);
|
|
|
|
}
|
|
|
|
scheduledTask = this.scheduler.schedule(task, cronTrigger);
|
|
|
|
jobsMap.put(taskId, scheduledTask);
|
2021-01-03 18:06:25 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 18:10:14 +01:00
|
|
|
// @Bean
|
|
|
|
// public String getFirstTourValue() {
|
|
|
|
// final AppConfig config = this.configService.getCurrentConfig();
|
|
|
|
// final LocalDate tourEnd = config.getFirstTourEnd().toLocalDate();
|
|
|
|
// final String cronExp = "0 0 0 " + tourEnd.getDayOfMonth() + " " +
|
|
|
|
// tourEnd.getMonthValue() + " "
|
|
|
|
// + tourEnd.getYear();
|
|
|
|
// return cronExp;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @Bean
|
|
|
|
// public String getSecondTourValue() {
|
|
|
|
// return "0 6 18 * * *";
|
|
|
|
// }
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
public void initialize() {
|
|
|
|
this.scheduler = new ThreadPoolTaskScheduler();
|
|
|
|
this.scheduler.initialize();
|
2021-01-03 18:06:25 +01:00
|
|
|
}
|
2020-12-21 17:12:10 +01:00
|
|
|
}
|