#79 fixing planner and year generation
This commit is contained in:
parent
65dea9bce2
commit
0de34c89fe
@ -2,7 +2,10 @@ package ru.ulstu.students.repository;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.ulstu.students.model.Scheduler;
|
import ru.ulstu.students.model.Scheduler;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
|
|
||||||
public interface SchedulerRepository extends JpaRepository<Scheduler, Integer> {
|
public interface SchedulerRepository extends JpaRepository<Scheduler, Integer> {
|
||||||
|
|
||||||
|
Scheduler findOneByTask(Task task);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
||||||
@ -16,10 +17,11 @@ public interface TaskRepository extends JpaRepository<Task, Integer> {
|
|||||||
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC")
|
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC")
|
||||||
List<Task> filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
List<Task> filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
||||||
|
|
||||||
@Query("SELECT t FROM Task t WHERE (EXTRACT(DAY FROM t.createDate) = :day) AND (EXTRACT(MONTH FROM t.createDate) = :month) AND (EXTRACT" +
|
|
||||||
"(YEAR FROM t.createDate) = :year)")
|
|
||||||
List<Task> findToGenerate(@Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year);
|
|
||||||
|
|
||||||
@Query("SELECT t FROM Task t WHERE(:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
@Query("SELECT t FROM Task t WHERE(:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
||||||
List<Task> findByTag(@Param("tag") Tag tag);
|
List<Task> findByTag(@Param("tag") Tag tag);
|
||||||
|
|
||||||
|
@Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC")
|
||||||
|
List<Task> findAllYear(@Param("date") Date date);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ public class SchedulerService {
|
|||||||
this.schedulerRepository = schedulerRepository;
|
this.schedulerRepository = schedulerRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void save(Tag tag) {
|
private void save(Tag tag) {
|
||||||
List<Task> taskList = taskService.findTasksByTag(tag);
|
List<Task> taskList = taskService.findTasksByTag(tag);
|
||||||
create(taskList.get(0));
|
create(taskList.get(0));
|
||||||
@ -52,21 +53,37 @@ public class SchedulerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkNewPlan(List<Scheduler> schedulerList) {
|
private void checkNewPlan(List<Scheduler> schedulerList) {
|
||||||
Set<Tag> tags = taskService.checkRepeatingTags();
|
Set<Tag> tags = taskService.checkRepeatingTags(false);
|
||||||
Tag newTag = null;
|
Set<Tag> newTags = null;
|
||||||
if (!schedulerList.isEmpty()) {
|
if (!schedulerList.isEmpty()) {
|
||||||
newTag = checkNewTag(tags, schedulerList);
|
newTags = checkNewTags(tags, schedulerList);
|
||||||
} else {
|
} else {
|
||||||
if (!tags.isEmpty()) {
|
if (!tags.isEmpty()) {
|
||||||
newTag = tags.iterator().next();
|
newTags = tags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newTag != null) {
|
|
||||||
save(newTag);
|
if (newTags != null) {
|
||||||
|
newTags.forEach(tag -> {
|
||||||
|
if (!hasNewTag(tag, schedulerList)) {
|
||||||
|
save(tag);
|
||||||
|
Task task = taskService.findTasksByTag(tag).get(0);
|
||||||
|
schedulerList.add(new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate()));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tag checkNewTag(Set<Tag> tags, List<Scheduler> schedulerList) {
|
private boolean hasNewTag(Tag tag, List<Scheduler> schedulerList) {
|
||||||
|
|
||||||
|
return schedulerList
|
||||||
|
.stream()
|
||||||
|
.anyMatch(scheduler -> scheduler.getTask().getTags().contains(tag));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Set<Tag> checkNewTags(Set<Tag> tags, List<Scheduler> schedulerList) {
|
||||||
Set<Tag> newTags = tags
|
Set<Tag> newTags = tags
|
||||||
.stream()
|
.stream()
|
||||||
.filter(tag -> schedulerList
|
.filter(tag -> schedulerList
|
||||||
@ -75,7 +92,7 @@ public class SchedulerService {
|
|||||||
!scheduler.getTask().getTags().contains(tag)))
|
!scheduler.getTask().getTags().contains(tag)))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
if (!newTags.isEmpty()) {
|
if (!newTags.isEmpty()) {
|
||||||
return newTags.iterator().next();
|
return newTags;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,15 @@ public class TaskGenerationService {
|
|||||||
this.schedulerService = schedulerService;
|
this.schedulerService = schedulerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 0 * * ?", zone = "Europe/Samara")
|
||||||
// public void generateYearTasks() {
|
public void generateTasks() {
|
||||||
// log.debug("TaskService.generateYearTasks started");
|
|
||||||
// taskService.generateYearTasks();
|
|
||||||
// log.debug("TaskService.generateYearTasks finished");
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara")
|
|
||||||
public void checkPlanToday() {
|
|
||||||
log.debug("SchedulerService.checkPlanToday started");
|
log.debug("SchedulerService.checkPlanToday started");
|
||||||
schedulerService.checkPlanToday();
|
schedulerService.checkPlanToday();
|
||||||
log.debug("SchedulerService.checkPlanToday finished");
|
log.debug("SchedulerService.checkPlanToday finished");
|
||||||
|
|
||||||
|
log.debug("TaskService.generateYearTasks started");
|
||||||
|
taskService.generateYearTasks();
|
||||||
|
log.debug("TaskService.generateYearTasks finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,13 @@ import ru.ulstu.students.model.Scheduler;
|
|||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.students.model.TaskDto;
|
import ru.ulstu.students.model.TaskDto;
|
||||||
import ru.ulstu.students.model.TaskFilterDto;
|
import ru.ulstu.students.model.TaskFilterDto;
|
||||||
|
import ru.ulstu.students.repository.SchedulerRepository;
|
||||||
import ru.ulstu.students.repository.TaskRepository;
|
import ru.ulstu.students.repository.TaskRepository;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.tags.model.Tag;
|
||||||
import ru.ulstu.tags.service.TagService;
|
import ru.ulstu.tags.service.TagService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -36,14 +38,17 @@ public class TaskService {
|
|||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final static int MAX_DISPLAY_SIZE = 40;
|
||||||
|
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
|
private final SchedulerRepository schedulerRepository;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
|
|
||||||
|
|
||||||
public TaskService(TaskRepository taskRepository,
|
public TaskService(TaskRepository taskRepository,
|
||||||
DeadlineService deadlineService, TagService tagService) {
|
DeadlineService deadlineService, TagService tagService, SchedulerRepository schedulerRepository) {
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.tagService = tagService;
|
this.tagService = tagService;
|
||||||
|
this.schedulerRepository = schedulerRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Task> findAll() {
|
public List<Task> findAll() {
|
||||||
@ -101,6 +106,11 @@ public class TaskService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer taskId) throws IOException {
|
public void delete(Integer taskId) throws IOException {
|
||||||
if (taskRepository.exists(taskId)) {
|
if (taskRepository.exists(taskId)) {
|
||||||
|
Task scheduleTask = taskRepository.findOne(taskId);
|
||||||
|
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
|
||||||
|
if (sch != null) {
|
||||||
|
schedulerRepository.delete(sch.getId());
|
||||||
|
}
|
||||||
taskRepository.delete(taskId);
|
taskRepository.delete(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,9 +134,9 @@ 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/Paris"));
|
Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara"));
|
||||||
cal1.setTime(newTask.getCreateDate());
|
cal1.setTime(newTask.getCreateDate());
|
||||||
Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris"));
|
Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara"));
|
||||||
cal2.setTime(task.getCreateDate());
|
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));
|
||||||
@ -169,32 +179,64 @@ public class TaskService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void generateYearTasks() {
|
public void generateYearTasks() {
|
||||||
Calendar cal = Calendar.getInstance();
|
Set<Tag> tags = checkRepeatingTags(true);
|
||||||
cal.setTime(new Date());
|
List<Task> tasks = new ArrayList<>();
|
||||||
List<Task> tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR) - 1);
|
tags.forEach(tag ->
|
||||||
tasks.forEach(task -> {
|
{
|
||||||
Task newTask = copyTaskWithNewYear(task);
|
Task singleTask = findTasksByTag(tag).get(0);
|
||||||
taskRepository.save(newTask);
|
Calendar taskDate = Calendar.getInstance();
|
||||||
|
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)) {
|
||||||
|
tasks.add(singleTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
if (tasks != null) {
|
||||||
|
tasks.forEach(task -> {
|
||||||
|
Task newTask = copyTaskWithNewYear(task);
|
||||||
|
taskRepository.save(newTask);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Set<Tag> checkRepeatingTags() {
|
public Set<Tag> checkRepeatingTags(Boolean param) { //param: true = year task; false = period task
|
||||||
Map<Tag, Long> tagsCount = new TreeMap<>();
|
Map<Tag, Long> tagsCount = new TreeMap<>();
|
||||||
List<Tag> tags = tagService.getTags();
|
List<Tag> tags = tagService.getTags();
|
||||||
List<Task> tasks = taskRepository.findAll();
|
Calendar cal = Calendar.getInstance();
|
||||||
|
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) {
|
||||||
|
return tagsCount
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(tagLongEntry -> tagLongEntry.getValue() == 1)
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
|
||||||
|
.keySet();
|
||||||
|
} else {
|
||||||
|
return tagsCount
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(tagLongEntry -> tagLongEntry.getValue() >= 2)
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
|
||||||
|
.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
return tagsCount
|
|
||||||
.entrySet()
|
|
||||||
.stream()
|
|
||||||
.filter(tagLongEntry -> tagLongEntry.getValue() >= 2)
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
|
|
||||||
.keySet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Task.TaskStatus> getTaskStatuses() {
|
public List<Task.TaskStatus> getTaskStatuses() {
|
||||||
|
@ -45,8 +45,12 @@ public class Tag extends BaseEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Tag tag = (Tag) o;
|
Tag tag = (Tag) o;
|
||||||
return tagName.equals(tag.tagName);
|
return tagName.equals(tag.tagName);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,29 @@
|
|||||||
width: auto;
|
width: auto;
|
||||||
max-width: inherit;
|
max-width: inherit;
|
||||||
}
|
}
|
||||||
|
.tag-info{
|
||||||
|
font-size: 10px;
|
||||||
|
color: white;
|
||||||
|
padding: 5px 15px;
|
||||||
|
background-color: black;
|
||||||
|
display: none;
|
||||||
|
margin-left: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
opacity: 0.8;
|
||||||
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-question-circle{
|
||||||
|
|
||||||
|
font-size: 15px;
|
||||||
|
color: #212529;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-question-circle:hover .tag-info{
|
||||||
|
display:inline-block;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
.tag {
|
.tag {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -19,7 +19,7 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
|
|
||||||
$("#input-tag").keyup(function (event) {
|
$("#input-tag").keyup(function (event) {
|
||||||
if(event.keyCode == 13 || event.keyCode == 188) {
|
if(event.keyCode == 13) {
|
||||||
var tagNumber = $("#tags .tag").length;
|
var tagNumber = $("#tags .tag").length;
|
||||||
if(tagNumber > 0) {
|
if(tagNumber > 0) {
|
||||||
tagNumber = $("#tags .tag").last()
|
tagNumber = $("#tags .tag").last()
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="tags">Теги:</label>
|
<label for="tags">Теги: <i class="fa fa-question-circle"><span class="tag-info">Для ввода тега наберите слово (или словосочетание) и нажмите Enter </span></i></label>
|
||||||
<div class="tags-container" id="tags">
|
<div class="tags-container" id="tags">
|
||||||
<div class="tag" th:each="tag, rowStat : *{tags}">
|
<div class="tag" th:each="tag, rowStat : *{tags}">
|
||||||
<input type="hidden" th:field="*{tags[__${rowStat.index}__].id}"/>
|
<input type="hidden" th:field="*{tags[__${rowStat.index}__].id}"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user