完成携程按月拉去结算流水接口

This commit is contained in:
Superdandan 2024-04-01 22:13:31 +08:00
parent bc11e0a9c9
commit 814064918e
6 changed files with 136 additions and 114 deletions

View File

@ -1,10 +1,7 @@
package com.chint.application.commands;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -15,4 +12,13 @@ public class OrderRecordGenerateCommand extends Command {
//将昨天的结算数据生成为财务共享需要的数据
private LocalDateTime startTime = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIDNIGHT);
private LocalDateTime endTime = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MAX);
public OrderRecordGenerateCommand startTime(LocalDateTime startTime) {
this.setStartTime(startTime);
return this;
}
public OrderRecordGenerateCommand endTime(LocalDateTime endTime) {
this.setEndTime(endTime);
return this;
}
}

View File

@ -7,6 +7,7 @@ import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.application.commands.OrderRecordGenerateCommand;
import com.chint.domain.factoriy.order_record.LyStatementOrder;
import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.util.DateTimeUtil;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.order.CTripOrderRecordAutoSave;
import io.swagger.annotations.ApiOperation;
@ -51,9 +52,13 @@ public class AutoWorkController {
@ApiOperation("拉取按月份的携程流水")
@PostMapping("/cTrip/record/save/month")
public Result<String> autoSaveCTripRecordByMonth(@RequestBody CTripRecordMonthSaveDTO cTripRecordMonthSaveDTO) {
cTripOrderRecordAutoSave.saveAll();
String date = cTripRecordMonthSaveDTO.getDate();
cTripOrderRecordAutoSave.saveAllByDate(date);
//将昨天的结算数据生成为财务共享需要的数据
Command.of(OrderRecordGenerateCommand.class).sendToQueue();
Command.of(OrderRecordGenerateCommand.class)
.startTime(DateTimeUtil.firstDayOfMonth(date))
.endTime(DateTimeUtil.endDayOfMonth(date))
.sendToQueue();
return Result.Success(SUCCESS);
}

View File

@ -1,20 +1,35 @@
package com.chint.infrastructure.util;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
public class DateTimeUtil {
private final static DateTimeFormatter formatterMM = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private final static DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private final static DateTimeFormatter formatterDateYYYYMM = DateTimeFormatter.ofPattern("yyyyMM");
private final static DateTimeFormatter formatterDateYYYYMMDD = DateTimeFormatter.ofPattern("yyyyMMdd");
public static String timeToStr(LocalDateTime input) {
return input.format(formatterDate);
}
public static String timeToStrYYYYMM(LocalDateTime input) {
return input.format(formatterDateYYYYMM);
}
public static DateTimeFormatter formatterDateYYYYMM() {
return formatterDateYYYYMM;
}
public static String timeToStrYYYYMMDD(LocalDateTime input) {
return input.format(formatterDateYYYYMMDD);
}
public static LocalDateTime strToTime(String input) {
return LocalDateTime.parse(input.substring(0, 19), formatter);
}
@ -22,4 +37,20 @@ public class DateTimeUtil {
public static LocalDateTime strToTimeMM(String input) {
return LocalDateTime.parse(input.substring(0, 23), formatterMM);
}
public static LocalDateTime firstDayOfMonth(String input) {
// 解析年份和月份
YearMonth yearMonth = YearMonth.parse(input, formatterDateYYYYMM);
// 获取月份的第一天和最后一天
return yearMonth.atDay(1).atStartOfDay();
}
public static LocalDateTime endDayOfMonth(String input) {
// 解析年份和月份
YearMonth yearMonth = YearMonth.parse(input, formatterDateYYYYMM);
// 获取月份的第一天和最后一天
return yearMonth.atEndOfMonth().atTime(23, 59, 59);
}
}

View File

@ -4,7 +4,7 @@ import com.chint.interfaces.rest.ctrip.dto.Authentification;
import lombok.Data;
@Data
public class OrderFlightParam {
public class OrderRecordParam {
private String AppKey;
private String Ticket;
@ -25,18 +25,18 @@ public class OrderFlightParam {
private Integer pageSize;
private String[] subBatchNoList;
// public static OrderFlightParam of(String requestId, String locale) {
// OrderFlightParam countryParam = new OrderFlightParam();
// public static OrderRecordParam of(String requestId, String locale) {
// OrderRecordParam countryParam = new OrderRecordParam();
// countryParam.requestId = requestId;
// countryParam.locale = locale;
// return countryParam;
// }
public static OrderFlightParam of (String accountId,
public static OrderRecordParam of (String accountId,
String dateFrom,
String dateTo,
String batchNo) {
OrderFlightParam countryParam = new OrderFlightParam();
OrderRecordParam countryParam = new OrderRecordParam();
countryParam.accountid = accountId;
countryParam.datefrom = dateFrom;
@ -54,7 +54,7 @@ public class OrderFlightParam {
return countryParam;
}
public OrderFlightParam auth(Authentification authentification) {
public OrderRecordParam auth(Authentification authentification) {
this.auth = authentification;
return this;
}
@ -64,7 +64,7 @@ public class OrderFlightParam {
return accountid;
}
public OrderFlightParam setAccountId(String accountId) {
public OrderRecordParam setAccountId(String accountId) {
this.accountid = accountId;
return this;
}
@ -73,7 +73,7 @@ public class OrderFlightParam {
return datefrom;
}
public OrderFlightParam setDateFrom(String dateFrom) {
public OrderRecordParam setDateFrom(String dateFrom) {
this.datefrom = dateFrom;
return this;
}
@ -82,7 +82,7 @@ public class OrderFlightParam {
return dateto;
}
public OrderFlightParam setDateTo(String dateTo) {
public OrderRecordParam setDateTo(String dateTo) {
this.dateto = dateTo;
return this;
}
@ -91,7 +91,7 @@ public class OrderFlightParam {
return batchno;
}
public OrderFlightParam setBatchNo(String batchNo) {
public OrderRecordParam setBatchNo(String batchNo) {
this.batchno = batchNo;
return this;
}
@ -100,7 +100,7 @@ public class OrderFlightParam {
return recordId;
}
public OrderFlightParam setRecordId(String recordId) {
public OrderRecordParam setRecordId(String recordId) {
this.recordId = recordId;
return this;
}
@ -109,7 +109,7 @@ public class OrderFlightParam {
return orderId;
}
public OrderFlightParam setOrderId(String orderId) {
public OrderRecordParam setOrderId(String orderId) {
this.orderId = orderId;
return this;
}
@ -118,7 +118,7 @@ public class OrderFlightParam {
return isCompensation;
}
public OrderFlightParam setCompensation(Boolean compensation) {
public OrderRecordParam setCompensation(Boolean compensation) {
isCompensation = compensation;
return this;
}
@ -127,7 +127,7 @@ public class OrderFlightParam {
return payType;
}
public OrderFlightParam setPayType(String payType) {
public OrderRecordParam setPayType(String payType) {
this.payType = payType;
return this;
}
@ -136,7 +136,7 @@ public class OrderFlightParam {
return pageIndex;
}
public OrderFlightParam setPageIndex(Integer pageIndex) {
public OrderRecordParam setPageIndex(Integer pageIndex) {
this.pageIndex = pageIndex;
return this;
}
@ -145,7 +145,7 @@ public class OrderFlightParam {
return pageSize;
}
public OrderFlightParam setPageSize(Integer pageSize) {
public OrderRecordParam setPageSize(Integer pageSize) {
this.pageSize = pageSize;
return this;
}
@ -154,7 +154,7 @@ public class OrderFlightParam {
return subBatchNoList;
}
public OrderFlightParam setSubBatchNoList(String[] subBatchNoList) {
public OrderRecordParam setSubBatchNoList(String[] subBatchNoList) {
this.subBatchNoList = subBatchNoList;
return this;
}
@ -163,7 +163,7 @@ public class OrderFlightParam {
return journeyNoList;
}
public OrderFlightParam setJourneyNoList(String[] journeyNoList) {
public OrderRecordParam setJourneyNoList(String[] journeyNoList) {
this.journeyNoList = journeyNoList;
return this;
}

View File

@ -1,5 +1,6 @@
package com.chint.interfaces.rest.ctrip.order;
import com.chint.infrastructure.util.DateTimeUtil;
import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.ctrip.CTripTicketRequest;
import com.chint.interfaces.rest.ctrip.dto.Authentification;
@ -8,10 +9,8 @@ import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@ -49,6 +48,8 @@ public class CTripOrderDetailRequest {
private String carOrderUrl;
private DateTimeFormatter formatter =
@PostConstruct
private void init() {
this.flightOrderUrl = C_TRIP_BASE_URL + C_TRIP_ORDER_FLIGHT_PATH;
@ -58,67 +59,43 @@ public class CTripOrderDetailRequest {
}
public OrderFlightResponse getFlightOrder() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1L);
return getFlightOrder(formatter.format(localDateTime), formatter.format(localDateTime));
}
public OrderFlightResponse getFlightOrder(String dateFrom,String dateTo){
String substring = dateFrom.substring(0, 6);
String dateFromNew = substring + "01";
String batchNo = C_TRIP_CORP_ID + "_" + C_TRIP_ACCOUNT_ID + "_" + dateFromNew;
OrderFlightParam orderFlightParam = OrderFlightParam.of(
C_TRIP_ACCOUNT_ID,
dateFrom,
dateTo,
batchNo
);
orderFlightParam.auth(Authentification.midOf(C_TRIP_APP_KEY, ticketRequest.loadTicket()));
orderFlightParam.setAppKey(C_TRIP_APP_KEY);
orderFlightParam.setTicket(ticketRequest.loadTicket());
OrderFlightResponse orderFlightResponse = postRequest.post(flightOrderUrl, orderFlightParam,
OrderFlightResponse.class);
return orderFlightResponse;
public OrderFlightResponse getFlightOrderByDate(String date) {
return getFlightOrder(DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.firstDayOfMonth(date)),
DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.endDayOfMonth(date)));
}
public OrderFlightResponse getFlightOrder(String dateFrom, String dateTo) {
return postRequest.post(flightOrderUrl, getParamByDateFromAndDateTo(dateFrom, dateTo),
OrderFlightResponse.class);
}
public OrderHotelResponse getHotelOrderByDate(String date) {
return getHotelOrder(DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.firstDayOfMonth(date)),
DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.endDayOfMonth(date)));
}
public OrderHotelResponse getHotelOrder() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1L);
return getHotelOrder(formatter.format(localDateTime), formatter.format(localDateTime));
}
public OrderHotelResponse getHotelOrder( String dateFrom, String dateTo){
String substring = dateFrom.substring(0, 6);
String dateFromNew = substring + "01";
String batchNo = C_TRIP_CORP_ID + "_" + C_TRIP_ACCOUNT_ID + "_" + dateFromNew;
OrderFlightParam orderFlightParam = OrderFlightParam.of(
C_TRIP_ACCOUNT_ID,
dateFrom,
dateTo,
batchNo
);
orderFlightParam.auth(Authentification.midOf(C_TRIP_APP_KEY, ticketRequest.loadTicket()));
orderFlightParam.setAppKey(C_TRIP_APP_KEY);
orderFlightParam.setTicket(ticketRequest.loadTicket());
OrderHotelResponse orderFlightResponse = postRequest.post(hotelOrderUrl, orderFlightParam,
public OrderHotelResponse getHotelOrder(String dateFrom, String dateTo) {
return postRequest.post(hotelOrderUrl, getParamByDateFromAndDateTo(dateFrom, dateTo),
OrderHotelResponse.class);
return orderFlightResponse;
}
public OrderTrainResponse getTrainOrderByDate(String date) {
return getTrainOrder(DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.firstDayOfMonth(date)),
DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.endDayOfMonth(date)));
}
public OrderTrainResponse getTrainOrder() {
@ -126,57 +103,41 @@ public class CTripOrderDetailRequest {
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1L);
return getTrainOrder(formatter.format(localDateTime), formatter.format(localDateTime));
}
public OrderTrainResponse getTrainOrder(String dateFrom, String dateTo){
String substring = dateFrom.substring(0, 6);
String dateFromNew = substring + "01";
String batchNo = C_TRIP_CORP_ID + "_" + C_TRIP_ACCOUNT_ID + "_" + dateFromNew;
OrderFlightParam orderFlightParam = OrderFlightParam.of(
C_TRIP_ACCOUNT_ID,
dateFrom,
dateTo,
batchNo
);
orderFlightParam.auth(Authentification.midOf(C_TRIP_APP_KEY, ticketRequest.loadTicket()));
orderFlightParam.setAppKey(C_TRIP_APP_KEY);
orderFlightParam.setTicket(ticketRequest.loadTicket());
OrderTrainResponse orderTrainResponse = postRequest.post(trainOrderUrl, orderFlightParam,
public OrderTrainResponse getTrainOrder(String dateFrom, String dateTo) {
return postRequest.post(trainOrderUrl, getParamByDateFromAndDateTo(dateFrom, dateTo),
OrderTrainResponse.class);
return orderTrainResponse;
}
public OrderCarResponse getCarOrderByDate(String date) {
return getCarOrder(DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.firstDayOfMonth(date)),
DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.endDayOfMonth(date)));
}
public OrderCarResponse getCarOrder() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1L);
return getCarOrder(formatter.format(localDateTime), formatter.format(localDateTime));
}
public OrderCarResponse getCarOrder(String dateFrom, String dateTo){
public OrderCarResponse getCarOrder(String dateFrom, String dateTo) {
return postRequest.post(carOrderUrl, getParamByDateFromAndDateTo(dateFrom, dateTo),
OrderCarResponse.class);
}
private OrderRecordParam getParamByDateFromAndDateTo(String dateFrom, String dateTo) {
String substring = dateFrom.substring(0, 6);
String dateFromNew = substring + "01";
String batchNo = C_TRIP_CORP_ID + "_" + C_TRIP_ACCOUNT_ID + "_" + dateFromNew;
OrderFlightParam orderFlightParam = OrderFlightParam.of(
OrderRecordParam orderFlightParam = OrderRecordParam.of(
C_TRIP_ACCOUNT_ID,
dateFrom,
dateTo,
batchNo
);
orderFlightParam.auth(Authentification.midOf(C_TRIP_APP_KEY, ticketRequest.loadTicket()));
orderFlightParam.setAppKey(C_TRIP_APP_KEY);
orderFlightParam.setTicket(ticketRequest.loadTicket());
OrderCarResponse orderCarResponse = postRequest.post(carOrderUrl, orderFlightParam,
OrderCarResponse.class);
return orderCarResponse;
return orderFlightParam;
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Component
@ -26,18 +27,25 @@ public class CTripOrderRecordAutoSave {
public void saveAll() {
this.cTripFlightRecordAutoSave();
this.cTripHotelRecordAutoSave();
this.cTripTrainRecordAutoSave();
this.cTripCarRecordAutoSave();
this.cTripFlightRecordAutoSave(Optional.empty());
this.cTripHotelRecordAutoSave(Optional.empty());
this.cTripTrainRecordAutoSave(Optional.empty());
this.cTripCarRecordAutoSave(Optional.empty());
}
public void saveByDate(){
public void saveAllByDate(String date) {
this.cTripFlightRecordAutoSave(Optional.of(date));
this.cTripHotelRecordAutoSave(Optional.of(date));
this.cTripTrainRecordAutoSave(Optional.of(date));
this.cTripCarRecordAutoSave(Optional.of(date));
}
public void cTripFlightRecordAutoSave() {
OrderFlightResponse flightOrder = cTripOrderDetailRequest.getFlightOrder();
public void cTripFlightRecordAutoSave(Optional<String> date) {
OrderFlightResponse flightOrder = date
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getFlightOrderByDate(it)))
.orElseGet(() -> cTripOrderDetailRequest.getFlightOrder());
List<OrderFlightResponse.FlightOrderAccountSettlementInfo> flightOrderAccountSettlementList = flightOrder
.getFlightOrderAccountSettlementList();
if (flightOrderAccountSettlementList != null && !flightOrderAccountSettlementList.isEmpty()) {
@ -73,8 +81,12 @@ public class CTripOrderRecordAutoSave {
}
public void cTripHotelRecordAutoSave() {
OrderHotelResponse hotelOrder = cTripOrderDetailRequest.getHotelOrder();
public void cTripHotelRecordAutoSave(Optional<String> date) {
OrderHotelResponse hotelOrder = date
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getHotelOrderByDate(it)))
.orElseGet(() -> cTripOrderDetailRequest.getHotelOrder());
List<OrderHotelResponse.HotelAccountSettlementInfo> lstHtlSettlement = hotelOrder.getLstHtlSettlement();
if (lstHtlSettlement != null && !lstHtlSettlement.isEmpty()) {
List<CTripHotelRecord> list = lstHtlSettlement.stream()
@ -106,8 +118,12 @@ public class CTripOrderRecordAutoSave {
}
public void cTripTrainRecordAutoSave() {
OrderTrainResponse trainOrder = cTripOrderDetailRequest.getTrainOrder();
public void cTripTrainRecordAutoSave(Optional<String> date) {
OrderTrainResponse trainOrder = date
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getTrainOrderByDate(it)))
.orElseGet(() -> cTripOrderDetailRequest.getTrainOrder());
List<OrderTrainResponse.CorpTrainAccountSettlement> lstTrainSettlement = trainOrder.getLstTrainSettlement();
if (lstTrainSettlement != null && !lstTrainSettlement.isEmpty()) {
List<CTripTrainRecord> list = lstTrainSettlement.stream()
@ -133,8 +149,11 @@ public class CTripOrderRecordAutoSave {
}
}
public void cTripCarRecordAutoSave() {
OrderCarResponse carOrder = cTripOrderDetailRequest.getCarOrder();
public void cTripCarRecordAutoSave(Optional<String> date) {
OrderCarResponse carOrder = date
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getCarOrderByDate(it)))
.orElseGet(() -> cTripOrderDetailRequest.getCarOrder());
List<OrderCarResponse.CarOrderAccountSettlementDetail> settlementList = carOrder.getCarOrderAccountSettlementList();
if (settlementList != null && !settlementList.isEmpty()) {
List<CTripCarRecord> list = settlementList.stream()