默认计费订单计费详情

This commit is contained in:
attiya 2025-04-27 09:57:38 +08:00
parent 6ba6096c6d
commit 3fa6ccaa1b
3 changed files with 91 additions and 24 deletions

View File

@ -0,0 +1,39 @@
package com.cdzy.orders.enums;
/**
* @author attiya
* @since 2025-04-25
*/
public interface OrderDetailsType {
/**
* 默认时长计费
*/
int CYCLING_DURATION_FEE = 1;
/**
* 运营区调度费用
*/
int OPERATION_AREA_SCHEDULING_FEE = 2;
/**
* 停车区调度费用
*/
int PARKING_AREA_DISPATCH_FEE = 3;
/**
* 高峰时段出行费用
*/
int TRAVEL_EXPENSES_DURING_PEAK_HOURS = 4;
/**
* 高峰日出行费用
*/
int TRAVEL_EXPENSES_ON_PEAK_DAYS = 5;
/**
* 起步费用
*/
int STARTING_FEE = 6;
}

View File

@ -33,12 +33,12 @@ public class EbikeOrderDetails implements Serializable {
* 费用项ID
*/
@Id
private String itemId;
private Long itemId;
/**
* 订单ID
*/
private String orderId;
private Long orderId;
/**
* 费用类型1-骑行时长费 2-运营区调度费用 3-停车区调度费用 4-高峰时段出行费用 5-高峰日出行费用

View File

@ -5,15 +5,13 @@ import com.cdzy.common.enums.Code;
import com.cdzy.common.model.JsonResult;
import com.cdzy.common.model.ResGPSDto;
import com.cdzy.orders.component.EbikeCoreHandler;
import com.cdzy.orders.enums.CmdCode;
import com.cdzy.orders.enums.EbikeRegionInOperation;
import com.cdzy.orders.enums.OrderStatus;
import com.cdzy.orders.enums.OrderType;
import com.cdzy.orders.enums.*;
import com.cdzy.orders.mapper.UserOrdersMapper;
import com.cdzy.orders.model.dto.req.ReqBikeDto;
import com.cdzy.orders.model.dto.req.ReqOrderDto;
import com.cdzy.orders.model.dto.res.RedisPoint;
import com.cdzy.orders.model.dto.res.RspBikeDto;
import com.cdzy.orders.model.entity.EbikeOrderDetails;
import com.cdzy.orders.model.entity.EbikeUserOrders;
import com.cdzy.orders.service.UserOrdersService;
import com.cdzy.orders.uitls.NumberUtils;
@ -34,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@ -144,7 +143,7 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, EbikeUs
String jsonString = JSONObject.toJSONString(redisUtil.get(ecuInfo.getEcuSn()));
ResGPSDto resGpsDto = JSONObject.parseObject(jsonString, ResGPSDto.class);
userOrders.setReturnPoint(resGpsDto.getLongitude() + "," + resGpsDto.getLatitude());
//计算骑行时长
JsonResult<ResFeignEbikeSysRcostsetDto> operateJsonResult = operateFeignClient.getRegionFeeConfigById(bikeInfoDto.getReginId());
if (operateJsonResult.getCode() != Code.SUCCESS) {
throw new RuntimeException("获取计费规则失败");
@ -333,6 +332,7 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, EbikeUs
*/
void costCalculation(ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto, ResGPSDto resGpsDto, FeignEbikeRegionDto regionDto, EbikeUserOrders userOrders) {
BigDecimal totalAmount = new BigDecimal(0);
List<EbikeOrderDetails> list = new ArrayList<>();
//是否在运营区内
boolean pointInOperation = bikeInOperation(resGpsDto.getLongitude(), resGpsDto.getLatitude(), regionDto.getOrgId(), regionDto.getRegionId());
//是否在停车区内
@ -347,19 +347,34 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, EbikeUs
if (pointInOperation && !pointInParking) {
//停车区调度费用
BigDecimal parkingAreaOutDispatchFee = feignEbikeSysRcostsetDto.getParkingAreaOutDispatchFee();
EbikeOrderDetails orderDetails = new EbikeOrderDetails();
orderDetails.setOrderId(userOrders.getOrderId());
orderDetails.setItemAmount(parkingAreaOutDispatchFee);
orderDetails.setItemType(OrderDetailsType.PARKING_AREA_DISPATCH_FEE);
orderDetails.setItemName("停车区调度费用");
orderDetails.setCalculationRule(JSONObject.toJSONString(feignEbikeSysRcostsetDto));
list.add(orderDetails);
totalAmount = totalAmount.add(parkingAreaOutDispatchFee);
} else if (!pointInOperation) {
//运营区调度费用
BigDecimal dispatchFeeOutOperateArea = feignEbikeSysRcostsetDto.getDispatchFeeOutOperateArea();
totalAmount = totalAmount.add(dispatchFeeOutOperateArea);
BigDecimal operationAreaSchedulingFee = feignEbikeSysRcostsetDto.getDispatchFeeOutOperateArea();
EbikeOrderDetails orderDetails = new EbikeOrderDetails();
orderDetails.setOrderId(userOrders.getOrderId());
orderDetails.setItemAmount(operationAreaSchedulingFee);
orderDetails.setItemType(OrderDetailsType.OPERATION_AREA_SCHEDULING_FEE);
orderDetails.setItemName("运营区调度费用");
orderDetails.setCalculationRule(JSONObject.toJSONString(feignEbikeSysRcostsetDto));
list.add(orderDetails);
totalAmount = totalAmount.add(operationAreaSchedulingFee);
}
//时长费用计算
Character timeDivisionCharging = feignEbikeSysRcostsetDto.getTimeDivisionCharging();
totalAmount = switch (timeDivisionCharging) {
case TIME_SLOT -> timeSlotCostCalculation(totalAmount, minutes, userOrders, feignEbikeSysRcostsetDto);
case WEEK -> weekCostCalculation(totalAmount, minutes, userOrders, feignEbikeSysRcostsetDto);
default -> defaultCostCalculation(totalAmount, minutes, feignEbikeSysRcostsetDto);
BigDecimal decimal = switch (timeDivisionCharging) {
case TIME_SLOT -> timeSlotCostCalculation(list,minutes, userOrders, feignEbikeSysRcostsetDto,userOrders.getOrderId());
case WEEK -> weekCostCalculation(list,minutes, userOrders, feignEbikeSysRcostsetDto,userOrders.getOrderId());
default -> defaultCostCalculation(list,minutes, feignEbikeSysRcostsetDto,userOrders.getOrderId());
};
totalAmount = totalAmount.add(decimal);
userOrders.setStatus(OrderStatus.PENDING_PAYMENT);
userOrders.setTotalAmount(totalAmount);
}
@ -367,41 +382,46 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, EbikeUs
/**
* 按照特殊时间段计费
*
* @param totalAmount 当前金额时间段计费前
* @param minutes 骑行总分钟
* @param userOrders 订单信息
* @param feignEbikeSysRcostsetDto 计费规则
* @return 计费后总金额
*/
BigDecimal timeSlotCostCalculation(BigDecimal totalAmount, long minutes, EbikeUserOrders userOrders, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto) {
return totalAmount;
BigDecimal timeSlotCostCalculation(List<EbikeOrderDetails> list, long minutes, EbikeUserOrders userOrders, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto,long orderId) {
return new BigDecimal(0);
}
/**
* 按照时间段计费
*
* @param totalAmount 当前金额时间段计费前
* @param minutes 骑行总分钟
* @param userOrders 订单信息
* @param feignEbikeSysRcostsetDto 计费规则
* @return 计费后总金额
*/
BigDecimal weekCostCalculation(BigDecimal totalAmount, long minutes, EbikeUserOrders userOrders, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto) {
return totalAmount;
BigDecimal weekCostCalculation(List<EbikeOrderDetails> list, long minutes, EbikeUserOrders userOrders, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto,long orderId) {
return new BigDecimal(0);
}
/**
* 按照时间段计费(默认
*
* @param totalAmount 当前金额时间段计费前
* @param minutes 骑行总分钟
* @param feignEbikeSysRcostsetDto 计费规则
* @return 计费后总金额
*/
BigDecimal defaultCostCalculation(BigDecimal totalAmount, long minutes, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto) {
BigDecimal defaultCostCalculation(List<EbikeOrderDetails> list, long minutes, ResFeignEbikeSysRcostsetDto feignEbikeSysRcostsetDto,long orderId) {
BigDecimal decimal = new BigDecimal(0);
Integer startupDuration = feignEbikeSysRcostsetDto.getStartupDuration();
BigDecimal startupCost = feignEbikeSysRcostsetDto.getStartupCost();
totalAmount = totalAmount.add(startupCost);
EbikeOrderDetails orderDetails = new EbikeOrderDetails();
orderDetails.setOrderId(orderId);
orderDetails.setItemAmount(startupCost);
orderDetails.setItemType(OrderDetailsType.STARTING_FEE);
orderDetails.setItemName("起步费用");
orderDetails.setCalculationRule(JSONObject.toJSONString(feignEbikeSysRcostsetDto));
list.add(orderDetails);
decimal = decimal.add(startupCost);
//超出起步时长计费
if (minutes > startupDuration) {
BigDecimal minutesNew = BigDecimal.valueOf(minutes);
@ -417,8 +437,16 @@ public class UserOrdersServiceImpl extends ServiceImpl<UserOrdersMapper, EbikeUs
BigDecimal ceilCost = BigDecimal.valueOf(ceil);
//最终值
BigDecimal multiply = durationCost.multiply(ceilCost);
totalAmount = totalAmount.add(multiply);
EbikeOrderDetails durationCostOrderDetails = new EbikeOrderDetails();
durationCostOrderDetails.setOrderId(orderId);
durationCostOrderDetails.setItemAmount(multiply);
durationCostOrderDetails.setItemType(OrderDetailsType.CYCLING_DURATION_FEE);
durationCostOrderDetails.setItemName("时长计费");
durationCostOrderDetails.setCalculationRule(JSONObject.toJSONString(feignEbikeSysRcostsetDto));
list.add(durationCostOrderDetails);
decimal = decimal.add(multiply);
}
return totalAmount;
return decimal;
}
}