Drew 6 yıl önce
ebeveyn
işleme
a8d12966a7

+ 13 - 13
src/main/java/com/izouma/ticketExchange/service/SyncService.java

@@ -73,7 +73,7 @@ public class SyncService {
             List<FilmDataThirdPartyHotshowsGetResponse.Show> hotShows = tppService.getHotShows(location.getCityCode());
             Set<Show> showSet = new HashSet<>();
             Gson gson = new Gson();
-            soonShows.forEach(soonShow -> {
+            Optional.ofNullable(soonShows).orElse(new ArrayList<>()).forEach(soonShow -> {
                 Show show = gson.fromJson(gson.toJson(soonShow), Show.class);
                 if (StringUtils.isNotEmpty(soonShow.getBackgroundPicture())) {
                     show.setBackground(imagePrefix + soonShow.getBackgroundPicture());
@@ -85,18 +85,18 @@ public class SyncService {
                 showSet.add(show);
                 allShows.add(show);
             });
-            hotShows.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()));
-                }
-                showSet.add(show);
-                allShows.add(show);
-            });
+//            Optional.ofNullable(hotShows).orElse(new ArrayList<>()).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()));
+//                }
+//                showSet.add(show);
+//                allShows.add(show);
+//            });
             location.setShows(new ArrayList<>(showSet));
 
             showRepo.saveAll(allShows);

+ 18 - 26
src/main/java/com/izouma/ticketExchange/service/TppService.java

@@ -1,33 +1,19 @@
 package com.izouma.ticketExchange.service;
 
-import com.google.gson.Gson;
-import com.izouma.ticketExchange.domain.Cinema;
-import com.izouma.ticketExchange.domain.Location;
-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.LocationRepo;
-import com.izouma.ticketExchange.repo.ScheduleRepo;
-import com.izouma.ticketExchange.repo.ShowRepo;
-import com.izouma.ticketExchange.utils.DateTimeUtils;
 import com.taobao.api.TaobaoClient;
 import com.taobao.api.request.*;
 import com.taobao.api.response.*;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.remoting.RemoteAccessException;
 import org.springframework.retry.annotation.Backoff;
 import org.springframework.retry.annotation.Retryable;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.util.ArrayList;
+import java.util.List;
 
 @Service
 @Slf4j
@@ -37,17 +23,10 @@ public class TppService {
     private Long         tbUserId;
     @Autowired
     private TaobaoClient client;
-    @Autowired
-    private LocationRepo locationRepo;
-    @Autowired
-    private ShowRepo     showRepo;
-    @Autowired
-    private CinemaRepo   cinemaRepo;
-    @Autowired
-    private ScheduleRepo scheduleRepo;
 
     @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 500, maxDelay = 3000))
     public List<FilmDataThirdPartyRegionsGetResponse.Region> getLocations() {
+        log.info("获取城市列表");
         FilmDataThirdPartyRegionsGetRequest req = new FilmDataThirdPartyRegionsGetRequest();
         req.setUserId(tbUserId);
         req.setPlatform(platform);
@@ -55,6 +34,7 @@ public class TppService {
         try {
             rsp = client.execute(req);
             if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                log.info("获取城市列表成功");
                 return rsp.getResult().getReturnValue().getRegions();
             }
             log.error("获取城市列表失败\n\t{}", rsp.getBody());
@@ -76,6 +56,7 @@ public class TppService {
         try {
             rsp = client.execute(req);
             if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                log.info("获取即将上映影片成功");
                 return rsp.getResult().getReturnValue().getSoonShows();
             }
             log.error("获取即将上映影片失败\n\t{}", rsp.getBody());
@@ -87,6 +68,7 @@ public class TppService {
 
     @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 500, maxDelay = 3000))
     public List<FilmDataThirdPartyHotshowsGetResponse.Show> getHotShows(Long cityCode) {
+        log.info("获取热映影片 {}", cityCode);
         FilmDataThirdPartyHotshowsGetRequest req = new FilmDataThirdPartyHotshowsGetRequest();
         req.setUserId(tbUserId);
         req.setCityCode(cityCode);
@@ -96,6 +78,7 @@ public class TppService {
         try {
             rsp = client.execute(req);
             if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                log.info("获取热映影片成功");
                 return rsp.getResult().getReturnValue().getHotShows();
             }
             log.error("获取热映影片失败\n\t{}", rsp.getBody());
@@ -106,9 +89,9 @@ public class TppService {
     }
 
 
-
     @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 500, maxDelay = 3000))
     public List<FilmDataThirdPartyCinemasGetResponse.MtopCinema> getCinemas(Integer page) {
+        log.info("获取影院 page: {}", page);
         FilmDataThirdPartyCinemasGetRequest req = new FilmDataThirdPartyCinemasGetRequest();
         req.setUserId(tbUserId);
         req.setPlatform(platform);
@@ -130,6 +113,7 @@ public class TppService {
                 if (rsp.getResult().getReturnValue().getTotalCount() > page) {
                     getCinemas(page + 1);
                 }
+                log.info("获取影院成功");
                 return list;
             }
             log.error("获取影院失败\n\t{}", rsp.getBody());
@@ -141,6 +125,7 @@ public class TppService {
 
     @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 500, maxDelay = 3000))
     public List<FilmDataThirdPartySchedulesGetResponse.Schedule> getSchedules(Long cinemaId) {
+        log.info("获取影院 {}", cinemaId);
         FilmDataThirdPartySchedulesGetRequest req = new FilmDataThirdPartySchedulesGetRequest();
         req.setUserId(tbUserId);
         req.setCinemaId(cinemaId);
@@ -150,6 +135,7 @@ public class TppService {
         try {
             rsp = client.execute(req);
             if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                log.info("获取影院成功");
                 return rsp.getResult().getReturnValue().getSchedules();
             }
             log.error("获取排片失败\n\t{}", rsp.getBody());
@@ -161,6 +147,7 @@ public class TppService {
 
     @Retryable(maxAttempts = 5, backoff = @Backoff(delay = 500, maxDelay = 3000))
     public FilmDataThirdPartySeatMapResponse.TopSeatMap getSeatMap(Long scheduleId) {
+        log.info("获取座位图 {}", scheduleId);
         FilmDataThirdPartySeatMapRequest req = new FilmDataThirdPartySeatMapRequest();
         req.setPlatform(platform);
         req.setParamsString("{}");
@@ -170,6 +157,7 @@ public class TppService {
         try {
             rsp = client.execute(req);
             if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                log.info("获取座位图成功");
                 return rsp.getResult().getReturnValue();
             }
             log.error("获取座位图失败\n\t{}", rsp.getBody());
@@ -180,6 +168,7 @@ public class TppService {
     }
 
     public FilmDataThirdPartyLockSeatResponse.SeatLocked lockSeat(Long scheduleId, String seatIds, String seatNames, String mobile, Long userId) {
+        log.info("锁座");
         FilmDataThirdPartyLockSeatRequest req = new FilmDataThirdPartyLockSeatRequest();
         req.setUserId(tbUserId);
         req.setPlatform(platform);
@@ -193,6 +182,7 @@ public class TppService {
         try {
             rsp = client.execute(req);
             if (rsp.getResult() != null && rsp.getResult().getReturnCode().equals("0")) {
+                log.info("锁座成功");
                 return rsp.getResult().getReturnValue();
             }
             log.error("锁座失败\n\t{}", rsp.getBody());
@@ -203,6 +193,7 @@ public class TppService {
     }
 
     public void unlockSeat(String applyKey, Long userId) {
+        log.info("解锁 {}", applyKey);
         FilmDataThirdPartyUnlockSeatRequest req = new FilmDataThirdPartyUnlockSeatRequest();
         req.setPlatform(platform);
         req.setParamsString("{}");
@@ -213,9 +204,10 @@ public class TppService {
         try {
             rsp = client.execute(req);
             if (rsp.getReturnCode() != null && rsp.getReturnCode().equals("0")) {
+                log.info("解锁成功");
                 return;
             }
-            log.error("锁失败\n\t{}", rsp.getBody());
+            log.error("锁失败\n\t{}", rsp.getBody());
         } catch (Exception e) {
             log.error("解锁失败", e);
         }

+ 53 - 1
src/test/java/com/izouma/ticketExchange/service/TppServiceTest.java

@@ -1,13 +1,31 @@
 package com.izouma.ticketExchange.service;
 
+import com.google.gson.Gson;
 import com.izouma.ticketExchange.ApplicationTests;
+import com.izouma.ticketExchange.domain.Location;
+import com.izouma.ticketExchange.domain.Show;
+import com.izouma.ticketExchange.repo.LocationRepo;
+import com.izouma.ticketExchange.repo.ShowRepo;
 import com.taobao.api.ApiException;
+import com.taobao.api.response.FilmDataThirdPartyHotshowsGetResponse;
+import com.taobao.api.response.FilmDataThirdPartySoonshowsGetResponse;
+import org.apache.commons.lang3.StringUtils;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+
+import java.util.*;
+import java.util.stream.Collectors;
 
 public class TppServiceTest extends ApplicationTests {
     @Autowired
-    private TppService tppService;
+    private TppService   tppService;
+    @Autowired
+    private LocationRepo locationRepo;
+    @Autowired
+    private ShowRepo     showRepo;
+    @Value("${taobao.imagePrefix}")
+    private String       imagePrefix;
 
     @Test
     public void updateLocation() throws ApiException {
@@ -44,4 +62,38 @@ public class TppServiceTest extends ApplicationTests {
         tppService.unlockSeat("85_44_729543745_[0300000200801209, 0300000200901210]", 44L);
     }
 
+    @Test
+    public void test() {
+        Location location = locationRepo.findByCityCode(232700L).get();
+        List<FilmDataThirdPartySoonshowsGetResponse.Show> soonShows = tppService.getSoonShows(location.getCityCode());
+        List<FilmDataThirdPartyHotshowsGetResponse.Show> hotShows = tppService.getHotShows(location.getCityCode());
+        Set<Show> showSet = new HashSet<>();
+        Gson gson = new Gson();
+        Optional.ofNullable(soonShows).orElse(new ArrayList<>()).forEach(soonShow -> {
+            Show show = gson.fromJson(gson.toJson(soonShow), Show.class);
+            if (StringUtils.isNotEmpty(soonShow.getBackgroundPicture())) {
+                show.setBackground(imagePrefix + soonShow.getBackgroundPicture());
+            }
+            show.setPoster(imagePrefix + show.getPoster());
+            if (show.getTrailerList() != null) {
+                show.setTrailerList(show.getTrailerList().stream().map(s -> imagePrefix + s).collect(Collectors.toList()));
+            }
+            showSet.add(show);
+        });
+        Optional.ofNullable(hotShows).orElse(new ArrayList<>()).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()));
+            }
+            showSet.add(show);
+        });
+        location.setShows(new ArrayList<>(showSet));
+
+        locationRepo.save(location);
+    }
+
 }