diff --git a/src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java b/src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java index 64f0a666..fac69fd3 100644 --- a/src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java +++ b/src/main/java/com/chint/domain/service/amount_estimate/LYEstimate.java @@ -2,19 +2,97 @@ package com.chint.domain.service.amount_estimate; import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.infrastructure.constant.Constant; +import com.chint.infrastructure.util.BigDecimalCalculator; +import com.chint.interfaces.rest.ly.LYPostRequest; +import com.chint.interfaces.rest.ly.dto.commonresult.Result; +import com.chint.interfaces.rest.ly.dto.estimateprice.Description; +import com.chint.interfaces.rest.ly.dto.estimateprice.TrainMaxPrice; +import com.chint.interfaces.rest.ly.vo.estimateprice.TrainPriceVo; +import com.google.gson.Gson; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.math.BigDecimal; +import java.time.format.DateTimeFormatter; +import java.util.Map; + +import static com.chint.infrastructure.constant.Constant.*; +import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_NOT_ORDERED_NAME; + @Component public class LYEstimate implements AmountEstimate { + + @Autowired + private LYPostRequest postRequest; + @Override public String amountEstimate(Leg leg) { - return null; + return switch (leg.getLegType()) { + //火车 + case LEG_TYPE_TRAIN -> trainMaxPrice(leg); + //飞机 + case LEG_TYPE_AIRPLANE -> ticketNewPrice(leg); + //酒店 + case LEG_TYPE_HOTEL -> hotelMinPrice(leg); + //出租车 + case LEG_TYPE_TAXI -> taxi(leg); + //其他 + default -> KEEP_TWO_DECIMAL_ZERO; + }; } @Override public String amountEstimate(RouteOrder routeOrder) { - return null; + return routeOrder.getLegItems() + .stream() + .map(Leg::getEstimateAmount) + .reduce(BigDecimalCalculator::add) + .orElse(KEEP_TWO_DECIMAL_ZERO); } + /** + * 火车票最高价格 + */ + public String trainMaxPrice(Leg leg) { + String maxPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_TRAIN_MAX_PRICE; + TrainMaxPrice trainMaxPrice = new TrainMaxPrice(); + trainMaxPrice.setTicketType(0); + trainMaxPrice.setDepartDate(leg.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + trainMaxPrice.setDepartCityName(leg.getOriginLocationId().getLocationName()); + trainMaxPrice.setArriveCityName(leg.getDestinationLocation().getLocationName()); + Description description = new Description<>(); + description.setParam(trainMaxPrice); + Result post = postRequest.post(maxPriceUrl, description, Result.class); + Gson gson = new Gson(); + TrainPriceVo trainPriceVo = gson.fromJson(String.valueOf(post.getData()), TrainPriceVo.class); + Map map = trainPriceVo.getDailySeatHigestPrices(); + BigDecimal maxPrice = map.values().stream() + .max(BigDecimal::compareTo) + .orElse(BigDecimal.ZERO); + return maxPrice.toString(); + } + /** + * 飞机 + */ + public String ticketNewPrice(Leg leg) { + + return ""; + } + + /** + * 酒店 + */ + public String hotelMinPrice(Leg leg) { + + return ""; + } + + /** + * 出租车 + */ + public String taxi(Leg leg) { + return KEEP_TWO_DECIMAL_ZERO; + } } diff --git a/src/main/java/com/chint/infrastructure/constant/Constant.java b/src/main/java/com/chint/infrastructure/constant/Constant.java index aa00b4d3..3333443f 100644 --- a/src/main/java/com/chint/infrastructure/constant/Constant.java +++ b/src/main/java/com/chint/infrastructure/constant/Constant.java @@ -172,9 +172,7 @@ public class Constant { public static final Integer L_Y_TRAVEL_TYPE_PERSON = 1; // (因公) public static final Integer L_Y_TRAVEL_TYPE_NO_PERSON = 2; // (因私) - - - + public static final String L_Y_TRAIN_MAX_PRICE = "/openapi/api/Train/TrainHighPirceSearchByCityName";//火车票价格查询 // status diff --git a/src/main/java/com/chint/interfaces/rest/ly/vo/estimateprice/TrainPriceVo.java b/src/main/java/com/chint/interfaces/rest/ly/vo/estimateprice/TrainPriceVo.java new file mode 100644 index 00000000..5ec01e09 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ly/vo/estimateprice/TrainPriceVo.java @@ -0,0 +1,13 @@ +package com.chint.interfaces.rest.ly.vo.estimateprice; + + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Map; + +@Data +public class TrainPriceVo { + + private Map dailySeatHigestPrices; +} diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index c11a96e3..4767057a 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -1,6 +1,8 @@ package com.chint; +import com.alibaba.fastjson2.JSON; import com.chint.domain.aggregates.user.User; +import com.chint.infrastructure.constant.Constant; import com.chint.infrastructure.util.BaseContext; import com.chint.interfaces.rest.ly.LYLoginRequest; import com.chint.interfaces.rest.ly.LYPostRequest; @@ -12,13 +14,24 @@ import com.chint.interfaces.rest.ly.dto.estimateprice.Description; import com.chint.interfaces.rest.ly.dto.estimateprice.HotleMinPrice; import com.chint.interfaces.rest.ly.dto.estimateprice.TicketNewPrice; import com.chint.interfaces.rest.ly.dto.estimateprice.TrainMaxPrice; +import com.chint.interfaces.rest.ly.vo.estimateprice.TrainPriceVo; +import com.google.gson.Gson; +import com.google.gson.internal.LinkedTreeMap; +import com.google.gson.reflect.TypeToken; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.lang.reflect.Type; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; -import static com.chint.infrastructure.constant.Constant.L_Y_ENTRANCE_HOME; +import static com.chint.infrastructure.constant.Constant.*; @SpringBootTest public class LYTest { @@ -49,7 +62,7 @@ public class LYTest { public static final String L_Y_HOTLE_MIN_PRICE_PATH = "/api/Hotel/GetHotelMinPrice"; public static final String L_Y_HOTLE_LIST_PATH = "/api/Hotel/GetHotelCityList"; private final String travelApplyOrderUrl = L_Y_BASE_URL + L_Y_ORDER_PATH; - // private final String maxPriceUrl = L_Y_BASE_URL + L_Y_MAX_PRICE_PATH; + // private final String maxPriceUrl = L_Y_BASE_URL + L_Y_MAX_PRICE_PATH; private final String maxPriceUrl = "https://api.qa.dttrip.cn/openapi/api/Train/TrainHighPirceSearchByCityName"; private final String flyPriceUrl = L_Y_BASE_URL + L_Y_FLYORDER_PRICE_PATH; private final String minPriceUrl = L_Y_BASE_URL + L_Y_HOTLE_MIN_PRICE_PATH; @@ -69,6 +82,7 @@ public class LYTest { Result post = postRequest.post(flyPriceUrl, description, Result.class); System.out.println(post); } + ///查询酒店最小价格 @Test void hotleMinPrice() { @@ -83,23 +97,33 @@ public class LYTest { Result post = postRequest.post(minPriceUrl, description, Result.class); System.out.println(post); } + //火车票最高价查询 @Test void maxPrice() { + String maxPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_TRAIN_MAX_PRICE; TrainMaxPrice trainMaxPrice = new TrainMaxPrice(); trainMaxPrice.setTicketType(0); + LocalDateTime dateTime = LocalDateTime.of(2024, 2, 6, 0, 0); + dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); trainMaxPrice.setDepartDate("2024-02-06"); trainMaxPrice.setDepartCityName("温州"); trainMaxPrice.setArriveCityName("贵阳"); - Description description = new Description(); description.setParam(trainMaxPrice); Result post = postRequest.post(maxPriceUrl, description, Result.class); - System.out.println(post); + Gson gson = new Gson(); + TrainPriceVo trainPriceVo = gson.fromJson(String.valueOf(post.getData()), TrainPriceVo.class); + Map map = trainPriceVo.getDailySeatHigestPrices(); + BigDecimal max = map.values().stream() + .max(BigDecimal::compareTo) + .orElse(BigDecimal.ZERO); + System.out.println(max); } - @Test //外部差旅单同步 - void ApplyOrderSync(){ + @Test + //外部差旅单同步 + void ApplyOrderSync() { AOSParam aosParam = new AOSParam(); aosParam.setOutTravelApplyNo("No000001"); aosParam.setTravelApplyType(1); // 差旅类型,根据实际情况填写 @@ -125,7 +149,7 @@ public class LYTest { AOSItem aosItem = new AOSItem(); aosItem.setStartDate("2021-04-20"); aosItem.setEndDate("2021-04-25"); - aosItem.setDepartCity( "北京"); + aosItem.setDepartCity("北京"); aosItem.setArriveCity("上海"); aosItems.add(aosItem); aosDetail.setItemList(aosItems); // 差旅内容 @@ -176,14 +200,15 @@ public class LYTest { } + @Test - void loadToken(){ + void loadToken() { System.out.println(lyTokenRequest.loadToken()); } @Test - void saveCurrentUser2Ly(){ - // BaseContext.setCurrentUser(user); + void saveCurrentUser2Ly() { + // BaseContext.setCurrentUser(user); BaseContext.setCurrentUser(hxh); System.out.println(lyUserRequest.saveCurrentUser()); } @@ -195,5 +220,4 @@ public class LYTest { } - }