修复携程超标推送不成功的问题

This commit is contained in:
lulz1 2024-03-13 14:03:16 +08:00
parent ce76c2e264
commit c125c86259
3 changed files with 51 additions and 32 deletions

View File

@ -209,19 +209,16 @@ public class OrderDomainService {
private void toBpmAuditETA(BPMAuditCommand command) {
OrderDetail orderDetail = command.getExtensionData();
Object data = orderDetail.getExtensionDataByProductType();
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
String sysCode = routeOrder.getApproveOrderNo().getSysCode();
ExceedStandardDto exceedStandardDto = switch (command.getProductType()) {
case LEG_TYPE_TRAIN -> bpmParamFactory.creatAuditParamByTrain((TrainOrderDetail) data);
case LEG_TYPE_AIRPLANE -> bpmParamFactory.creatAuditParamByFlight(orderDetail, (FlightOrderDetail) data);
case LEG_TYPE_HOTEL ->
bpmParamFactory.creatAuditParamByHotel(orderDetail, (HotelOrderDetail) data);
case LEG_TYPE_TAXI -> bpmParamFactory.creatAuditParamByCar((CarOrderDetail) data);
case LEG_TYPE_OTHER -> bpmParamFactory.creatAuditParamByOther((OtherOrderDetail) data);
case LEG_TYPE_TRAIN -> bpmParamFactory.creatAuditParamByTrain(orderDetail);
case LEG_TYPE_AIRPLANE -> bpmParamFactory.creatAuditParamByFlight(orderDetail);
case LEG_TYPE_HOTEL -> bpmParamFactory.creatAuditParamByHotel(orderDetail);
case LEG_TYPE_TAXI -> bpmParamFactory.creatAuditParamByCar(orderDetail);
case LEG_TYPE_OTHER -> bpmParamFactory.creatAuditParamByOther(orderDetail);
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
};
exceedStandardDto.setReason(command.getReason());
DelayDispatch.attemptToSend(() -> bpmRequest.exceedStandard(exceedStandardDto, sysCode).getSuccess(),
0);
@ -232,8 +229,6 @@ public class OrderDomainService {
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
String sysCode = routeOrder.getApproveOrderNo().getSysCode();
String reason = command.getReason();
RescheduleDto rescheduleDto = new RescheduleDto();
rescheduleDto.setFee(orderDetail.getPrice() == null ? new BigDecimal(0) : new BigDecimal(orderDetail.getPrice()))

View File

@ -0,0 +1,14 @@
package com.chint.infrastructure.util;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class DaysUtil {
public static int calculateNightsBetweenDates(LocalDate start, LocalDate end) {
// 计算两个日期之间的天数差异不包括结束日期
long daysBetween = ChronoUnit.DAYS.between(start, end);
// 将天数差异转换为晚上数量
return (int) daysBetween;
}
}

View File

@ -5,8 +5,7 @@ import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.LegRepository;
import com.chint.infrastructure.constant.BPMConstant;
import com.chint.infrastructure.constant.CommonMessageConstant;
import com.chint.infrastructure.constant.SupplierNameConstant;
import com.chint.infrastructure.util.BigDecimalCalculator;
import com.chint.infrastructure.util.DaysUtil;
import com.chint.interfaces.rest.bpm.dto.ExceedStandardDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -14,10 +13,10 @@ import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalDate;
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_HOTEL;
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP_BPM_NAME;
import static com.chint.infrastructure.constant.SupplierNameConstant.*;
@Component
public class BPMParamFactory {
@ -25,29 +24,33 @@ public class BPMParamFactory {
@Autowired
private LegRepository legRepository;
public ExceedStandardDto creatAuditParamByCar(CarOrderDetail carOrderDetail) {
public ExceedStandardDto creatAuditParamByCar(OrderDetail orderDetail) {
CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail();
ExceedStandardDto exceedStandardDto = new ExceedStandardDto();
String supplierName = orderDetail.getSupplierName();
exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_CAR)
.setOrderSource(getSupplierName(carOrderDetail.getSupplier()))
.setOrderSource(getSupplierName(supplierName))
.setOrderNo(carOrderDetail.getOrderNo())
.setExcessAmount(BigDecimal.valueOf(Double.parseDouble(carOrderDetail.getOrderAmount())))
.setReason(carOrderDetail.getOverStandardReason());
return exceedStandardDto;
}
public ExceedStandardDto creatAuditParamByTrain(TrainOrderDetail trainOrderDetail) {
public ExceedStandardDto creatAuditParamByTrain(OrderDetail orderDetail) {
TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail();
ExceedStandardDto exceedStandardDto = new ExceedStandardDto();
String supplierName = getSupplierName(trainOrderDetail.getSupplier());
String supplierName = getSupplierName(orderDetail.getSupplierName());
exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_TRAIN)
.setSeatingStandard(trainOrderDetail.getSeatName())
.setOrderSource(getSupplierName(trainOrderDetail.getSupplier()))
.setOrderSource(supplierName)
.setOrderNo(trainOrderDetail.getOrderNo())
.setExcessAmount(BigDecimal.valueOf(Double.parseDouble(trainOrderDetail.getOrderAmount())))
.setReason(trainOrderDetail.getOverStandardReason());
return exceedStandardDto;
}
public ExceedStandardDto creatAuditParamByHotel(OrderDetail orderDetail, HotelOrderDetail hotelOrderDetail) {
public ExceedStandardDto creatAuditParamByHotel(OrderDetail orderDetail) {
HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail();
ExceedStandardDto exceedStandardDto = new ExceedStandardDto();
Long legId = orderDetail.getLegId();
//差旅标准金额
@ -68,12 +71,18 @@ public class BPMParamFactory {
}
//金额计算
BigDecimal bigTotalPrice = new BigDecimal(orderDetail.getPrice() == null ? "0" : orderDetail.getPrice());//获取酒店需要支付的总价格
Duration duration = Duration.between(orderDetail.getStartTime(), orderDetail.getEndTime());
//获取实际的入住天数
long actualDays = duration.toDays(); // 获取天数差异
//超标总金额
int actualDays = DaysUtil.calculateNightsBetweenDates(LocalDate.from(orderDetail.getStartTime()), LocalDate.from(orderDetail.getEndTime()));
BigDecimal result = bigTotalPrice.subtract(standardPrice.multiply(BigDecimal.valueOf(actualDays)));
String supplierName = getSupplierName(hotelOrderDetail.getSupplier());
BigDecimal divide;
if (actualDays > 0) {
divide = result.divide(new BigDecimal(actualDays), 3, RoundingMode.HALF_UP);
} else {
divide = result;
}
//超标总金额
String supplierName = getSupplierName(orderDetail.getSupplierName());
exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_HOTEL)
.setHotelStandard(String.valueOf(standardPrice))//差旅标准
.setHouseLayout(hotelOrderDetail.getRoomTypeName())
@ -84,23 +93,24 @@ public class BPMParamFactory {
.setReason(hotelOrderDetail.getOverStandardReason())
.setOccupant(hotelOrderDetail.getBookingName())//入住人
.setDays(Integer.valueOf(hotelOrderDetail.getNightCount()))//入住天数
.setExcessAmountDay(result.divide(new BigDecimal(actualDays), 3, RoundingMode.HALF_UP));//超标金额(/)
.setExcessAmountDay(divide);//超标金额(/)
return exceedStandardDto;
}
public ExceedStandardDto creatAuditParamByFlight(OrderDetail orderDetail, FlightOrderDetail flightOrderDetail) {
public ExceedStandardDto creatAuditParamByFlight(OrderDetail orderDetail) {
FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail();
ExceedStandardDto exceedStandardDto = new ExceedStandardDto();
String supplierName = getSupplierName(flightOrderDetail.getSupplier());
String supplierName = getSupplierName(orderDetail.getSupplierName());
exceedStandardDto.setOrderType(BPMConstant.EXCEED_STANDARD_TYPE_FLIGHT)
.setCabinClass(flightOrderDetail.getSeatPointName())
.setOrderSource(getSupplierName(flightOrderDetail.getSupplier()))
.setOrderSource(supplierName)
.setOrderNo(flightOrderDetail.getOrderNo())
.setExcessAmount(BigDecimal.valueOf(Double.parseDouble(flightOrderDetail.getOrderAmount())))
.setReason(flightOrderDetail.getOverStandardReason());
return exceedStandardDto;
}
public ExceedStandardDto creatAuditParamByOther(OtherOrderDetail otherOrderDetail) {
public ExceedStandardDto creatAuditParamByOther(OrderDetail orderDetail) {
ExceedStandardDto exceedStandardDto = new ExceedStandardDto();
// exceedStandardDto.setOrderType(EXCEED_STANDARD_TYPE_CAR)
// .setOrderSource(getSupplierName(carOrderDetail.getSupplier()))
@ -113,8 +123,8 @@ public class BPMParamFactory {
private String getSupplierName(String supplier) {
return switch (supplier) {
case SupplierNameConstant.SUPPLIER_C_TRIP_EXTENSION_NAME -> SUPPLIER_C_TRIP_BPM_NAME;
case SupplierNameConstant.SUPPLIER_L_Y_EXTENSION_NAME -> SupplierNameConstant.SUPPLIER_L_Y_BPM_NAME;
case SUPPLIER_C_TRIP -> SUPPLIER_C_TRIP_BPM_NAME;
case SUPPLIER_L_Y -> SUPPLIER_L_Y_BPM_NAME;
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
};
}