计算续租时间和金额
This commit is contained in:
@ -149,7 +149,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
orderMainPO.setFirstOrderTime(LocalDateTime.now());
|
orderMainPO.setFirstOrderTime(LocalDateTime.now());
|
||||||
|
|
||||||
//设置预计还车时间
|
//设置预计还车时间
|
||||||
LocalDateTime endRentTime = OrderUtil.getEndRentTime(orderMainPO.getFirstOrderTime(),rentCarRuleDTO.getRentalDays(), rentCarRuleDTO.getRentalType());
|
LocalDateTime endRentTime = OrderUtil.getEndRentTime(orderMainPO.getFirstOrderTime(),1,rentCarRuleDTO.getRentalDays(), rentCarRuleDTO.getRentalType());
|
||||||
orderMainPO.setEndRentTime(endRentTime);
|
orderMainPO.setEndRentTime(endRentTime);
|
||||||
|
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
orderSubPOList.add(depositOrder);
|
orderSubPOList.add(depositOrder);
|
||||||
}
|
}
|
||||||
//生成租车订单
|
//生成租车订单
|
||||||
BigDecimal rentCarOrderAmount = getRentCarAmount(rentCarRuleDTO.getRentalType(), rentCarRuleDTO.getRentalPrice(), rentCarRuleDTO.getRentalDays());
|
BigDecimal rentCarOrderAmount = OrderUtil.getRentCarAmount(rentCarRuleDTO.getRentalType(), rentCarRuleDTO.getRentalPrice(), rentCarRuleDTO.getRentalDays());
|
||||||
OrderSubPO rentOrder = new OrderSubPO();
|
OrderSubPO rentOrder = new OrderSubPO();
|
||||||
rentOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.ZC_PREFIX));
|
rentOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.ZC_PREFIX));
|
||||||
rentOrder.setSuborderType(SubOrderTypeEnum.RENTCAR.getCode());
|
rentOrder.setSuborderType(SubOrderTypeEnum.RENTCAR.getCode());
|
||||||
@ -270,8 +270,10 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
}else {
|
}else {
|
||||||
paymentType = PaymentTypeEnum.ZFB_PAY.getCode();
|
paymentType = PaymentTypeEnum.ZFB_PAY.getCode();
|
||||||
}
|
}
|
||||||
|
//计算续租周期
|
||||||
|
int rerentInterval = OrderUtil.calculateRerentRoundsToCoverOverdue(orderMainPO.getOverdueDays(), orderMainPO.getRentalDays());
|
||||||
//获取续租车金额
|
//获取续租车金额
|
||||||
BigDecimal rentCarOrderAmount = getReRentCarAmount(orderMainPO.getEndRentTime(), orderMainPO.getRentalType(), orderMainPO.getRentalPrice(), orderMainPO.getRentalDays());
|
BigDecimal rentCarOrderAmount = OrderUtil.getReRentCarAmount(rerentInterval, orderMainPO.getRentalPrice());
|
||||||
//获取租电金额
|
//获取租电金额
|
||||||
BigDecimal rentBatteyOrderAmount = BigDecimal.ZERO ;
|
BigDecimal rentBatteyOrderAmount = BigDecimal.ZERO ;
|
||||||
RentBatteyRuleDTO rentBatteyRuleDTO = null;
|
RentBatteyRuleDTO rentBatteyRuleDTO = null;
|
||||||
@ -289,7 +291,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
LocalDateTime nowTime = LocalDateTime.now();
|
LocalDateTime nowTime = LocalDateTime.now();
|
||||||
LocalDateTime oldEndRentTime = orderMainPO.getEndRentTime().isAfter(nowTime) ? orderMainPO.getEndRentTime() : nowTime;
|
LocalDateTime oldEndRentTime = orderMainPO.getEndRentTime().isAfter(nowTime) ? orderMainPO.getEndRentTime() : nowTime;
|
||||||
//刷新预计还车时间
|
//刷新预计还车时间
|
||||||
LocalDateTime newEndRentTime = OrderUtil.getEndRentTime(oldEndRentTime, orderMainPO.getRentalDays(), orderMainPO.getRentalType());
|
LocalDateTime newEndRentTime = OrderUtil.getEndRentTime(oldEndRentTime, rerentInterval,orderMainPO.getRentalDays(), orderMainPO.getRentalType());
|
||||||
|
|
||||||
//生成租车子订单
|
//生成租车子订单
|
||||||
OrderSubPO rentOrder = new OrderSubPO();
|
OrderSubPO rentOrder = new OrderSubPO();
|
||||||
@ -654,9 +656,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
orderDetailDTO.setPayOrderDTOList(OrderSubConvert.INSTANCE.posToPayOrderDtos(orderSubPOList2));
|
orderDetailDTO.setPayOrderDTOList(OrderSubConvert.INSTANCE.posToPayOrderDtos(orderSubPOList2));
|
||||||
orderDetailDTO.setRentBatteyOrderNo(orderSubPOList2.stream().filter(orderSubPO -> StringUtils.equalsIgnoreCase(orderSubPO.getSuborderType(), SubOrderTypeEnum.RENTBATTEY.getCode())).findFirst().map(OrderSubPO::getSuborderNo).orElse( null));
|
orderDetailDTO.setRentBatteyOrderNo(orderSubPOList2.stream().filter(orderSubPO -> StringUtils.equalsIgnoreCase(orderSubPO.getSuborderType(), SubOrderTypeEnum.RENTBATTEY.getCode())).findFirst().map(OrderSubPO::getSuborderNo).orElse( null));
|
||||||
}
|
}
|
||||||
//计算续租金额
|
|
||||||
BigDecimal reRentCarAmount = getReRentCarAmount(orderMainPO.getEndRentTime(), orderMainPO.getRentalType(), orderMainPO.getRentalPrice(), orderMainPO.getRentalDays());
|
|
||||||
orderDetailDTO.setRerentAmount(reRentCarAmount);
|
|
||||||
|
|
||||||
if(OrderStatusEnum.RENT_ING.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
if(OrderStatusEnum.RENT_ING.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||||||
//如果是租车中,需要判断是否逾期了
|
//如果是租车中,需要判断是否逾期了
|
||||||
@ -687,13 +687,22 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
updateWrapper.set(OrderMainPO::getOverdueDays, overdueDays);
|
updateWrapper.set(OrderMainPO::getOverdueDays, overdueDays);
|
||||||
updateWrapper.eq(OrderMainPO::getOrderId, orderMainPO.getOrderId());
|
updateWrapper.eq(OrderMainPO::getOrderId, orderMainPO.getOrderId());
|
||||||
orderMainRepo.update(updateWrapper);
|
orderMainRepo.update(updateWrapper);
|
||||||
|
//计算续租周期
|
||||||
|
int rerentInterval = OrderUtil.calculateRerentRoundsToCoverOverdue(overdueDays, orderMainPO.getRentalDays());
|
||||||
|
//获取续租车金额
|
||||||
|
BigDecimal reRentCarAmount = OrderUtil.getReRentCarAmount(rerentInterval, orderMainPO.getRentalPrice());
|
||||||
|
orderDetailDTO.setRerentAmount(reRentCarAmount);
|
||||||
}else {
|
}else {
|
||||||
//没逾期则计算到期天数
|
//没逾期则计算到期天数
|
||||||
orderDetailDTO.setExpectedDays(OrderUtil.getOrderExpectedDays(orderMainPO.getEndRentTime()));
|
orderDetailDTO.setExpectedDays(OrderUtil.getOrderExpectedDays(orderMainPO.getEndRentTime()));
|
||||||
|
//计算续租金额
|
||||||
|
BigDecimal reRentCarAmount = OrderUtil.getReRentCarAmount(1, orderMainPO.getRentalPrice());
|
||||||
|
orderDetailDTO.setRerentAmount(reRentCarAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if(OrderStatusEnum.RENT_OVERDUE.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
} else if(OrderStatusEnum.RENT_OVERDUE.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||||||
log.info("订单已逾期的,计算逾期金额");
|
log.info("订单已逾期的,计算逾期金额");
|
||||||
if(orderMainPO.getEndRentTime()!=null){
|
if(orderMainPO.getEndRentTime()!=null){
|
||||||
@ -702,7 +711,11 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
overdueDaysOrHours = OrderUtil.getOrderOverdueHours(orderMainPO.getEndRentTime());
|
overdueDaysOrHours = OrderUtil.getOrderOverdueHours(orderMainPO.getEndRentTime());
|
||||||
}
|
}
|
||||||
orderDetailDTO.setOverdueAmount(OrderUtil.getOrderOverdueAmount(overdueDaysOrHours, orderMainPO.getOverdueFee()));
|
orderDetailDTO.setOverdueAmount(OrderUtil.getOrderOverdueAmount(overdueDaysOrHours, orderMainPO.getOverdueFee()));
|
||||||
|
//计算续租周期
|
||||||
|
int rerentInterval = OrderUtil.calculateRerentRoundsToCoverOverdue(overdueDaysOrHours, orderMainPO.getRentalDays());
|
||||||
|
//获取续租车金额
|
||||||
|
BigDecimal reRentCarAmount = OrderUtil.getReRentCarAmount(rerentInterval, orderMainPO.getRentalPrice());
|
||||||
|
orderDetailDTO.setRerentAmount(reRentCarAmount);
|
||||||
}
|
}
|
||||||
} else if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())
|
} else if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())
|
||||||
||OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||||||
@ -865,7 +878,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
LocalDateTime currentTime = LocalDateTime.now();
|
LocalDateTime currentTime = LocalDateTime.now();
|
||||||
|
|
||||||
//设置预计还车时间
|
//设置预计还车时间
|
||||||
LocalDateTime endRentTime = OrderUtil.getEndRentTime(currentTime,orderMainPO.getRentalDays(), orderMainPO.getRentalType());
|
LocalDateTime endRentTime = OrderUtil.getEndRentTime(currentTime,1,orderMainPO.getRentalDays(), orderMainPO.getRentalType());
|
||||||
|
|
||||||
LambdaUpdateWrapper<OrderMainPO> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<OrderMainPO> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
updateWrapper.set(OrderMainPO::getOrderStatus, OrderStatusEnum.RENT_ING.getCode());
|
updateWrapper.set(OrderMainPO::getOrderStatus, OrderStatusEnum.RENT_ING.getCode());
|
||||||
@ -1215,50 +1228,5 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取租车订单金额
|
|
||||||
* @param rentalType
|
|
||||||
* @param rentalPrice
|
|
||||||
* @param rentalDays
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static BigDecimal getRentCarAmount(String rentalType, BigDecimal rentalPrice, Integer rentalDays) {
|
|
||||||
// BigDecimal rentCarOrderAmount = new BigDecimal(0);
|
|
||||||
// if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)||RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
|
||||||
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice);
|
|
||||||
// } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
|
||||||
// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(rentalDays));
|
|
||||||
// } else {
|
|
||||||
// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(30));
|
|
||||||
// }
|
|
||||||
return rentalPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取续租订单金额
|
|
||||||
* @param endRentTime
|
|
||||||
* @param rentalType
|
|
||||||
* @param rentalPrice
|
|
||||||
* @param ruleRentalDays
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static BigDecimal getReRentCarAmount(LocalDateTime endRentTime,String rentalType, BigDecimal rentalPrice, Integer ruleRentalDays) {
|
|
||||||
//计算续租金额
|
|
||||||
// BigDecimal rentCarOrderAmount = new BigDecimal(0);
|
|
||||||
// if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
|
||||||
// Integer overdueHours = OrderUtil.getOrderOverdueHours(endRentTime);
|
|
||||||
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(overdueHours+1)));
|
|
||||||
// } else if(RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
|
||||||
// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
|
||||||
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+1)));
|
|
||||||
// } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
|
||||||
// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
|
||||||
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+ruleRentalDays)));
|
|
||||||
// } else {
|
|
||||||
// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
|
||||||
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+30)));
|
|
||||||
// }
|
|
||||||
return rentalPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,19 +114,63 @@ public class OrderUtil {
|
|||||||
* @param rentalType 租期类型
|
* @param rentalType 租期类型
|
||||||
* @return 预计还车时间
|
* @return 预计还车时间
|
||||||
*/
|
*/
|
||||||
public static LocalDateTime getEndRentTime(LocalDateTime origTime,Integer rentalDays, String rentalType) {
|
public static LocalDateTime getEndRentTime(LocalDateTime origTime,Integer rerentInterval,Integer rentalDays, String rentalType) {
|
||||||
LocalDateTime endRentTime = null;
|
LocalDateTime endRentTime = null;
|
||||||
//设置预计还车时间
|
//设置预计还车时间
|
||||||
if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.HOUR_RENTAL.getCode(), rentalType)){
|
if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.HOUR_RENTAL.getCode(), rentalType)){
|
||||||
endRentTime = origTime.plusHours(1);
|
endRentTime = origTime.plusHours(rerentInterval);
|
||||||
}else if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.DAILY_RENTAL.getCode(), rentalType)){
|
}else if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.DAILY_RENTAL.getCode(), rentalType)){
|
||||||
endRentTime = origTime.plusDays(1);
|
endRentTime = origTime.plusDays(rerentInterval);
|
||||||
} else if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.DAYS_RENTAL.getCode(), rentalType)){
|
} else if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.DAYS_RENTAL.getCode(), rentalType)){
|
||||||
endRentTime = origTime.plusDays(rentalDays);
|
endRentTime = origTime.plusDays((long) rerentInterval * rentalDays);
|
||||||
} else if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.RENT_INSTEAD_SELL.getCode(), rentalType)){
|
} else if(StringUtils.equalsIgnoreCase(RentCarTypeEnum.RENT_INSTEAD_SELL.getCode(), rentalType)){
|
||||||
//以租代售默认期限为30天
|
//以租代售默认期限为30天
|
||||||
endRentTime = origTime.plusDays(30);
|
endRentTime = origTime.plusDays(rerentInterval*30);
|
||||||
}
|
}
|
||||||
return endRentTime;
|
return endRentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取租车订单金额
|
||||||
|
* @param rentalType
|
||||||
|
* @param rentalPrice
|
||||||
|
* @param rentalDays
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BigDecimal getRentCarAmount(String rentalType, BigDecimal rentalPrice, Integer rentalDays) {
|
||||||
|
// BigDecimal rentCarOrderAmount = new BigDecimal(0);
|
||||||
|
// if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)||RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
||||||
|
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice);
|
||||||
|
// } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
||||||
|
// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(rentalDays));
|
||||||
|
// } else {
|
||||||
|
// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(30));
|
||||||
|
// }
|
||||||
|
return rentalPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取续租订单金额
|
||||||
|
* @param rerentInterval 续租周期
|
||||||
|
* @param rentalPrice
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BigDecimal getReRentCarAmount(int rerentInterval,BigDecimal rentalPrice) {
|
||||||
|
//计算续租金额
|
||||||
|
return rentalPrice.multiply(new BigDecimal(rerentInterval));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算续租轮数以覆盖逾期天数
|
||||||
|
* @param overdueDays 逾期天数
|
||||||
|
* @param rentalDays 每轮续租天数
|
||||||
|
* @return 需要的续租轮数
|
||||||
|
*/
|
||||||
|
public static int calculateRerentRoundsToCoverOverdue(Integer overdueDays, Integer rentalDays) {
|
||||||
|
overdueDays = overdueDays == null|| overdueDays == 0 ? 1 : overdueDays;
|
||||||
|
rentalDays = rentalDays == null|| rentalDays == 0 ? 1 : overdueDays;
|
||||||
|
// 使用向上取整计算需要的续租轮数
|
||||||
|
return (int) Math.ceil((double) overdueDays / rentalDays);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user