|
|
@@ -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("解锁失败");
|
|
|
+ }
|
|
|
}
|