From 11fda4a8806d69f5737bb9696c1cf30792bc4e0b Mon Sep 17 00:00:00 2001 From: dengwc Date: Wed, 27 Mar 2024 16:07:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E7=A8=8B=E7=BB=93=E7=AE=97=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=95=B0=E6=8D=AE=E6=8B=89=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/in/AutoWorkController.java | 14 ++++++- .../order_record/LyStatementOrder.java | 36 ++++++++++++++---- .../repository/jdbc/JdbcLyOrderCarRecord.java | 4 +- .../jdbc/JdbcLyOrderFlightRecord.java | 4 +- .../jdbc/JdbcLyOrderHotelRecord.java | 4 +- .../jdbc/JdbcLyOrderTrainRecord.java | 4 +- src/test/java/com/chint/ExcelTest.java | 37 +++++++++++++------ 7 files changed, 75 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/chint/application/in/AutoWorkController.java b/src/main/java/com/chint/application/in/AutoWorkController.java index 252ccee0..fdb2d8d1 100644 --- a/src/main/java/com/chint/application/in/AutoWorkController.java +++ b/src/main/java/com/chint/application/in/AutoWorkController.java @@ -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 autoSaveCTripRecord(){ + public Result autoSaveCTripRecord() { cTripOrderRecordAutoSave.saveAll(); return Result.Success(SUCCESS); } + @Transactional + @ApiOperation("自动拉取同程上个月的流水号") + @PostMapping("/ly/record/save") + public Result autoSaveLYRecord() { + lyStatementOrder.saveAll(); + return Result.Success(SUCCESS); + } + } diff --git a/src/main/java/com/chint/domain/factoriy/order_record/LyStatementOrder.java b/src/main/java/com/chint/domain/factoriy/order_record/LyStatementOrder.java index 076f9c0e..3866ade9 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/LyStatementOrder.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/LyStatementOrder.java @@ -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 statementOrderList = flightStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderFlightRecord.queryOrderSerialNo(beginDate, endDate); + List orderSerialNoList = jdbcLyOrderFlightRecord.queryBillOrderNo(beginDate, endDate); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class); jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords); @@ -116,10 +135,10 @@ public class LyStatementOrder { //保存数据 List statementOrderList = hotelStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderHotelRecord.queryOrderSerialNo(beginDate, endDate); + List orderSerialNoList = jdbcLyOrderHotelRecord.queryBillOrderNo(beginDate, endDate); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class); jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords); @@ -140,10 +159,10 @@ public class LyStatementOrder { //保存数据 List statementOrderList = trainStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderTrainRecord.queryOrderSerialNo(beginDate, endDate); + List orderSerialNoList = jdbcLyOrderTrainRecord.queryBillOrderNo(beginDate, endDate); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class); jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords); @@ -165,10 +184,10 @@ public class LyStatementOrder { //保存数据 List statementOrderList = carStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderCarRecord.queryOrderSerialNo(beginDate, endDate); + List orderSerialNoList = jdbcLyOrderCarRecord.queryBillOrderNo(beginDate, endDate); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List lyOrderCarRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderCarRecord.class); jdbcLyOrderCarRecord.saveAll(lyOrderCarRecords); @@ -176,4 +195,5 @@ public class LyStatementOrder { } while (carCount < carPageCount); } + } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderCarRecord.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderCarRecord.java index bfa30235..757b69de 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderCarRecord.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderCarRecord.java @@ -11,6 +11,6 @@ import java.util.List; @Repository public interface JdbcLyOrderCarRecord extends CrudRepository { - @Query(value = "SELECT order_serial_no FROM ly_order_car_record WHERE enter_account BETWEEN :beginDate AND :endDate") - List 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 queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderFlightRecord.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderFlightRecord.java index 87f46b38..ad9e1b83 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderFlightRecord.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderFlightRecord.java @@ -13,6 +13,6 @@ import java.util.List; @Repository public interface JdbcLyOrderFlightRecord extends CrudRepository { - @Query(value = "SELECT order_serial_no FROM ly_order_flight_record WHERE enter_account BETWEEN :beginDate AND :endDate") - List 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 queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderHotelRecord.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderHotelRecord.java index d1f9a5a3..e9c62fca 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderHotelRecord.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderHotelRecord.java @@ -12,6 +12,6 @@ import java.util.List; @Repository public interface JdbcLyOrderHotelRecord extends CrudRepository { - @Query(value = "SELECT order_serial_no FROM ly_order_hotel_record WHERE enter_account BETWEEN :beginDate AND :endDate") - List 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 queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderTrainRecord.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderTrainRecord.java index 79b7db8f..8bc7b8cb 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderTrainRecord.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcLyOrderTrainRecord.java @@ -12,6 +12,6 @@ import java.util.List; @Repository public interface JdbcLyOrderTrainRecord extends CrudRepository { - @Query(value = "SELECT order_serial_no FROM ly_order_train_record WHERE enter_account BETWEEN :beginDate AND :endDate") - List 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 queryBillOrderNo(@Param("beginDate") String beginDate, @Param("endDate") String endDate); } diff --git a/src/test/java/com/chint/ExcelTest.java b/src/test/java/com/chint/ExcelTest.java index 2e1d4790..8ff9b578 100644 --- a/src/test/java/com/chint/ExcelTest.java +++ b/src/test/java/com/chint/ExcelTest.java @@ -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 onlineStatementList = resStatementList.getData().getOnlineStatementList(); for (ResStatementList.OnlineStatementList onlineStatement : onlineStatementList) { String statementCode = onlineStatement.getStatementCode();//对账单编码 @@ -516,10 +517,10 @@ public class ExcelTest { //保存数据 List statementOrderList = flightStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderFlightRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); + List orderSerialNoList = jdbcLyOrderFlightRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List lyOrderFlightRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderFlightRecord.class); jdbcLyOrderFlightRecord.saveAll(lyOrderFlightRecords); @@ -536,10 +537,10 @@ public class ExcelTest { //保存数据 List statementOrderList = hotelStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderHotelRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); + List orderSerialNoList = jdbcLyOrderHotelRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List lyOrderHotelRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderHotelRecord.class); jdbcLyOrderHotelRecord.saveAll(lyOrderHotelRecords); @@ -556,10 +557,10 @@ public class ExcelTest { //保存数据 List statementOrderList = trainStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderTrainRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); + List orderSerialNoList = jdbcLyOrderTrainRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List lyOrderTrainRecords = BeanCopyUtils.copyBeanList(statementOrderListNew, LyOrderTrainRecord.class); jdbcLyOrderTrainRecord.saveAll(lyOrderTrainRecords); @@ -577,10 +578,10 @@ public class ExcelTest { //保存数据 List statementOrderList = carStatement.getData().getStatementOrderList(); //查询已经保存的数据 - List orderSerialNoList = jdbcLyOrderCarRecord.queryOrderSerialNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); + List orderSerialNoList = jdbcLyOrderCarRecord.queryBillOrderNo("2024-03-01 00:00:00", "2024-03-26 23:00:00"); //过滤出已经保存的数据 List statementOrderListNew = statementOrderList.stream().filter(o -> - !orderSerialNoList.contains(o.getOrderSerialNo()) + !orderSerialNoList.contains(o.getBillOrderNo()) ).toList(); List 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); + + + } }