diff --git a/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java b/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java index 7d7b0390..6ec12dc9 100644 --- a/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java +++ b/src/main/java/com/chint/application/commands/OrderRecordGenerateCommand.java @@ -12,13 +12,26 @@ 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); + private String date; + private String supplierName; public OrderRecordGenerateCommand startTime(LocalDateTime startTime) { this.setStartTime(startTime); return this; } + public OrderRecordGenerateCommand endTime(LocalDateTime endTime) { this.setEndTime(endTime); return this; } + + public OrderRecordGenerateCommand supplierName(String supplierName) { + this.setSupplierName(supplierName); + return this; + } + + public OrderRecordGenerateCommand date(String date) { + this.setDate(date); + return this; + } } diff --git a/src/main/java/com/chint/application/dtos/CTripRecordMonthSaveDTO.java b/src/main/java/com/chint/application/dtos/RecordMonthSaveDTO.java similarity index 57% rename from src/main/java/com/chint/application/dtos/CTripRecordMonthSaveDTO.java rename to src/main/java/com/chint/application/dtos/RecordMonthSaveDTO.java index 562571d4..b3cfd972 100644 --- a/src/main/java/com/chint/application/dtos/CTripRecordMonthSaveDTO.java +++ b/src/main/java/com/chint/application/dtos/RecordMonthSaveDTO.java @@ -3,6 +3,7 @@ package com.chint.application.dtos; import lombok.Data; @Data -public class CTripRecordMonthSaveDTO { +public class RecordMonthSaveDTO { private String date; + private String supplierName; } diff --git a/src/main/java/com/chint/application/in/AutoWorkController.java b/src/main/java/com/chint/application/in/AutoWorkController.java index 8e08bee3..7fb55fec 100644 --- a/src/main/java/com/chint/application/in/AutoWorkController.java +++ b/src/main/java/com/chint/application/in/AutoWorkController.java @@ -2,9 +2,10 @@ package com.chint.application.in; import com.chint.application.commands.LYOrderRecordGenerateCommand; import com.chint.application.commands.OrderRecordGenerateCommand; -import com.chint.application.dtos.CTripRecordMonthSaveDTO; +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.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository; import com.chint.infrastructure.util.DateTimeUtil; @@ -24,6 +25,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; @RestController @@ -43,6 +46,9 @@ public class AutoWorkController { @Autowired private JdbcRouteRepository jdbcRouteRepository; + @Autowired + private OrderRecordDomainService orderRecordDomainService; + @ApiOperation("用户状态检查,离职用户将关闭开卡") @PostMapping("/user/status/check") @@ -62,21 +68,45 @@ public class AutoWorkController { return Result.Success(SUCCESS); } + @Transactional - @ApiOperation("拉取按月份的携程流水") - @PostMapping("/cTrip/record/save/month") - public Result autoSaveCTripRecordByMonth(@RequestBody CTripRecordMonthSaveDTO cTripRecordMonthSaveDTO) { - String date = cTripRecordMonthSaveDTO.getDate(); - cTripOrderRecordAutoSave.saveAllByDate(date); + @ApiOperation("拉取按月份的流水并自动生成结算记录") + @PostMapping("/record/pullAndSave/month") + public Result autoDownloadDataAndSaveRecordByMonth(@RequestBody RecordMonthSaveDTO recordMonthSaveDTO) { + String date = recordMonthSaveDTO.getDate(); + if (recordMonthSaveDTO.getSupplierName().equals(SUPPLIER_C_TRIP)) { + cTripOrderRecordAutoSave.saveAllByDate(date); + } else if (recordMonthSaveDTO.getSupplierName().equals(SUPPLIER_AMAP)) { + orderRecordDomainService.saveAllAmapCarOrderRecord(date); + } //将昨天的结算数据生成为财务共享需要的数据 Command.of(OrderRecordGenerateCommand.class) .startTime(DateTimeUtil.firstDayOfMonth(date)) .endTime(DateTimeUtil.endDayOfMonth(date)) + .date(date) + .supplierName(recordMonthSaveDTO.getSupplierName()) .sendToQueue(); return Result.Success(SUCCESS); } + @Transactional + @ApiOperation("根据月份生成结算记录") + @PostMapping("/record/save/month") + public Result autoSaveRecordByMonth(@RequestBody RecordMonthSaveDTO recordMonthSaveDTO) { + String date = recordMonthSaveDTO.getDate(); + //将昨天的结算数据生成为财务共享需要的数据 + Command.of(OrderRecordGenerateCommand.class) + .startTime(DateTimeUtil.firstDayOfMonth(date)) + .endTime(DateTimeUtil.endDayOfMonth(date)) + .date(date) + .supplierName(recordMonthSaveDTO.getSupplierName()) + .sendToQueue(); + return Result.Success(SUCCESS); + } + + + @ApiOperation("自动拉取同程上个月的流水号") @PostMapping("/ly/record/save") public Result autoSaveLYRecord() { diff --git a/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java b/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java index 8492a589..6f87b6c7 100644 --- a/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java +++ b/src/main/java/com/chint/application/queryies/estimate/CTripEstimatePrice.java @@ -39,6 +39,7 @@ import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_LOCATI import static com.chint.infrastructure.constant.CommonMessageConstant.NO_PRICE_ERROR; import static com.chint.infrastructure.constant.LocationConstant.LOCATION_LEVEL_COUNTY; import static com.chint.infrastructure.constant.RankConstant.STANDARD_LEVEL_ONE; +import static com.chint.infrastructure.constant.UtilConstant.KEEP_TWO_DECIMAL_ZERO; @Component public class CTripEstimatePrice implements EstimatePrice { @@ -262,7 +263,8 @@ public class CTripEstimatePrice implements EstimatePrice { Boolean success = estimate.getStatus().getSuccess(); if (success) { HotelValuationResult hotelValuationResult = estimate.getData().getHotelValuationResult(); - String price = hotelValuationResult.getMaxPrice().toString(); + BigDecimal maxPrice = hotelValuationResult.getMaxPrice(); + String price = maxPrice == null ? KEEP_TWO_DECIMAL_ZERO : maxPrice.toString(); ; if (Double.parseDouble(price) == 0) { hotelPriceData.setSuccess(false); diff --git a/src/main/java/com/chint/domain/aggregates/order/HotelOrderDetail.java b/src/main/java/com/chint/domain/aggregates/order/HotelOrderDetail.java index 6a825dd1..0fada4f4 100644 --- a/src/main/java/com/chint/domain/aggregates/order/HotelOrderDetail.java +++ b/src/main/java/com/chint/domain/aggregates/order/HotelOrderDetail.java @@ -4,7 +4,6 @@ package com.chint.domain.aggregates.order; import lombok.Data; import lombok.experimental.Accessors; import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; import org.springframework.data.relational.core.mapping.MappedCollection; import org.springframework.data.relational.core.mapping.Table; @@ -165,6 +164,11 @@ public class HotelOrderDetail implements Serializable { if (this.customers == null) { this.customers = new ArrayList<>(); } + if (this.customers.stream().anyMatch(it -> it.getUserName().equals(customer.getUserName()) && + it.getPhone().equals(customer.getPhone()) && + it.getUserCode().equals(customer.getUserCode()))) { + return this; + } this.customers.add(customer); return this; } diff --git a/src/main/java/com/chint/domain/aggregates/supplier/Supplier.java b/src/main/java/com/chint/domain/aggregates/supplier/Supplier.java index 3c19e607..00912a79 100644 --- a/src/main/java/com/chint/domain/aggregates/supplier/Supplier.java +++ b/src/main/java/com/chint/domain/aggregates/supplier/Supplier.java @@ -8,6 +8,9 @@ import org.springframework.data.relational.core.mapping.Table; import java.io.Serial; import java.io.Serializable; import java.util.List; +import java.util.Optional; + +import static com.chint.infrastructure.constant.LegConstant.*; @Data @Table("supplier") @@ -20,4 +23,29 @@ public class Supplier implements Serializable { private String cnName; @MappedCollection(idColumn = "supplier_id", keyColumn = "supplier_key") private List supplierProductList; + + public Optional carSupplierProduct() { + return getSupplierProductByProductType(LEG_TYPE_TAXI); + } + + public Optional hotelSupplierProduct() { + return getSupplierProductByProductType(LEG_TYPE_HOTEL); + } + + public Optional flightSupplierProduct() { + return getSupplierProductByProductType(LEG_TYPE_AIRPLANE); + } + + public Optional trainSupplierProduct() { + return getSupplierProductByProductType(LEG_TYPE_TRAIN); + } + + private Optional getSupplierProductByProductType(Integer productType) { + if (supplierProductList == null || supplierProductList.isEmpty()) { + return Optional.empty(); + } else { + return supplierProductList.stream() + .filter(it -> it.getProductType().equals(productType)).findFirst(); + } + } } diff --git a/src/main/java/com/chint/domain/aggregates/supplier/SupplierProduct.java b/src/main/java/com/chint/domain/aggregates/supplier/SupplierProduct.java index b1902dd4..65d13b63 100644 --- a/src/main/java/com/chint/domain/aggregates/supplier/SupplierProduct.java +++ b/src/main/java/com/chint/domain/aggregates/supplier/SupplierProduct.java @@ -3,10 +3,12 @@ package com.chint.domain.aggregates.supplier; import lombok.Data; import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.MappedCollection; import org.springframework.data.relational.core.mapping.Table; import java.io.Serial; import java.io.Serializable; +import java.util.List; @Data @Table("supplier_product") @@ -20,4 +22,6 @@ public class SupplierProduct implements Serializable { private Integer productType; private Integer ifCanOrder; private String ifCanCancelRule; + @MappedCollection(idColumn = "supplier_product_id", keyColumn = "supplier_product_key") + private List supplierProductStandardLevelList; } diff --git a/src/main/java/com/chint/domain/aggregates/supplier/SupplierProductStandardLevel.java b/src/main/java/com/chint/domain/aggregates/supplier/SupplierProductStandardLevel.java new file mode 100644 index 00000000..3eb94f47 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/supplier/SupplierProductStandardLevel.java @@ -0,0 +1,26 @@ +package com.chint.domain.aggregates.supplier; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Table("supplier_product_standard_level") +public class SupplierProductStandardLevel implements Serializable { + @Serial + private static final long serialVersionUID = 1864551962257811354L; + @Id + private Long id; + private Long supplierProductId; + private Long standardLevelId; + private String standardLevelName; + private Integer status; + private String extension; + + public boolean inUse() { + return status == 1; + } +} 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 f900ef4b..87b2a1e9 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 @@ -1,19 +1,128 @@ package com.chint.domain.factoriy.order_record; +import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.order_record.OrderCarRecord; 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.infrastructure.util.BigDecimalCalculator; import com.chint.interfaces.rest.amap.dto.settlement.FinishedOrderResponse; import org.springframework.stereotype.Component; import java.util.Optional; +import static com.chint.infrastructure.constant.UtilConstant.KEEP_TWO_DECIMAL_ZERO; + @Component public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFactory { + private final String isCancel = "取消费订单"; + private final String isNotCancel = "非取消费订单"; + + + private OrderRecordBasic buildWithRecord(Object orderCarRecordData) { + AmapCarOrderRecord carRecordData = (AmapCarOrderRecord) orderCarRecordData; + OrderRecordBasic orderRecordBasic = new OrderRecordBasic(); + orderRecordBasic.loadBookingInfo(carRecordData.getEUserId(), + carRecordData.getRealName(), + null, + carRecordData.getRealName(), + carRecordData.getEUserId() + ); + return orderRecordBasic; + } + + @Override + public OrderCarRecord createCarOrderRecord(Object orderCarRecordData, Optional routeOrder) { + AmapCarOrderRecord carRecordData = (AmapCarOrderRecord) orderCarRecordData; + OrderCarRecord orderCarRecord = buildWithRecord(orderCarRecordData).carRecord(); + + Optional orderDetail = routeOrder + .stream() + .flatMap(order -> order + .getOrderDetails() + .stream() + .filter(it -> it.getOrderNo().equals(carRecordData.getAmapOrderId()))) + .findFirst(); + + String orderStatus; + if (carRecordData.getIsCancelFeeOrder().equals(isCancel)) { + orderStatus = "3"; + } else { + orderStatus = "1"; + } + orderCarRecord.loadBasicOrderInfo(carRecordData.getAmapOrderId(), + orderStatus, + carRecordData.getGmtCreate()) + .loadBelongDeport( + routeOrder.stream().flatMap(order -> + Optional.ofNullable(order.getRouterOrderExtensionField().getBelongDeptCode()).stream() + ).findFirst().orElseGet(carRecordData::getDepartmentId) + ); + + String ds = carRecordData.getDs(); + orderCarRecord.loadTravelInfo( + carRecordData.getGmtCreateStartTime106(), + carRecordData.getGmtCreateEndTime106(), + carRecordData.getCityName(), + carRecordData.getEndCity(), + carRecordData.getStartName(), + carRecordData.getEndName() + ).loadVehicleAndTravelInfo( + carRecordData.getAmapRideType(), + orderDetail.flatMap(it -> Optional.ofNullable(it.getCarOrderDetail().getRunTime())).orElse(KEEP_TWO_DECIMAL_ZERO), + String.valueOf(carRecordData.getMileage()) + ).loadFinancialInfo( + ds.substring(0, 6), + ds, + String.valueOf(carRecordData.getOrderAmount()), + BigDecimalCalculator.add(String.valueOf(carRecordData.getOrderAmount()), String.valueOf(carRecordData.getServicefee())) + ).loadFeeDetails( + "", + "", + String.valueOf(carRecordData.getServicefee()), + String.valueOf(carRecordData.getCancelFee()), + String.valueOf(carRecordData.getHighwayFee()), + "" + ); + + Double enterpriseAmount = carRecordData.getEnterpriseAmount(); + Double individualAmount = carRecordData.getIndividualAmount(); + String paymentType; + if (enterpriseAmount > 0 && enterpriseAmount < carRecordData.getOrderAmount()) { + paymentType = "2"; // 企业支付部分,个人支付部分 + } else if (enterpriseAmount.equals(carRecordData.getOrderAmount())) { + paymentType = "0"; // 全部由企业支付 + } else { + paymentType = "1"; // 全部由个人支付 + } + + String outApplyRecordId = carRecordData.getOutApplyRecordId(); + orderCarRecord.loadPayment( + paymentType, + String.valueOf(enterpriseAmount), + String.valueOf(individualAmount) + ).loadOrganizationalInfo( + carRecordData.getDep1(), + carRecordData.getDep2(), + carRecordData.getDep3() + ).loadSource( + outApplyRecordId == null || outApplyRecordId.isEmpty() ? "N" : "Y" + ).loadRelatedOrderInfo( + orderDetail.flatMap(it -> Optional.ofNullable(it.getOrderId())).orElse(Long.parseLong(carRecordData.getAmapOrderId())), + carRecordData.getAmapOrderId(), + carRecordData.getOutApplyRecordId(), + carRecordData.getOutApplyRecordId(), + carRecordData.getAmapOrderId(), + carRecordData.getAmapOrderId() + ); + orderDetail.ifPresentOrElse(orderCarRecord::loadComplianceInfo, orderCarRecord::loadComplianceInfoNot); + return orderCarRecord; + } + @Override public OrderCarRecord createCarOrderRecord(Object orderCarRecordData) { @@ -43,19 +152,6 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact return null; } - private OrderRecordBasic buildWithRecord(Object orderCarRecordData) { - FinishedOrderResponse.ListElement carRecordData = (FinishedOrderResponse.ListElement) orderCarRecordData; - OrderRecordBasic orderRecordBasic = new OrderRecordBasic(); -// orderRecordBasic.loadBookingInfo( -// carRecordData.get -// ) - return null; - } - - @Override - public OrderCarRecord createCarOrderRecord(Object orderCarRecordData, Optional routeOrder) { - return null; - } @Override public OrderTrainRecord createTrainOrderRecord(Object orderTrainRecordData, Optional routeOrder) { diff --git a/src/main/java/com/chint/domain/repository/AmapCarOrderRecordRepository.java b/src/main/java/com/chint/domain/repository/AmapCarOrderRecordRepository.java new file mode 100644 index 00000000..5a26daa1 --- /dev/null +++ b/src/main/java/com/chint/domain/repository/AmapCarOrderRecordRepository.java @@ -0,0 +1,12 @@ +package com.chint.domain.repository; + +import com.chint.domain.aggregates.order.order_record.amap_order_record.AmapCarOrderRecord; + +import java.util.List; + +public interface AmapCarOrderRecordRepository { + + List saveAll(List records); + + List findByDs(String ds); +} diff --git a/src/main/java/com/chint/domain/service/OrderRecordDomainService.java b/src/main/java/com/chint/domain/service/OrderRecordDomainService.java index 4f6b2ad4..8e4534ed 100644 --- a/src/main/java/com/chint/domain/service/OrderRecordDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderRecordDomainService.java @@ -4,10 +4,10 @@ import com.chint.domain.aggregates.order.order_record.OrderCarRecord; 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.repository.OrderCarRecordRepository; -import com.chint.domain.repository.OrderFlightRecordRepository; -import com.chint.domain.repository.OrderHotelRecordRepository; -import com.chint.domain.repository.OrderTrainRecordRepository; +import com.chint.domain.aggregates.order.order_record.amap_order_record.AmapCarOrderRecord; +import com.chint.domain.repository.*; +import com.chint.interfaces.rest.amap.dto.settlement.FinishedOrderResponse; +import com.chint.interfaces.rest.amap.request.AmapSettleBillRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,6 +29,12 @@ public class OrderRecordDomainService { @Autowired private SystemDomainService systemDomainService; + @Autowired + private AmapCarOrderRecordRepository amapCarOrderRecordRepository; + + @Autowired + private AmapSettleBillRequest amapSettleBillRequest; + @Transactional public void reloadClerkAndSave(String accountPeriod) { List orderCarRecordList = orderCarRecordRepository.findByAccountPeriod(accountPeriod); @@ -49,4 +55,10 @@ public class OrderRecordDomainService { } + public void saveAllAmapCarOrderRecord(String date) { + List listElements = amapSettleBillRequest.amapRecordByMonth(date); + List list = listElements.stream().map(AmapCarOrderRecord::of).toList(); + amapCarOrderRecordRepository.saveAll(list); + } + } diff --git a/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordDomainService.java b/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordDomainService.java index eaab8b27..9efc7ac8 100644 --- a/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordDomainService.java +++ b/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordDomainService.java @@ -1,14 +1,46 @@ package com.chint.domain.service.order_record; import com.chint.application.commands.OrderRecordGenerateCommand; +import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.order_record.OrderCarRecord; 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.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.infrastructure.echo_framework.annotation.ListenTo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import java.util.List; +import java.util.Map; +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; + +@Component public class AmapOrderRecordDomainService implements OrderRecordDomainService{ + + @Autowired + private AmapCarOrderRecordRepository aMapCarOrderRecordRepository; + + @Autowired + private OrderRecordFactorySelector orderRecordFactorySelector; + + @Autowired + private RouteRequestDomainService routeRequestDomainService; + + @Autowired + private OrderDetailDomainService orderDetailDomainService; + @Override public List generateHotelRecord(OrderRecordGenerateCommand command) { return List.of(); @@ -24,8 +56,23 @@ public class AmapOrderRecordDomainService implements OrderRecordDomainService{ return List.of(); } + @ListenTo(command = "OrderRecordGenerateCommand", order = 0) @Override public List generateCarRecord(OrderRecordGenerateCommand command) { - return List.of(); + if (!command.getSupplierName().equals(SUPPLIER_AMAP)) { + return List.of(); + } + List amapCarOrderRecordList = aMapCarOrderRecordRepository.findByDs(command.getDate()); + OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP); + List routeOrderNoList = amapCarOrderRecordList.stream().map(AmapCarOrderRecord::getOutApplyRecordId).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 = amapCarOrderRecordList + .stream() + .map(it -> orderRecordExtensionFactory.createCarOrderRecord(it, collect.get(it.getOutApplyRecordId()))) + .toList(); + return orderDetailDomainService.saveCarOrderRecordBatch(orderCarRecordList); } } diff --git a/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordDomainService.java b/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordDomainService.java index d58ec193..9d0b1780 100644 --- a/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordDomainService.java +++ b/src/main/java/com/chint/domain/service/order_record/CTripOrderRecordDomainService.java @@ -40,7 +40,6 @@ public class CTripOrderRecordDomainService implements OrderRecordDomainService { private CTripOrderDetailRepository cTripOrderDetailRepository; @Autowired private OrderRecordFactorySelector orderRecordFactorySelector; - @Autowired private RouteRequestDomainService routeRequestDomainService; @@ -50,6 +49,9 @@ public class CTripOrderRecordDomainService implements OrderRecordDomainService { @ListenTo(command = "OrderRecordGenerateCommand", order = 0) @Override public List generateHotelRecord(OrderRecordGenerateCommand command) { + 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); List routeOrderNoList = records.stream().map(CTripHotelRecord::getRouteOrderNo).distinct().toList(); @@ -73,13 +75,16 @@ public class CTripOrderRecordDomainService implements OrderRecordDomainService { @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); 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())); + it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst())); List orderFlightRecordList = records .stream() .map(it -> orderRecordExtensionFactory.createFlightOrderRecord(it, collect.get(it.getRouteOrderNo()))) @@ -90,13 +95,16 @@ public class CTripOrderRecordDomainService implements OrderRecordDomainService { @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); 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())); + it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst())); List orderCarRecordList = records .stream() .map(it -> orderRecordExtensionFactory.createCarOrderRecord(it, collect.get(it.getRouteOrderNo()))) diff --git a/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java b/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java index 3b67e24b..08f38cdd 100644 --- a/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java +++ b/src/main/java/com/chint/domain/service/order_sync/AmapOrderSyncAdapter.java @@ -2,10 +2,14 @@ package com.chint.domain.service.order_sync; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.supplier.AmapRouteRelationship; +import com.chint.domain.aggregates.supplier.Supplier; +import com.chint.domain.aggregates.supplier.SupplierProductStandardLevel; import com.chint.domain.aggregates.user.User; +import com.chint.domain.exceptions.AuthException; import com.chint.domain.exceptions.CommandException; import com.chint.domain.repository.AmapPolicyRepository; import com.chint.domain.repository.AmapRouteRelationshipRepository; +import com.chint.domain.repository.SupplierRepository; import com.chint.domain.repository.UserRepository; import com.chint.domain.service.LegDomainService; import com.chint.infrastructure.util.DateTimeUtil; @@ -26,6 +30,7 @@ import java.util.List; import java.util.Optional; import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI; +import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP; @Slf4j @Component @@ -49,6 +54,9 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync { @Autowired private AmapPolicyRepository amapPolicyRepository; + @Autowired + private SupplierRepository supplierRepository; + private Gson gson = new Gson(); @Override @@ -139,9 +147,19 @@ public class AmapOrderSyncAdapter implements SupplierOrderSync { dto.setProcessContent(gson.toJson(processContent)); dto.setStatus("1"); - amapPolicyRepository.findByStandardLevel(routeRequestFields.getStandardLevel()) - .ifPresent(policy -> dto.setRegulationId(policy.getAmapPolicyCode())); - + Optional supplier = supplierRepository.findBySupplierName(SUPPLIER_AMAP); + supplier.flatMap(Supplier::carSupplierProduct).ifPresent(carSupplierProduct -> { + if (carSupplierProduct.getSupplierProductStandardLevelList() + .stream() + .filter(SupplierProductStandardLevel::inUse) + .map(SupplierProductStandardLevel::getStandardLevelName) + .anyMatch(standardLevel -> standardLevel.equals(routeRequestFields.getStandardLevel()))) { + amapPolicyRepository.findByStandardLevel(routeRequestFields.getStandardLevel()) + .ifPresent(policy -> dto.setRegulationId(policy.getAmapPolicyCode())); + } else { + throw new AuthException("你目前的差标不支持使用高德打车"); + } + }); return dto; } diff --git a/src/main/java/com/chint/infrastructure/repository/AmapCarOrderRecordRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/AmapCarOrderRecordRepositoryImpl.java new file mode 100644 index 00000000..4dac86f8 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/AmapCarOrderRecordRepositoryImpl.java @@ -0,0 +1,29 @@ +package com.chint.infrastructure.repository; + +import com.chint.domain.aggregates.order.order_record.amap_order_record.AmapCarOrderRecord; +import com.chint.domain.repository.AmapCarOrderRecordRepository; +import com.chint.infrastructure.repository.jdbc.JdbcAmapCarOrderRecordRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; + +@Repository +public class AmapCarOrderRecordRepositoryImpl implements AmapCarOrderRecordRepository { + + @Autowired + private JdbcAmapCarOrderRecordRepository jdbcAmapCarOrderRecordRepository; + + @Override + public List saveAll(List records) { + List res = new ArrayList<>(); + jdbcAmapCarOrderRecordRepository.saveAll(records).forEach(res::add); + return res; + } + + @Override + public List findByDs(String ds) { + return jdbcAmapCarOrderRecordRepository.findByDsContaining(ds); + } +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapCarOrderRecordRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapCarOrderRecordRepository.java new file mode 100644 index 00000000..8e9bc1c9 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcAmapCarOrderRecordRepository.java @@ -0,0 +1,12 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.order.order_record.amap_order_record.AmapCarOrderRecord; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface JdbcAmapCarOrderRecordRepository extends CrudRepository { + List findByDsContaining(String ds); +} diff --git a/src/main/java/com/chint/interfaces/rest/amap/request/SettleBillRequest.java b/src/main/java/com/chint/interfaces/rest/amap/request/AmapSettleBillRequest.java similarity index 73% rename from src/main/java/com/chint/interfaces/rest/amap/request/SettleBillRequest.java rename to src/main/java/com/chint/interfaces/rest/amap/request/AmapSettleBillRequest.java index f92ff012..9816b212 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/request/SettleBillRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/request/AmapSettleBillRequest.java @@ -7,14 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import static com.chint.infrastructure.constant.AmapConstant.FINISHED_ORDER_URL; @Component -public class SettleBillRequest { +public class AmapSettleBillRequest { @Value("${amap.baseUrl}") private String baseUrl; @@ -49,12 +48,16 @@ public class SettleBillRequest { } - public List amapRecordLastMonth(){ + public List amapRecordLastMonth() { String lastMonthStr = DateTimeUtil.lastMonthStr(); - LocalDateTime firstDayOfMonth = DateTimeUtil.firstDayOfMonth(lastMonthStr); - LocalDateTime endDayOfMonth = DateTimeUtil.endDayOfMonth(lastMonthStr); - - return null; + String firstDayOfMonth = DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.firstDayOfMonth(lastMonthStr)); + String endDayOfMonth = DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.endDayOfMonth(lastMonthStr)); + return pageFinishedOrder(firstDayOfMonth, endDayOfMonth); } + public List amapRecordByMonth(String date) { + String firstDayOfMonth = DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.firstDayOfMonth(date)); + String endDayOfMonth = DateTimeUtil.timeToStrYYYYMMDD(DateTimeUtil.endDayOfMonth(date)); + return pageFinishedOrder(firstDayOfMonth, endDayOfMonth); + } } diff --git a/src/test/java/com/chint/AmapTest.java b/src/test/java/com/chint/AmapTest.java index 567d4813..a537fdab 100644 --- a/src/test/java/com/chint/AmapTest.java +++ b/src/test/java/com/chint/AmapTest.java @@ -13,10 +13,9 @@ import com.chint.interfaces.rest.amap.BaseResponse; import com.chint.interfaces.rest.amap.dto.UserQueryResponse; import com.chint.interfaces.rest.amap.dto.detail.AmapOrderDetailResponse; import com.chint.interfaces.rest.amap.dto.location.LocationResponse; -import com.chint.interfaces.rest.amap.dto.settlement.FinishedOrderResponse; import com.chint.interfaces.rest.amap.dto.token.TokenResponse; import com.chint.interfaces.rest.amap.request.AmapOrderDetailRequest; -import com.chint.interfaces.rest.amap.request.SettleBillRequest; +import com.chint.interfaces.rest.amap.request.AmapSettleBillRequest; import com.chint.interfaces.rest.amap.request.TakeCarRequest; import com.chint.interfaces.rest.amap.request.TokenRequest; import com.chint.interfaces.rest.base.dto.H5LoginResponse; @@ -26,7 +25,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import java.util.List; import java.util.Optional; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP; @@ -56,7 +54,7 @@ public class AmapTest { @Autowired - private SettleBillRequest settleBillRequest; + private AmapSettleBillRequest settleBillRequest; @Test public void search() { diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index be8d3cb6..661c9588 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -246,7 +246,7 @@ public class CTripTest { @Test void search() { BaseContext.setCurrentUser(user); - SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32527114975"); + SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31674878596"); System.out.println(response); } diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index ad9971da..e940b9bf 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -828,7 +828,7 @@ public class LYTest { @Test void searchHotel() { - HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240330143900871266"); + HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240523153100458921"); Gson gson = new Gson(); String json = gson.toJson(hotelOrderDetail); System.out.println(json); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index a2649ca1..ac8886a0 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -299,10 +299,10 @@ class RouteApplicationTests { @Test void loginSign() { - String sfno = "220531010"; + String sfno = "030710001"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; - String companycode = "A70000021"; + String companycode = "正泰集团股份有限公司"; String timespan = "1708908662738"; String s = Digest.md5(sfno + syscode + billcode + companycode + LOGIN_SECRET_KEY + timespan); System.out.println(s);