Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
lulz1 2024-02-06 07:59:30 +08:00
commit 4b6aa38719
7 changed files with 213 additions and 22 deletions

View File

@ -1,7 +1,10 @@
package com.chint.application.out; package com.chint.application.out;
import com.chint.application.services.SupplierLoginService;
import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -12,10 +15,14 @@ import static com.chint.infrastructure.constant.Constant.SUCCESS;
@RequestMapping("/supplier") @RequestMapping("/supplier")
public class SupplierLoginController { public class SupplierLoginController {
@Autowired
private SupplierLoginService supplierLoginService;
@PostMapping("/ly/login") @PostMapping("/ly/login")
public Result<String> lyLogin() { public Result<LYRedirectUrlResponse> lyLogin() {
return Result.Success(SUCCESS); //登录
LYRedirectUrlResponse data = supplierLoginService.lyLogin();
return Result.Success(SUCCESS,data);
} }
@PostMapping("/CTrip/login") @PostMapping("/CTrip/login")

View File

@ -0,0 +1,22 @@
package com.chint.application.services;
import com.chint.interfaces.rest.ly.LYLoginRequest;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.chint.infrastructure.constant.Constant.L_Y_ENTRANCE_HOME;
@Service
public class SupplierLoginService {
@Autowired
private LYLoginRequest lyLoginRequest;
/**
* 登录接口
*/
public LYRedirectUrlResponse lyLogin() {
return lyLoginRequest.login(L_Y_ENTRANCE_HOME);
}
}

View File

@ -2,19 +2,124 @@ package com.chint.domain.service.amount_estimate;
import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.RouteOrder; 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.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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Map;
import static com.chint.infrastructure.constant.Constant.*;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_NOT_ORDERED_NAME;
@Component @Component
public class LYEstimate implements AmountEstimate { public class LYEstimate implements AmountEstimate {
@Autowired
private LYPostRequest postRequest;
@Override @Override
public String amountEstimate(Leg leg) { 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 @Override
public String amountEstimate(RouteOrder routeOrder) { 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<TrainMaxPrice> 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<String, BigDecimal> map = trainPriceVo.getDailySeatHigestPrices();
//取最大金额
BigDecimal maxPrice = map.values().stream()
.max(BigDecimal::compareTo)
.orElse(BigDecimal.ZERO);
return maxPrice.toString();
}
/**
* 飞机票价格
*/
public String ticketNewPrice(Leg leg) {
//地址
String flyPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_FLY_PRICE;
TicketNewPrice ticketNewPrice = new TicketNewPrice();
ticketNewPrice.setOrderSerialNo("");
Description<TicketNewPrice> description = new Description<TicketNewPrice>();
description.setParam(ticketNewPrice);
Result post = postRequest.post(flyPriceUrl, description, Result.class);
return "";
}
/**
* 查询酒店价格
*/
public String hotelMinPrice(Leg leg) {
//1.查询附近酒店
ArrayList<String> hotelCodes = new ArrayList<>();
hotelCodes.add("114");//添加酒店一次最多50个
//2.查询酒店价格
String minPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_HOTEL_MIN_PRICE;
HotleMinPrice hotleMinPrice = new HotleMinPrice();
hotleMinPrice.setBeginDate(leg.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//开始时间
hotleMinPrice.setEndDate(leg.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//结束时间
hotleMinPrice.setHotelIdList(hotelCodes);//添加酒店
Description<HotleMinPrice> description = new Description<>();
description.setParam(hotleMinPrice);
Result post = postRequest.post(minPriceUrl, description, Result.class);
return "";
}
/**
* 出租车默认为"0.00"
*/
public String taxi(Leg leg) {
return KEEP_TWO_DECIMAL_ZERO;
}
} }

View File

@ -172,10 +172,12 @@ public class Constant {
public static final Integer L_Y_TRAVEL_TYPE_PERSON = 1; // (因公) public static final Integer L_Y_TRAVEL_TYPE_PERSON = 1; // (因公)
public static final Integer L_Y_TRAVEL_TYPE_NO_PERSON = 2; // (因私) public static final Integer L_Y_TRAVEL_TYPE_NO_PERSON = 2; // (因私)
public static final String L_Y_TRAIN_MAX_PRICE = "/openapi/api/Train/TrainHighPirceSearchByCityName";//火车票价格查询
public static final String L_Y_FLY_PRICE = "/openapi/api/DomesticFlight/CheckFlightOrderBookableStatus";//飞机表估算价格
public static final String L_Y_HOTEL_List = "/openapi/api/Hotel/GetHotelCityList"; //酒店城市列表
public static final String L_Y_HOTEL_MIN_PRICE = "/openapi/api/Hotel/GetHotelMinPrice";//酒店估算价格
// status // status
public static final int STATUS_DISABLED = 0; public static final int STATUS_DISABLED = 0;

View File

@ -0,0 +1,10 @@
package com.chint.interfaces.rest.ly.dto.estimateprice;
import lombok.Data;
@Data
public class HotelCityList {
private String keyword;//城市名
private Integer type;//1.国内 2.国际 3.都返回
}

View File

@ -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<String, BigDecimal> dailySeatHigestPrices;
}

View File

@ -1,6 +1,8 @@
package com.chint; package com.chint;
import com.alibaba.fastjson2.JSON;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.constant.Constant;
import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ly.LYLoginRequest; import com.chint.interfaces.rest.ly.LYLoginRequest;
import com.chint.interfaces.rest.ly.LYPostRequest; import com.chint.interfaces.rest.ly.LYPostRequest;
@ -8,17 +10,25 @@ import com.chint.interfaces.rest.ly.LYTokenRequest;
import com.chint.interfaces.rest.ly.LYUserRequest; import com.chint.interfaces.rest.ly.LYUserRequest;
import com.chint.interfaces.rest.ly.dto.applyordersync.*; import com.chint.interfaces.rest.ly.dto.applyordersync.*;
import com.chint.interfaces.rest.ly.dto.commonresult.Result; 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.*;
import com.chint.interfaces.rest.ly.dto.estimateprice.HotleMinPrice; import com.chint.interfaces.rest.ly.vo.estimateprice.TrainPriceVo;
import com.chint.interfaces.rest.ly.dto.estimateprice.TicketNewPrice; import com.google.gson.Gson;
import com.chint.interfaces.rest.ly.dto.estimateprice.TrainMaxPrice; import com.google.gson.internal.LinkedTreeMap;
import com.google.gson.reflect.TypeToken;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; 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.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 @SpringBootTest
public class LYTest { public class LYTest {
@ -62,6 +72,7 @@ public class LYTest {
//机票订单最新价格校验 //机票订单最新价格校验
@Test @Test
void ticketNewPrice() { void ticketNewPrice() {
String flyPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_FLY_PRICE;
TicketNewPrice ticketNewPrice = new TicketNewPrice(); TicketNewPrice ticketNewPrice = new TicketNewPrice();
ticketNewPrice.setOrderSerialNo(""); ticketNewPrice.setOrderSerialNo("");
Description<TicketNewPrice> description = new Description<TicketNewPrice>(); Description<TicketNewPrice> description = new Description<TicketNewPrice>();
@ -69,36 +80,57 @@ public class LYTest {
Result post = postRequest.post(flyPriceUrl, description, Result.class); Result post = postRequest.post(flyPriceUrl, description, Result.class);
System.out.println(post); System.out.println(post);
} }
///查询酒店最小价格 ///查询酒店最小价格
@Test @Test
void hotleMinPrice() { void hotleMinPrice() {
String HotelListUrl = Constant.L_Y_BASE_URL + Constant.L_Y_HOTEL_List;
HotelCityList hotelCityList = new HotelCityList();
hotelCityList.setKeyword("广州");
hotelCityList.setType(1);
Description<HotelCityList> HotelRequest = new Description<>();
HotelRequest.setParam(hotelCityList);
Result result = postRequest.post(HotelListUrl, HotelRequest, Result.class);
System.out.println("result = " + result);
String minPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_HOTEL_MIN_PRICE;
HotleMinPrice hotleMinPrice = new HotleMinPrice(); HotleMinPrice hotleMinPrice = new HotleMinPrice();
hotleMinPrice.setBeginDate("2024-02-04"); hotleMinPrice.setBeginDate("2024-02-04");
hotleMinPrice.setEndDate("2024-02-05"); hotleMinPrice.setEndDate("2024-02-05");
ArrayList<String> strings = new ArrayList<>(); ArrayList<String> strings = new ArrayList<>();
strings.add("114"); strings.add("114");
hotleMinPrice.setHotelIdList(strings); hotleMinPrice.setHotelIdList(strings);
Description<HotleMinPrice> description = new Description<HotleMinPrice>(); Description<HotleMinPrice> description = new Description<>();
description.setParam(hotleMinPrice); description.setParam(hotleMinPrice);
Result post = postRequest.post(minPriceUrl, description, Result.class); Result post = postRequest.post(minPriceUrl, description, Result.class);
System.out.println(post); System.out.println(post);
} }
//火车票最高价查询 //火车票最高价查询
@Test @Test
void maxPrice() { void maxPrice() {
String maxPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_TRAIN_MAX_PRICE;
TrainMaxPrice trainMaxPrice = new TrainMaxPrice(); TrainMaxPrice trainMaxPrice = new TrainMaxPrice();
trainMaxPrice.setTicketType(0); 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.setDepartDate("2024-02-06");
trainMaxPrice.setDepartCityName("温州"); trainMaxPrice.setDepartCityName("温州");
trainMaxPrice.setArriveCityName("贵阳"); trainMaxPrice.setArriveCityName("贵阳");
Description<TrainMaxPrice> description = new Description<TrainMaxPrice>(); Description<TrainMaxPrice> description = new Description<TrainMaxPrice>();
description.setParam(trainMaxPrice); description.setParam(trainMaxPrice);
Result post = postRequest.post(maxPriceUrl, description, Result.class); 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<String, BigDecimal> map = trainPriceVo.getDailySeatHigestPrices();
BigDecimal max = map.values().stream()
.max(BigDecimal::compareTo)
.orElse(BigDecimal.ZERO);
System.out.println(max);
} }
@Test //外部差旅单同步 @Test
//外部差旅单同步
void ApplyOrderSync() { void ApplyOrderSync() {
AOSParam aosParam = new AOSParam(); AOSParam aosParam = new AOSParam();
aosParam.setOutTravelApplyNo("No000001"); aosParam.setOutTravelApplyNo("No000001");
@ -176,6 +208,7 @@ public class LYTest {
} }
@Test @Test
void loadToken() { void loadToken() {
System.out.println(lyTokenRequest.loadToken()); System.out.println(lyTokenRequest.loadToken());
@ -195,5 +228,4 @@ public class LYTest {
} }
} }