diff --git a/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java b/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java index 276fcf97..a8cd2c80 100644 --- a/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java +++ b/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java @@ -1,11 +1,14 @@ package com.chint.application.commands; import com.chint.infrastructure.echo_framework.command.Command; +import com.chint.infrastructure.util.DateTimeUtil; import lombok.Data; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; @Data public class OrderRecordGenerateCommand extends Command { @@ -17,6 +20,22 @@ public class OrderRecordGenerateCommand extends Command { private String supplierName; private Integer productType; + public void generateStartAndEndTime() { + if (oneDate != null && !oneDate.isEmpty()) { + LocalDate specificDate = LocalDate.parse(oneDate, DateTimeFormatter.BASIC_ISO_DATE); + startTime = LocalDateTime.of(specificDate, LocalTime.MIDNIGHT); + endTime = LocalDateTime.of(specificDate, LocalTime.MAX); + } else if (date != null && !date.isEmpty()) { + YearMonth specificMonth = YearMonth.parse(date, DateTimeUtil.formatterDateYYYYMM); + startTime = LocalDateTime.of(specificMonth.atDay(1), LocalTime.MIDNIGHT); + endTime = LocalDateTime.of(specificMonth.atEndOfMonth(), LocalTime.MAX); + } else { + LocalDate yesterday = LocalDate.now().minusDays(1); + startTime = LocalDateTime.of(yesterday, LocalTime.MIDNIGHT); + endTime = LocalDateTime.of(yesterday, LocalTime.MAX); + } + } + public OrderRecordGenerateCommand startTime(LocalDateTime startTime) { this.setStartTime(startTime); 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 6c55da04..5e64d524 100644 --- a/src/main/java/com/chint/application/in/AutoWorkController.java +++ b/src/main/java/com/chint/application/in/AutoWorkController.java @@ -6,6 +6,7 @@ import com.chint.application.dtos.RecordMonthSaveDTO; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.factoriy.order_record.LyStatementOrder; import com.chint.domain.service.OrderRecordDomainService; +import com.chint.domain.service.order_record.OrderRecordGenerator; import com.chint.domain.service.order_record.OrderRecordPuller; import com.chint.domain.service.supplier.SupplierAdapterSelector; import com.chint.infrastructure.echo_framework.command.Command; @@ -126,13 +127,30 @@ public class AutoWorkController { } -// @ApiOperation("生成结算数据根据时间参数") -// @PostMapping("/record/pull") -// public Result generateFromRecord(@RequestBody RecordMonthSaveDTO param) { -// -// return Result.Success(SUCCESS); -// -// } + @ApiOperation("生成结算数据根据时间参数") + @PostMapping("/record/generate") + public Result generateRecord(@RequestBody RecordMonthSaveDTO param) { + OrderRecordGenerator orderRecordGenerator = supplierAdapterSelector + .of(param.getSupplierName(), OrderRecordGenerator.class); + //将昨天的结算数据生成为财务共享需要的数据 + OrderRecordGenerateCommand command = Command.of(OrderRecordGenerateCommand.class) + .oneDate(param.getOneDate()) + .date(param.getDate()) + .supplierName(param.getSupplierName()); + if (param.getProductType().equals(LEG_TYPE_TRAIN)) { + orderRecordGenerator.generateTrainRecordMultiParam(command); + } + if (param.getProductType().equals(LEG_TYPE_AIRPLANE)) { + orderRecordGenerator.generateFlightRecordMultiParam(command); + } + if (param.getProductType().equals(LEG_TYPE_HOTEL)) { + orderRecordGenerator.generateHotelRecordMultiParam(command); + } + if (param.getProductType().equals(LEG_TYPE_TAXI)) { + orderRecordGenerator.generateCarRecordMultiParam(command); + } + return Result.Success(SUCCESS); + } @Transactional diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java index b5a7307b..d2dfd3bc 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java @@ -22,7 +22,7 @@ public class OrderCarRecord extends OrderBaseRecord { private String detailId; // 结算明细唯一标识 private String accountCompanyId; // 核算企业code private String accountCompanyName; // 核算企业名称 -// private String ticketClerk; // 票务员 + // private String ticketClerk; // 票务员 private String accountPeriod; // 账期号 private String billNo; // 账单号 private String receiptsNum; // 关联申请单号 @@ -65,9 +65,20 @@ public class OrderCarRecord extends OrderBaseRecord { private String orderSource; // 预订来源:线上/线下 private String payAmount;//支付总金额 private String receiptsNumOrigin;//支付总金额 -// private String belongDepart; //归属部门 + // private String belongDepart; //归属部门 private String settleOrderFlag; + public OrderCarRecord loadSystemInfo(String trvaleSysType, + String belongSysType, + String accountCompanyId, + String accountCompanyName) { + this.setTrvaleSysType(trvaleSysType); + this.setBelongSysType(belongSysType); + this.setAccountCompanyId(accountCompanyId); + this.setAccountCompanyName(accountCompanyName); + return this; + } + public OrderCarRecord loadBelongDeport(String belongDeport ) { // 行程信息 diff --git a/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java index 6c6b4769..f853f558 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java @@ -9,21 +9,27 @@ import com.chint.domain.aggregates.order.order_record.OrderTrainRecord; import com.chint.domain.aggregates.order.order_record.amap_order_record.AmapCarOrderRecord; import com.chint.infrastructure.util.BigDecimalCalculator; import com.chint.interfaces.rest.amap.dto.settlement.FinishedOrderResponse; +import com.chint.interfaces.rest.data_center.user.UserHttpRequest; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Optional; +import static com.chint.domain.service.supplier.SupplierUtil.getBelongSysType; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP_FSSC; import static com.chint.infrastructure.constant.UtilConstant.KEEP_TWO_DECIMAL_ZERO; @Component public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFactory { + @Autowired + private UserHttpRequest userHttpRequest; + private final String isCancel = "取消费订单"; private final String isNotCancel = "非取消费订单"; - private OrderRecordBasic buildWithRecord(Object orderCarRecordData) { AmapCarOrderRecord carRecordData = (AmapCarOrderRecord) orderCarRecordData; OrderRecordBasic orderRecordBasic = new OrderRecordBasic(); @@ -61,7 +67,8 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact .loadBelongDeport( routeOrder.stream().flatMap(order -> Optional.ofNullable(order.getRouterOrderExtensionField().getBelongDeptCode()).stream() - ).findFirst().orElseGet(carRecordData::getDepartmentId) + ).findFirst().orElseGet(()-> + userHttpRequest.belongDeport(orderCarRecord.getBookingUserCode(), orderCarRecord.getAccountCompanyName())) ); String ds = carRecordData.getDs(); @@ -93,15 +100,19 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact Double enterpriseAmount = carRecordData.getEnterpriseAmount(); Double individualAmount = carRecordData.getIndividualAmount(); String paymentType; - if (enterpriseAmount > 0 && enterpriseAmount < carRecordData.getOrderAmount()) { + if (enterpriseAmount > 0 && individualAmount > 0) { paymentType = "2"; // 企业支付部分,个人支付部分 - } else if (enterpriseAmount.equals(carRecordData.getOrderAmount())) { - paymentType = "0"; // 全部由企业支付 - } else { + } else if (enterpriseAmount == 0 && individualAmount > 0) { paymentType = "1"; // 全部由个人支付 + } else { + paymentType = "0"; // 全部由企业支付 } - String outApplyRecordId = carRecordData.getOutApplyRecordId(); + String[] split = carRecordData.getRemark().split("-"); + if (outApplyRecordId == null || outApplyRecordId.isEmpty()) { + outApplyRecordId = split[split.length - 1]; + } + orderCarRecord.loadSystemInfo(SUPPLIER_AMAP_FSSC, getBelongSysType(split[4]), split[1], split[0]); orderCarRecord.loadPayment( paymentType, String.valueOf(enterpriseAmount), @@ -113,10 +124,10 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact ).loadSource( outApplyRecordId == null || outApplyRecordId.isEmpty() ? "N" : "Y" ).loadRelatedOrderInfo( - orderDetail.flatMap(it -> Optional.ofNullable(it.getOrderId())).orElse(Long.parseLong(carRecordData.getAmapOrderId())), + orderDetail.flatMap(it -> Optional.ofNullable(it.getOrderId())).orElse(1L), carRecordData.getAmapOrderId(), - carRecordData.getOutApplyRecordId(), - carRecordData.getOutApplyRecordId(), + outApplyRecordId, + outApplyRecordId, carRecordData.getAmapOrderId(), carRecordData.getAmapOrderId() ); diff --git a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java index 5ecb4869..2561cab4 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java @@ -25,7 +25,8 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import static com.chint.infrastructure.constant.BelongSystemConstant.*; +import static com.chint.domain.service.supplier.SupplierUtil.getBelongSysType; +import static com.chint.infrastructure.constant.BelongSystemConstant.TRAVAL_SYS_TYPE_CTRIP; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; import static com.chint.infrastructure.constant.UtilConstant.KEEP_TWO_DECIMAL_ZERO; @@ -56,24 +57,25 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac private UserCustomCodeRepository userCustomCodeRepository; private String getBeLongSysType(String sysCode) { - String res = null; - if (sysCode != null) { - if (sysCode.equals(BELONG_SYS_CODE_FSSC) || sysCode.contains(BELONG_SYS_TYPE_FSSC)) { - res = BELONG_SYS_TYPE_FSSC; - } - if (sysCode.equals(BELONG_SYS_CODE_H3BPM) || sysCode.contains(BELONG_SYS_TYPE_H3BPM)) { - res = BELONG_SYS_TYPE_H3BPM; - } - if (sysCode.equals(BELONG_SYS_CODE_XNFSSC) || sysCode.contains(BELONG_SYS_TYPE_XNFSSC)) { - res = BELONG_SYS_TYPE_XNFSSC; - } - if (sysCode.equals(BELONG_SYS_CODE_ANFSSC) || sysCode.contains(BELONG_SYS_TYPE_ANFSSC)) { - res = BELONG_SYS_TYPE_ANFSSC; - } - } else { - res = BELONG_SYS_TYPE_NOT; - } - return res; +// String res = null; +// if (sysCode != null) { +// if (sysCode.equals(BELONG_SYS_CODE_FSSC) || sysCode.contains(BELONG_SYS_TYPE_FSSC)) { +// res = BELONG_SYS_TYPE_FSSC; +// } +// if (sysCode.equals(BELONG_SYS_CODE_H3BPM) || sysCode.contains(BELONG_SYS_TYPE_H3BPM)) { +// res = BELONG_SYS_TYPE_H3BPM; +// } +// if (sysCode.equals(BELONG_SYS_CODE_XNFSSC) || sysCode.contains(BELONG_SYS_TYPE_XNFSSC)) { +// res = BELONG_SYS_TYPE_XNFSSC; +// } +// if (sysCode.equals(BELONG_SYS_CODE_ANFSSC) || sysCode.contains(BELONG_SYS_TYPE_ANFSSC)) { +// res = BELONG_SYS_TYPE_ANFSSC; +// } +// } else { +// res = BELONG_SYS_TYPE_NOT; +// } +// return res; + return null; } private OrderRecordBasic buildWithRecord(CTripCarRecord record) { @@ -90,7 +92,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac orderRecordBasic.setAccountCompanyName(cTripCarPassengerInfo.getCostCenter2()); orderRecordBasic.setOfflineCcomyCode(cTripCarPassengerInfo.getCostCenter1()); orderRecordBasic.setProjectOrderNo(cTripCarPassengerInfo.getCostCenter5()); - orderRecordBasic.setBelongSysType(getBeLongSysType(cTripCarPassengerInfo.getCostCenter3())); + orderRecordBasic.setBelongSysType(getBelongSysType(cTripCarPassengerInfo.getCostCenter3())); return orderRecordBasic; } @@ -288,7 +290,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac orderRecordBasic.setAccountCompanyName(cTripFlightBaseInfo.getCostCenter2()); orderRecordBasic.setOfflineCcomyCode(cTripFlightBaseInfo.getCostCenter()); orderRecordBasic.setProjectOrderNo(cTripFlightBaseInfo.getCostCenter5()); - orderRecordBasic.setBelongSysType(getBeLongSysType(cTripFlightBaseInfo.getCostCenter3())); + orderRecordBasic.setBelongSysType(getBelongSysType(cTripFlightBaseInfo.getCostCenter3())); return orderRecordBasic; } @@ -503,7 +505,7 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac orderRecordBasic.setAccountCompanyName(cTripHotelOrderDetail.getCostCenter2()); orderRecordBasic.setOfflineCcomyCode(cTripHotelOrderDetail.getCostCenter()); orderRecordBasic.setProjectOrderNo(cTripHotelOrderDetail.getCostCenter5()); - orderRecordBasic.setBelongSysType(getBeLongSysType(cTripHotelOrderDetail.getCostCenter3())); + orderRecordBasic.setBelongSysType(getBelongSysType(cTripHotelOrderDetail.getCostCenter3())); return orderRecordBasic; } diff --git a/src/main/java/com/chint/domain/repository/AmapCarOrderRecordRepository.java b/src/main/java/com/chint/domain/repository/AmapCarOrderRecordRepository.java index 945b2c2d..03efb55e 100644 --- a/src/main/java/com/chint/domain/repository/AmapCarOrderRecordRepository.java +++ b/src/main/java/com/chint/domain/repository/AmapCarOrderRecordRepository.java @@ -11,4 +11,7 @@ public interface AmapCarOrderRecordRepository { List findByOrderIds(List orderIds); List findByDs(String ds); + + List findByOneDate(String oneDate); + List findByDate(String date); } diff --git a/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordDomainService.java b/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordGenerator.java similarity index 63% rename from src/main/java/com/chint/domain/service/order_record/AmapOrderRecordDomainService.java rename to src/main/java/com/chint/domain/service/order_record/AmapOrderRecordGenerator.java index a451982f..15d2b992 100644 --- a/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordDomainService.java +++ b/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordGenerator.java @@ -7,27 +7,33 @@ import com.chint.domain.aggregates.order.order_record.OrderFlightRecord; import com.chint.domain.aggregates.order.order_record.OrderHotelRecord; import com.chint.domain.aggregates.order.order_record.OrderTrainRecord; import com.chint.domain.aggregates.order.order_record.amap_order_record.AmapCarOrderRecord; -import com.chint.domain.aggregates.order.order_record.ctrip_order_record.CTripHotelRecord; +import com.chint.domain.factoriy.order_record.AmapOrderRecordExtensionFactory; import com.chint.domain.factoriy.order_record.OrderRecordExtensionFactory; import com.chint.domain.factoriy.order_record.OrderRecordFactorySelector; import com.chint.domain.repository.AmapCarOrderRecordRepository; import com.chint.domain.service.OrderDetailDomainService; import com.chint.domain.service.RouteRequestDomainService; +import com.chint.domain.service.supplier.SupplierAdapterSelector; import com.chint.infrastructure.echo_framework.annotation.ListenTo; +import com.chint.infrastructure.util.DateTimeUtil; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP; -import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; + +@Slf4j @Component -public class AmapOrderRecordDomainService implements OrderRecordDomainService{ +public class AmapOrderRecordGenerator implements OrderRecordGenerator { @Autowired private AmapCarOrderRecordRepository aMapCarOrderRecordRepository; @@ -41,29 +47,67 @@ public class AmapOrderRecordDomainService implements OrderRecordDomainService{ @Autowired private OrderDetailDomainService orderDetailDomainService; + @Autowired + private SupplierAdapterSelector supplierAdapterSelector; + @Override public List generateHotelRecord(OrderRecordGenerateCommand command) { return List.of(); } + @Override + public List generateHotelRecordMultiParam(OrderRecordGenerateCommand command) { + return List.of(); + } + @Override public List generateTrainRecord(OrderRecordGenerateCommand command) { return List.of(); } + @Override + public List generateTrainRecordMultiParam(OrderRecordGenerateCommand command) { + return List.of(); + } + @Override public List generateFlightRecord(OrderRecordGenerateCommand command) { return List.of(); } + @Override + public List generateFlightRecordMultiParam(OrderRecordGenerateCommand command) { + return List.of(); + } + @ListenTo(command = "OrderRecordGenerateCommand", order = 0) @Override public List generateCarRecord(OrderRecordGenerateCommand command) { if (!command.getSupplierName().equals(SUPPLIER_AMAP)) { return List.of(); } - List amapCarOrderRecordList = aMapCarOrderRecordRepository.findByDs(command.getDate()); - OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP); + return getOrderCarRecords(command); + } + + @Override + public List generateCarRecordMultiParam(OrderRecordGenerateCommand command) { + return getOrderCarRecords(command); + } + + private List getOrderCarRecords(OrderRecordGenerateCommand command) { + List amapCarOrderRecordList; + String oneDate = command.getOneDate(); + String date = command.getDate(); + if (oneDate != null) { + amapCarOrderRecordList = aMapCarOrderRecordRepository.findByDs(oneDate); + } else + amapCarOrderRecordList = aMapCarOrderRecordRepository.findByDate(Objects + .requireNonNullElseGet(date, () -> DateTimeUtil.timeToStrYYYYMMDD(LocalDateTime.now().minusDays(1)))); + return mapToCarRecord(amapCarOrderRecordList); + } + + private List mapToCarRecord(List amapCarOrderRecordList) { + OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_AMAP, OrderRecordExtensionFactory.class); List routeOrderNoList = amapCarOrderRecordList.stream().map(AmapCarOrderRecord::getOutApplyRecordId).distinct().toList(); List routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList); // 根据RouteOrder的checkIfMine方法,创建一个包含自己订单的Map diff --git a/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordDomainService.java b/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordGenerator.java similarity index 62% rename from src/main/java/com/chint/domain/service/order_record/CTripOrderRecordDomainService.java rename to src/main/java/com/chint/domain/service/order_record/CTripOrderRecordGenerator.java index 76261150..b35294aa 100644 --- a/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordDomainService.java +++ b/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordGenerator.java @@ -16,10 +16,12 @@ import com.chint.domain.repository.CTripOrderDetailRepository; import com.chint.domain.repository.RouteRepository; import com.chint.domain.service.OrderDetailDomainService; import com.chint.domain.service.RouteRequestDomainService; +import com.chint.domain.service.supplier.SupplierAdapterSelector; import com.chint.infrastructure.echo_framework.annotation.ListenTo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.Optional; @@ -29,7 +31,7 @@ import java.util.stream.Collectors; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; @Component -public class CTripOrderRecordDomainService implements OrderRecordDomainService { +public class CTripOrderRecordGenerator implements OrderRecordGenerator { @Autowired @@ -43,6 +45,9 @@ public class CTripOrderRecordDomainService implements OrderRecordDomainService { @Autowired private RouteRequestDomainService routeRequestDomainService; + @Autowired + private SupplierAdapterSelector supplierAdapterSelector; + @Autowired private RouteRepository routeRepository; @@ -52,16 +57,24 @@ public class CTripOrderRecordDomainService implements OrderRecordDomainService { if (!command.getSupplierName().equals(SUPPLIER_C_TRIP)) { return List.of(); } - List records = cTripOrderDetailRepository.findHotelRecordByCreateTime(command.getStartTime(), command.getEndTime()); - OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP); + return generateHotelRecord(command.getStartTime(), command.getEndTime()); + } + + public List generateHotelRecordMultiParam(OrderRecordGenerateCommand command) { + command.generateStartAndEndTime(); + return generateHotelRecord(command.getStartTime(), command.getEndTime()); + } + + private List generateHotelRecord(LocalDateTime startTime, LocalDateTime endTime) { + List records = cTripOrderDetailRepository.findHotelRecordByCreateTime(startTime, endTime); + OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_C_TRIP, OrderRecordExtensionFactory.class); List routeOrderNoList = records.stream().map(CTripHotelRecord::getRouteOrderNo).distinct().toList(); List routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList); // 根据RouteOrder的checkIfMine方法,创建一个包含自己订单的Map - Map> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(), - it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst())); + Map> routeOrderMap = createRouteOrderMap(routeOrderNoList, routeOrderList); List orderHotelRecordList = records .stream() - .map(it -> orderRecordExtensionFactory.createHotelOrderRecord(it, collect.get(it.getRouteOrderNo()))) + .map(it -> orderRecordExtensionFactory.createHotelOrderRecord(it, routeOrderMap.get(it.getRouteOrderNo()))) .toList(); return orderDetailDomainService.saveHotelOrderRecordBatch(orderHotelRecordList); } @@ -72,42 +85,67 @@ public class CTripOrderRecordDomainService implements OrderRecordDomainService { return null; } + @Override + public List generateTrainRecordMultiParam(OrderRecordGenerateCommand command) { + return List.of(); + } + @ListenTo(command = "OrderRecordGenerateCommand", order = 1) @Override public List generateFlightRecord(OrderRecordGenerateCommand command) { if (!command.getSupplierName().equals(SUPPLIER_C_TRIP)) { return List.of(); } - List records = cTripOrderDetailRepository.findFlightRecordByCreateTime(command.getStartTime(), command.getEndTime()); - OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP); + return generateFlightRecord(command.getStartTime(), command.getEndTime()); + } + + public List generateFlightRecordMultiParam(OrderRecordGenerateCommand command) { + command.generateStartAndEndTime(); + return generateFlightRecord(command.getStartTime(), command.getEndTime()); + } + + + private List generateFlightRecord(LocalDateTime startTime, LocalDateTime endTime) { + List records = cTripOrderDetailRepository.findFlightRecordByCreateTime(startTime, endTime); + OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_C_TRIP, OrderRecordExtensionFactory.class); List routeOrderNoList = records.stream().map(CTripFlightRecord::getRouteOrderNo).distinct().toList(); List routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList); - // 根据RouteOrder的checkIfMine方法,创建一个包含自己订单的Map - Map> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(), - it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst())); - List orderFlightRecordList = records - .stream() - .map(it -> orderRecordExtensionFactory.createFlightOrderRecord(it, collect.get(it.getRouteOrderNo()))) + Map> routeOrderMap = createRouteOrderMap(routeOrderNoList, routeOrderList); + List orderFlightRecordList = records.stream() + .map(it -> orderRecordExtensionFactory.createFlightOrderRecord(it, routeOrderMap.get(it.getRouteOrderNo()))) .toList(); return orderDetailDomainService.saveFlightOrderRecordBatch(orderFlightRecordList); } + private Map> createRouteOrderMap(List routeOrderNoList, List routeOrderList) { + return routeOrderNoList.parallelStream().collect(Collectors.toMap( + Function.identity(), + it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst() + )); + } + @ListenTo(command = "OrderRecordGenerateCommand", order = 2) @Override public List generateCarRecord(OrderRecordGenerateCommand command) { if (!command.getSupplierName().equals(SUPPLIER_C_TRIP)) { return List.of(); } - List records = cTripOrderDetailRepository.findCarRecordByCreateTime(command.getStartTime(), command.getEndTime()); - OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP); + return generateCarRecord(command.getStartTime(), command.getEndTime()); + } + + public List generateCarRecordMultiParam(OrderRecordGenerateCommand command){ + command.generateStartAndEndTime(); + return generateCarRecord(command.getStartTime(), command.getEndTime()); + } + + private List generateCarRecord(LocalDateTime startTime, LocalDateTime endTime){ + List records = cTripOrderDetailRepository.findCarRecordByCreateTime(startTime, endTime); + OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_C_TRIP, OrderRecordExtensionFactory.class); List routeOrderNoList = records.stream().map(CTripCarRecord::getRouteOrderNo).distinct().toList(); List routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList); - // 根据RouteOrder的checkIfMine方法,创建一个包含自己订单的Map - Map> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(), - it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst())); - List orderCarRecordList = records - .stream() - .map(it -> orderRecordExtensionFactory.createCarOrderRecord(it, collect.get(it.getRouteOrderNo()))) + Map> routeOrderMap = createRouteOrderMap(routeOrderNoList, routeOrderList); + List orderCarRecordList = records.stream() + .map(it -> orderRecordExtensionFactory.createCarOrderRecord(it, routeOrderMap.get(it.getRouteOrderNo()))) .toList(); return orderDetailDomainService.saveCarOrderRecordBatch(orderCarRecordList); } diff --git a/src/main/java/com/chint/domain/service/order_record/OrderRecordDomainService.java b/src/main/java/com/chint/domain/service/order_record/OrderRecordGenerator.java similarity index 65% rename from src/main/java/com/chint/domain/service/order_record/OrderRecordDomainService.java rename to src/main/java/com/chint/domain/service/order_record/OrderRecordGenerator.java index e7f1dbaa..a109a1be 100644 --- a/src/main/java/com/chint/domain/service/order_record/OrderRecordDomainService.java +++ b/src/main/java/com/chint/domain/service/order_record/OrderRecordGenerator.java @@ -9,9 +9,13 @@ import com.chint.domain.service.supplier.SupplierAdapter; import java.util.List; -public interface OrderRecordDomainService extends SupplierAdapter { +public interface OrderRecordGenerator extends SupplierAdapter { List generateHotelRecord(OrderRecordGenerateCommand command); + List generateHotelRecordMultiParam(OrderRecordGenerateCommand command); List generateTrainRecord(OrderRecordGenerateCommand command); + List generateTrainRecordMultiParam(OrderRecordGenerateCommand command); List generateFlightRecord(OrderRecordGenerateCommand command); + List generateFlightRecordMultiParam(OrderRecordGenerateCommand command); List generateCarRecord(OrderRecordGenerateCommand command); + List generateCarRecordMultiParam(OrderRecordGenerateCommand command); } diff --git a/src/main/java/com/chint/domain/service/supplier/SupplierAdapterSelector.java b/src/main/java/com/chint/domain/service/supplier/SupplierAdapterSelector.java index 24778e15..07b556d2 100644 --- a/src/main/java/com/chint/domain/service/supplier/SupplierAdapterSelector.java +++ b/src/main/java/com/chint/domain/service/supplier/SupplierAdapterSelector.java @@ -1,10 +1,13 @@ package com.chint.domain.service.supplier; import com.chint.domain.exceptions.NotFoundException; +import com.chint.domain.service.order_record.OrderRecordGenerator; import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; import java.util.HashMap; @@ -14,7 +17,7 @@ import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; @Slf4j @Component -public class SupplierAdapterSelector { +public class SupplierAdapterSelector implements ApplicationListener { private final Map, SupplierAdapter>> adapterMap = new HashMap<>(); @@ -23,14 +26,7 @@ public class SupplierAdapterSelector { @PostConstruct public void init() { - log.info("开始注入供应商适配器到选择器。。。。。"); - Map beansOfType = applicationContext.getBeansOfType(SupplierAdapter.class); - for (SupplierAdapter adapter : beansOfType.values()) { - String supplierName = adapter.getSupplierName(); - adapterMap - .computeIfAbsent(supplierName, k -> new HashMap<>()) - .put(adapter.getClass().getInterfaces()[0], adapter); - } + } @SuppressWarnings("unchecked") @@ -45,4 +41,16 @@ public class SupplierAdapterSelector { } return (T) adapter; } + + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { + log.info("开始注入供应商适配器到选择器。。。。。"); + Map beansOfType = applicationContext.getBeansOfType(SupplierAdapter.class); + for (SupplierAdapter adapter : beansOfType.values()) { + String supplierName = adapter.getSupplierName(); + adapterMap + .computeIfAbsent(supplierName, k -> new HashMap<>()) + .put(adapter.getClass().getInterfaces()[0], adapter); + } + } } diff --git a/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java b/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java index ea6696f5..f871639a 100644 --- a/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java +++ b/src/main/java/com/chint/domain/service/supplier/SupplierServiceImpl.java @@ -84,12 +84,15 @@ public class SupplierServiceImpl implements SupplierService { @Autowired private BPMOrderDomainService bpmOrderDomainService; + @Autowired + private SupplierAdapterSelector supplierAdapterSelector; + @Transactional @Override public OrderDetail handleSupplierCallback(SupplierCallbackData callbackData) { String supplierName = callbackData.getSupplierName(); - Optional data = orderDataAdapterSelector.of(supplierName).adapt(callbackData); + Optional data = supplierAdapterSelector.of(supplierName, OrderDataAdapter.class).adapt(callbackData); if (data.isPresent()) { OrderLegData orderLegData = data.get(); return processOrderLegData(orderLegData, callbackData); @@ -102,8 +105,8 @@ public class SupplierServiceImpl implements SupplierService { RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(orderLegData.getSelfOrderNo()); String supplierName = callbackData.getSupplierName(); OrderDetail orderDetail = routeUpdateOrder(orderLegData, routeOrder); - List commandList = orderDataAdapterSelector - .of(supplierName) + List commandList = supplierAdapterSelector + .of(supplierName, OrderDataAdapter.class) .orderStatusToCommand(routeOrder, callbackData) .stream() .filter(Objects::nonNull) @@ -113,7 +116,7 @@ public class SupplierServiceImpl implements SupplierService { command.routeOrder(routeOrder); orderDetailStatusChange(command); } - OrderExtensionFactory orderExtensionFactory = orderExtensionCreator.of(orderLegData.getSupplierName()); + OrderExtensionFactory orderExtensionFactory = supplierAdapterSelector.of(supplierName, OrderExtensionFactory.class); switch (orderLegData.getProductType()) { case LegConstant.LEG_TYPE_TRAIN -> addTrainOrderData(orderDetail, orderLegData, orderExtensionFactory, routeOrder); @@ -144,8 +147,8 @@ public class SupplierServiceImpl implements SupplierService { OrderDetail orderDetail = (OrderDetail) byPropertyName.getValue(); Integer productType = orderLegData.getProductType(); - OrderExtensionFactory orderExtensionFactory = orderExtensionCreator - .of(orderLegData.getSupplierName()); + OrderExtensionFactory orderExtensionFactory = supplierAdapterSelector.of(orderLegData.getSupplierName() + , OrderExtensionFactory.class); //根据产品的不同类型添加不同的扩展字段 switch (productType) { @@ -661,7 +664,7 @@ public class SupplierServiceImpl implements SupplierService { trainOrderDetail.setCreateTime(command.getCreateTime()); trainOrderDetail.setId(null); if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) { - trainOrderDetail = orderExtensionCreator.of(SUPPLIER_L_Y).updateTrainOrderDetailData(trainOrderDetail, command.getOrderInfo()); + trainOrderDetail = supplierAdapterSelector.of(SUPPLIER_L_Y, OrderExtensionFactory.class).updateTrainOrderDetailData(trainOrderDetail, command.getOrderInfo()); } trainOrderDetail.setDetailId(newOrderNo); orderDetail.setTrainOrderDetail(trainOrderDetail); @@ -676,9 +679,9 @@ public class SupplierServiceImpl implements SupplierService { flightOrderDetail.setCreateTime(command.getCreateTime()); flightOrderDetail.setId(null); if (orderDetail.getSupplierName().equals(SUPPLIER_C_TRIP)) { - flightOrderDetail = orderExtensionCreator.of(SUPPLIER_C_TRIP).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo()); - } else { - flightOrderDetail = orderExtensionCreator.of(SUPPLIER_L_Y).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo()); + flightOrderDetail = supplierAdapterSelector.of(SUPPLIER_C_TRIP, OrderExtensionFactory.class).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo()); + } else if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) { + flightOrderDetail = supplierAdapterSelector.of(SUPPLIER_L_Y, OrderExtensionFactory.class).updateFlightOrderDetailData(flightOrderDetail, command.getOrderInfo()); } flightOrderDetail.setDetailId(newOrderNo); orderDetail.setFlightOrderDetail(flightOrderDetail); @@ -700,7 +703,7 @@ public class SupplierServiceImpl implements SupplierService { } hotelOrderDetail.setCustomers(newCustomers); if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) { - hotelOrderDetail = orderExtensionCreator.of(SUPPLIER_L_Y).updateHotelOrderDetailData(hotelOrderDetail, command.getOrderInfo()); + hotelOrderDetail = supplierAdapterSelector.of(SUPPLIER_L_Y, OrderExtensionFactory.class).updateHotelOrderDetailData(hotelOrderDetail, command.getOrderInfo()); } hotelOrderDetail.setDetailId(newOrderNo); orderDetail.setHotelOrderDetail(hotelOrderDetail); diff --git a/src/main/java/com/chint/domain/service/supplier/SupplierUtil.java b/src/main/java/com/chint/domain/service/supplier/SupplierUtil.java new file mode 100644 index 00000000..2c9db615 --- /dev/null +++ b/src/main/java/com/chint/domain/service/supplier/SupplierUtil.java @@ -0,0 +1,26 @@ +package com.chint.domain.service.supplier; + +import static com.chint.infrastructure.constant.BelongSystemConstant.*; + +public class SupplierUtil { + public static String getBelongSysType(String sysCode) { + String res = null; + if (sysCode != null) { + if (sysCode.equals(BELONG_SYS_CODE_FSSC) || sysCode.contains(BELONG_SYS_TYPE_FSSC)) { + res = BELONG_SYS_TYPE_FSSC; + } + if (sysCode.equals(BELONG_SYS_CODE_H3BPM) || sysCode.contains(BELONG_SYS_TYPE_H3BPM)) { + res = BELONG_SYS_TYPE_H3BPM; + } + if (sysCode.equals(BELONG_SYS_CODE_XNFSSC) || sysCode.contains(BELONG_SYS_TYPE_XNFSSC)) { + res = BELONG_SYS_TYPE_XNFSSC; + } + if (sysCode.equals(BELONG_SYS_CODE_ANFSSC) || sysCode.contains(BELONG_SYS_TYPE_ANFSSC)) { + res = BELONG_SYS_TYPE_ANFSSC; + } + } else { + res = BELONG_SYS_TYPE_NOT; + } + return res; + } +} diff --git a/src/main/java/com/chint/infrastructure/constant/SupplierNameConstant.java b/src/main/java/com/chint/infrastructure/constant/SupplierNameConstant.java index 33494e9c..32ba5798 100644 --- a/src/main/java/com/chint/infrastructure/constant/SupplierNameConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/SupplierNameConstant.java @@ -15,4 +15,5 @@ public class SupplierNameConstant { public static final String SUPPLIER_AMAP_CN_NAME = "高德"; public static final String SUPPLIER_AMAP_EXTENSION_NAME = "高德预定"; public static final String SUPPLIER_AMAP_BPM_NAME = "高德商旅"; + public static final String SUPPLIER_AMAP_FSSC = "GD"; } diff --git a/src/main/java/com/chint/infrastructure/repository/AmapCarOrderRecordRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/AmapCarOrderRecordRepositoryImpl.java index 616c89f8..2029b70f 100644 --- a/src/main/java/com/chint/infrastructure/repository/AmapCarOrderRecordRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/AmapCarOrderRecordRepositoryImpl.java @@ -31,4 +31,14 @@ public class AmapCarOrderRecordRepositoryImpl implements AmapCarOrderRecordRepos public List findByDs(String ds) { return jdbcAmapCarOrderRecordRepository.findByDsContaining(ds); } + + @Override + public List findByOneDate(String oneDate) { + return jdbcAmapCarOrderRecordRepository.findByDs(oneDate); + } + + @Override + public List findByDate(String date) { + return jdbcAmapCarOrderRecordRepository.findByDsContaining(date); + } } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapCarOrderRecordRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapCarOrderRecordRepository.java index 731801a5..0d889ac5 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapCarOrderRecordRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapCarOrderRecordRepository.java @@ -10,5 +10,6 @@ import java.util.List; @Repository public interface JdbcAmapCarOrderRecordRepository extends CrudRepository { List findByDsContaining(String ds); + List findByDs(String ds); List findByAmapOrderIdIn(Collection amapOrderId); } 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 8b6f9798..c99226cc 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 @@ -134,7 +134,7 @@ public class CTripOrderRecordAutoSave { OrderHotelResponse response = Optional.ofNullable(command.getOneDate()) .map(cTripOrderDetailRequest::getHotelOrder) .or(() -> Optional.ofNullable(command.getDate()) - .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getHotelOrder(it)))) + .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getHotelOrderByDate(it)))) .orElseGet(cTripOrderDetailRequest::getHotelOrder); cTripHotelRecordAutoSave(response); } @@ -234,9 +234,9 @@ public class CTripOrderRecordAutoSave { public void cTripCarRecordAutoSave(OrderRecordGenerateCommand command){ OrderCarResponse response = Optional.ofNullable(command.getOneDate()) - .map(cTripOrderDetailRequest::getCarOrder) + .flatMap(oneDate -> Optional.ofNullable(cTripOrderDetailRequest.getCarOrder(oneDate))) .or(() -> Optional.ofNullable(command.getDate()) - .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getCarOrder(it)))) + .flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getCarOrderByDate(it)))) .orElseGet(cTripOrderDetailRequest::getCarOrder); cTripCarRecordAutoSave(response); } diff --git a/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java index 77fcadc1..76b9e1b9 100644 --- a/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java @@ -114,16 +114,17 @@ public class UserHttpRequestImpl implements UserHttpRequest { rankName = DEFAULT_RANK_NAME; } } - if (rankName.contains("L")) { - rankName = rankName.replace("L", "P"); - } Ranks ranks = rankDomainService.queryRanks(rankName, user.getCompanyCode()); - if (ranks != null) { - user.setStandardLevel(ranks.getStandardLevel()); - } else { - ranks = rankDomainService.queryRanks(rankName, JT_COMPANY_CODE); - user.setStandardLevel(ranks.getStandardLevel()); + if (ranks == null) { + if (rankName.contains("L")) { + rankName = rankName.replace("L", "P"); + } + ranks = rankDomainService.queryRanks(rankName, user.getCompanyCode()); } + if (ranks == null) { + ranks = rankDomainService.queryRanks(rankName, JT_COMPANY_CODE); + } + user.setStandardLevel(ranks.getStandardLevel()); return user; } diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 881c477f..6faf442c 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -250,7 +250,7 @@ public class CTripTest { @Test void search() { BaseContext.setCurrentUser(user); - SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31839097186"); + SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32430240547"); System.out.println(response); } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 4e144051..8a7bc2c8 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -310,7 +310,7 @@ class RouteApplicationTests { @Test void loginSign() { - String sfno = "190506003"; + String sfno = "190401151"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司";