From dbaea6f133dddb49d950829da2c4ba3c6ed05bf3 Mon Sep 17 00:00:00 2001 From: Superdandan <1033719135@qq.com> Date: Mon, 1 Apr 2024 22:13:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=90=BA=E7=A8=8B=E6=8C=89?= =?UTF-8?q?=E6=9C=88=E6=8B=89=E5=8E=BB=E7=BB=93=E7=AE=97=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/OrderRecordGenerateCommand.java | 12 +- .../application/in/AutoWorkController.java | 9 +- .../infrastructure/util/DateTimeUtil.java | 35 +++++- ...FlightParam.java => OrderRecordParam.java} | 36 +++--- .../ctrip/order/CTripOrderDetailRequest.java | 111 ++++++------------ .../ctrip/order/CTripOrderRecordAutoSave.java | 47 +++++--- 6 files changed, 136 insertions(+), 114 deletions(-) rename src/main/java/com/chint/interfaces/rest/ctrip/dto/order/{OrderFlightParam.java => OrderRecordParam.java} (75%) diff --git a/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java b/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java index b93f456b..7d7b0390 100644 --- a/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java +++ b/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java @@ -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; + } } diff --git a/src/main/java/com/chint/application/in/AutoWorkController.java b/src/main/java/com/chint/application/in/AutoWorkController.java index 7761a317..26a9da28 100644 --- a/src/main/java/com/chint/application/in/AutoWorkController.java +++ b/src/main/java/com/chint/application/in/AutoWorkController.java @@ -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 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); } diff --git a/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java b/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java index ab1037a8..347d89c2 100644 --- a/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java +++ b/src/main/java/com/chint/infrastructure/util/DateTimeUtil.java @@ -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 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); + } + } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/dto/order/OrderFlightParam.java b/src/main/java/com/chint/interfaces/rest/ctrip/dto/order/OrderRecordParam.java similarity index 75% rename from src/main/java/com/chint/interfaces/rest/ctrip/dto/order/OrderFlightParam.java rename to src/main/java/com/chint/interfaces/rest/ctrip/dto/order/OrderRecordParam.java index 278b5648..64de9e80 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/dto/order/OrderFlightParam.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/dto/order/OrderRecordParam.java @@ -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; } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderDetailRequest.java b/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderDetailRequest.java index 5e613686..7f5ae56f 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderDetailRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderDetailRequest.java @@ -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; } } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java b/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java index cef780fd..8b588697 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/order/CTripOrderRecordAutoSave.java @@ -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 date) { + + OrderFlightResponse flightOrder = date + .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getFlightOrderByDate(it))) + .orElseGet(() -> cTripOrderDetailRequest.getFlightOrder()); + List 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 date) { + + OrderHotelResponse hotelOrder = date + .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getHotelOrderByDate(it))) + .orElseGet(() -> cTripOrderDetailRequest.getHotelOrder()); + List lstHtlSettlement = hotelOrder.getLstHtlSettlement(); if (lstHtlSettlement != null && !lstHtlSettlement.isEmpty()) { List list = lstHtlSettlement.stream() @@ -106,8 +118,12 @@ public class CTripOrderRecordAutoSave { } - public void cTripTrainRecordAutoSave() { - OrderTrainResponse trainOrder = cTripOrderDetailRequest.getTrainOrder(); + public void cTripTrainRecordAutoSave(Optional date) { + + OrderTrainResponse trainOrder = date + .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getTrainOrderByDate(it))) + .orElseGet(() -> cTripOrderDetailRequest.getTrainOrder()); + List lstTrainSettlement = trainOrder.getLstTrainSettlement(); if (lstTrainSettlement != null && !lstTrainSettlement.isEmpty()) { List list = lstTrainSettlement.stream() @@ -133,8 +149,11 @@ public class CTripOrderRecordAutoSave { } } - public void cTripCarRecordAutoSave() { - OrderCarResponse carOrder = cTripOrderDetailRequest.getCarOrder(); + public void cTripCarRecordAutoSave(Optional date) { + OrderCarResponse carOrder = date + .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getCarOrderByDate(it))) + .orElseGet(() -> cTripOrderDetailRequest.getCarOrder()); + List settlementList = carOrder.getCarOrderAccountSettlementList(); if (settlementList != null && !settlementList.isEmpty()) { List list = settlementList.stream()