同程结算接口数据拉取

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;
import com.chint.domain.factoriy.order_record.LyStatementOrder;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.order.CTripOrderRecordAutoSave;
import io.swagger.annotations.ApiOperation;
@ -20,14 +21,25 @@ public class AutoWorkController {
@Autowired
private CTripOrderRecordAutoSave cTripOrderRecordAutoSave;
@Autowired
private LyStatementOrder lyStatementOrder;
@Transactional
@ApiOperation("自动拉取携程昨天的流水号每天晚上8点执行")
@PostMapping("/cTrip/record/save")
public Result<String> autoSaveCTripRecord(){
public Result<String> autoSaveCTripRecord() {
cTripOrderRecordAutoSave.saveAll();
return Result.Success(SUCCESS);
}
@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.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@ -45,6 +47,23 @@ public class LyStatementOrder {
@Autowired
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<String> orderSerialNoList = jdbcLyOrderFlightRecord.queryOrderSerialNo(beginDate, endDate);
List<String> orderSerialNoList = jdbcLyOrderFlightRecord.queryBillOrderNo(beginDate, endDate);
//过滤出已经保存的数据
List<FlightStatement.StatementOrderList> statementOrderListNew = statementOrderList.stream().filter(o ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderFlightRecord> lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class);
jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords);
@ -116,10 +135,10 @@ public class LyStatementOrder {
//保存数据
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 ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderHotelRecord> lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class);
jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords);
@ -140,10 +159,10 @@ public class LyStatementOrder {
//保存数据
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 ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderTrainRecord> lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class);
jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords);
@ -165,10 +184,10 @@ public class LyStatementOrder {
//保存数据
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 ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderCarRecord> lyOrderCarRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderCarRecord.class);
jdbcLyOrderCarRecord.saveAll(lyOrderCarRecords);
@ -176,4 +195,5 @@ public class LyStatementOrder {
} while (carCount < carPageCount);
}
}

View File

@ -11,6 +11,6 @@ import java.util.List;
@Repository
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")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
@Query(value = "SELECT bill_order_no FROM ly_order_car_record WHERE enter_account BETWEEN :beginDate AND :endDate")
List<String> queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
}

View File

@ -13,6 +13,6 @@ import java.util.List;
@Repository
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")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
@Query(value = "SELECT bill_order_no FROM ly_order_flight_record WHERE enter_account BETWEEN :beginDate AND :endDate")
List<String> queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
}

View File

@ -12,6 +12,6 @@ import java.util.List;
@Repository
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")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
@Query(value = "SELECT bill_order_no FROM ly_order_hotel_record WHERE enter_account BETWEEN :beginDate AND :endDate")
List<String> queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
}

View File

@ -12,6 +12,6 @@ import java.util.List;
@Repository
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")
List<String> queryOrderSerialNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
@Query(value = "SELECT bill_order_no FROM ly_order_train_record WHERE enter_account BETWEEN :beginDate AND :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.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -491,16 +492,16 @@ public class ExcelTest {
@Autowired
private JdbcLyOrderCarRecord jdbcLyOrderCarRecord;
// @Test
@Test
void statementTest() {
StatementPageList param = new StatementPageList();
param.setPageIndex(1)
.setPageSize(10)
.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);
ResStatementList resStatementList = reqStatement.queryStatementList(statementList);
log.info("resStatementList: {}",resStatementList);
log.info("resStatementList: {}", resStatementList);
ArrayList<ResStatementList.OnlineStatementList> onlineStatementList = resStatementList.getData().getOnlineStatementList();
for (ResStatementList.OnlineStatementList onlineStatement : onlineStatementList) {
String statementCode = onlineStatement.getStatementCode();//对账单编码
@ -516,10 +517,10 @@ public class ExcelTest {
//保存数据
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 ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderFlightRecord> lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class);
jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords);
@ -536,10 +537,10 @@ public class ExcelTest {
//保存数据
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 ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderHotelRecord> lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class);
jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords);
@ -556,10 +557,10 @@ public class ExcelTest {
//保存数据
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 ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderTrainRecord> lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class);
jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords);
@ -577,10 +578,10 @@ public class ExcelTest {
//保存数据
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 ->
!orderSerialNoList.contains(o.getOrderSerialNo())
!orderSerialNoList.contains(o.getBillOrderNo())
).toList();
List<LyOrderCarRecord> lyOrderCarRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderCarRecord.class);
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);
}
}