Drew 6 years ago
parent
commit
0071815835

+ 8 - 3
src/main/java/com/izouma/ticketExchange/service/TppService.java

@@ -1,6 +1,7 @@
 package com.izouma.ticketExchange.service;
 
 import com.izouma.ticketExchange.exception.BusinessException;
+import com.izouma.ticketExchange.utils.JsonUtils;
 import com.taobao.api.TaobaoClient;
 import com.taobao.api.request.*;
 import com.taobao.api.response.*;
@@ -217,15 +218,19 @@ public class TppService {
     @Retryable(value = BusinessException.class,
             maxAttempts = 100,
             backoff = @Backoff(delay = 1000, multiplier = 2))
-    public void issueOrder(Long userId, Long orderId, String applyKey, BigDecimal totalPrice) throws Exception {
+    public void issueOrder(Long userId, Long orderId, String applyKey, Long totalPrice) throws Exception {
         FilmDataThirdPartyIssueOrderRequest req = new FilmDataThirdPartyIssueOrderRequest();
         req.setPlatform(platform);
-        req.setParamsString("{\"price_detail\":\"user-3000,other-2000\"}");
+        String params = new JsonUtils.Builder()
+                .add("price_detail", "user-0,other-" + totalPrice)
+                .build();
+        System.out.println(params);
+        req.setParamsString(params);
         req.setUserId(tbUserId);
         req.setLockSeatApplyKey(applyKey);
         req.setExtUserId(userId.toString());
         req.setExtOrderId(orderId.toString());
-        req.setTotalPrice(totalPrice.multiply(BigDecimal.valueOf(100)).longValueExact());
+        req.setTotalPrice(totalPrice);
         FilmDataThirdPartyIssueOrderResponse rsp = client.execute(req);
         System.out.println(rsp.getBody());
     }

+ 37 - 17
src/test/java/com/izouma/ticketExchange/service/TppServiceTest.java

@@ -6,8 +6,10 @@ import com.izouma.ticketExchange.domain.Location;
 import com.izouma.ticketExchange.domain.Schedule;
 import com.izouma.ticketExchange.domain.Show;
 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.izouma.ticketExchange.utils.SnowflakeIdWorker;
 import com.taobao.api.ApiException;
 import com.taobao.api.response.FilmDataThirdPartyHotshowsGetResponse;
 import com.taobao.api.response.FilmDataThirdPartySchedulesGetResponse;
@@ -18,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -30,6 +33,8 @@ public class TppServiceTest extends ApplicationTests {
     private ShowRepo     showRepo;
     @Value("${taobao.imagePrefix}")
     private String       imagePrefix;
+    @Autowired
+    private ScheduleRepo scheduleRepo;
 
     @Test
     public void updateLocation() throws ApiException {
@@ -68,26 +73,41 @@ public class TppServiceTest extends ApplicationTests {
 
     @Test
     public void test() {
-        List<FilmDataThirdPartySchedulesGetResponse.Schedule> list = tppService.getSchedules(4353L);
+        List<FilmDataThirdPartySchedulesGetResponse.Schedule> list = tppService.getSchedules(45100L);
         list.forEach(s -> {
-            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();
+            Schedule ss = Schedule.builder()
+                                  .id(s.getId())
+                                  .cinemaId(s.getCinemaId())
+                                  .showId(s.getShowId())
+                                  .price(BigDecimal.valueOf(s.getPrice()).divide(BigDecimal.valueOf(100), RoundingMode.HALF_EVEN))
+                                  .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.save(ss);
         });
         System.out.println(list);
     }
 
+    @Test
+    public void testOrder() throws Exception {
+        Long orderId = new SnowflakeIdWorker(1, 1).nextId();
+        System.out.println(orderId);
+        tppService.issueOrder(9L, orderId, "85_44_732009272_[0300000400600701, 0300000400500701]", 5600L);
+    }
+
+    @Test
+    public void addSchedule() {
+        tppService.getSchedules(45100L).forEach(schedule -> {
+
+        });
+    }
+
 }