Bladeren bron

锁座/解锁

Drew 6 jaren geleden
bovenliggende
commit
36cce1f1d4

+ 2 - 0
src/main/java/com/izouma/ticketExchange/Application.java

@@ -2,12 +2,14 @@ package com.izouma.ticketExchange;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
 @SpringBootApplication
 @EnableJpaAuditing
 @EnableSwagger2
+@EnableCaching
 public class Application {
 
     public static void main(String[] args) {

+ 3 - 0
src/main/java/com/izouma/ticketExchange/domain/CouponReceive.java

@@ -44,6 +44,9 @@ public class CouponReceive extends BaseEntity {
     @ApiModelProperty(value = "绑定用户", name = "userId")
     private Long userId;
 
+    @ApiModelProperty(value = "手机号", name = "phone")
+    private String phone;
+
     @ApiModelProperty(value = "绑定时间", name = "receiveTime")
     private LocalDateTime receiveTime;
 

+ 4 - 1
src/main/java/com/izouma/ticketExchange/repo/Order.java → src/main/java/com/izouma/ticketExchange/domain/Order.java

@@ -1,4 +1,4 @@
-package com.izouma.ticketExchange.repo;
+package com.izouma.ticketExchange.domain;
 
 
 import com.izouma.ticketExchange.domain.BaseEntity;
@@ -56,6 +56,9 @@ public class Order extends BaseEntity {
     @ApiModelProperty(value = "取票码", name = "ticketContents")
     private String ticketContents;
 
+    @ApiModelProperty(value = "二维码", name = "qrCode")
+    private String qrCode;
+
     @ApiModelProperty(value = "淘票票订单ID", name = "tbOrderId")
     private String tbOrderId;
 

+ 16 - 0
src/main/java/com/izouma/ticketExchange/dto/LockSeatRequest.java

@@ -0,0 +1,16 @@
+package com.izouma.ticketExchange.dto;
+
+import lombok.Data;
+import lombok.NonNull;
+
+import java.util.List;
+
+@Data
+public class LockSeatRequest {
+    private Long         couponId;
+    private Long         scheduleId;
+    @NonNull
+    private List<String> seatIds;
+    @NonNull
+    private List<String> seatNames;
+}

+ 2 - 0
src/main/java/com/izouma/ticketExchange/repo/CouponReceiveRepo.java

@@ -20,5 +20,7 @@ public interface CouponReceiveRepo extends JpaRepository<CouponReceive, Long>, J
 
     int countByCouponIdAndUserId(Long couponId, Long userId);
 
+    int countByCouponIdAndUserIdAndUsedFalse(Long couponId, Long userId);
+
     List<CouponReceive> findAllByUserIdAndCouponId(Long userId, Long couponId);
 }

+ 34 - 16
src/main/java/com/izouma/ticketExchange/service/SeatService.java

@@ -1,29 +1,20 @@
 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.domain.*;
+import com.izouma.ticketExchange.enums.CouponStatus;
 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.izouma.ticketExchange.repo.*;
 import com.taobao.api.ApiException;
+import com.taobao.api.response.FilmDataThirdPartyLockSeatResponse;
 import com.taobao.api.response.FilmDataThirdPartySeatMapResponse;
 import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
-import java.time.LocalDate;
-import java.time.format.DateTimeFormatter;
 import java.util.*;
-import java.util.function.BinaryOperator;
-import java.util.function.Function;
-import java.util.function.ToIntFunction;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
-import static java.time.temporal.ChronoUnit.DAYS;
-
 @Service
 @AllArgsConstructor
 public class SeatService {
@@ -31,9 +22,10 @@ public class SeatService {
     private ScheduleRepo      scheduleRepo;
     private ShowRepo          showRepo;
     private CinemaRepo        cinemaRepo;
+    private CouponInfoRepo    couponInfoRepo;
     private CouponReceiveRepo couponReceiveRepo;
 
-    public Map seatMap(Long scheduleId, Long couponId, Long userId) throws ApiException {
+    public Map seatMap(Long scheduleId, Long couponId, Long userId) {
         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("无记录"));
@@ -53,4 +45,30 @@ public class SeatService {
         map.put("usableCouponCount", couponReceiveRepo.findAllByUserIdAndCouponId(userId, couponId).stream().filter(couponReceive -> !couponReceive.getUsed()).count());
         return map;
     }
+
+    public FilmDataThirdPartyLockSeatResponse.SeatLocked lockSeat(Long couponId, Long scheduleId, List<String> seatIds, List<String> seatNames, Long userId) {
+        if (seatIds.size() != seatNames.size() || seatIds.isEmpty()) {
+            throw new BusinessException("参数错误");
+        }
+        CouponInfo couponInfo = couponInfoRepo.findById(couponId).orElseThrow(new BusinessException("优惠券不存在"));
+        if (couponInfo.getStatus() != CouponStatus.AVAILABLE) {
+            throw new BusinessException("该优惠券不可用");
+        }
+        Schedule schedule = scheduleRepo.findById(scheduleId).orElseThrow(new BusinessException("该场次不存在"));
+        if (couponInfo.getShows() != null && !couponInfo.getShows().isEmpty()) {
+            if (couponInfo.getShows().stream().noneMatch(show -> show.getId().equals(schedule.getShowId()))) {
+                throw new BusinessException("该优惠券不能用于该影片");
+            }
+        }
+        int usableCount = couponReceiveRepo.countByCouponIdAndUserIdAndUsedFalse(userId, couponId);
+        if (usableCount < seatIds.size()) {
+            throw new BusinessException("最多可选" + usableCount + "个");
+        }
+
+        return tppService.lockSeat(scheduleId, StringUtils.join(seatIds, "|"), StringUtils.join(seatNames, "|"), "", userId);
+    }
+
+    public void unlockSeat(String applyKey, Long userId) {
+        tppService.unlockSeat(applyKey, userId);
+    }
 }

+ 175 - 105
src/main/java/com/izouma/ticketExchange/service/TppService.java

@@ -12,7 +12,6 @@ import com.izouma.ticketExchange.repo.ScheduleRepo;
 import com.izouma.ticketExchange.repo.ShowRepo;
 import com.izouma.ticketExchange.utils.DateTimeUtils;
 import com.taobao.api.ApiException;
-import com.taobao.api.DefaultTaobaoClient;
 import com.taobao.api.TaobaoClient;
 import com.taobao.api.request.*;
 import com.taobao.api.response.*;
@@ -22,12 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -35,7 +32,7 @@ import java.util.stream.Collectors;
 public class TppService {
     private Long         platform = 85L;
     @Value("${taobao.userId}")
-    private Long         userId;
+    private Long         tbUserId;
     @Value("${taobao.imagePrefix}")
     private String       imagePrefix;
     @Autowired
@@ -50,152 +47,225 @@ public class TppService {
     private ScheduleRepo scheduleRepo;
 
 
-    public List<Location> updateLocation() throws ApiException {
+    public List<Location> updateLocation() {
         FilmDataThirdPartyRegionsGetRequest req = new FilmDataThirdPartyRegionsGetRequest();
-        req.setUserId(userId);
+        req.setUserId(tbUserId);
         req.setPlatform(platform);
-        FilmDataThirdPartyRegionsGetResponse rsp = client.execute(req);
-        if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
-            List<Location> locationList = new ArrayList<>();
-            rsp.getResult().getReturnValue().getRegions().forEach(region -> {
-                locationList.add(Location.builder()
-                                         .id(region.getId())
-                                         .parentId(region.getParentId())
-                                         .cityCode(region.getCityCode())
-                                         .regionName(region.getRegionName())
-                                         .city(region.getRegionName())
-                                         .pinYin(region.getPinYin())
-                                         .hot(false)
-                                         .build());
-            });
-            locationRepo.saveAll(locationList);
-            return locationList;
+        FilmDataThirdPartyRegionsGetResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+            if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                List<Location> locationList = new ArrayList<>();
+                rsp.getResult().getReturnValue().getRegions().forEach(region -> {
+                    locationList.add(Location.builder()
+                                             .id(region.getId())
+                                             .parentId(region.getParentId())
+                                             .cityCode(region.getCityCode())
+                                             .regionName(region.getRegionName())
+                                             .city(region.getRegionName())
+                                             .pinYin(region.getPinYin())
+                                             .hot(false)
+                                             .build());
+                });
+                locationRepo.saveAll(locationList);
+                return locationList;
+            }
+            log.error("获取城市列表失败\n\t{}", rsp.getBody());
+        } catch (ApiException e) {
+            log.error("获取城市列表失败", e);
         }
-        log.error("获取城市列表失败\n\t{}", rsp.getBody());
         throw new BusinessException("获取城市列表失败");
     }
 
-    public void getSoonShows(Long cityCode) throws ApiException {
+    public void getSoonShows(Long cityCode) {
         FilmDataThirdPartySoonshowsGetRequest req = new FilmDataThirdPartySoonshowsGetRequest();
-        req.setUserId(userId);
+        req.setUserId(tbUserId);
         req.setCityCode(cityCode);
         req.setPlatform(platform);
         req.setParamsString("{\"\":\"\"}");
-        FilmDataThirdPartySoonshowsGetResponse rsp = client.execute(req);
+        FilmDataThirdPartySoonshowsGetResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
         System.out.println(rsp.getBody());
     }
 
-    public List<Show> getHotShows(Long cityCode) throws ApiException {
+    public List<Show> getHotShows(Long cityCode) {
         Location location = locationRepo.findByCityCode(cityCode).orElseThrow(new BusinessException("无记录"));
         FilmDataThirdPartyHotshowsGetRequest req = new FilmDataThirdPartyHotshowsGetRequest();
-        req.setUserId(userId);
+        req.setUserId(tbUserId);
         req.setCityCode(cityCode);
         req.setPlatform(platform);
         req.setParamsString("{\"\":\"\"}");
-        FilmDataThirdPartyHotshowsGetResponse rsp = client.execute(req);
-        if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
-            List<Show> showList = new ArrayList<>();
-            Gson gson = new Gson();
-            rsp.getResult().getReturnValue().getHotShows().forEach(hotShow -> {
-                Show show = gson.fromJson(gson.toJson(hotShow), Show.class);
-                if (StringUtils.isNotEmpty(hotShow.getBackgroundPicture())) {
-                    show.setBackground(imagePrefix + hotShow.getBackgroundPicture());
-                }
-                show.setPoster(imagePrefix + show.getPoster());
-                if (show.getTrailerList() != null) {
-                    show.setTrailerList(show.getTrailerList().stream().map(s -> imagePrefix + s).collect(Collectors.toList()));
-                }
-                showList.add(show);
-            });
-            showRepo.saveAll(showList);
-            location.setShows(showList);
-            locationRepo.save(location);
-            return showList;
+        FilmDataThirdPartyHotshowsGetResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+            if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                List<Show> showList = new ArrayList<>();
+                Gson gson = new Gson();
+                rsp.getResult().getReturnValue().getHotShows().forEach(hotShow -> {
+                    Show show = gson.fromJson(gson.toJson(hotShow), Show.class);
+                    if (StringUtils.isNotEmpty(hotShow.getBackgroundPicture())) {
+                        show.setBackground(imagePrefix + hotShow.getBackgroundPicture());
+                    }
+                    show.setPoster(imagePrefix + show.getPoster());
+                    if (show.getTrailerList() != null) {
+                        show.setTrailerList(show.getTrailerList().stream().map(s -> imagePrefix + s).collect(Collectors.toList()));
+                    }
+                    showList.add(show);
+                });
+                showRepo.saveAll(showList);
+                location.setShows(showList);
+                locationRepo.save(location);
+                return showList;
+            }
+            log.error("获取热映影片失败\n\t{}", rsp.getBody());
+        } catch (ApiException e) {
+            log.error("获取热映影片失败", e);
         }
-        log.error("获取热映影片失败\n\t{}", rsp.getBody());
         throw new BusinessException("获取热映影片失败");
     }
 
-    public List<Cinema> getCinemas(Integer page) throws ApiException {
+    public List<Cinema> getCinemas(Integer page) {
         FilmDataThirdPartyCinemasGetRequest req = new FilmDataThirdPartyCinemasGetRequest();
-        req.setUserId(userId);
+        req.setUserId(tbUserId);
         req.setPlatform(platform);
         req.setParamsString("{\"cityId\":\"1\"}");
         req.setPageIndex(Long.valueOf(page));
-        FilmDataThirdPartyCinemasGetResponse rsp = client.execute(req);
-        if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
-            List<Cinema> cinemaList = new ArrayList<>();
-            rsp.getResult().getReturnValue().getMtopCinemas().forEach(c -> {
-                cinemaList.add(Cinema.builder()
-                                     .id(c.getId())
-                                     .cinemaName(c.getCinemaName())
-                                     .addr(c.getAddress())
-                                     .cityId(c.getCityId())
-                                     .lat(Double.parseDouble(c.getLatitude()))
-                                     .lng(Double.parseDouble(c.getLongitude()))
-                                     .tel(c.getPhone())
-                                     .regionName(c.getRegionName())
-                                     .scheduleCloseTime(Integer.valueOf(c.getScheduleCloseTime().toString()))
-                                     .ableRefund(c.getSupportThirdPartyRefund())
-                                     .standardId(c.getStandardId())
-                                     .build());
+        FilmDataThirdPartyCinemasGetResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+            if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                List<Cinema> cinemaList = new ArrayList<>();
+                rsp.getResult().getReturnValue().getMtopCinemas().forEach(c -> {
+                    cinemaList.add(Cinema.builder()
+                                         .id(c.getId())
+                                         .cinemaName(c.getCinemaName())
+                                         .addr(c.getAddress())
+                                         .cityId(c.getCityId())
+                                         .lat(Double.parseDouble(c.getLatitude()))
+                                         .lng(Double.parseDouble(c.getLongitude()))
+                                         .tel(c.getPhone())
+                                         .regionName(c.getRegionName())
+                                         .scheduleCloseTime(Integer.valueOf(c.getScheduleCloseTime().toString()))
+                                         .ableRefund(c.getSupportThirdPartyRefund())
+                                         .standardId(c.getStandardId())
+                                         .build());
 
-            });
-            cinemaRepo.saveAll(cinemaList);
-            if (rsp.getResult().getReturnValue().getTotalCount() > page) {
-                getCinemas(page + 1);
+                });
+                cinemaRepo.saveAll(cinemaList);
+                if (rsp.getResult().getReturnValue().getTotalCount() > page) {
+                    getCinemas(page + 1);
+                }
+                return cinemaList;
             }
-            return cinemaList;
+            log.error("获取影院失败\n\t{}", rsp.getBody());
+        } catch (ApiException e) {
+            log.error("获取影院失败", e);
         }
-        log.error("获取影院失败\n\t{}", rsp.getBody());
         throw new BusinessException("获取影院失败");
     }
 
-    public List<Schedule> getSchedules(Long cinemaId) throws ApiException {
+    public List<Schedule> getSchedules(Long cinemaId) {
         FilmDataThirdPartySchedulesGetRequest req = new FilmDataThirdPartySchedulesGetRequest();
-        req.setUserId(userId);
+        req.setUserId(tbUserId);
         req.setCinemaId(cinemaId);
         req.setPlatform(platform);
         req.setParamsString("{'':''}");
-        FilmDataThirdPartySchedulesGetResponse rsp = client.execute(req);
-        if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
-            List<Schedule> scheduleList = new ArrayList<>();
-            rsp.getResult().getReturnValue().getSchedules().forEach(s -> {
-                scheduleList.add(Schedule.builder()
-                                         .id(s.getId())
-                                         .cinemaId(s.getCinemaId())
-                                         .showId(s.getShowId())
-                                         .price(BigDecimal.valueOf(s.getPrice() / 100f))
-                                         .hallName(s.getHallName())
-                                         .maxCanBuy(Math.toIntExact(s.getMaxCanBuy()))
-                                         .showTime(DateTimeUtils.toLocalDateTime(s.getShowTime(), "yyyy-MM-dd HH:mm:ss"))
-                                         .closeTime(DateTimeUtils.toLocalDateTime(s.getCloseTime(), "yyyy-MM-dd HH:mm:ss"))
-                                         .scheduleArea(s.getScheduleArea())
-                                         .sectionId(s.getSectionId())
-                                         .serviceFee(BigDecimal.valueOf(Optional.ofNullable(s.getServiceFee()).orElse(0L) / 100f))
-                                         .showVersion(s.getShowVersion())
-                                         .showDate(DateTimeUtils.toLocalDate(s.getShowDate(), "yyyy-MM-dd"))
-                                         .isExpired(s.getIsExpired())
-                                         .build());
-            });
-            scheduleRepo.saveAll(scheduleList);
-            return scheduleList;
+        FilmDataThirdPartySchedulesGetResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+            if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                List<Schedule> scheduleList = new ArrayList<>();
+                rsp.getResult().getReturnValue().getSchedules().forEach(s -> {
+                    scheduleList.add(Schedule.builder()
+                                             .id(s.getId())
+                                             .cinemaId(s.getCinemaId())
+                                             .showId(s.getShowId())
+                                             .price(BigDecimal.valueOf(s.getPrice() / 100f))
+                                             .hallName(s.getHallName())
+                                             .maxCanBuy(Math.toIntExact(s.getMaxCanBuy()))
+                                             .showTime(DateTimeUtils.toLocalDateTime(s.getShowTime(), "yyyy-MM-dd HH:mm:ss"))
+                                             .closeTime(DateTimeUtils.toLocalDateTime(s.getCloseTime(), "yyyy-MM-dd HH:mm:ss"))
+                                             .scheduleArea(s.getScheduleArea())
+                                             .sectionId(s.getSectionId())
+                                             .serviceFee(BigDecimal.valueOf(Optional.ofNullable(s.getServiceFee()).orElse(0L) / 100f))
+                                             .showVersion(s.getShowVersion())
+                                             .showDate(DateTimeUtils.toLocalDate(s.getShowDate(), "yyyy-MM-dd"))
+                                             .isExpired(s.getIsExpired())
+                                             .build());
+                });
+                scheduleRepo.saveAll(scheduleList);
+                return scheduleList;
+            }
+            log.error("获取排片失败\n\t{}", rsp.getBody());
+        } catch (ApiException e) {
+            log.error("获取排片失败", e);
         }
-        log.error("获取排片失败\n\t{}", rsp.getBody());
         throw new BusinessException("获取排片失败");
     }
 
-    public FilmDataThirdPartySeatMapResponse.TopSeatMap getSeatMap(Long scheduleId) throws ApiException {
+    public FilmDataThirdPartySeatMapResponse.TopSeatMap getSeatMap(Long scheduleId) {
         FilmDataThirdPartySeatMapRequest req = new FilmDataThirdPartySeatMapRequest();
         req.setPlatform(platform);
         req.setParamsString("{}");
-        req.setUserId(userId);
+        req.setUserId(tbUserId);
         req.setScheduleId(scheduleId);
-        FilmDataThirdPartySeatMapResponse rsp = client.execute(req);
-        if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
-            return rsp.getResult().getReturnValue();
+        FilmDataThirdPartySeatMapResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+            if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                return rsp.getResult().getReturnValue();
+            }
+            log.error("获取座位图失败\n\t{}", rsp.getBody());
+        } catch (ApiException e) {
+            log.error("获取座位图失败", e);
         }
-        log.error("获取座位图失败\n\t{}", rsp.getBody());
         throw new BusinessException("获取座位图失败");
     }
+
+    public FilmDataThirdPartyLockSeatResponse.SeatLocked lockSeat(Long scheduleId, String seatIds, String seatNames, String mobile, Long userId) {
+        FilmDataThirdPartyLockSeatRequest req = new FilmDataThirdPartyLockSeatRequest();
+        req.setUserId(tbUserId);
+        req.setPlatform(platform);
+        req.setScheduleId(scheduleId);
+        req.setSeatIds(seatIds);
+        req.setSeatNames(seatNames);
+        req.setMobile(mobile);
+        req.setParamsString("{}");
+        req.setExtUserId(userId.toString());
+        FilmDataThirdPartyLockSeatResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+            if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                return rsp.getResult().getReturnValue();
+            }
+            log.error("锁座失败\n\t{}", rsp.getBody());
+        } catch (ApiException e) {
+            log.error("锁座失败", e);
+        }
+        throw new BusinessException("锁座失败");
+    }
+
+    public void unlockSeat(String applyKey, Long userId) {
+        FilmDataThirdPartyUnlockSeatRequest req = new FilmDataThirdPartyUnlockSeatRequest();
+        req.setPlatform(platform);
+        req.setParamsString("{}");
+        req.setUserId(tbUserId);
+        req.setLockSeatApplyKey(applyKey);
+        req.setExtUserId(userId.toString());
+        FilmDataThirdPartyUnlockSeatResponse rsp = null;
+        try {
+            rsp = client.execute(req);
+            if (rsp.getReturnCode() != null && rsp.getReturnCode().equals("0")) {
+                return;
+            }
+            log.error("锁座失败\n\t{}", rsp.getBody());
+        } catch (ApiException e) {
+            log.error("解锁失败", e);
+        }
+        throw new BusinessException("解锁失败");
+    }
 }

+ 1 - 0
src/main/java/com/izouma/ticketExchange/service/UserCouponService.java

@@ -52,6 +52,7 @@ public class UserCouponService {
         }
         couponReceive.setStatus(ReceiveStatus.CLAIMED);
         couponReceive.setUserId(userId);
+        couponReceive.setPhone(phone);
         couponReceiveRepo.save(couponReceive);
     }
 

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

@@ -1,8 +1,13 @@
 package com.izouma.ticketExchange.web;
 
+import com.izouma.ticketExchange.domain.CouponInfo;
+import com.izouma.ticketExchange.dto.LockSeatRequest;
+import com.izouma.ticketExchange.repo.CouponInfoRepo;
+import com.izouma.ticketExchange.repo.CouponReceiveRepo;
 import com.izouma.ticketExchange.service.SeatService;
 import com.izouma.ticketExchange.utils.SecurityUtils;
 import com.taobao.api.ApiException;
+import com.taobao.api.response.FilmDataThirdPartyLockSeatResponse;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
@@ -12,10 +17,22 @@ import java.util.Map;
 @RequestMapping("/seat")
 @AllArgsConstructor
 public class SeatController {
-    private SeatService seatService;
+    private SeatService       seatService;
+    private CouponInfoRepo    couponInfoRepo;
+    private CouponReceiveRepo couponReceiveRepo;
 
     @GetMapping("/schedule/{scheduleId}/map")
     public Map seatMap(@PathVariable Long scheduleId, @RequestParam Long couponId) throws ApiException {
         return seatService.seatMap(scheduleId, couponId, SecurityUtils.getAuthenticatedUser().getId());
     }
+
+    @GetMapping("/lock")
+    public FilmDataThirdPartyLockSeatResponse.SeatLocked lockSeat(@RequestBody LockSeatRequest request) {
+        return seatService.lockSeat(request.getCouponId(), request.getScheduleId(), request.getSeatIds(), request.getSeatNames(), SecurityUtils.getAuthenticatedUser().getId());
+    }
+
+    @GetMapping("/unlock")
+    public void unlockSeat(@RequestParam String applyKey) {
+        seatService.unlockSeat(applyKey, SecurityUtils.getAuthenticatedUser().getId());
+    }
 }