use of alfio.util.PreReservedTicketDistributor in project alf.io by alfio-event.
the class WaitingQueueManager method preReserveTickets.
private void preReserveTickets(Event event, int ticketsNeeded, int eventId, int alreadyReserved) {
final int toBeGenerated = Math.abs(alreadyReserved - ticketsNeeded);
EventStatisticView eventStatisticView = eventRepository.findStatisticsFor(eventId);
Map<Integer, TicketCategoryStatisticView> ticketCategoriesStats = ticketCategoryRepository.findStatisticsForEventIdByCategoryId(eventId);
List<Pair<Integer, TicketCategoryStatisticView>> collectedTickets = ticketCategoryRepository.findAllTicketCategories(eventId).stream().filter(tc -> !tc.isAccessRestricted()).sorted(Comparator.comparing(t -> t.getExpiration(event.getZoneId()))).map(tc -> Pair.of(determineAvailableSeats(ticketCategoriesStats.get(tc.getId()), eventStatisticView), ticketCategoriesStats.get(tc.getId()))).collect(new PreReservedTicketDistributor(toBeGenerated));
MapSqlParameterSource[] candidates = collectedTickets.stream().flatMap(p -> selectTicketsForPreReservation(eventId, p).stream()).map(id -> new MapSqlParameterSource().addValue("id", id)).toArray(MapSqlParameterSource[]::new);
jdbc.batchUpdate(ticketRepository.preReserveTicket(), candidates);
}
Aggregations