Actualizar BD - Actualizar el estado de los registros de solicitudes de vacaciones
This commit is contained in:
parent
1e22223f27
commit
4615febec3
@ -10,7 +10,35 @@ import jakarta.annotation.security.PermitAll;
|
|||||||
@Route(value = "", layout = MainLayout.class)
|
@Route(value = "", layout = MainLayout.class)
|
||||||
@PermitAll
|
@PermitAll
|
||||||
public class MainView extends Main {
|
public class MainView extends Main {
|
||||||
public MainView() {
|
|
||||||
add(new Text("Welcome to PFS Intra."));
|
private final TimeOffRequestService requestService;
|
||||||
|
|
||||||
|
public MainView(final TimeOffRequestService requestService) {
|
||||||
|
this.requestService = requestService;
|
||||||
|
add(new Text("Welcome"));
|
||||||
|
updateRequestStatuses();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateRequestStatuses() {
|
||||||
|
List<TimeOffRequest> requests = requestService.findAllTimeOffRequests();
|
||||||
|
LocalDate now = LocalDate.now();
|
||||||
|
|
||||||
|
for (TimeOffRequest request : requests) {
|
||||||
|
if (request.getState() == TimeOffRequestStatus.APROBADO) {
|
||||||
|
LocalDate expirationDate = request.getExpiration();
|
||||||
|
LocalDate startDate = request.getStartDate();
|
||||||
|
LocalDate endDate = request.getEndDate();
|
||||||
|
|
||||||
|
if (now.isAfter(expirationDate)) {
|
||||||
|
request.setState(TimeOffRequestStatus.VENCIDO);
|
||||||
|
} else if (now.isAfter(endDate) && now.isBefore(expirationDate)) {
|
||||||
|
request.setState(TimeOffRequestStatus.TOMADO);
|
||||||
|
} else if (now.isEqual(startDate) || now.isAfter(startDate) && now.isBefore(endDate)) {
|
||||||
|
request.setState(TimeOffRequestStatus.EN_USO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requestService.saveAll(requests);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user