|
32 | 32 | import java.io.InputStream; |
33 | 33 | import java.time.Instant; |
34 | 34 | import java.time.ZoneOffset; |
35 | | -import java.util.List; |
36 | | -import java.util.Map; |
| 35 | +import java.util.*; |
37 | 36 | import java.time.LocalDateTime; |
38 | | -import java.util.Optional; |
| 37 | +import java.util.function.Function; |
| 38 | +import java.util.stream.Collectors; |
39 | 39 |
|
40 | 40 | import static TiCatch.backend.domain.ticketing.entity.TicketingLevel.*; |
41 | 41 | import static TiCatch.backend.global.constant.TicketingConstants.*; |
@@ -192,6 +192,30 @@ public Mono<Map<String, Boolean>> getSectionSeats(Long ticketingId, String secti |
192 | 192 | ); |
193 | 193 | } |
194 | 194 |
|
| 195 | + public Mono<Map<String, Long>> getSeatCountBySection(Long ticketingId) { |
| 196 | + String redisKey = TICKETING_SEAT_PREFIX + ticketingId; |
| 197 | + |
| 198 | + return reactiveRedisTemplate.<String, String>opsForHash().entries(redisKey) |
| 199 | + .collectList() |
| 200 | + .flatMap(entries -> { |
| 201 | + Set<String> allSections = entries.stream() |
| 202 | + .map(entry -> entry.getKey().split(":")[0]) |
| 203 | + .collect(Collectors.toSet()); |
| 204 | + |
| 205 | + Map<String, Long> availableCounts = entries.stream() |
| 206 | + .filter(entry -> "0".equals(entry.getValue())) |
| 207 | + .map(entry -> entry.getKey().split(":")[0]) |
| 208 | + .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); |
| 209 | + |
| 210 | + Map<String, Long> result = new HashMap<>(); |
| 211 | + for (String section : allSections) { |
| 212 | + result.put(section, availableCounts.getOrDefault(section, 0L)); |
| 213 | + } |
| 214 | + |
| 215 | + return Mono.just(result); |
| 216 | + }); |
| 217 | + } |
| 218 | + |
195 | 219 | public void isAvailable(Long ticketingId, String seatKey) { |
196 | 220 | String redisKey = TICKETING_SEAT_PREFIX + ticketingId; |
197 | 221 | HashOperations<String, String, String> hashOperations = redisTemplate.opsForHash(); |
|
0 commit comments