@ -104,11 +104,15 @@ public class OrderServiceImpl implements OrderService {
orderMainPO . setOrderStatus ( OrderStatusEnum . WAIT_PICK . getCode ( ) ) ;
orderMainPO . setFirstOrderTime ( LocalDateTime . now ( ) ) ;
//设置预计还车时间
if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . DAILY _RENTAL. getCode ( ) , rentCarRuleDT O. getRentalType ( ) )
| | StringUtils . equalsIgnoreCase ( RentCarTypeEnum . HOUR_RENTAL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . HOUR _RENTAL. getCode ( ) , orderMainP O. getRentalType ( ) ) ) {
orderMainPO . setEndRentTime ( LocalDateTime . now ( ) . plusHours ( 1 ) ) ;
} else if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . DAILY_RENTAL . getCode ( ) , rentCarRuleDTO . getRentalType ( ) ) ) {
orderMainPO . setEndRentTime ( LocalDateTime . now ( ) . plusDays ( 1 ) ) ;
} else if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . DAYS_RENTAL . getCode ( ) , rentCarRuleDTO . getRentalType ( ) ) ) {
orderMainPO . setEndRentTime ( LocalDateTime . now ( ) . plusDays ( rentCarRuleDTO . getRentalDays ( ) ) ) ;
} else if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . RENT_INSTEAD_SELL . getCode ( ) , rentCarRuleDTO . getRentalType ( ) ) ) {
//以租代售默认期限为30天
orderMainPO . setEndRentTime ( LocalDateTime . now ( ) . plusDays ( 30 ) ) ;
}
//生成子表订单
@ -150,12 +154,7 @@ public class OrderServiceImpl implements OrderService {
orderSubPOList . add ( depositOrder ) ;
}
//生成租车订单
BigDecimal rentCarOrderAmount = new BigDecimal ( 0 ) ;
if ( RentCarTypeEnum . DAYS_RENTAL . getCode ( ) . equalsIgnoreCase ( rentCarRuleDTO . getRentalType ( ) ) ) {
rentCarOrderAmount = rentCarRuleDTO . getRentalPrice ( ) . multiply ( new BigDecimal ( rentCarRuleDTO . getRentalDays ( ) ) ) ;
} else {
rentCarOrderAmount = rentCarOrderAmount . add ( rentCarRuleDTO . getRentalPrice ( ) ) ;
}
BigDecimal rentCarOrderAmount = getRentCarAmount ( rentCarRuleDTO . getRentalType ( ) , rentCarRuleDTO . getRentalPrice ( ) , rentCarRuleDTO . getRentalDays ( ) ) ;
OrderSubPO rentOrder = new OrderSubPO ( ) ;
rentOrder . setSuborderNo ( OrderUtil . generateSubOrderNo ( OrderUtil . ZC_PREFIX ) ) ;
rentOrder . setSuborderType ( SubOrderTypeEnum . RENTCAR . getCode ( ) ) ;
@ -198,6 +197,8 @@ public class OrderServiceImpl implements OrderService {
}
}
@Transactional ( rollbackFor = Exception . class )
@Override
public RentCarOrderResultDTO reRentalCarOrder ( ReRentCarReq rentCarOrderReq ) {
@ -228,12 +229,24 @@ public class OrderServiceImpl implements OrderService {
}
}
//生成租车订单
// BigDecimal rentCarOrderAmount = getRentCarAmount(orderMainPO.getRentalType(), orderMainPO.getRentalPrice(), orderMainPO.getRentalDays());
//计算续租金额
BigDecimal rentCarOrderAmount = new BigDecimal ( 0 ) ;
if ( RentCarTypeEnum . DAYS _RENTAL. getCode ( ) . equalsIgnoreCase ( orderMainPO . getRentalType ( ) ) ) {
rentCarOrderAmount = o rderMainPO . getRentalPrice ( ) . multiply ( new BigDecimal ( orderMainPO . getRentalDays ( ) ) ) ;
if ( RentCarTypeEnum . HOUR _RENTAL. getCode ( ) . equalsIgnoreCase ( orderMainPO . getRentalType ( ) ) ) {
Integer overdueHours = O rderUtil . getOrderOverdueHours ( orderMainPO . getEnd RentTime ( ) ) ;
rentCarOrderAmount = rentCarOrderAmount . add ( orderMainPO . getRentalPrice ( ) . multiply ( new BigDecimal ( overdueHours + 1 ) ) ) ;
} else if ( RentCarTypeEnum . DAILY_RENTAL . getCode ( ) . equalsIgnoreCase ( orderMainPO . getRentalType ( ) ) ) {
Integer rentalDays = OrderUtil . getOrderExpectedDays ( orderMainPO . getEndRentTime ( ) ) ;
rentCarOrderAmount = rentCarOrderAmount . add ( orderMainPO . getRentalPrice ( ) . multiply ( new BigDecimal ( rentalDays + 1 ) ) ) ;
} else if ( RentCarTypeEnum . DAYS_RENTAL . getCode ( ) . equalsIgnoreCase ( orderMainPO . getRentalType ( ) ) ) {
Integer rentalDays = OrderUtil . getOrderExpectedDays ( orderMainPO . getEndRentTime ( ) ) ;
rentCarOrderAmount = rentCarOrderAmount . add ( orderMainPO . getRentalPrice ( ) . multiply ( new BigDecimal ( rentalDays + orderMainPO . getRentalDays ( ) ) ) ) ;
} else {
rentCarOrderAmount = rentCarOrderAmount . add ( orderMainPO . getRentalPric e ( ) ) ;
Integer rentalDays = OrderUtil . getOrderExpectedDays ( orderMainPO . getEnd RentTim e ( ) ) ;
rentCarOrderAmount = rentCarOrderAmount . add ( orderMainPO . getRentalPrice ( ) . multiply ( new BigDecimal ( rentalDays + 30 ) ) ) ;
}
//生成租车子订单
OrderSubPO rentOrder = new OrderSubPO ( ) ;
rentOrder . setOrderId ( orderMainPO . getOrderId ( ) ) ;
@ -244,15 +257,18 @@ public class OrderServiceImpl implements OrderService {
rentOrder . setPaymentMethod ( paymentType ) ;
orderSubRepo . save ( rentOrder ) ;
LocalDateTime oldEndRent Time = orderMainPO . getEndRentTime ( ) ;
LocalDateTime now Time = LocalDateTime . now ( ) ;
LocalDateTime oldEndRentTime = orderMainPO . getEndRentTime ( ) . isAfter ( nowTime ) ? orderMainPO . getEndRentTime ( ) : nowTime ;
LocalDateTime newEndRentTime = oldEndRentTime ;
//刷新预计还车时间
if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . DAILY _RENTAL. getCode ( ) , orderMainPO . getRentalType ( ) )
| | StringUtils . equalsIgnoreCase ( RentCarTypeEnum . HOUR_RENTAL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . HOUR _RENTAL. getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
newEndRentTime = oldEndRentTime . plusHours ( 1 ) ;
} else if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . DAILY_RENTAL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
newEndRentTime = oldEndRentTime . plusDays ( 1 ) ;
} else if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . DAYS_RENTAL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
orderMainPO . setEndRentTime ( LocalDateTime . now ( ) . plusDays ( orderMainPO . getRentalDays ( ) ) ) ;
newEndRentTime = oldEndRentTime . plusDays ( orderMainPO . getRentalDays ( ) ) ;
} else if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . RENT_INSTEAD_SELL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
newEndRentTime = oldEndRentTime . plusDays ( 30 ) ;
}
//更新订单状态及信息
LambdaUpdateWrapper < OrderMainPO > updateWrapper = new LambdaUpdateWrapper < > ( ) ;
@ -314,8 +330,12 @@ public class OrderServiceImpl implements OrderService {
paymentType = PaymentTypeEnum . ZFB_PAY . getCode ( ) ;
}
}
Integer overDueDaysOrHours = OrderUtil . getOrderOverdueDays ( orderMainPO . getEndRentTime ( ) ) ;
if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . HOUR_RENTAL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
overDueDaysOrHours = OrderUtil . getOrderOverdueHours ( orderMainPO . getEndRentTime ( ) ) ;
}
//生成租车订单
BigDecimal overDueAmount = OrderUtil . getOrderOverdueAmount ( orderMainPO . getO verd ueDays( ) , orderMainPO . getOverdueFee ( ) ) ;
BigDecimal overDueAmount = OrderUtil . getOrderOverdueAmount ( overD ueDaysOrHours , orderMainPO . getOverdueFee ( ) ) ;
//生成租车子订单
OrderSubPO rentOrder = new OrderSubPO ( ) ;
rentOrder . setOrderId ( orderMainPO . getOrderId ( ) ) ;
@ -436,6 +456,18 @@ public class OrderServiceImpl implements OrderService {
//如果是租车中,需要判断是否逾期了
log . info ( " 判断订单是否逾期 " ) ;
if ( orderMainPO . getEndRentTime ( ) ! = null ) {
if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . HOUR_RENTAL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
Integer overdueHours = OrderUtil . getOrderOverdueHours ( orderMainPO . getEndRentTime ( ) ) ;
log . info ( " 预计还车时间:{},订单逾期小时数:{} " , orderMainPO . getEndRentTime ( ) , overdueHours ) ;
if ( overdueHours > 0 ) {
orderDetailDTO . setOverdueAmount ( OrderUtil . getOrderOverdueAmount ( overdueHours , orderMainPO . getOverdueFee ( ) ) ) ;
orderDetailDTO . setOrderStatus ( OrderStatusEnum . RENT_OVERDUE . getCode ( ) ) ;
LambdaUpdateWrapper < OrderMainPO > updateWrapper = new LambdaUpdateWrapper < > ( ) ;
updateWrapper . set ( OrderMainPO : : getOrderStatus , OrderStatusEnum . RENT_OVERDUE . getCode ( ) ) ;
updateWrapper . eq ( OrderMainPO : : getOrderId , orderMainPO . getOrderId ( ) ) ;
orderMainRepo . update ( updateWrapper ) ;
}
} else {
Integer overdueDays = OrderUtil . getOrderOverdueDays ( orderMainPO . getEndRentTime ( ) ) ;
log . info ( " 预计还车时间:{},订单逾期天数:{} " , orderMainPO . getEndRentTime ( ) , overdueDays ) ;
//逾期天数>0, 则改为逾期, 并且计算逾期天数以及逾期金额
@ -453,11 +485,17 @@ public class OrderServiceImpl implements OrderService {
orderDetailDTO . setExpectedDays ( OrderUtil . getOrderExpectedDays ( orderMainPO . getEndRentTime ( ) ) ) ;
}
}
}
} else if ( OrderStatusEnum . RENT_OVERDUE . getCode ( ) . equalsIgnoreCase ( orderMainPO . getOrderStatus ( ) ) ) {
log . info ( " 订单已逾期的,计算逾期金额 " ) ;
if ( orderMainPO . getEndRentTime ( ) ! = null ) {
orderDetailDTO . setOverdueAmount ( OrderUtil . getOrderOverdueAmount ( orderMainPO . getOverdueDays ( ) , orderMainPO . getOverdueFe e ( ) ) ) ;
Integer overdueDaysOrHours = OrderUtil . getOrderOverdueDays ( orderMainPO . getEndRentTim e ( ) ) ;
if ( StringUtils . equalsIgnoreCase ( RentCarTypeEnum . HOUR_RENTAL . getCode ( ) , orderMainPO . getRentalType ( ) ) ) {
overdueDaysOrHours = OrderUtil . getOrderOverdueHours ( orderMainPO . getEndRentTime ( ) ) ;
}
orderDetailDTO . setOverdueAmount ( OrderUtil . getOrderOverdueAmount ( overdueDaysOrHours , orderMainPO . getOverdueFee ( ) ) ) ;
}
} else if ( OrderStatusEnum . WAIT_PAY . getCode ( ) . equalsIgnoreCase ( orderMainPO . getOrderStatus ( ) ) | | OrderStatusEnum . RERENT_WAIT_PAY . getCode ( ) . equalsIgnoreCase ( orderMainPO . getOrderStatus ( ) ) ) {
//TODO 待支付状态要拉起支付
@ -608,4 +646,24 @@ public class OrderServiceImpl implements OrderService {
List < String > orderStatusList = orderQueryReq . getOrderStatusList ( ) . stream ( ) . map ( OrderStatusEnum : : getCode ) . collect ( Collectors . toList ( ) ) ;
return orderMainRepo . pageQueryOrder ( pageNo , pageSize , orderQueryReq . getCustomerId ( ) , orderQueryReq . getStoreId ( ) , orderStatusList , orderQueryReq . getQueryBrandName ( ) ) ;
}
/**
* 获取租车订单金额
* @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 rentCarOrderAmount ;
}
}