diff --git a/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java b/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java index 3d235ba3..85e2f107 100644 --- a/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java +++ b/src/main/java/com/chint/domain/service/order_sync/LYOrderSyncAdapter.java @@ -1,19 +1,120 @@ package com.chint.domain.service.order_sync; -import com.chint.domain.aggregates.order.Location; +import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.LocationRepository; +import com.chint.infrastructure.constant.Constant; +import com.chint.infrastructure.util.BaseContext; +import com.chint.interfaces.rest.ly.LYPostRequest; +import com.chint.interfaces.rest.ly.dto.applyordersync.*; +import com.chint.interfaces.rest.ly.dto.commonresult.Result; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; + @Component -public class LYOrderSyncAdapter implements SupplierOrderSync { +public class LYOrderSyncAdapter implements SupplierOrderSync { + + @Autowired + private LYPostRequest postRequest; @Autowired private LocationRepository locationRepository; @Override public void syncSupplierOrder(RouteOrder order) { + String supplierOrderSyncUrl = Constant.L_Y_BASE_URL + Constant.L_Y_ORDER_PATH;//请求地址 + //1.设置订单参数 + SupplierOrderParam param = new SupplierOrderParam();//参数 + param.setOutEmployeeIdType(0);//外部员工ID类型,默认为0 + param.setOutTravelApplyNo(order.getApproveOrderNo().getActualOrderNo());//审批订单号 + param.setTravelApplyType(1); //差旅类型:1 普通差旅,2 福利差旅 + param.setStatus(1);//状态:1通过,2作废 + //日期格式化 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + String applyTime = order.getCreateTime().format(formatter); + String updateTime = order.getUpdateTime().format(formatter); + param.setTravelApplyTime(applyTime);//开始(创建)时间 + param.setTravelUpdateTime(updateTime);//最后更新时间 + param.setOperationType(1);//1新增,2更新 + //获取用户信息 + User user = BaseContext.getCurrentUser(); + param.setOutEmployeeId(String.valueOf(user.getUserId()));//用户id + param.setTravelDescription("同程订单");//描述信息 + param.setBookableProducts("1,3,5");//1:国内机票,2:国际机票,3:国内酒店,4:海外酒店,5:火车票,6:用车 + //2.同程的行程节点集合 + ArrayList aosItems = getAosItems(order); + //3.差旅人信息 + ArrayList aosPeople = new ArrayList<>(); + AOSPerson aosPerson = new AOSPerson(); + aosPerson.setName(user.getName());//用户名 + aosPerson.setRelation(0);//0:内部员工,1:配偶,2:子女,3:父母,4:面试候选人,5:实习生,6:外部宾客 + aosPerson.setPassengerType(0);//0:成人, 1:儿童, 2:婴儿 + aosPerson.setOutEmployeeId(String.valueOf(user.getEmployeeNo()));//SF号(长工号) + aosPeople.add(aosPerson); + //4.前置差旅政策 + ArrayList aosPreTravelPolicies = new ArrayList<>(); + AOSPreTravelPolicy aosPreTravelPolicy = new AOSPreTravelPolicy(); + aosPreTravelPolicy.setPolicyCode("");//一般指客户经理提供的差旅政策标题 + aosPreTravelPolicy.setProductTypeId(0);//产品ID 1:国内机票,2:国际机票,3:国内酒店,4:海外酒店,5:火车票,6:用车 + aosPreTravelPolicies.add(aosPreTravelPolicy); + + param.setItemList(aosItems); // 同程节点内容 + param.setPersonList(aosPeople);// 同程信息(实际出行人) + param.setPreTravelPolicyList(aosPreTravelPolicies);// 同程政策 + param.setApproveRuleType(0);//审批规则 + SupplierOrderSyncDto supplierOrderSyncDto = new SupplierOrderSyncDto(); + supplierOrderSyncDto.setParam(param); + Result post = postRequest.post(supplierOrderSyncUrl, supplierOrderSyncDto, Result.class); + System.out.println("post = " + post); System.out.println("开始同步同程订单"); } + + //同程Leg集合解析 + private static ArrayList getAosItems(RouteOrder order) { + ArrayList aosItems = new ArrayList<>(); + AOSItem aosItem = new AOSItem(); + LocalDateTime startDate = LocalDateTime.MAX; + LocalDateTime endDate = LocalDateTime.MIN; + StringBuilder departCityStr = new StringBuilder(); + StringBuilder arriveCityStr = new StringBuilder(); + //提取所有行程节点信息 + List legItems = order.getLegItems(); + for (Leg leg : legItems) { + //开始时间 + LocalDateTime startTime = leg.getStartTime(); + if (startTime.isBefore(startDate)) { + startDate = startTime; + } + //结束时间 + LocalDateTime endTime = leg.getEndTime(); + if (endTime.isAfter(endDate)) { + endDate = endTime; + } + String departCity = leg.getOriginLocation().getLocationName();//出发城市名 + String arriveCity = leg.getDestinationLocation().getLocationName();//到达城市名 + departCityStr.append(departCity).append(","); + arriveCityStr.append(arriveCity).append(","); + + } + // 移除最后一个逗号 + if (!departCityStr.isEmpty()) { + departCityStr.setLength(departCityStr.length() - 1); + } + if (!arriveCityStr.isEmpty()) { + arriveCityStr.setLength(arriveCityStr.length() - 1); + } + aosItem.setStartDate(startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//行程最早时间 + aosItem.setEndDate(endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//行程最晚时间 + aosItem.setDepartCity(String.valueOf(departCityStr));//各行程节点出发城市 + aosItem.setArriveCity(String.valueOf(arriveCityStr));//各行程节点到达城市 + aosItem.setOtherCity("");//其它城市 + aosItems.add(aosItem); + return aosItems; + } } diff --git a/src/main/java/com/chint/infrastructure/constant/Constant.java b/src/main/java/com/chint/infrastructure/constant/Constant.java index e202d6df..dea0b347 100644 --- a/src/main/java/com/chint/infrastructure/constant/Constant.java +++ b/src/main/java/com/chint/infrastructure/constant/Constant.java @@ -165,7 +165,7 @@ public class Constant { //同程 public static final String L_Y_BASE_URL = "https://api.qa.dttrip.cn"; public static final String L_Y_TOKEN_PATH = "/openapi/api/OAuth/v2/GetAccessToken"; - public static final String L_Y_ORDER_PATH = "openapi/api/TravelApplyOrder/ApplyOrderSync"; + public static final String L_Y_ORDER_PATH = "/openapi/api/TravelApplyOrder/ApplyOrderSync"; public static final String L_Y_USER_PATH = "/openapi/api/Employee/SyncEmployeeInfo"; public static final String L_Y_LOGIN_PATH = "/openapi/api/Employee/SSO"; public static final String L_Y_ACCOUNT = "4f9cb1080b564dd0a94aa95f7a19c8b5"; // 测试appkey diff --git a/src/main/java/com/chint/interfaces/rest/ly/dto/applyordersync/SupplierOrderParam.java b/src/main/java/com/chint/interfaces/rest/ly/dto/applyordersync/SupplierOrderParam.java new file mode 100644 index 00000000..b1ab2f4f --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ly/dto/applyordersync/SupplierOrderParam.java @@ -0,0 +1,26 @@ +package com.chint.interfaces.rest.ly.dto.applyordersync; + +import lombok.Data; + + +import java.util.List; + +@Data +public class SupplierOrderParam { + private Integer outEmployeeIdType; //外部人员Id类型 + private String outTravelApplyNo;//外部同程单单号 + private Integer travelApplyType;//同程类型 + private Integer status;//同程单状态 + private String travelApplyTime;//同程单申请时间 + private String travelUpdateTime;//同程单更新时间 + private Integer operationType;//操作类型 + private String outEmployeeId;//外部员工ID(申请人) + private String travelDescription;//同程内容 + private String bookableProducts;//可预订产品 + + private List itemList;//同程内容 + private List personList;//同程人信息(实际出行人) + private List preTravelPolicyList;//前置同程政策 + + private Integer approveRuleType;//审批规则类型 +} diff --git a/src/main/java/com/chint/interfaces/rest/ly/dto/applyordersync/SupplierOrderSyncDto.java b/src/main/java/com/chint/interfaces/rest/ly/dto/applyordersync/SupplierOrderSyncDto.java new file mode 100644 index 00000000..3da889d2 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ly/dto/applyordersync/SupplierOrderSyncDto.java @@ -0,0 +1,9 @@ +package com.chint.interfaces.rest.ly.dto.applyordersync; + +import com.chint.interfaces.rest.ly.dto.LYBaseRequest; +import lombok.Data; + +@Data +public class SupplierOrderSyncDto extends LYBaseRequest { + private SupplierOrderParam param; +} diff --git a/src/main/java/com/chint/interfaces/rest/ly/vo/estimateprice/HotelListVo.java b/src/main/java/com/chint/interfaces/rest/ly/vo/estimateprice/HotelListVo.java new file mode 100644 index 00000000..2263e850 --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/ly/vo/estimateprice/HotelListVo.java @@ -0,0 +1,28 @@ +package com.chint.interfaces.rest.ly.vo.estimateprice; + +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Data +public class HotelListVo { + + private List hotelList; + + @Data + public static class HotelInfo { + private String hotelId; + private List priceList; + + // 构造函数、getter和setter方法 + @Data + public static class PriceInfo { + private LocalDateTime saleDate; + private int paymentType; + private double price; + + // 构造函数、getter和setter方法 + } + } +} diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index 3412471b..5b8eeb7d 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -1,6 +1,6 @@ package com.chint; -import com.alibaba.fastjson2.JSON; +import com.chint.domain.aggregates.base.BaseEntity; import com.chint.domain.aggregates.user.User; import com.chint.infrastructure.constant.Constant; import com.chint.infrastructure.util.BaseContext; @@ -11,21 +11,18 @@ import com.chint.interfaces.rest.ly.LYUserRequest; import com.chint.interfaces.rest.ly.dto.applyordersync.*; import com.chint.interfaces.rest.ly.dto.commonresult.Result; import com.chint.interfaces.rest.ly.dto.estimateprice.*; +import com.chint.interfaces.rest.ly.vo.estimateprice.HotelListVo; 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.List; import java.util.Map; import static com.chint.infrastructure.constant.Constant.*; @@ -74,8 +71,8 @@ public class LYTest { void ticketNewPrice() { String flyPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_FLY_PRICE; TicketNewPrice ticketNewPrice = new TicketNewPrice(); - ticketNewPrice.setOrderSerialNo(""); - Description description = new Description(); + ticketNewPrice.setOrderSerialNo("");//订单号 + Description description = new Description<>(); description.setParam(ticketNewPrice); Result post = postRequest.post(flyPriceUrl, description, Result.class); System.out.println(post); @@ -103,7 +100,8 @@ public class LYTest { Description description = new Description<>(); description.setParam(hotleMinPrice); Result post = postRequest.post(minPriceUrl, description, Result.class); - System.out.println(post); + HotelListVo hotelListVo = new HotelListVo(); + List hotelList = hotelListVo.getHotelList(); } //火车票最高价查询 @@ -209,6 +207,62 @@ public class LYTest { } + //同步同程订单 + @Test + void syncSupplierOrder() { + String supplierOrderSyncUrl = Constant.L_Y_BASE_URL + Constant.L_Y_ORDER_PATH; + SupplierOrderParam param = new SupplierOrderParam(); + param.setOutEmployeeIdType(0); + param.setOutTravelApplyNo("string"); + param.setTravelApplyType(1); //同程类型 + param.setStatus(1); + /* + 时间转换 + LocalDateTime localDateTime = LocalDateTime.of(2024, 2, 6, 12, 57, 33, 6000000); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + String formattedDateTime = localDateTime.format(formatter); + DateTimeFormatter formatter1 = DateTimeFormatter.ISO_DATE_TIME; + LocalDateTime dateTime = LocalDateTime.parse(formattedDateTime, formatter1);*/ + param.setTravelApplyTime("2024-02-05T02:24:49.601Z"); + param.setTravelUpdateTime("2024-02-06T02:24:49.601Z"); + param.setOperationType(1); + param.setOutEmployeeId("string"); + param.setTravelDescription("string"); + param.setBookableProducts("string"); + //行程节点 + ArrayList aosItems = new ArrayList<>(); + AOSItem aosItem = new AOSItem(); + aosItem.setStartDate("2024-02-05");//行程最早时间 + aosItem.setEndDate("2024-02-06");//行程最晚时间 + aosItem.setDepartCity("string"); + aosItem.setArriveCity("HGH"); + aosItem.setOtherCity("string"); + aosItems.add(aosItem); + //差旅人信息 + ArrayList aosPeople = new ArrayList<>(); + AOSPerson aosPerson = new AOSPerson(); + aosPerson.setName("测试"); + aosPerson.setRelation(0); + aosPerson.setPassengerType(0); + aosPerson.setOutEmployeeId("string"); + aosPeople.add(aosPerson); + //同程政策 + ArrayList aosPreTravelPolicies = new ArrayList<>(); + AOSPreTravelPolicy aosPreTravelPolicy = new AOSPreTravelPolicy(); + aosPreTravelPolicy.setPolicyCode("string"); + aosPreTravelPolicy.setProductTypeId(0); + aosPreTravelPolicies.add(aosPreTravelPolicy); + + param.setItemList(aosItems); // 同程节点内容 + param.setPersonList(aosPeople);// 同程信息(实际出行人) + param.setPreTravelPolicyList(aosPreTravelPolicies);// 同程政策 + param.setApproveRuleType(0); + SupplierOrderSyncDto supplierOrderSyncDto = new SupplierOrderSyncDto(); + supplierOrderSyncDto.setParam(param); + Result post = postRequest.post(supplierOrderSyncUrl, supplierOrderSyncDto, Result.class); + System.out.println(post); + } + @Test void loadToken() { System.out.println(lyTokenRequest.loadToken());