fix: 优化携程结算功能,高德结算功能

This commit is contained in:
lulz1 2024-06-14 14:50:57 +08:00
parent 88872c2922
commit f89b8b803d
19 changed files with 302 additions and 102 deletions

View File

@ -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;

View File

@ -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<String> generateFromRecord(@RequestBody RecordMonthSaveDTO param) {
//
// return Result.Success(SUCCESS);
//
// }
@ApiOperation("生成结算数据根据时间参数")
@PostMapping("/record/generate")
public Result<String> 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

View File

@ -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
) {
// 行程信息

View File

@ -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()
);

View File

@ -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;
}

View File

@ -11,4 +11,7 @@ public interface AmapCarOrderRecordRepository {
List<AmapCarOrderRecord> findByOrderIds(List<String> orderIds);
List<AmapCarOrderRecord> findByDs(String ds);
List<AmapCarOrderRecord> findByOneDate(String oneDate);
List<AmapCarOrderRecord> findByDate(String date);
}

View File

@ -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<OrderHotelRecord> generateHotelRecord(OrderRecordGenerateCommand command) {
return List.of();
}
@Override
public List<OrderHotelRecord> generateHotelRecordMultiParam(OrderRecordGenerateCommand command) {
return List.of();
}
@Override
public List<OrderTrainRecord> generateTrainRecord(OrderRecordGenerateCommand command) {
return List.of();
}
@Override
public List<OrderTrainRecord> generateTrainRecordMultiParam(OrderRecordGenerateCommand command) {
return List.of();
}
@Override
public List<OrderFlightRecord> generateFlightRecord(OrderRecordGenerateCommand command) {
return List.of();
}
@Override
public List<OrderFlightRecord> generateFlightRecordMultiParam(OrderRecordGenerateCommand command) {
return List.of();
}
@ListenTo(command = "OrderRecordGenerateCommand", order = 0)
@Override
public List<OrderCarRecord> generateCarRecord(OrderRecordGenerateCommand command) {
if (!command.getSupplierName().equals(SUPPLIER_AMAP)) {
return List.of();
}
List<AmapCarOrderRecord> amapCarOrderRecordList = aMapCarOrderRecordRepository.findByDs(command.getDate());
OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP);
return getOrderCarRecords(command);
}
@Override
public List<OrderCarRecord> generateCarRecordMultiParam(OrderRecordGenerateCommand command) {
return getOrderCarRecords(command);
}
private List<OrderCarRecord> getOrderCarRecords(OrderRecordGenerateCommand command) {
List<AmapCarOrderRecord> 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<OrderCarRecord> mapToCarRecord(List<AmapCarOrderRecord> amapCarOrderRecordList) {
OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_AMAP, OrderRecordExtensionFactory.class);
List<String> routeOrderNoList = amapCarOrderRecordList.stream().map(AmapCarOrderRecord::getOutApplyRecordId).distinct().toList();
List<RouteOrder> routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList);
// 根据RouteOrder的checkIfMine方法创建一个包含自己订单的Map

View File

@ -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<CTripHotelRecord> records = cTripOrderDetailRepository.findHotelRecordByCreateTime(command.getStartTime(), command.getEndTime());
OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP);
return generateHotelRecord(command.getStartTime(), command.getEndTime());
}
public List<OrderHotelRecord> generateHotelRecordMultiParam(OrderRecordGenerateCommand command) {
command.generateStartAndEndTime();
return generateHotelRecord(command.getStartTime(), command.getEndTime());
}
private List<OrderHotelRecord> generateHotelRecord(LocalDateTime startTime, LocalDateTime endTime) {
List<CTripHotelRecord> records = cTripOrderDetailRepository.findHotelRecordByCreateTime(startTime, endTime);
OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_C_TRIP, OrderRecordExtensionFactory.class);
List<String> routeOrderNoList = records.stream().map(CTripHotelRecord::getRouteOrderNo).distinct().toList();
List<RouteOrder> routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList);
// 根据RouteOrder的checkIfMine方法创建一个包含自己订单的Map
Map<String, Optional<RouteOrder>> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(),
it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst()));
Map<String, Optional<RouteOrder>> routeOrderMap = createRouteOrderMap(routeOrderNoList, routeOrderList);
List<OrderHotelRecord> 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<OrderTrainRecord> generateTrainRecordMultiParam(OrderRecordGenerateCommand command) {
return List.of();
}
@ListenTo(command = "OrderRecordGenerateCommand", order = 1)
@Override
public List<OrderFlightRecord> generateFlightRecord(OrderRecordGenerateCommand command) {
if (!command.getSupplierName().equals(SUPPLIER_C_TRIP)) {
return List.of();
}
List<CTripFlightRecord> records = cTripOrderDetailRepository.findFlightRecordByCreateTime(command.getStartTime(), command.getEndTime());
OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP);
return generateFlightRecord(command.getStartTime(), command.getEndTime());
}
public List<OrderFlightRecord> generateFlightRecordMultiParam(OrderRecordGenerateCommand command) {
command.generateStartAndEndTime();
return generateFlightRecord(command.getStartTime(), command.getEndTime());
}
private List<OrderFlightRecord> generateFlightRecord(LocalDateTime startTime, LocalDateTime endTime) {
List<CTripFlightRecord> records = cTripOrderDetailRepository.findFlightRecordByCreateTime(startTime, endTime);
OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_C_TRIP, OrderRecordExtensionFactory.class);
List<String> routeOrderNoList = records.stream().map(CTripFlightRecord::getRouteOrderNo).distinct().toList();
List<RouteOrder> routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList);
// 根据RouteOrder的checkIfMine方法创建一个包含自己订单的Map
Map<String, Optional<RouteOrder>> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(),
it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst()));
List<OrderFlightRecord> orderFlightRecordList = records
.stream()
.map(it -> orderRecordExtensionFactory.createFlightOrderRecord(it, collect.get(it.getRouteOrderNo())))
Map<String, Optional<RouteOrder>> routeOrderMap = createRouteOrderMap(routeOrderNoList, routeOrderList);
List<OrderFlightRecord> orderFlightRecordList = records.stream()
.map(it -> orderRecordExtensionFactory.createFlightOrderRecord(it, routeOrderMap.get(it.getRouteOrderNo())))
.toList();
return orderDetailDomainService.saveFlightOrderRecordBatch(orderFlightRecordList);
}
private Map<String, Optional<RouteOrder>> createRouteOrderMap(List<String> routeOrderNoList, List<RouteOrder> 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<OrderCarRecord> generateCarRecord(OrderRecordGenerateCommand command) {
if (!command.getSupplierName().equals(SUPPLIER_C_TRIP)) {
return List.of();
}
List<CTripCarRecord> records = cTripOrderDetailRepository.findCarRecordByCreateTime(command.getStartTime(), command.getEndTime());
OrderRecordExtensionFactory orderRecordExtensionFactory = orderRecordFactorySelector.extensionFactoryOfSupplierName(SUPPLIER_C_TRIP);
return generateCarRecord(command.getStartTime(), command.getEndTime());
}
public List<OrderCarRecord> generateCarRecordMultiParam(OrderRecordGenerateCommand command){
command.generateStartAndEndTime();
return generateCarRecord(command.getStartTime(), command.getEndTime());
}
private List<OrderCarRecord> generateCarRecord(LocalDateTime startTime, LocalDateTime endTime){
List<CTripCarRecord> records = cTripOrderDetailRepository.findCarRecordByCreateTime(startTime, endTime);
OrderRecordExtensionFactory orderRecordExtensionFactory = supplierAdapterSelector.of(SUPPLIER_C_TRIP, OrderRecordExtensionFactory.class);
List<String> routeOrderNoList = records.stream().map(CTripCarRecord::getRouteOrderNo).distinct().toList();
List<RouteOrder> routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList);
// 根据RouteOrder的checkIfMine方法创建一个包含自己订单的Map
Map<String, Optional<RouteOrder>> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(),
it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst()));
List<OrderCarRecord> orderCarRecordList = records
.stream()
.map(it -> orderRecordExtensionFactory.createCarOrderRecord(it, collect.get(it.getRouteOrderNo())))
Map<String, Optional<RouteOrder>> routeOrderMap = createRouteOrderMap(routeOrderNoList, routeOrderList);
List<OrderCarRecord> orderCarRecordList = records.stream()
.map(it -> orderRecordExtensionFactory.createCarOrderRecord(it, routeOrderMap.get(it.getRouteOrderNo())))
.toList();
return orderDetailDomainService.saveCarOrderRecordBatch(orderCarRecordList);
}

View File

@ -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<OrderHotelRecord> generateHotelRecord(OrderRecordGenerateCommand command);
List<OrderHotelRecord> generateHotelRecordMultiParam(OrderRecordGenerateCommand command);
List<OrderTrainRecord> generateTrainRecord(OrderRecordGenerateCommand command);
List<OrderTrainRecord> generateTrainRecordMultiParam(OrderRecordGenerateCommand command);
List<OrderFlightRecord> generateFlightRecord(OrderRecordGenerateCommand command);
List<OrderFlightRecord> generateFlightRecordMultiParam(OrderRecordGenerateCommand command);
List<OrderCarRecord> generateCarRecord(OrderRecordGenerateCommand command);
List<OrderCarRecord> generateCarRecordMultiParam(OrderRecordGenerateCommand command);
}

View File

@ -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<ApplicationReadyEvent> {
private final Map<String, Map<Class<?>, SupplierAdapter>> adapterMap = new HashMap<>();
@ -23,14 +26,7 @@ public class SupplierAdapterSelector {
@PostConstruct
public void init() {
log.info("开始注入供应商适配器到选择器。。。。。");
Map<String, SupplierAdapter> 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<String, SupplierAdapter> 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);
}
}
}

View File

@ -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<OrderLegData> data = orderDataAdapterSelector.of(supplierName).adapt(callbackData);
Optional<OrderLegData> 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<OrderStatusChangeCommand> commandList = orderDataAdapterSelector
.of(supplierName)
List<OrderStatusChangeCommand> 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);

View File

@ -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;
}
}

View File

@ -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";
}

View File

@ -31,4 +31,14 @@ public class AmapCarOrderRecordRepositoryImpl implements AmapCarOrderRecordRepos
public List<AmapCarOrderRecord> findByDs(String ds) {
return jdbcAmapCarOrderRecordRepository.findByDsContaining(ds);
}
@Override
public List<AmapCarOrderRecord> findByOneDate(String oneDate) {
return jdbcAmapCarOrderRecordRepository.findByDs(oneDate);
}
@Override
public List<AmapCarOrderRecord> findByDate(String date) {
return jdbcAmapCarOrderRecordRepository.findByDsContaining(date);
}
}

View File

@ -10,5 +10,6 @@ import java.util.List;
@Repository
public interface JdbcAmapCarOrderRecordRepository extends CrudRepository<AmapCarOrderRecord, Long> {
List<AmapCarOrderRecord> findByDsContaining(String ds);
List<AmapCarOrderRecord> findByDs(String ds);
List<AmapCarOrderRecord> findByAmapOrderIdIn(Collection<String> amapOrderId);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -310,7 +310,7 @@ class RouteApplicationTests {
@Test
void loginSign() {
String sfno = "190506003";
String sfno = "190401151";
String syscode = "FSSC";
String billcode = "CLSQ240225000099";
String companycode = "正泰集团股份有限公司";