|
|
@ -24,7 +24,6 @@ import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
import java.util.TreeMap;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -134,10 +133,8 @@ public class TaskService {
|
|
|
|
public Task copyTaskWithNewDates(Task task) {
|
|
|
|
public Task copyTaskWithNewDates(Task task) {
|
|
|
|
Task newTask = new Task();
|
|
|
|
Task newTask = new Task();
|
|
|
|
copyMainPart(newTask, task);
|
|
|
|
copyMainPart(newTask, task);
|
|
|
|
Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara"));
|
|
|
|
Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate());
|
|
|
|
cal1.setTime(newTask.getCreateDate());
|
|
|
|
Calendar cal2 = DateUtils.getCalendar(task.getCreateDate());
|
|
|
|
Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara"));
|
|
|
|
|
|
|
|
cal2.setTime(task.getCreateDate());
|
|
|
|
|
|
|
|
Integer interval = cal1.get(Calendar.DAY_OF_YEAR) - cal2.get(Calendar.DAY_OF_YEAR);
|
|
|
|
Integer interval = cal1.get(Calendar.DAY_OF_YEAR) - cal2.get(Calendar.DAY_OF_YEAR);
|
|
|
|
newTask.setDeadlines(newDatesDeadlines(task.getDeadlines(), interval));
|
|
|
|
newTask.setDeadlines(newDatesDeadlines(task.getDeadlines(), interval));
|
|
|
|
return newTask;
|
|
|
|
return newTask;
|
|
|
@ -167,29 +164,31 @@ public class TaskService {
|
|
|
|
.stream()
|
|
|
|
.stream()
|
|
|
|
.map(deadline -> {
|
|
|
|
.map(deadline -> {
|
|
|
|
Deadline newDeadline = new Deadline();
|
|
|
|
Deadline newDeadline = new Deadline();
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
|
|
|
cal.setTime(deadline.getDate());
|
|
|
|
|
|
|
|
cal.add(Calendar.YEAR, 1);
|
|
|
|
|
|
|
|
newDeadline.setDescription(deadline.getDescription());
|
|
|
|
newDeadline.setDescription(deadline.getDescription());
|
|
|
|
newDeadline.setDate(cal.getTime());
|
|
|
|
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
|
|
|
return deadlineService.create(newDeadline);
|
|
|
|
return deadlineService.create(newDeadline);
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean equalsDate(Task task) {
|
|
|
|
|
|
|
|
Calendar taskDate = DateUtils.getCalendar(task.getCreateDate());
|
|
|
|
|
|
|
|
Calendar nowDate = DateUtils.getCalendar(new Date());
|
|
|
|
|
|
|
|
if (taskDate.get(Calendar.DAY_OF_MONTH) == nowDate.get(Calendar.DAY_OF_MONTH) &&
|
|
|
|
|
|
|
|
taskDate.get(Calendar.MONTH) + 1 == nowDate.get(Calendar.MONTH) + 1 &&
|
|
|
|
|
|
|
|
taskDate.get(Calendar.YEAR) + 1 == nowDate.get(Calendar.YEAR)) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public void generateYearTasks() {
|
|
|
|
public void generateYearTasks() {
|
|
|
|
Set<Tag> tags = checkRepeatingTags(true);
|
|
|
|
Set<Tag> tags = checkRepeatingTags(false);
|
|
|
|
List<Task> tasks = new ArrayList<>();
|
|
|
|
List<Task> tasks = new ArrayList<>();
|
|
|
|
tags.forEach(tag -> {
|
|
|
|
tags.forEach(tag -> {
|
|
|
|
Task singleTask = findTasksByTag(tag).get(0);
|
|
|
|
Task singleTask = findTasksByTag(tag).get(0);
|
|
|
|
Calendar taskDate = Calendar.getInstance();
|
|
|
|
if (equalsDate(singleTask)) {
|
|
|
|
Calendar nowDate = Calendar.getInstance();
|
|
|
|
|
|
|
|
taskDate.setTime(singleTask.getCreateDate());
|
|
|
|
|
|
|
|
nowDate.setTime(new Date());
|
|
|
|
|
|
|
|
if (taskDate.get(Calendar.DAY_OF_MONTH) == nowDate.get(Calendar.DAY_OF_MONTH) &&
|
|
|
|
|
|
|
|
taskDate.get(Calendar.MONTH) + 1 == nowDate.get(Calendar.MONTH) + 1 &&
|
|
|
|
|
|
|
|
taskDate.get(Calendar.YEAR) + 1 == nowDate.get(Calendar.YEAR)) {
|
|
|
|
|
|
|
|
if (!tasks.contains(singleTask)) {
|
|
|
|
if (!tasks.contains(singleTask)) {
|
|
|
|
tasks.add(singleTask);
|
|
|
|
tasks.add(singleTask);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -205,21 +204,16 @@ public class TaskService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Set<Tag> checkRepeatingTags(Boolean param) { //param: true = year task; false = period task
|
|
|
|
public Set<Tag> checkRepeatingTags(Boolean createPeriodTask) { //param: false = year task; true = period task
|
|
|
|
Map<Tag, Long> tagsCount = new TreeMap<>();
|
|
|
|
Map<Tag, Long> tagsCount = new TreeMap<>();
|
|
|
|
List<Tag> tags = tagService.getTags();
|
|
|
|
List<Tag> tags = tagService.getTags();
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
List<Task> tasks = taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)));
|
|
|
|
cal.setTime(new Date());
|
|
|
|
|
|
|
|
cal.add(Calendar.YEAR, -1);
|
|
|
|
|
|
|
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
|
|
|
|
System.out.println(cal.getTime());
|
|
|
|
|
|
|
|
List<Task> tasks = taskRepository.findAllYear(cal.getTime());
|
|
|
|
|
|
|
|
tags.forEach(tag ->
|
|
|
|
tags.forEach(tag ->
|
|
|
|
tagsCount.put(tag, tasks
|
|
|
|
tagsCount.put(tag, tasks
|
|
|
|
.stream()
|
|
|
|
.stream()
|
|
|
|
.filter(task -> task.getTags().contains(tag))
|
|
|
|
.filter(task -> task.getTags().contains(tag))
|
|
|
|
.count()));
|
|
|
|
.count()));
|
|
|
|
if (param) {
|
|
|
|
if (!createPeriodTask) {
|
|
|
|
return tagsCount
|
|
|
|
return tagsCount
|
|
|
|
.entrySet()
|
|
|
|
.entrySet()
|
|
|
|
.stream()
|
|
|
|
.stream()
|
|
|
|