From 17dddc27a2f14d6e41e38a1ce165778746217a0b Mon Sep 17 00:00:00 2001 From: zhangli <123879394@qq.com> Date: Thu, 25 Sep 2025 00:33:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BB=AD=E7=A7=9F=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=92=8C=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/impl/OrderServiceImpl.java | 76 ++++++------------- .../java/com/sczx/order/utils/OrderUtil.java | 54 +++++++++++-- 2 files changed, 71 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java index 8c6c691..2e5f7a2 100644 --- a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java @@ -149,7 +149,7 @@ public class OrderServiceImpl implements OrderService { 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); @@ -184,7 +184,7 @@ public class OrderServiceImpl implements OrderService { 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(); rentOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.ZC_PREFIX)); rentOrder.setSuborderType(SubOrderTypeEnum.RENTCAR.getCode()); @@ -270,8 +270,10 @@ public class OrderServiceImpl implements OrderService { }else { 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 ; RentBatteyRuleDTO rentBatteyRuleDTO = null; @@ -289,7 +291,7 @@ public class OrderServiceImpl implements OrderService { LocalDateTime nowTime = LocalDateTime.now(); 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(); @@ -654,9 +656,7 @@ public class OrderServiceImpl implements OrderService { 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)); } - //计算续租金额 - BigDecimal reRentCarAmount = getReRentCarAmount(orderMainPO.getEndRentTime(), orderMainPO.getRentalType(), orderMainPO.getRentalPrice(), orderMainPO.getRentalDays()); - orderDetailDTO.setRerentAmount(reRentCarAmount); + if(OrderStatusEnum.RENT_ING.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){ //如果是租车中,需要判断是否逾期了 @@ -687,13 +687,22 @@ public class OrderServiceImpl implements OrderService { updateWrapper.set(OrderMainPO::getOverdueDays, overdueDays); updateWrapper.eq(OrderMainPO::getOrderId, orderMainPO.getOrderId()); orderMainRepo.update(updateWrapper); + //计算续租周期 + int rerentInterval = OrderUtil.calculateRerentRoundsToCoverOverdue(overdueDays, orderMainPO.getRentalDays()); + //获取续租车金额 + BigDecimal reRentCarAmount = OrderUtil.getReRentCarAmount(rerentInterval, orderMainPO.getRentalPrice()); + orderDetailDTO.setRerentAmount(reRentCarAmount); }else { //没逾期则计算到期天数 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())){ log.info("订单已逾期的,计算逾期金额"); if(orderMainPO.getEndRentTime()!=null){ @@ -702,7 +711,11 @@ public class OrderServiceImpl implements OrderService { overdueDaysOrHours = OrderUtil.getOrderOverdueHours(orderMainPO.getEndRentTime()); } 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()) ||OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){ @@ -865,7 +878,7 @@ public class OrderServiceImpl implements OrderService { LocalDateTime currentTime = LocalDateTime.now(); //设置预计还车时间 - LocalDateTime endRentTime = OrderUtil.getEndRentTime(currentTime,orderMainPO.getRentalDays(), orderMainPO.getRentalType()); + LocalDateTime endRentTime = OrderUtil.getEndRentTime(currentTime,1,orderMainPO.getRentalDays(), orderMainPO.getRentalType()); LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); 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; - } } diff --git a/src/main/java/com/sczx/order/utils/OrderUtil.java b/src/main/java/com/sczx/order/utils/OrderUtil.java index b1c7c6c..8c89b50 100644 --- a/src/main/java/com/sczx/order/utils/OrderUtil.java +++ b/src/main/java/com/sczx/order/utils/OrderUtil.java @@ -114,19 +114,63 @@ public class OrderUtil { * @param rentalType 租期类型 * @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; //设置预计还车时间 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)){ - endRentTime = origTime.plusDays(1); + endRentTime = origTime.plusDays(rerentInterval); } 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)){ //以租代售默认期限为30天 - endRentTime = origTime.plusDays(30); + endRentTime = origTime.plusDays(rerentInterval*30); } 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); + } }