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