Commit 7568c12d authored by Ololw's avatar Ololw
Browse files

Fix available vehicles

parent eb8df832
Pipeline #17198 failed with stages
in 0 seconds
......@@ -18,27 +18,6 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
@PersistenceContext
EntityManager entityManager;
// Retourne les vehicules disponibles d'une agence entre deux dates
public List<Vehicule> findAllAvailableVehiculesrate(long idAgence, Instant startDate, Instant endDate)
{
Query query = entityManager.createNativeQuery("" + "SELECT * FROM mytransport.vehicule as vehicule "
+ "WHERE vehicule.agence_id = ? " + "AND NOT EXISTS( "
+ "SELECT id FROM mytransport.reservation as reservation WHERE reservation.vehicule_id = vehicule.id) "
+ "UNION " + "SELECT * FROM mytransport.vehicule as vehi " + "WHERE vehi.agence_id = ? "
+ "AND vehi.id NOT IN ( " + "SELECT DISTINCT id FROM mytransport.reservation "
+ "WHERE mytransport.reservation.start_date BETWEEN ? AND ? "
+ "OR mytransport.reservation.end_date BETWEEN ? AND ? " + ") " + "", Vehicule.class);
query.setParameter(1, idAgence);
query.setParameter(2, idAgence);
query.setParameter(3, startDate);
query.setParameter(4, endDate);
query.setParameter(5, startDate);
query.setParameter(6, endDate);
return query.getResultList();
}
public List<Vehicule> findAllAvailableVehicules(long idAgence, Instant startDate, Instant endDate)
{
List<Vehicule> vehicules;
......@@ -60,17 +39,10 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
vehicule = vehicules.get(i);
// On recupere les reservations
/*query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND (reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ?) "
+ "ORDER BY reservation.start_date",
Reservation.class);*/
query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND (? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) ",
+ "AND (reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ?) "
+ "OR (? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) ",
Reservation.class);
......@@ -79,6 +51,10 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
query.setParameter(1, vehicule.getId());
query.setParameter(2, startDate);
query.setParameter(3, endDate);
query.setParameter(4, startDate);
query.setParameter(5, endDate);
query.setParameter(6, startDate);
query.setParameter(7, endDate);
reservations = query.getResultList();
......@@ -97,7 +73,11 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
Reservation reservationNext;
if (reservations.isEmpty())
{
System.out.println("ici0");
return true;
}
for (int i = 0; i < reservations.size(); i++)
{
......@@ -110,6 +90,7 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
Instant dateLimiteDebut = reservation.getStartDate().minus(nbJours, ChronoUnit.DAYS);
if (dateLimiteDebut.compareTo(startDate) > 0)
{
System.out.println("ici1");
return true;
}
}
......@@ -121,6 +102,7 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
Instant dateLimiteFin = reservation.getEndDate().plus(nbJours, ChronoUnit.DAYS);
if (dateLimiteFin.compareTo(endDate) < 0)
{
System.out.println("ici2");
return true;
}
}
......@@ -131,6 +113,7 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
if (reservation.getEndDate().plus(nbJours, ChronoUnit.DAYS)
.compareTo(reservationNext.getStartDate()) < 0)
{
System.out.println("ici3");
return true;
}
}
......@@ -160,22 +143,22 @@ public class VehiculeRepositoryImpl implements VehiculeRepositoryCustom
vehicule = vehicules.get(i);
// On recupere les reservations
/*query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND (reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ?) "
+ "ORDER BY reservation.start_date",
Reservation.class);*/
query = entityManager.createNativeQuery(
"" + "SELECT * FROM mytransport.reservation as reservation " + "WHERE reservation.vehicule_id = ? "
+ "AND ( ? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) "
// + "AND ( ? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) "
+ "AND ( reservation.start_date BETWEEN ? AND ? OR reservation.end_date BETWEEN ? AND ? ) "
+ "OR ( ? BETWEEN reservation.start_date AND reservation.end_date OR ? BETWEEN reservation.start_date AND reservation.end_date) "
+ "ORDER BY reservation.start_date",
Reservation.class);
query.setParameter(1, vehicule.getId());
query.setParameter(2, startDate);
query.setParameter(3, endDate);
query.setParameter(4, startDate);
query.setParameter(5, endDate);
query.setParameter(6, startDate);
query.setParameter(7, endDate);
reservations = query.getResultList();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment