Drew 6 lat temu
rodzic
commit
e2d68d04e1

+ 12 - 7
src/main/java/com/izouma/ticketExchange/service/SeatService.java

@@ -1,10 +1,12 @@
 package com.izouma.ticketExchange.service;
 
 import com.izouma.ticketExchange.domain.Cinema;
+import com.izouma.ticketExchange.domain.CouponReceive;
 import com.izouma.ticketExchange.domain.Schedule;
 import com.izouma.ticketExchange.domain.Show;
 import com.izouma.ticketExchange.exception.BusinessException;
 import com.izouma.ticketExchange.repo.CinemaRepo;
+import com.izouma.ticketExchange.repo.CouponReceiveRepo;
 import com.izouma.ticketExchange.repo.ScheduleRepo;
 import com.izouma.ticketExchange.repo.ShowRepo;
 import com.taobao.api.ApiException;
@@ -25,12 +27,13 @@ import static java.time.temporal.ChronoUnit.DAYS;
 @Service
 @AllArgsConstructor
 public class SeatService {
-    private TppService   tppService;
-    private ScheduleRepo scheduleRepo;
-    private ShowRepo     showRepo;
-    private CinemaRepo   cinemaRepo;
+    private TppService        tppService;
+    private ScheduleRepo      scheduleRepo;
+    private ShowRepo          showRepo;
+    private CinemaRepo        cinemaRepo;
+    private CouponReceiveRepo couponReceiveRepo;
 
-    public Map seatMap(Long scheduleId, Long couponId) throws ApiException {
+    public Map seatMap(Long scheduleId, Long couponId, Long userId) throws ApiException {
         Schedule schedule = scheduleRepo.findById(scheduleId).orElseThrow(new BusinessException("无记录"));
         Show show = showRepo.findById(schedule.getShowId()).orElseThrow(new BusinessException("无记录"));
         Cinema cinema = cinemaRepo.findById(schedule.getCinemaId()).orElseThrow(new BusinessException("无记录"));
@@ -39,13 +42,15 @@ public class SeatService {
         map.put("seatMap", seatMap);
         map.put("show", show);
         map.put("cinema", cinema);
-        map.put("width", seatMap.getSeats().stream().mapToInt(value -> Math.toIntExact(value.getLeftPx())).max().orElse(0) - seatMap.getSeats().stream().mapToInt(value -> Math.toIntExact(value.getLeftPx())).min().orElse(0));
-        map.put("height", seatMap.getSeats().stream().mapToInt(value -> Math.toIntExact(value.getTopPx())).max().orElse(0) - seatMap.getSeats().stream().mapToInt(value -> Math.toIntExact(value.getTopPx())).min().orElse(0));
+        map.put("schedule", schedule);
+        map.put("width", seatMap.getSeats().stream().mapToInt(value -> Math.toIntExact(value.getLeftPx())).max().orElse(0) + 60);
+        map.put("height", seatMap.getSeats().stream().mapToInt(value -> Math.toIntExact(value.getTopPx())).max().orElse(0) + 60);
         map.put("rowNames", new ArrayList<>(seatMap.getSeats()
                                                    .stream()
                                                    .collect(Collectors.groupingBy(FilmDataThirdPartySeatMapResponse.Seat::getRowName))
                                                    .keySet())
                 .stream().sorted(Comparator.comparingInt(Integer::parseInt)).collect(Collectors.toList()));
+        map.put("usableCouponCount", couponReceiveRepo.findAllByUserIdAndCouponId(userId, couponId).stream().filter(couponReceive -> !couponReceive.getUsed()).count());
         return map;
     }
 }

+ 2 - 1
src/main/java/com/izouma/ticketExchange/web/SeatController.java

@@ -1,6 +1,7 @@
 package com.izouma.ticketExchange.web;
 
 import com.izouma.ticketExchange.service.SeatService;
+import com.izouma.ticketExchange.utils.SecurityUtils;
 import com.taobao.api.ApiException;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
@@ -15,6 +16,6 @@ public class SeatController {
 
     @GetMapping("/schedule/{scheduleId}/map")
     public Map seatMap(@PathVariable Long scheduleId, @RequestParam Long couponId) throws ApiException {
-        return seatService.seatMap(scheduleId, couponId);
+        return seatService.seatMap(scheduleId, couponId, SecurityUtils.getAuthenticatedUser().getId());
     }
 }