车辆计费规则保存
This commit is contained in:
parent
74552ac204
commit
08416252f7
@ -100,6 +100,14 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
|||||||
.orderType(OrderType.ONCE)
|
.orderType(OrderType.ONCE)
|
||||||
.startLocation(orderDto.getStartPoint())
|
.startLocation(orderDto.getStartPoint())
|
||||||
.startTime(LocalDateTime.now())
|
.startTime(LocalDateTime.now())
|
||||||
|
.baseFee(bikeInfo.getBaseFee())
|
||||||
|
.durationFee(bikeInfo.getDurationFee())
|
||||||
|
.freeDurationMinutes(bikeInfo.getFreeDurationMinutes())
|
||||||
|
.chargeDurationMinutes(bikeInfo.getChargeDurationMinutes())
|
||||||
|
.noParkingZoneFee(bikeInfo.getNoParkingZoneFee())
|
||||||
|
.outOfParkingAreaFee(bikeInfo.getOutOfParkingAreaFee())
|
||||||
|
.outOfServiceAreaFee(bikeInfo.getOutOfServiceAreaFee())
|
||||||
|
.maxFeeAmount(bikeInfo.getMaxFeeAmount())
|
||||||
.createTime(LocalDateTime.now())
|
.createTime(LocalDateTime.now())
|
||||||
.build();
|
.build();
|
||||||
save(order);
|
save(order);
|
||||||
@ -201,19 +209,8 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
|||||||
public Long doneRide(EbikeUserCyclingEndDto endDto) {
|
public Long doneRide(EbikeUserCyclingEndDto endDto) {
|
||||||
// 先校验是否有当前订单
|
// 先校验是否有当前订单
|
||||||
EbikeOrder order = getOrder(endDto);
|
EbikeOrder order = getOrder(endDto);
|
||||||
// 获取车辆信息,计算费用
|
|
||||||
EbikeBikeInfoVo bikeInfo = queryBikeInfo(endDto.getBikeCode());
|
|
||||||
order.setEndTime(LocalDateTime.now());
|
order.setEndTime(LocalDateTime.now());
|
||||||
order.setEndLocation(endDto.getEndPoint());
|
order.setEndLocation(endDto.getEndPoint());
|
||||||
order.setOperatorId(bikeInfo.getOperatorId());
|
|
||||||
order.setBaseFee(bikeInfo.getBaseFee());
|
|
||||||
order.setDurationFee(bikeInfo.getDurationFee());
|
|
||||||
order.setFreeDurationMinutes(bikeInfo.getFreeDurationMinutes());
|
|
||||||
order.setChargeDurationMinutes(bikeInfo.getChargeDurationMinutes());
|
|
||||||
order.setNoParkingZoneFee(bikeInfo.getNoParkingZoneFee());
|
|
||||||
order.setOutOfParkingAreaFee(bikeInfo.getOutOfParkingAreaFee());
|
|
||||||
order.setOutOfServiceAreaFee(bikeInfo.getOutOfServiceAreaFee());
|
|
||||||
order.setMaxFeeAmount(bikeInfo.getMaxFeeAmount());
|
|
||||||
// 关锁
|
// 关锁
|
||||||
EbikeLockVo ebikeLockVo = new EbikeLockVo();
|
EbikeLockVo ebikeLockVo = new EbikeLockVo();
|
||||||
ebikeLockVo.setBikeCode(endDto.getBikeCode());
|
ebikeLockVo.setBikeCode(endDto.getBikeCode());
|
||||||
@ -224,7 +221,7 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
|||||||
}
|
}
|
||||||
FeignEbikeUserLockDto data = jsonResult.getData();
|
FeignEbikeUserLockDto data = jsonResult.getData();
|
||||||
// 订单费用计算
|
// 订单费用计算
|
||||||
BigDecimal totalAmount = costCalculation(order.getStartTime(), order.getEndTime(), bikeInfo, data);
|
BigDecimal totalAmount = costCalculation(order.getEndTime(), order, data);
|
||||||
// 费用为0,不生成支付订单,直接订单已支付,返回订单id
|
// 费用为0,不生成支付订单,直接订单已支付,返回订单id
|
||||||
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||||
order.setPaymentTime(LocalDateTime.now());
|
order.setPaymentTime(LocalDateTime.now());
|
||||||
@ -248,8 +245,8 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
|||||||
.tradeId(StringUtils.generateLongSnowflakeId("tradeId"))
|
.tradeId(StringUtils.generateLongSnowflakeId("tradeId"))
|
||||||
.currency("CNY")
|
.currency("CNY")
|
||||||
.userId(endDto.getUserId())
|
.userId(endDto.getUserId())
|
||||||
|
.createBy(endDto.getUserId())
|
||||||
.operatorId(order.getOperatorId())
|
.operatorId(order.getOperatorId())
|
||||||
.createTime(LocalDateTime.now())
|
|
||||||
.tradeStatus(EbikePaymentTradeStatus.NO_PAYMENT)
|
.tradeStatus(EbikePaymentTradeStatus.NO_PAYMENT)
|
||||||
.build();
|
.build();
|
||||||
ebikePaymentService.save(payment);
|
ebikePaymentService.save(payment);
|
||||||
@ -384,21 +381,20 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
|||||||
/**
|
/**
|
||||||
* 计算订单费用
|
* 计算订单费用
|
||||||
*
|
*
|
||||||
* @param startTime 订单开始时间
|
* @param endTime 订单结束时间
|
||||||
* @param endTime 订单结束时间
|
* @param order 自行车详情
|
||||||
* @param bikeInfo 自行车详情
|
* @param data 是否在停车区
|
||||||
* @param data 是否在停车区
|
|
||||||
* @return 订单费用
|
* @return 订单费用
|
||||||
*/
|
*/
|
||||||
private BigDecimal costCalculation(LocalDateTime startTime, LocalDateTime endTime,
|
private BigDecimal costCalculation(LocalDateTime endTime,
|
||||||
EbikeBikeInfoVo bikeInfo, FeignEbikeUserLockDto data) {
|
EbikeOrder order, FeignEbikeUserLockDto data) {
|
||||||
// 基础费用计算
|
// 基础费用计算
|
||||||
BigDecimal baseFee = bikeInfo.getBaseFee();
|
BigDecimal baseFee = Objects.requireNonNullElse(order.getBaseFee(), BigDecimal.ZERO);
|
||||||
BigDecimal durationFee = bikeInfo.getDurationFee();
|
BigDecimal durationFee = Objects.requireNonNullElse(order.getDurationFee(), BigDecimal.ZERO);
|
||||||
Integer freeDurationMinutes = bikeInfo.getFreeDurationMinutes();
|
Integer freeDurationMinutes = order.getFreeDurationMinutes();
|
||||||
Integer chargeDurationMinutes = bikeInfo.getChargeDurationMinutes();
|
Integer chargeDurationMinutes = order.getChargeDurationMinutes();
|
||||||
// 获取总骑行时长(秒)
|
// 获取总骑行时长(秒)
|
||||||
long totalRideSeconds = Duration.between(startTime, endTime).toSeconds();
|
long totalRideSeconds = Duration.between(order.getStartTime(), endTime).toSeconds();
|
||||||
// 免费时间(秒)
|
// 免费时间(秒)
|
||||||
long freeDurationSeconds = freeDurationMinutes * GlobalConstants.LONG_SIXTY;
|
long freeDurationSeconds = freeDurationMinutes * GlobalConstants.LONG_SIXTY;
|
||||||
// 如果骑行时长小于等于免费时长,不收费
|
// 如果骑行时长小于等于免费时长,不收费
|
||||||
@ -419,19 +415,19 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
|||||||
if (data != null) {
|
if (data != null) {
|
||||||
// 运营区
|
// 运营区
|
||||||
if (Boolean.FALSE.equals(data.getBikeInRegion())) {
|
if (Boolean.FALSE.equals(data.getBikeInRegion())) {
|
||||||
additionalFee = bikeInfo.getOutOfServiceAreaFee() != null ? bikeInfo.getOutOfServiceAreaFee() : BigDecimal.ZERO;
|
additionalFee = order.getOutOfServiceAreaFee() != null ? order.getOutOfServiceAreaFee() : BigDecimal.ZERO;
|
||||||
} else if (Boolean.FALSE.equals(data.getBikeInParking())) {
|
} else if (Boolean.FALSE.equals(data.getBikeInParking())) {
|
||||||
// 不在运营区内但在停车区内
|
// 不在运营区内但在停车区内
|
||||||
additionalFee = bikeInfo.getOutOfParkingAreaFee() != null ? bikeInfo.getOutOfParkingAreaFee() : BigDecimal.ZERO;
|
additionalFee = order.getOutOfParkingAreaFee() != null ? order.getOutOfParkingAreaFee() : BigDecimal.ZERO;
|
||||||
} else if (Boolean.FALSE.equals(data.getBikeInNoParking())) {
|
} else if (Boolean.FALSE.equals(data.getBikeInNoParking())) {
|
||||||
// 不在运营区内也不在停车区内,但在禁停区内
|
// 不在运营区内也不在停车区内,但在禁停区内
|
||||||
additionalFee = bikeInfo.getNoParkingZoneFee() != null ? bikeInfo.getNoParkingZoneFee() : BigDecimal.ZERO;
|
additionalFee = order.getNoParkingZoneFee() != null ? order.getNoParkingZoneFee() : BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 计算总费用
|
// 计算总费用
|
||||||
BigDecimal totalCost = baseCost.add(additionalFee);
|
BigDecimal totalCost = baseCost.add(additionalFee);
|
||||||
// 检查是否超过封顶金额
|
// 检查是否超过封顶金额
|
||||||
BigDecimal maxFee = bikeInfo.getMaxFeeAmount();
|
BigDecimal maxFee = order.getMaxFeeAmount();
|
||||||
if (maxFee != null && totalCost.compareTo(maxFee) > 0) {
|
if (maxFee != null && totalCost.compareTo(maxFee) > 0) {
|
||||||
totalCost = maxFee;
|
totalCost = maxFee;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user