|
|
|
@ -4,10 +4,8 @@ import core.api.models.timemanager.tasks.repeatinginfo.DeadlineStrategy;
|
|
|
|
|
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatDayInfo;
|
|
|
|
|
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekDayInfo;
|
|
|
|
|
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekInfo;
|
|
|
|
|
import core.entities.timemanager.Task;
|
|
|
|
|
import core.entities.timemanager.TaskSerie;
|
|
|
|
|
import core.entities.timemanager.TaskSerieItem;
|
|
|
|
|
import core.entities.timemanager.Taskgroup;
|
|
|
|
|
import core.entities.timemanager.*;
|
|
|
|
|
import core.repositories.timemanager.ScheduleRepository;
|
|
|
|
|
import core.repositories.timemanager.TaskRepository;
|
|
|
|
|
import core.repositories.timemanager.TaskSerieItemRepository;
|
|
|
|
|
import core.repositories.timemanager.TaskSeriesRepository;
|
|
|
|
@ -16,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -27,11 +26,14 @@ public class TaskSeriesService {
|
|
|
|
|
@Autowired private TaskRepository taskRepository;
|
|
|
|
|
@Autowired private TaskSeriesRepository taskSeriesRepository;
|
|
|
|
|
@Autowired private TaskSerieItemRepository taskSerieItemRepository;
|
|
|
|
|
@Autowired private ScheduleRepository scheduleRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ServiceExitCode createTaskSeries(TaskRepeatWeekInfo taskRepeatInfo) {
|
|
|
|
|
List<Task> createdTasks = new ArrayList<>();
|
|
|
|
|
TaskSerie taskSerie = new TaskSerie();
|
|
|
|
|
List<AbstractSchedule> abstractSchedules = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for(TaskRepeatWeekDayInfo taskRepeatDayInfo : taskRepeatInfo.getWeekDayInfos()) {
|
|
|
|
|
Optional<Task> task = taskRepository.findById(taskRepeatDayInfo.getTaskID());
|
|
|
|
|
if(task.isEmpty()) return ServiceExitCode.MISSING_ENTITY;
|
|
|
|
@ -48,6 +50,7 @@ public class TaskSeriesService {
|
|
|
|
|
clonedTask.setTaskSerieItem(taskSerieItem);
|
|
|
|
|
createdTasks.add(clonedTask);
|
|
|
|
|
|
|
|
|
|
abstractSchedules.addAll(cloneSchedules(task.get(), clonedTask));
|
|
|
|
|
currentTaskDate = currentTaskDate.plusDays(taskRepeatDayInfo.getOffset());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -75,6 +78,7 @@ public class TaskSeriesService {
|
|
|
|
|
taskSeriesRepository.save(taskSerie);
|
|
|
|
|
taskRepository.saveAll(createdTasks);
|
|
|
|
|
taskSerieItemRepository.saveAll(taskSerie.getTasks());
|
|
|
|
|
scheduleRepository.saveAll(abstractSchedules);
|
|
|
|
|
|
|
|
|
|
return ServiceExitCode.OK;
|
|
|
|
|
}
|
|
|
|
@ -85,6 +89,7 @@ public class TaskSeriesService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Task> taskList = new ArrayList<>();
|
|
|
|
|
List<AbstractSchedule> abstractSchedules = new ArrayList<>();
|
|
|
|
|
TaskSerie taskSerie = new TaskSerie();
|
|
|
|
|
TaskSerieItem rootItem = taskSerie.addTask(rootTask);
|
|
|
|
|
rootTask.setTaskSerieItem(rootItem);
|
|
|
|
@ -101,16 +106,32 @@ public class TaskSeriesService {
|
|
|
|
|
TaskSerieItem taskSerieItem = taskSerie.addTask(task);
|
|
|
|
|
taskList.add(task);
|
|
|
|
|
task.setTaskSerieItem(taskSerieItem);
|
|
|
|
|
|
|
|
|
|
abstractSchedules.addAll(cloneSchedules(rootTask, task));
|
|
|
|
|
currentTaskDate = currentTaskDate.plusDays(taskRepeatInfo.getOffset());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taskSeriesRepository.save(taskSerie);
|
|
|
|
|
taskRepository.saveAll(taskList);
|
|
|
|
|
taskSerieItemRepository.saveAll(taskSerie.getTasks());
|
|
|
|
|
scheduleRepository.saveAll(abstractSchedules);
|
|
|
|
|
|
|
|
|
|
return ServiceExitCode.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<AbstractSchedule> cloneSchedules(Task previousTask, Task nextTask) {
|
|
|
|
|
long numberDays = ChronoUnit.DAYS.between(previousTask.getStartDate(), nextTask.getStartDate());
|
|
|
|
|
|
|
|
|
|
List<AbstractSchedule> clonedSchedules = new ArrayList<>();
|
|
|
|
|
for(AbstractSchedule abstractSchedule : previousTask.getBasicTaskSchedules()) {
|
|
|
|
|
AbstractSchedule clonedSchedule = abstractSchedule.cloneSchedule();
|
|
|
|
|
clonedSchedule.shiftSchedule(numberDays);
|
|
|
|
|
|
|
|
|
|
clonedSchedules.add(clonedSchedule);
|
|
|
|
|
}
|
|
|
|
|
return clonedSchedules;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteTaskSeriesItem(Task task) {
|
|
|
|
|
TaskSerieItem item = task.getTaskSerieItem();
|
|
|
|
|
TaskSerie taskSerie = task.getTaskSerieItem().getTaskSerie();
|
|
|
|
|