fix statistics
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -35,7 +35,7 @@
|
||||
<dependency>
|
||||
<groupId>de.infinimotion</groupId>
|
||||
<artifactId>model-persistence</artifactId>
|
||||
<version>0.0.110</version>
|
||||
<version>0.0.116</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Quarkus -->
|
||||
|
||||
@@ -11,10 +11,14 @@ public class CommandListStatisticsProcessor implements de.infinimotion.model.per
|
||||
|
||||
@Transactional(Transactional.TxType.NOT_SUPPORTED)
|
||||
@Override
|
||||
public CommandListStatisticsResponse processCommandListStatistics(CommandListStatistics commandListStatistics) {
|
||||
public CommandListStatisticsResponse processCommandListStatistics(CommandListStatistics req) {
|
||||
CommandListStatisticsResponse resp = new CommandListStatisticsResponse();
|
||||
resp.setMovies(StatisticsFilm.findAll().list());
|
||||
if (req.isShows()) {
|
||||
resp.setShows(StatisticsVorstellung.findAll().list());
|
||||
}
|
||||
if (req.isMovies()) {
|
||||
resp.setMovies(StatisticsFilm.findAll().list());
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.infinimotion.persistence.processor;
|
||||
|
||||
import de.infinimotion.model.persistence.*;
|
||||
import io.quarkus.narayana.jta.QuarkusTransaction;
|
||||
import io.vertx.core.Vertx;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -9,6 +10,7 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -26,6 +28,9 @@ public class CommandResponseInterceptor {
|
||||
@Inject
|
||||
Vertx vertx;
|
||||
|
||||
@Inject
|
||||
GenericFilterQuery filterQuery;
|
||||
|
||||
public static final AtomicBoolean LOCK = new AtomicBoolean(true);
|
||||
|
||||
public void intercept(CommandWrapper response) {
|
||||
@@ -58,123 +63,94 @@ public class CommandResponseInterceptor {
|
||||
});
|
||||
}
|
||||
|
||||
// Aktualisiert Preise und Ticket-Anzahl bei Erstellung einer Eintrittskarte
|
||||
public void interceptCreate(Eintrittskarte ticket) {
|
||||
if (!checkOrderActive(ticket.getOrder()))
|
||||
return;
|
||||
|
||||
int price = ticket.getSeat().getRow().getCategory().getPrice();
|
||||
int showId = ticket.getShow().getId();
|
||||
String showHallName = ticket.getShow().getHall().getName();
|
||||
LocalDateTime showStart = ticket.getShow().getStart();
|
||||
String movieTitle = ticket.getShow().getMovie().getTitle();
|
||||
int movieId = ticket.getShow().getMovie().getId();
|
||||
boolean active = checkOrderActive(ticket.getOrder());
|
||||
|
||||
Optional<StatisticsVorstellung> show = StatisticsVorstellung.find("show._id", showId).firstResultOptional();
|
||||
Optional<StatisticsFilm> movie = StatisticsFilm.find("movie._id", movieId).firstResultOptional();
|
||||
Optional<StatisticsVorstellung> show = StatisticsVorstellung.find("showId", showId).firstResultOptional();
|
||||
Optional<StatisticsFilm> movie = StatisticsFilm.find("movieId", movieId).firstResultOptional();
|
||||
|
||||
if (show.isEmpty()) {
|
||||
StatisticsVorstellung newShow = new StatisticsVorstellung();
|
||||
newShow.setShow(ticket.getShow());
|
||||
newShow.setTickets(List.of(ticket));
|
||||
if (active) {
|
||||
newShow.setShowId(showId);
|
||||
newShow.setShowHallName(showHallName);
|
||||
newShow.setShowStart(showStart);
|
||||
newShow.setMovieTitle(movieTitle);
|
||||
newShow.setTickets(1);
|
||||
newShow.setEarnings(price);
|
||||
}
|
||||
newShow.persist();
|
||||
} else {
|
||||
StatisticsVorstellung existingShow = show.orElseThrow();
|
||||
existingShow.getTickets().add(ticket);
|
||||
if (active) {
|
||||
existingShow.setTickets(existingShow.getTickets() + 1);
|
||||
existingShow.setEarnings(existingShow.getEarnings() + price);
|
||||
}
|
||||
existingShow.update();
|
||||
}
|
||||
|
||||
if (movie.isEmpty()) {
|
||||
StatisticsFilm newMovie = new StatisticsFilm();
|
||||
newMovie.setMovie(ticket.getShow().getMovie());
|
||||
newMovie.setTickets(List.of(ticket));
|
||||
if (active) {
|
||||
newMovie.setMovieId(movieId);
|
||||
newMovie.setMovieTitle(movieTitle);
|
||||
newMovie.setTickets(1);
|
||||
newMovie.setEarnings(price);
|
||||
}
|
||||
newMovie.persist();
|
||||
} else {
|
||||
StatisticsFilm existingMovie = movie.orElseThrow();
|
||||
existingMovie.getTickets().add(ticket);
|
||||
if (active) {
|
||||
existingMovie.setTickets(existingMovie.getTickets() + 1);
|
||||
existingMovie.setEarnings(existingMovie.getEarnings() + price);
|
||||
}
|
||||
existingMovie.update();
|
||||
}
|
||||
}
|
||||
|
||||
// public void interceptUpdate(Eintrittskarte ticket) {
|
||||
// int price = ticket.getSeat().getRow().getCategory().getPrice();
|
||||
// int showId = ticket.getShow().getId();
|
||||
// int movieId = ticket.getShow().getMovie().getId();
|
||||
//
|
||||
// StatisticsVorstellung show = StatisticsVorstellung.find("show._id", showId).firstResult();
|
||||
// StatisticsFilm movie = StatisticsFilm.find("movie._id", movieId).firstResult();
|
||||
//
|
||||
// Optional<Eintrittskarte> existingTicketShow = show.getTickets().stream().filter(t -> Objects.equals(t.getId(), ticket.getId())).findAny();
|
||||
// int existingPriceShow = existingTicketShow
|
||||
// .map(Eintrittskarte::getSeat)
|
||||
// .map(Sitzplatz::getRow)
|
||||
// .map(Sitzreihe::getCategory)
|
||||
// .map(Sitzkategorie::getPrice)
|
||||
// .orElse(0);
|
||||
// show.getTickets().remove(existingTicketShow.orElse(null));
|
||||
// show.getTickets().add(ticket);
|
||||
// show.setEarnings(show.getEarnings() - existingPriceShow + price);
|
||||
// show.update();
|
||||
//
|
||||
// Optional<Eintrittskarte> existingTicketMovie = show.getTickets().stream().filter(t -> Objects.equals(t.getId(), ticket.getId())).findAny();
|
||||
// int existingPriceMovie = existingTicketMovie
|
||||
// .map(Eintrittskarte::getSeat)
|
||||
// .map(Sitzplatz::getRow)
|
||||
// .map(Sitzreihe::getCategory)
|
||||
// .map(Sitzkategorie::getPrice)
|
||||
// .orElse(0);
|
||||
// movie.getTickets().remove(existingTicketMovie.orElse(null));
|
||||
// movie.getTickets().add(ticket);
|
||||
// movie.setEarnings(movie.getEarnings() - existingPriceMovie + price);
|
||||
// movie.update();
|
||||
// }
|
||||
|
||||
// Aktualisiert Preise und Ticket-Anzahl bei Änderung der Bestellung (Reserved -> Booked und Booked - Cancelled)
|
||||
public void interceptUpdate(Bestellung order) {
|
||||
boolean orderActive = checkOrderActive(order);
|
||||
List<Eintrittskarte> tickets = QuarkusTransaction.disallowingExisting()
|
||||
.call(() -> filterQuery.query(Eintrittskarte.class, List.of("eq;order.id;int;" + order.getId())));
|
||||
int price = tickets.stream().mapToInt(ticket -> ticket.getSeat().getRow().getCategory().getPrice()).sum();
|
||||
if (price <= 0)
|
||||
return;
|
||||
|
||||
Optional<StatisticsVorstellung> showOpt = StatisticsVorstellung.find("tickets.order._id", order.getId()).firstResultOptional();
|
||||
int showId = tickets.getFirst().getShow().getId();
|
||||
Optional<StatisticsVorstellung> showOpt = StatisticsVorstellung.find("showId", showId).firstResultOptional();
|
||||
if (showOpt.isPresent()) {
|
||||
// sollte immer bereits mit CreateEintrittskarte erzeugt werden
|
||||
StatisticsVorstellung show = showOpt.orElseThrow();
|
||||
show.getTickets().stream()
|
||||
.filter(t -> t.getOrder().getId().equals(order.getId()))
|
||||
.forEach(ticket -> {
|
||||
boolean ticketActive = checkOrderActive(ticket.getOrder());
|
||||
if (ticketActive && !orderActive) {
|
||||
show.setEarnings(show.getEarnings() - ticket.getSeat().getRow().getCategory().getPrice());
|
||||
} else if (!ticketActive && orderActive) {
|
||||
show.setEarnings(show.getEarnings() + ticket.getSeat().getRow().getCategory().getPrice());
|
||||
if (orderActive) {
|
||||
show.setEarnings(show.getEarnings() + price);
|
||||
show.setTickets(show.getTickets() + tickets.size());
|
||||
} else if (order.getBooked() != null) {
|
||||
show.setEarnings(show.getEarnings() - price);
|
||||
show.setTickets(show.getTickets() - tickets.size());
|
||||
}
|
||||
ticket.setOrder(order);
|
||||
});
|
||||
show.update();
|
||||
}
|
||||
|
||||
Optional<StatisticsFilm> movieOpt = StatisticsFilm.find("tickets.order._id", order.getId()).firstResultOptional();
|
||||
int movieId = tickets.getFirst().getShow().getMovie().getId();
|
||||
Optional<StatisticsFilm> movieOpt = StatisticsFilm.find("movieId", movieId).firstResultOptional();
|
||||
if (movieOpt.isPresent()) {
|
||||
// sollte immer bereits mit CreateEintrittskarte erzeugt werden
|
||||
StatisticsFilm movie = movieOpt.orElseThrow();
|
||||
movie.getTickets().stream()
|
||||
.filter(t -> t.getOrder().getId().equals(order.getId()))
|
||||
.forEach(ticket -> {
|
||||
boolean ticketActive = checkOrderActive(ticket.getOrder());
|
||||
if (ticketActive && !orderActive) {
|
||||
movie.setEarnings(movie.getEarnings() - ticket.getSeat().getRow().getCategory().getPrice());
|
||||
} else if (!ticketActive && orderActive) {
|
||||
movie.setEarnings(movie.getEarnings() + ticket.getSeat().getRow().getCategory().getPrice());
|
||||
if (orderActive) {
|
||||
movie.setEarnings(movie.getEarnings() + price);
|
||||
movie.setTickets(movie.getTickets() + tickets.size());
|
||||
} else if (order.getBooked() != null) {
|
||||
movie.setEarnings(movie.getEarnings() - price);
|
||||
movie.setTickets(movie.getTickets() - tickets.size());
|
||||
}
|
||||
ticket.setOrder(order);
|
||||
});
|
||||
movie.update();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkOrderActive(Bestellung order) {
|
||||
return order.getCancelled() == null && order.getBooked() != null;
|
||||
return order.getBooked() != null && order.getCancelled() == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user