|
|
@@ -4,17 +4,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import pl.sudra.domain.Bill;
|
|
|
import pl.sudra.domain.Reservation;
|
|
|
import pl.sudra.repository.BillRepository;
|
|
|
import pl.sudra.repository.ReservationRepository;
|
|
|
|
|
|
import java.sql.Date;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.LocalDate;
|
|
|
import java.time.LocalTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.time.temporal.ChronoUnit;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -92,7 +88,7 @@ public class ReservationServiceImpl implements ReservationService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public List<Reservation> findReservations(long boat_id, Date date) {
|
|
|
- return this.reservationRepository.findReservationsByBoatIdAndDate(boat_id, date);
|
|
|
+ return this.reservationRepository.findAllByBoatIdAndDate(boat_id, date);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -107,24 +103,15 @@ public class ReservationServiceImpl implements ReservationService {
|
|
|
|
|
|
// every hour at 0 minutes
|
|
|
// @Scheduled(cron = "0 0 * * * *")
|
|
|
- @Scheduled(cron = "0 * * * * *")
|
|
|
+ @Scheduled(cron = "0 0 * * * *")
|
|
|
public void updateBill() {
|
|
|
java.util.Date currentDate = new java.util.Date();
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String formattedDate = dateFormat.format(currentDate);
|
|
|
LocalTime date_now = LocalTime.now();
|
|
|
int hour_now = date_now.getHour();
|
|
|
-// System.out.println("Updating reservation's Bill: ");
|
|
|
-// System.out.println("Date: " + formattedDate);
|
|
|
-// System.out.println("Hour: " + hour_now);
|
|
|
List<Reservation> reservations = reservationRepository.findAll();
|
|
|
reservations.forEach(reservation -> {
|
|
|
-// System.out.println("Hour: " + hour_now);
|
|
|
-// System.out.println("Start: " + reservation.getStartHour());
|
|
|
-// System.out.println("End: " + reservation.getEndHour());
|
|
|
-// System.out.println("Date: " + reservation.getDate().toString());
|
|
|
-// System.out.println("Status: " + reservation.getBill().getStatus());
|
|
|
-
|
|
|
if (formattedDate.equals(reservation.getDate().toString()) &&
|
|
|
hour_now == reservation.getStartHour() &&
|
|
|
Objects.equals(reservation.getBill().getStatus(), "Confirmed")) {
|
|
|
@@ -137,20 +124,6 @@ public class ReservationServiceImpl implements ReservationService {
|
|
|
reservation.getBill().setStatus("Completed");
|
|
|
reservationRepository.saveAndFlush(reservation);
|
|
|
}
|
|
|
-
|
|
|
-// LocalDate date1 = LocalDate.parse(bill.getIssueDate().toString());
|
|
|
-// LocalDate date2 = LocalDate.parse(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")).toString());
|
|
|
-//
|
|
|
-// System.out.println(date1.toString() + ">" + date2.toString());
|
|
|
-//
|
|
|
-// if (ChronoUnit.DAYS.between(
|
|
|
-// LocalDate.parse(bill.getIssueDate().toString()),
|
|
|
-// LocalDate.parse(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")).toString())) > 30
|
|
|
-// && date1.isBefore(date2)) {
|
|
|
-// bill.setStatus("CANCELLED");
|
|
|
-// billRepository.saveAndFlush(bill);
|
|
|
-// System.out.println(bill.getId());
|
|
|
-// }
|
|
|
});
|
|
|
}
|
|
|
}
|