Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Antonio Rueda
/
reserva-hoteles
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
22e7f5b9
authored
Oct 03, 2024
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Añadida servicio programado para eliminación de reservas antiguas.
parent
61614bfc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
0 deletions
src/main/java/es/ujaen/dae/reservahoteles/app/ReservaHoteles.java
src/main/java/es/ujaen/dae/reservahoteles/entidades/Hotel.java
src/main/java/es/ujaen/dae/reservahoteles/servicios/ServicioReservas.java
src/main/resources/application.yml
src/main/java/es/ujaen/dae/reservahoteles/app/ReservaHoteles.java
View file @
22e7f5b9
...
...
@@ -3,12 +3,14 @@ package es.ujaen.dae.reservahoteles.app;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
/**
*
* @author ajrueda
*/
@SpringBootApplication
(
scanBasePackages
=
"es.ujaen.dae.reservahoteles.servicios"
)
@EnableScheduling
public
class
ReservaHoteles
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ReservaHoteles
.
class
);
...
...
src/main/java/es/ujaen/dae/reservahoteles/entidades/Hotel.java
View file @
22e7f5b9
...
...
@@ -171,4 +171,17 @@ public class Hotel {
private
static
boolean
fechaEnIntervalo
(
LocalDate
fecha
,
LocalDate
fechaInicio
,
LocalDate
fechaFin
)
{
return
fecha
.
isAfter
(
fechaInicio
.
minusDays
(
1
))
&&
fecha
.
isBefore
(
fechaFin
.
plusDays
(
1
));
}
/**
* Elimina las reservas anteriores a una fecha limite
* @param fechaLimite la fecha límite para preservar una reserva
*/
public
void
eliminarReservasAnteriores
(
LocalDate
fechaLimite
)
{
var
i
=
reservas
.
iterator
();
while
(
i
.
hasNext
())
{
Reserva
reserva
=
i
.
next
();
if
(
reserva
.
fechaFin
().
isBefore
(
fechaLimite
))
i
.
remove
();
}
}
}
src/main/java/es/ujaen/dae/reservahoteles/servicios/ServicioReservas.java
View file @
22e7f5b9
...
...
@@ -18,6 +18,8 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.TreeMap
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -31,6 +33,9 @@ public class ServicioReservas {
Map
<
Integer
,
Hotel
>
hoteles
;
Map
<
String
,
Usuario
>
clientes
;
@Value
(
"${meses-historico}"
)
int
mesesHistorico
;
// Cliente especial de dirección
private
static
final
Usuario
direccion
=
new
Usuario
(
"direccion"
,
"-"
,
"670343332"
,
"direccion@hotelxyz.es"
,
"SeCrEtO"
);
...
...
@@ -145,4 +150,13 @@ public class ServicioReservas {
return
reserva
;
}
@Scheduled
(
cron
=
"0 0 0 1 * ?"
)
public
void
eliminarReservasAntiguas
()
{
var
fechaLimite
=
LocalDate
.
now
().
minusMonths
(
mesesHistorico
);
for
(
var
hotel:
hoteles
.
values
())
{
hotel
.
eliminarReservasAnteriores
(
fechaLimite
);
}
}
}
src/main/resources/application.yml
0 → 100644
View file @
22e7f5b9
meses-historico
:
3
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment