同程结算接口数据拉取

This commit is contained in:
dengwc 2024-03-27 16:07:08 +08:00
parent 216a41b1fd
commit 11fda4a880
7 changed files with 75 additions and 28 deletions

View File

@ -1,6 +1,7 @@
package com.chint.application.in; package com.chint.application.in;
import com.chint.domain.factoriy.order_record.LyStatementOrder;
import com.chint.infrastructure.util.Result; import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.order.CTripOrderRecordAutoSave; import com.chint.interfaces.rest.ctrip.order.CTripOrderRecordAutoSave;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -20,6 +21,9 @@ public class AutoWorkController {
@Autowired @Autowired
private CTripOrderRecordAutoSave cTripOrderRecordAutoSave; private CTripOrderRecordAutoSave cTripOrderRecordAutoSave;
@Autowired
private LyStatementOrder lyStatementOrder;
@Transactional @Transactional
@ApiOperation("自动拉取携程昨天的流水号每天晚上8点执行") @ApiOperation("自动拉取携程昨天的流水号每天晚上8点执行")
@ -30,4 +34,12 @@ public class AutoWorkController {
} }
@Transactional
@ApiOperation("自动拉取同程上个月的流水号")
@PostMapping("/ly/record/save")
public Result<String> autoSaveLYRecord() {
lyStatementOrder.saveAll();
return Result.Success(SUCCESS);
}
} }

View File

@ -23,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -45,6 +47,23 @@ public class LyStatementOrder {
@Autowired @Autowired
private JdbcLyOrderCarRecord jdbcLyOrderCarRecord; private JdbcLyOrderCarRecord jdbcLyOrderCarRecord;
/**
* 拉取保存数据
*/
@Transactional
public void saveAll() {
LocalDate today = LocalDate.now();
LocalDate firstDayOfLastMonth = today.minusMonths(1).withDayOfMonth(1);
LocalDate lastDayOfLastMonth = today.withDayOfMonth(1).minusDays(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String beginDate = firstDayOfLastMonth.atStartOfDay().format(formatter);
String endDate = lastDayOfLastMonth.atTime(23, 59, 59).format(formatter);
//同步
statementOrder(beginDate, endDate);
}
/** /**
* 同程账单数据拉取 * 同程账单数据拉取
* *
@ -92,10 +111,10 @@ public class LyStatementOrder {
//保存数据 //保存数据
List<FlightStatement.StatementOrderList> statementOrderList = flightStatement.getData().getStatementOrderList(); List<FlightStatement.StatementOrderList> statementOrderList = flightStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderFlightRecord.queryOrderSerialNo(beginDate, endDate); List<String> orderSerialNoList = jdbcLyOrderFlightRecord.queryBillOrderNo(beginDate, endDate);
//过滤出已经保存的数据 //过滤出已经保存的数据
List<FlightStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<FlightStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderFlightRecord> lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class); List<LyOrderFlightRecord> lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class);
jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords); jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords);
@ -116,10 +135,10 @@ public class LyStatementOrder {
//保存数据 //保存数据
List<HotelStatement.StatementOrderList> statementOrderList = hotelStatement.getData().getStatementOrderList(); List<HotelStatement.StatementOrderList> statementOrderList = hotelStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderHotelRecord.queryOrderSerialNo(beginDate, endDate); List<String> orderSerialNoList = jdbcLyOrderHotelRecord.queryBillOrderNo(beginDate, endDate);
//过滤出已经保存的数据 //过滤出已经保存的数据
List<HotelStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<HotelStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderHotelRecord> lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class); List<LyOrderHotelRecord> lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class);
jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords); jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords);
@ -140,10 +159,10 @@ public class LyStatementOrder {
//保存数据 //保存数据
List<TrainStatement.StatementOrderList> statementOrderList = trainStatement.getData().getStatementOrderList(); List<TrainStatement.StatementOrderList> statementOrderList = trainStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderTrainRecord.queryOrderSerialNo(beginDate, endDate); List<String> orderSerialNoList = jdbcLyOrderTrainRecord.queryBillOrderNo(beginDate, endDate);
//过滤出已经保存的数据 //过滤出已经保存的数据
List<TrainStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<TrainStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderTrainRecord> lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class); List<LyOrderTrainRecord> lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class);
jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords); jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords);
@ -165,10 +184,10 @@ public class LyStatementOrder {
//保存数据 //保存数据
List<CarStatement.StatementOrderList> statementOrderList = carStatement.getData().getStatementOrderList(); List<CarStatement.StatementOrderList> statementOrderList = carStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderCarRecord.queryOrderSerialNo(beginDate, endDate); List<String> orderSerialNoList = jdbcLyOrderCarRecord.queryBillOrderNo(beginDate, endDate);
//过滤出已经保存的数据 //过滤出已经保存的数据
List<CarStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<CarStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderCarRecord> lyOrderCarRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderCarRecord.class); List<LyOrderCarRecord> lyOrderCarRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderCarRecord.class);
jdbcLyOrderCarRecord.saveAll(lyOrderCarRecords); jdbcLyOrderCarRecord.saveAll(lyOrderCarRecords);
@ -176,4 +195,5 @@ public class LyStatementOrder {
} while (carCount < carPageCount); } while (carCount < carPageCount);
} }
} }

View File

@ -11,6 +11,6 @@ import java.util.List;
@Repository @Repository
public interface JdbcLyOrderCarRecord extends CrudRepository<LyOrderCarRecord, Long> { public interface JdbcLyOrderCarRecord extends CrudRepository<LyOrderCarRecord, Long> {
@Query(value = "SELECT order_serial_no FROM ly_order_car_record WHERE enter_account BETWEEN :beginDate AND :endDate") @Query(value = "SELECT bill_order_no FROM ly_order_car_record WHERE enter_account BETWEEN :beginDate AND :endDate")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); List<String> queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
} }

View File

@ -13,6 +13,6 @@ import java.util.List;
@Repository @Repository
public interface JdbcLyOrderFlightRecord extends CrudRepository<LyOrderFlightRecord, Long> { public interface JdbcLyOrderFlightRecord extends CrudRepository<LyOrderFlightRecord, Long> {
@Query(value = "SELECT order_serial_no FROM ly_order_flight_record WHERE enter_account BETWEEN :beginDate AND :endDate") @Query(value = "SELECT bill_order_no FROM ly_order_flight_record WHERE enter_account BETWEEN :beginDate AND :endDate")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); List<String> queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
} }

View File

@ -12,6 +12,6 @@ import java.util.List;
@Repository @Repository
public interface JdbcLyOrderHotelRecord extends CrudRepository<LyOrderHotelRecord, Long> { public interface JdbcLyOrderHotelRecord extends CrudRepository<LyOrderHotelRecord, Long> {
@Query(value = "SELECT order_serial_no FROM ly_order_hotel_record WHERE enter_account BETWEEN :beginDate AND :endDate") @Query(value = "SELECT bill_order_no FROM ly_order_hotel_record WHERE enter_account BETWEEN :beginDate AND :endDate")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); List<String> queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
} }

View File

@ -12,6 +12,6 @@ import java.util.List;
@Repository @Repository
public interface JdbcLyOrderTrainRecord extends CrudRepository<LyOrderTrainRecord, Long> { public interface JdbcLyOrderTrainRecord extends CrudRepository<LyOrderTrainRecord, Long> {
@Query(value = "SELECT order_serial_no FROM ly_order_train_record WHERE enter_account BETWEEN :beginDate AND :endDate") @Query(value = "SELECT bill_order_no FROM ly_order_train_record WHERE enter_account BETWEEN :beginDate AND :endDate")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); List<String> queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
} }

View File

@ -63,6 +63,7 @@ import java.io.File;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
@ -491,13 +492,13 @@ public class ExcelTest {
@Autowired @Autowired
private JdbcLyOrderCarRecord jdbcLyOrderCarRecord; private JdbcLyOrderCarRecord jdbcLyOrderCarRecord;
// @Test @Test
void statementTest() { void statementTest() {
StatementPageList param = new StatementPageList(); StatementPageList param = new StatementPageList();
param.setPageIndex(1) param.setPageIndex(1)
.setPageSize(10) .setPageSize(10)
.setBeginDate("2024-03-01 00:00:00")//2024-03-01 00:00:00 .setBeginDate("2024-03-01 00:00:00")//2024-03-01 00:00:00
.setEndDate("2024-03-26 00:00:00"); .setEndDate("2024-03-31 23:59:59");
StatementList statementList = new StatementList(param); StatementList statementList = new StatementList(param);
ResStatementList resStatementList = reqStatement.queryStatementList(statementList); ResStatementList resStatementList = reqStatement.queryStatementList(statementList);
log.info("resStatementList: {}", resStatementList); log.info("resStatementList: {}", resStatementList);
@ -516,10 +517,10 @@ public class ExcelTest {
//保存数据 //保存数据
List<FlightStatement.StatementOrderList> statementOrderList = flightStatement.getData().getStatementOrderList(); List<FlightStatement.StatementOrderList> statementOrderList = flightStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderFlightRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); List<String> orderSerialNoList = jdbcLyOrderFlightRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00");
//过滤出已经保存的数据 //过滤出已经保存的数据
List<FlightStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<FlightStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderFlightRecord> lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class); List<LyOrderFlightRecord> lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class);
jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords); jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords);
@ -536,10 +537,10 @@ public class ExcelTest {
//保存数据 //保存数据
List<HotelStatement.StatementOrderList> statementOrderList = hotelStatement.getData().getStatementOrderList(); List<HotelStatement.StatementOrderList> statementOrderList = hotelStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderHotelRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); List<String> orderSerialNoList = jdbcLyOrderHotelRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00");
//过滤出已经保存的数据 //过滤出已经保存的数据
List<HotelStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<HotelStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderHotelRecord> lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class); List<LyOrderHotelRecord> lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class);
jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords); jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords);
@ -556,10 +557,10 @@ public class ExcelTest {
//保存数据 //保存数据
List<TrainStatement.StatementOrderList> statementOrderList = trainStatement.getData().getStatementOrderList(); List<TrainStatement.StatementOrderList> statementOrderList = trainStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderTrainRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); List<String> orderSerialNoList = jdbcLyOrderTrainRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00");
//过滤出已经保存的数据 //过滤出已经保存的数据
List<TrainStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<TrainStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderTrainRecord> lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class); List<LyOrderTrainRecord> lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class);
jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords); jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords);
@ -577,10 +578,10 @@ public class ExcelTest {
//保存数据 //保存数据
List<CarStatement.StatementOrderList> statementOrderList = carStatement.getData().getStatementOrderList(); List<CarStatement.StatementOrderList> statementOrderList = carStatement.getData().getStatementOrderList();
//查询已经保存的数据 //查询已经保存的数据
List<String> orderSerialNoList = jdbcLyOrderCarRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); List<String> orderSerialNoList = jdbcLyOrderCarRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00");
//过滤出已经保存的数据 //过滤出已经保存的数据
List<CarStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o -> List<CarStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo()) !orderSerialNoList.contains(o.getBillOrderNo())
).toList(); ).toList();
List<LyOrderCarRecord> lyOrderCarRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderCarRecord.class); List<LyOrderCarRecord> lyOrderCarRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderCarRecord.class);
jdbcLyOrderCarRecord.saveAll(lyOrderCarRecords); jdbcLyOrderCarRecord.saveAll(lyOrderCarRecords);
@ -592,5 +593,19 @@ public class ExcelTest {
} }
// @Test
void awwe1() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDate parse = LocalDate.parse("2024-01-04 00:00:00",formatter);
LocalDate firstDayOfLastMonth = parse.minusMonths(1).withDayOfMonth(1);
LocalDate lastDayOfLastMonth = parse.withDayOfMonth(1).minusDays(1);
String beginDate = firstDayOfLastMonth.atStartOfDay().format(formatter);
System.out.println("beginDate = " + beginDate);
String endDate = lastDayOfLastMonth.atTime(23, 59, 59).format(formatter);
System.out.println("endDate = " + endDate);
}
} }