车辆详情新增里程
This commit is contained in:
parent
e2c7ab3ac7
commit
74552ac204
@ -6,7 +6,6 @@ import com.cdzy.user.model.dto.EbikeUserCyclingDto;
|
||||
import com.cdzy.user.model.dto.EbikeUserCyclingEndDto;
|
||||
import com.cdzy.user.model.entity.EbikeOrder;
|
||||
import com.cdzy.user.model.vo.EbikeBikeInfoVo;
|
||||
import com.cdzy.user.model.vo.EbikeBikeRealInfoVo;
|
||||
import com.cdzy.user.model.vo.EbikeRevenueStatisticsVo;
|
||||
import com.cdzy.user.model.vo.EbikeUserAllOrdersVo;
|
||||
import com.cdzy.user.service.EbikeOrderService;
|
||||
@ -131,15 +130,4 @@ public class EbikeOrderController {
|
||||
List<EbikeRevenueStatisticsVo> revenueStatistics = ebikeOrderService.getRevenueStatistics();
|
||||
return JsonResult.success(revenueStatistics);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询车辆实时信息
|
||||
*
|
||||
* @return 车辆实时信息
|
||||
*/
|
||||
@GetMapping("getBikeRealTimeInfo")
|
||||
public JsonResult<?> getBikeRealTimeInfo(@RequestParam("orderId") Long orderId) {
|
||||
EbikeBikeRealInfoVo revenueStatistics = ebikeOrderService.getBikeRealTimeInfo(orderId);
|
||||
return JsonResult.success(revenueStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,11 @@ public class EbikeBikeInfoVo implements Serializable {
|
||||
*/
|
||||
private Float soc;
|
||||
|
||||
/**
|
||||
* 车辆可用里程
|
||||
*/
|
||||
private Long mileage;
|
||||
|
||||
/**
|
||||
* 车辆编号(与车辆二维码编号相同
|
||||
*/
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
package com.cdzy.user.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 车辆实时信息
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2025-12-26 11:03
|
||||
*/
|
||||
@Data
|
||||
public class EbikeBikeRealInfoVo implements Serializable {
|
||||
|
||||
/**
|
||||
* 当前费用
|
||||
*/
|
||||
private BigDecimal cost;
|
||||
|
||||
/**
|
||||
* 车辆可用里程
|
||||
*/
|
||||
private Long mileage;
|
||||
}
|
||||
@ -5,11 +5,9 @@ import com.cdzy.user.model.dto.EbikeUserCyclingDto;
|
||||
import com.cdzy.user.model.dto.EbikeUserCyclingEndDto;
|
||||
import com.cdzy.user.model.entity.EbikeOrder;
|
||||
import com.cdzy.user.model.vo.EbikeBikeInfoVo;
|
||||
import com.cdzy.user.model.vo.EbikeBikeRealInfoVo;
|
||||
import com.cdzy.user.model.vo.EbikeRevenueStatisticsVo;
|
||||
import com.cdzy.user.model.vo.EbikeUserAllOrdersVo;
|
||||
import com.ebike.feign.model.dto.FeignEbikeDto;
|
||||
import com.ebike.feign.model.dto.FeignOrderPaymentDto;
|
||||
import com.ebike.feign.model.vo.FeignEbikeBikeRadiusVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
@ -40,13 +38,6 @@ public interface EbikeOrderService extends IService<EbikeOrder> {
|
||||
*/
|
||||
EbikeOrder checkHistoryOrder(Long userId);
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
*
|
||||
* @param orderPaymentDto 订单支付信息
|
||||
*/
|
||||
void payment(FeignOrderPaymentDto orderPaymentDto);
|
||||
|
||||
/**
|
||||
* 订单发起退款
|
||||
*
|
||||
@ -61,20 +52,6 @@ public interface EbikeOrderService extends IService<EbikeOrder> {
|
||||
*/
|
||||
void refund(Long orderId);
|
||||
|
||||
/**
|
||||
* 订单退款完成
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
void doneRefund(Long orderId);
|
||||
|
||||
/**
|
||||
* 订单退款失败
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
void failRefund(Long orderId);
|
||||
|
||||
/**
|
||||
* 订单退款驳回
|
||||
*
|
||||
@ -128,12 +105,4 @@ public interface EbikeOrderService extends IService<EbikeOrder> {
|
||||
* @return 营收统计
|
||||
*/
|
||||
List<EbikeRevenueStatisticsVo> getRevenueStatistics();
|
||||
|
||||
/**
|
||||
* 查询车辆实时信息
|
||||
*
|
||||
* @param orderId 订单id
|
||||
* @return 车辆实时信息
|
||||
*/
|
||||
EbikeBikeRealInfoVo getBikeRealTimeInfo(Long orderId);
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import com.cdzy.user.model.entity.EbikeOrder;
|
||||
import com.cdzy.user.model.entity.EbikeOrderDetail;
|
||||
import com.cdzy.user.model.entity.EbikePayment;
|
||||
import com.cdzy.user.model.vo.EbikeBikeInfoVo;
|
||||
import com.cdzy.user.model.vo.EbikeBikeRealInfoVo;
|
||||
import com.cdzy.user.model.vo.EbikeRevenueStatisticsVo;
|
||||
import com.cdzy.user.model.vo.EbikeUserAllOrdersVo;
|
||||
import com.cdzy.user.service.EbikeOrderDetailService;
|
||||
@ -25,7 +24,6 @@ import com.ebike.feign.clients.OperationsFeignClient;
|
||||
import com.ebike.feign.model.dto.FeignEbikeDto;
|
||||
import com.ebike.feign.model.dto.FeignEbikeUserBikeInfo;
|
||||
import com.ebike.feign.model.dto.FeignEbikeUserLockDto;
|
||||
import com.ebike.feign.model.dto.FeignOrderPaymentDto;
|
||||
import com.ebike.feign.model.vo.EbikeLockVo;
|
||||
import com.ebike.feign.model.vo.FeignEbikeBikeRadiusVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
@ -129,15 +127,6 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
||||
return ebikeOrderTransactionMapper.selectOneByQuery(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void payment(FeignOrderPaymentDto orderPaymentDto) {
|
||||
EbikeOrder ebikeOrderTransaction = this.mapper.selectOneById(orderPaymentDto.getOrderId());
|
||||
ebikeOrderTransaction.setOrderStatus(OrderStatus.PAID);
|
||||
ebikeOrderTransaction.setPaymentTime(orderPaymentDto.getPaymentTime());
|
||||
ebikeOrderTransaction.setPaymentMethod(orderPaymentDto.getPaymentMethod());
|
||||
this.mapper.update(ebikeOrderTransaction);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void refundApply(Long orderId) {
|
||||
@ -159,26 +148,6 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
||||
this.mapper.update(userOrders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doneRefund(Long orderId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_ORDER.ORDER_ID.eq(orderId))
|
||||
.where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.REFUNDING));
|
||||
EbikeOrder userOrders = this.mapper.selectOneByQuery(queryWrapper);
|
||||
userOrders.setOrderStatus(OrderStatus.REFUNDED);
|
||||
this.mapper.update(userOrders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failRefund(Long orderId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_ORDER.ORDER_ID.eq(orderId))
|
||||
.where(EBIKE_ORDER.ORDER_STATUS.eq(OrderStatus.REFUNDING));
|
||||
EbikeOrder userOrders = this.mapper.selectOneByQuery(queryWrapper);
|
||||
userOrders.setOrderStatus(OrderStatus.REFUND_FAILED);
|
||||
this.mapper.update(userOrders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rejectRefund(Long orderId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
@ -205,10 +174,13 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
||||
throw new EbikeException("获取车辆详情失败");
|
||||
}
|
||||
FeignEbikeUserBikeInfo source = jsonResult.getData();
|
||||
Float soc = source.getSoc();
|
||||
long mileage = (long) Math.floor(Math.max(GlobalConstants.NUMBER_ZERO, soc * 0.7));
|
||||
return EbikeBikeInfoVo.builder()
|
||||
.operatorId(source.getOperatorId())
|
||||
.regionId(source.getRegionId())
|
||||
.soc(source.getSoc())
|
||||
.mileage(mileage)
|
||||
.bikeCode(source.getBikeCode())
|
||||
.freeDurationMinutes(source.getFreeDurationMinutes())
|
||||
.baseDurationMinutes(source.getBaseDurationMinutes())
|
||||
@ -327,76 +299,6 @@ public class EbikeOrderServiceImpl extends ServiceImpl<EbikeOrderMapper, EbikeOr
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算订单当前实时费用
|
||||
*/
|
||||
@Override
|
||||
public EbikeBikeRealInfoVo getBikeRealTimeInfo(Long orderId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(
|
||||
EBIKE_ORDER.ORDER_STATUS,
|
||||
EBIKE_ORDER.START_TIME,
|
||||
EBIKE_ORDER.FREE_DURATION_MINUTES,
|
||||
EBIKE_ORDER.BASE_FEE,
|
||||
EBIKE_ORDER.DURATION_FEE,
|
||||
EBIKE_ORDER.MAX_FEE_AMOUNT,
|
||||
EBIKE_ORDER.BIKE_CODE
|
||||
)
|
||||
.where(EBIKE_ORDER.ORDER_ID.eq(orderId));
|
||||
EbikeOrder ebikeOrder = this.mapper.selectOneByQuery(queryWrapper);
|
||||
if (Objects.isNull(ebikeOrder)) {
|
||||
throw new EbikeException("当前订单不存在");
|
||||
}
|
||||
// 查询车辆信息
|
||||
EbikeBikeInfoVo bikeInfo = queryBikeInfo(ebikeOrder.getBikeCode());
|
||||
// 计算实时费用(包含封顶)
|
||||
BigDecimal cost = calculateRealTimeCost(ebikeOrder, bikeInfo);
|
||||
|
||||
// 计算可用里程:剩余电量 × 0.7 (公里)
|
||||
Float soc = bikeInfo.getSoc();
|
||||
long mileage = (long) Math.floor(Math.max(GlobalConstants.NUMBER_ZERO, soc * 0.7));
|
||||
|
||||
EbikeBikeRealInfoVo result = new EbikeBikeRealInfoVo();
|
||||
result.setCost(cost);
|
||||
result.setMileage(mileage);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 辅助方法:计算订单当前实时费用(含封顶金额限制)
|
||||
*/
|
||||
private BigDecimal calculateRealTimeCost(EbikeOrder order, EbikeBikeInfoVo bikeInfo) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Duration duration = Duration.between(order.getStartTime(), now);
|
||||
long totalSeconds = duration.getSeconds();
|
||||
int currentMinutes = (int) ((totalSeconds + 59) / 60);
|
||||
|
||||
Integer freeMinutes = bikeInfo.getFreeDurationMinutes();
|
||||
if (freeMinutes == null) {
|
||||
freeMinutes = 0;
|
||||
}
|
||||
|
||||
if (currentMinutes <= freeMinutes) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return computeTotalFee(bikeInfo, currentMinutes - freeMinutes);
|
||||
}
|
||||
|
||||
private BigDecimal computeTotalFee(EbikeBikeInfoVo bikeInfo, int chargeableMinutes) {
|
||||
BigDecimal baseFee = Objects.requireNonNullElse(bikeInfo.getBaseFee(), BigDecimal.ZERO);
|
||||
BigDecimal durationFee = Objects.requireNonNullElse(bikeInfo.getDurationFee(), BigDecimal.ZERO);
|
||||
|
||||
BigDecimal totalFee = baseFee.add(durationFee.multiply(BigDecimal.valueOf(chargeableMinutes)))
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
BigDecimal maxFee = bikeInfo.getMaxFeeAmount();
|
||||
if (maxFee != null && maxFee.compareTo(BigDecimal.ZERO) > 0 && totalFee.compareTo(maxFee) > 0) {
|
||||
totalFee = maxFee;
|
||||
}
|
||||
return totalFee;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算增长率并格式化为百分比字符串
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user