This commit is contained in:
parent
4d532c4dbc
commit
311edbb6fc
@ -189,4 +189,10 @@ public class ScheduleController {
|
|||||||
return ResponseEntity.ok(new TaskScheduleStopResponse(scheduleResult.getResult().getActiveTime()));
|
return ResponseEntity.ok(new TaskScheduleStopResponse(scheduleResult.getResult().getActiveTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/schedules/missed")
|
||||||
|
public ResponseEntity<?> loadMissedSchedules() {
|
||||||
|
List<AbstractSchedule> missedSchedules = taskScheduleService.getAllMissedSchedulesOfUser(SecurityContextHolder.getContext().getAuthentication().getName());
|
||||||
|
return ResponseEntity.ok(missedSchedules.stream().map(AbstractSchedule::toScheduleInfo).toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import core.api.models.timemanager.taskSchedule.ScheduleInfo;
|
|||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -106,4 +107,6 @@ public abstract class AbstractSchedule {
|
|||||||
public boolean isStartable() {
|
public boolean isStartable() {
|
||||||
return startTime == null;
|
return startTime == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract boolean isMissed(LocalDateTime timeReference);
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,9 @@ public class AdvancedTaskSchedule extends AbstractSchedule {
|
|||||||
public ScheduleInfo toScheduleInfo() {
|
public ScheduleInfo toScheduleInfo() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMissed(LocalDateTime timeReference) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,11 @@ public class BasicTaskSchedule extends AbstractSchedule{
|
|||||||
return new BasicScheduleInfo(scheduleID, ScheduleType.BASIC, startTime, stopTime, activeMinutes, task, taskgroupEntityInfos);
|
return new BasicScheduleInfo(scheduleID, ScheduleType.BASIC, startTime, stopTime, activeMinutes, task, taskgroupEntityInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMissed(LocalDateTime timeReference) {
|
||||||
|
return startTime == null && scheduleDate.isBefore(timeReference.toLocalDate());
|
||||||
|
}
|
||||||
|
|
||||||
public int calcActiveMinutes() {
|
public int calcActiveMinutes() {
|
||||||
if(startTime == null) {
|
if(startTime == null) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -16,4 +16,5 @@ public interface ScheduleRepository extends CrudRepository<AbstractSchedule, Lon
|
|||||||
|
|
||||||
@Query(value = "SELECT s FROM AbstractSchedule s WHERE s.task.taskgroup.user.username = ?1 AND s.startTime is NOT NULL and s.stopTime is NULL")
|
@Query(value = "SELECT s FROM AbstractSchedule s WHERE s.task.taskgroup.user.username = ?1 AND s.startTime is NOT NULL and s.stopTime is NULL")
|
||||||
Optional<AbstractSchedule> getActiveScheduleOfUser(String username);
|
Optional<AbstractSchedule> getActiveScheduleOfUser(String username);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -134,4 +135,16 @@ public class TaskScheduleService {
|
|||||||
|
|
||||||
return new ServiceResult<>(basicTaskSchedule);
|
return new ServiceResult<>(basicTaskSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<AbstractSchedule> getAllMissedSchedulesOfUser(String username) {
|
||||||
|
List<AbstractSchedule> missedSchedules = new ArrayList<>();
|
||||||
|
List<AbstractSchedule> schedules = getAllSchedulesOfUser(username);
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
for(AbstractSchedule schedule : schedules) {
|
||||||
|
if(schedule.isMissed(now)) {
|
||||||
|
missedSchedules.add(schedule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return missedSchedules;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,15 +129,13 @@ public class ScheduleServiceTest {
|
|||||||
|
|
||||||
//user with tasks and schedules
|
//user with tasks and schedules
|
||||||
List<AbstractSchedule> result_1 = taskScheduleService.getFilteredScheduledOfUser(LocalDate.of(2024,11,11), false, username);
|
List<AbstractSchedule> result_1 = taskScheduleService.getFilteredScheduledOfUser(LocalDate.of(2024,11,11), false, username);
|
||||||
assertEquals(5, result_1.size());
|
assertEquals(3, result_1.size());
|
||||||
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 1L)));
|
|
||||||
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 2L)));
|
|
||||||
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 3L)));
|
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 3L)));
|
||||||
|
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 4L)));
|
||||||
|
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 5L)));
|
||||||
|
|
||||||
List<AbstractSchedule> result_2 = taskScheduleService.getFilteredScheduledOfUser(LocalDate.of(2024,11,11), true, username);
|
List<AbstractSchedule> result_2 = taskScheduleService.getFilteredScheduledOfUser(LocalDate.of(2024,11,11), true, username);
|
||||||
assertEquals(3, result_2.size());
|
assertEquals(1, result_2.size());
|
||||||
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 1L)));
|
|
||||||
assertTrue(result_1.contains(entityManager.find(BasicTaskSchedule.class, 2L)));
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@SqlGroup({
|
@SqlGroup({
|
||||||
@ -225,6 +223,15 @@ public class ScheduleServiceTest {
|
|||||||
assertEquals(startTime, result_2.getResult().getStartTime());
|
assertEquals(startTime, result_2.getResult().getStartTime());
|
||||||
assertEquals(finishTime, result_2.getResult().getStopTime());
|
assertEquals(finishTime, result_2.getResult().getStopTime());
|
||||||
assertThat(entityManager.find(BasicTaskSchedule.class, result_2.getResult().getScheduleID())).isNotNull();
|
assertThat(entityManager.find(BasicTaskSchedule.class, result_2.getResult().getScheduleID())).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SqlGroup({
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
|
||||||
|
@Sql("classpath:taskRepositoryEntries.sql"),
|
||||||
|
@Sql("classpath:basicScheduleEntries.sql")
|
||||||
|
})
|
||||||
|
void getAllMissedSchedulesOfUser() {
|
||||||
|
assertEquals(1, taskScheduleService.getAllMissedSchedulesOfUser(username).size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
INSERT INTO abstract_schedule (schedule_type, scheduleid, start_time, stop_time, schedule_date, task, schedule_end, schedule_start)
|
INSERT INTO abstract_schedule (schedule_type, scheduleid, start_time, stop_time, schedule_date, task, schedule_end, schedule_start)
|
||||||
VALUES (0, 1, null, null, '2024-11-11', 1, null, null),
|
VALUES (0, 1, null, null, '2010-11-11', 1, null, null),
|
||||||
(0, 2, null, null, '2024-11-11', 2, null, null),
|
(0, 2, null, null, '2048-11-11', 2, null, null),
|
||||||
(0, 3, '2023-10-10', '2023-10-10', '2024-11-11', 1, null, null),
|
(0, 3, '2023-10-10', '2022-10-10', '2024-11-11', 1, null, null),
|
||||||
(0, 4, '2023-10-10', null, '2024-11-11', 3, null, null),
|
(0, 4, '2023-10-10', null, '2024-11-11', 3, null, null),
|
||||||
(0, 5, null, null, '2024-11-11', 5, null, null),
|
(0, 5, null, null, '2024-11-11', 5, null, null),
|
||||||
(0, 6, '2023-10-10', null, '2024-11-11', 16, null, null),
|
(0, 6, '2023-10-10', null, '2024-11-11', 16, null, null),
|
||||||
|
Loading…
Reference in New Issue
Block a user