无关风月
2026-02-12 a85cb54075d8ee97d06e261ddaa4480e23b3303e
修改费用明细返回结构
1个文件已添加
6个文件已修改
428 ■■■■■ 已修改文件
xp-robotaxi-api/src/main/java/com/xiaopeng/api/model/order/XpOrderEvaluate.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-api/src/main/java/com/xiaopeng/api/vo/order/FareBreakdownDetailVo.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-api/src/main/java/com/xiaopeng/api/vo/order/FareBreakdownVo.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/utils/XpPricingUtil.java 294 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/controller/XpOrderController.java 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/model/dto/XpOrderCommentDto.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/service/impl/XpOrderServiceImpl.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-api/src/main/java/com/xiaopeng/api/model/order/XpOrderEvaluate.java
@@ -48,5 +48,10 @@
    @ApiModelProperty(value = "评价时间")
    private LocalDateTime evaluateTime;
    @ApiModelProperty(value = "问题类型id")
    private Integer feedbackTypeId;
    @ApiModelProperty(value = "反馈内容")
    private Integer feedbackContent;
    @ApiModelProperty(value = "图片 json格式")
    private Integer feedbackPictures;
}
xp-robotaxi-api/src/main/java/com/xiaopeng/api/vo/order/FareBreakdownDetailVo.java
New file
@@ -0,0 +1,22 @@
package com.xiaopeng.api.vo.order;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
@ApiModel("订单费用明细详情VO")
public class FareBreakdownDetailVo {
    @ApiModelProperty(value = "type=1 普通时段 type=2 夜间行驶时段 type=3节假日时段")
    private Integer type;
    @ApiModelProperty(value = "时段 例:18:00-19:00")
    private String time;
    @ApiModelProperty(value = "里程 单位公里")
    private BigDecimal mileage;
    @ApiModelProperty(value = "时间")
    private BigDecimal duration;
    @ApiModelProperty(value = "金额")
    private BigDecimal money;
}
xp-robotaxi-api/src/main/java/com/xiaopeng/api/vo/order/FareBreakdownVo.java
@@ -5,38 +5,23 @@
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
@ApiModel("订单费用明细VO")
public class FareBreakdownVo {
    @ApiModelProperty("起步里程")
    private Double startMileage;
    @ApiModelProperty(value = "起步价")
    private BigDecimal startMoney;
    @ApiModelProperty(value = "里程公里")
    private Double mileageKilometers;
    @ApiModelProperty(value = "里程费")
    private BigDecimal mileageMoney;
    @ApiModelProperty(value = "时长分钟")
    private Double duration;
    @ApiModelProperty(value = "时长费")
    private BigDecimal durationMoney;
    @ApiModelProperty(value = "等待分钟")
    private Double wait;
    @ApiModelProperty(value = "等待费")
    private BigDecimal waitMoney;
    @ApiModelProperty(value = "远途公里")
    private Double longDistance;
    @ApiModelProperty(value = "远途费")
    private BigDecimal longDistancemoney;
    @ApiModelProperty("起步价格明细")
    private List<FareBreakdownDetailVo> start;
    @ApiModelProperty("里程费价格明细")
    private List<FareBreakdownDetailVo> mileage;
    @ApiModelProperty("时长费价格明细")
    private List<FareBreakdownDetailVo> duration;
    @ApiModelProperty("远途费价格明细")
    private List<FareBreakdownDetailVo> longDistance;
    @ApiModelProperty(value = "红包抵扣金额")
    private BigDecimal redPacketMoney;
    @ApiModelProperty(value = "优惠券抵扣金额")
    private BigDecimal couponMoney;
    @ApiModelProperty(value = "订单金额")
    private BigDecimal orderMoney;
    @ApiModelProperty(value = "订单全程公里数")
    private BigDecimal totalKilometers;
    @ApiModelProperty(value = "订单全程时间(单位分钟)")
    private BigDecimal totalTime;
}
xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/utils/XpPricingUtil.java
@@ -327,6 +327,300 @@
        return xpPricingCardVo;
    }
    /**
     *  行程结束后计算费用
     * @param rule 基础规则
     * @param distance 里程
     * @param duration  时间
     * @param wait  时间
     * @param waitMoney 等待费
     * @param openCityId 开通城市id
     * @param isDynamicPriceStatus 是否开启动态调价
     * @return
     * @throws Exception
     */
    public XpPricingCardVo calculationFinalPrice(String uid,JSONObject rule, JSONArray startingFareJson, double distance, long duration, long wait, Double waitMoney,Integer isDynamicPriceStatus,Long openCityId,String dynamicPricingJson) {
        // 默认费率1
        double priceRate=1;
        if(isDynamicPriceStatus==1){
            // 先判断是否已经调价过了
            Object userDynamicPriceObj = redisService.getCacheObject("USER_DYNAMIC_PRICE_" + openCityId + "_" + uid);
            if(userDynamicPriceObj!=null){
                // 是否调价过了
                priceRate = Double.parseDouble(userDynamicPriceObj.toString());
            }else {
                // 没有调过
                //是否触发动态调价 redis获取
                Object dynamicPriceObj = redisService.getCacheObject("DYNAMIC_PRICE_" + openCityId);
                if(dynamicPriceObj!=null){
                    JSONObject jsonObject = JSONObject.parseObject(dynamicPricingJson);
                    // 触发动态调价
                    // value=时间
                    String timeStr = dynamicPriceObj.toString();
                    // 判断当前距离这个时间范围的新增订单数(排除取消) / 上浮数量 算出应该增加的价格率
                    R<Integer> r = xpOrderClient.getOrderNum(timeStr);
                    if(r.getData()==200){
                        int num = r.getData();
                        // X单上升一次调价
                        Integer orderNum = getOrderNum(jsonObject, 4);
                        // 需要调价的次数
                        int count = num / orderNum;
                        if(count>0){
                            // 计算每次上升的费率
                            Integer upRate = getOrderNum(jsonObject, 5);
                            BigDecimal divide = new BigDecimal(upRate).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
                            for (int i = count; i > 0; i--) {
                                // 当前费率+(费率*上升百分比)
                                priceRate =  new BigDecimal(priceRate).multiply(divide).add(new BigDecimal(priceRate)).setScale(2, RoundingMode.HALF_UP).doubleValue();
                            }
                            // 冷却时间
                            Integer time = getOrderNum(jsonObject, 6);
                            // 触发调价了
                            redisService.setCacheObject("USER_DYNAMIC_PRICE_" + openCityId + "_" + uid, priceRate,time.longValue(), TimeUnit.MINUTES);
                        }
                    }
                }
            }
        }
        XpPricingCardVo xpPricingCardVo = new XpPricingCardVo();
        double amount = 0;
        //等待费
        Date date = new Date();
        // 计算出是在那个时间段内
        for (Object o : startingFareJson) {
            JSONObject startingFare = (JSONObject) o;
            Calendar calendarStart = Calendar.getInstance();
            calendarStart.setTime(date);
            calendarStart.set(Calendar.HOUR_OF_DAY, Integer.valueOf(startingFare.getString("num1").split(":")[0]));
            calendarStart.set(Calendar.MINUTE, Integer.valueOf(startingFare.getString("num1").split(":")[1]));
            Calendar calendarEnd = Calendar.getInstance();
            calendarEnd.setTime(date);
            calendarEnd.set(Calendar.HOUR_OF_DAY, Integer.valueOf(startingFare.getString("num2").split(":")[0]));
            calendarEnd.set(Calendar.MINUTE, Integer.valueOf(startingFare.getString("num2").split(":")[1]));
            // 找到符合条件的直接跳出循环
            if (date.getTime() > calendarStart.getTimeInMillis() && date.getTime() < calendarEnd.getTimeInMillis()) {
                rule.put("num1", startingFare.get("num3"));
                rule.put("num2", startingFare.get("num4"));
                rule.put("num3", startingFare.get("num5"));
                rule.put("num4", startingFare.get("num6"));
                rule.put("num5", startingFare.get("num7"));
                rule.put("startTime", startingFare.getString("num1"));
                rule.put("endTime", startingFare.getString("num2"));
                break;
            }
        }
        double realDistance = distance / 1000;//实际公里
        double realTime = duration / 60;//实际时间
        double exceedDistance = (realDistance - rule.getDouble("num2")) < 0 ? 0 : realDistance - rule.getDouble("num2");//超出起步里程的公里
        double exceedTime = (realTime - rule.getDouble("num3")) < 0 ? 0 : realTime - rule.getDouble("num3");//超过起步分钟数的时间
        double longDistanceOne = 0;//远途1段
        double longDistanceTwo = 0;//远途2段
        double longDistanceThree = 0;//远途3段
        //夜间服务处理逻辑
        Calendar calendarNight = Calendar.getInstance();
        calendarNight.setTime(date);
        calendarNight.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[0]));
        calendarNight.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[1]));
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[0]));
        calendar.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[1]));
        // 先判断今日是否节假日
        boolean holiday = holidayUtil.isHoliday();
        if (holiday) {
            if (realDistance > rule.getDouble("num6")) {
                longDistanceOne = rule.getDouble("num32") * (realDistance - rule.getDouble("num6"));
            }
            if (realDistance > rule.getDouble("num9")) {
                longDistanceTwo = rule.getDouble("num33") * (realDistance - rule.getDouble("num9"));
            }
            if (realDistance > rule.getDouble("num12")) {
                longDistanceThree = rule.getDouble("num34") * (realDistance - rule.getDouble("num12"));
            }
            amount = rule.getDouble("num29") + (exceedDistance * rule.getDouble("num30")) + (exceedTime * rule.getDouble("num31")) + (wait * waitMoney) + longDistanceOne + longDistanceTwo + longDistanceThree;
            // 起步价
            xpPricingCardVo.setStartPrice(rule.getDouble("num29"));
            // 时间段
            xpPricingCardVo.setTime("节假日");
            // 里程
            xpPricingCardVo.setDistance(realDistance);
            // 里程费
            double distancePrice = (exceedDistance * rule.getDouble("num30")) + longDistanceOne + longDistanceTwo + longDistanceThree;
            xpPricingCardVo.setDistancePrice(distancePrice);
            // 时长
            xpPricingCardVo.setDuration(realTime);
            // 时长费
            xpPricingCardVo.setDurationPrice((exceedTime * rule.getDouble("num31")));
        } else {
            if (date.getTime() > calendarNight.getTimeInMillis() && date.getTime() < calendar.getTimeInMillis()) {
                if (realDistance > rule.getDouble("num6")) {
                    longDistanceOne = rule.getDouble("num18") * (realDistance - rule.getDouble("num6"));
                }
                if (realDistance > rule.getDouble("num9")) {
                    longDistanceTwo = rule.getDouble("num19") * (realDistance - rule.getDouble("num9"));
                }
                if (realDistance > rule.getDouble("num12")) {
                    longDistanceThree = rule.getDouble("num20") * (realDistance - rule.getDouble("num12"));
                }
                amount = rule.getDouble("num15") + (exceedDistance * rule.getDouble("num16")) + (exceedTime * rule.getDouble("num17")) + (wait * waitMoney) + longDistanceOne + longDistanceTwo + longDistanceThree;
                // 起步价
                xpPricingCardVo.setStartPrice(rule.getDouble("num15"));
                // 时间段
                xpPricingCardVo.setTime(rule.getString("num14"));
                // 里程
                xpPricingCardVo.setDistance(realDistance);
                // 里程费
                double distancePrice = (exceedDistance * rule.getDouble("num16")) + longDistanceOne + longDistanceTwo + longDistanceThree;
                xpPricingCardVo.setDistancePrice(distancePrice);
                // 时长
                xpPricingCardVo.setDuration(realTime);
                // 时长费
                xpPricingCardVo.setDurationPrice((exceedTime * rule.getDouble("num17")));
            } else {
                // 高峰处理
                Calendar calendarStart = Calendar.getInstance();
                calendarStart.setTime(date);
                calendarStart.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[0]));
                calendarStart.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[1]));
                Calendar calendarEnd = Calendar.getInstance();
                calendarEnd.setTime(date);
                calendarEnd.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[0]));
                calendarEnd.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[1]));
                Calendar s2 = Calendar.getInstance();
                s2.setTime(date);
                s2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[0]));
                s2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[0].split(":")[1]));
                Calendar e2 = Calendar.getInstance();
                e2.setTime(date);
                e2.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[0]));
                e2.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num22").split(" - ")[1].split(":")[1]));
                //高峰时段处理逻辑
                if ((date.getTime() > calendarStart.getTimeInMillis() && date.getTime() < calendarEnd.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())) {
                    if (realDistance > rule.getDouble("num6")) {
                        longDistanceOne = rule.getDouble("num26") * (realDistance - rule.getDouble("num6"));
                    }
                    if (realDistance > rule.getDouble("num9")) {
                        longDistanceTwo = rule.getDouble("num27") * (realDistance - rule.getDouble("num9"));
                    }
                    if (realDistance > rule.getDouble("num12")) {
                        longDistanceThree = rule.getDouble("num28") * (realDistance - rule.getDouble("num12"));
                    }
                    amount = rule.getDouble("num23") + (exceedDistance * rule.getDouble("num24")) + (exceedTime * rule.getDouble("num25")) + (wait * waitMoney) + longDistanceOne + longDistanceTwo + longDistanceThree;
                    // 起步价
                    xpPricingCardVo.setStartPrice(rule.getDouble("num23"));
                    // 时间段
                    if (date.getTime() > calendarStart.getTimeInMillis() && date.getTime() < calendarEnd.getTimeInMillis()) {
                        xpPricingCardVo.setTime(rule.getString("num21"));
                    } else {
                        xpPricingCardVo.setTime(rule.getString("num22"));
                    }
                    // 里程
                    xpPricingCardVo.setDistance(realDistance);
                    // 里程费
                    double distancePrice = (exceedDistance * rule.getDouble("num24")) + longDistanceOne + longDistanceTwo + longDistanceThree;
                    xpPricingCardVo.setDistancePrice(distancePrice);
                    // 时长
                    xpPricingCardVo.setDuration(realTime);
                    // 时长费
                    xpPricingCardVo.setDurationPrice((exceedTime * rule.getDouble("num25")));
                } else {
                    //其他时间段的计算
                    if (realDistance > rule.getDouble("num6")) {
                        longDistanceOne = rule.getDouble("num8") * (realDistance - rule.getDouble("num6"));
                    }
                    if (realDistance > rule.getDouble("num9")) {
                        longDistanceTwo = rule.getDouble("num11") * (realDistance - rule.getDouble("num9"));
                    }
                    if (realDistance > rule.getDouble("num12")) {
                        longDistanceThree = rule.getDouble("num13") * (realDistance - rule.getDouble("num12"));
                    }
                    amount = rule.getDouble("num1") + (exceedDistance * rule.getDouble("num4")) + (exceedTime * rule.getDouble("num5")) + (wait * waitMoney) + longDistanceOne + longDistanceTwo + longDistanceThree;
                    // 起步价
                    xpPricingCardVo.setStartPrice(rule.getDouble("num1"));
                    // 时间段
                    xpPricingCardVo.setTime(rule.getString("startTime") + " - " + rule.getString("endTime"));
                    xpPricingCardVo.setDistancePriceNormal(rule.getDouble("num2"));
                    xpPricingCardVo.setDurationPriceNormal(rule.getDouble("num3"));
                    // 里程
                    xpPricingCardVo.setDistance(realDistance);
                    // 里程费
                    double distancePrice = (exceedDistance * rule.getDouble("num4")) + longDistanceOne + longDistanceTwo + longDistanceThree;
                    xpPricingCardVo.setDistancePrice(distancePrice);
                    // 时长
                    xpPricingCardVo.setDuration(realTime);
                    // 时长费
                    xpPricingCardVo.setDurationPrice((exceedTime * rule.getDouble("num5")));
                }
            }
        }
        // 订单总额
        Double startPrice = xpPricingCardVo.getStartPrice();
        // 先减去起步价重新计算
        amount = amount - startPrice;
        // 动态计算费用
        startPrice= new BigDecimal(startPrice).multiply(new BigDecimal(priceRate)).setScale(2, RoundingMode.HALF_UP).doubleValue();
        amount = amount+startPrice;
        xpPricingCardVo.setTotalPrice(amount);
        return xpPricingCardVo;
    }
    /**
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/controller/XpOrderController.java
@@ -354,6 +354,7 @@
        String uid = request.getHeader("XP-Uid");
        return xpOrderService.payment(dto,uid);
    }
    /**
     * 订单评价
     */
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/model/dto/XpOrderCommentDto.java
@@ -11,4 +11,10 @@
    @ApiModelProperty(value = "订单评分")
    private Integer orderRating;
    @ApiModelProperty(value = "问题类型id")
    private Integer feedbackTypeId;
    @ApiModelProperty(value = "反馈内容")
    private Integer feedbackContent;
    @ApiModelProperty(value = "图片 json格式")
    private Integer feedbackPictures;
}
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/service/impl/XpOrderServiceImpl.java
@@ -104,6 +104,7 @@
    private final RedisService redisService;
    private final XpPricingClient xpPricingClient;
    @Override
    public OrderStatisticsDTO getOrderStatistics(StatisticsQueryDTO query) {
        OrderStatisticsDTO dto = new OrderStatisticsDTO();
@@ -765,6 +766,9 @@
        evaluate.setAppUserId(Long.valueOf(uid));
        evaluate.setOrderRating(dto.getOrderRating());
        evaluate.setEvaluateTime(LocalDateTime.now());
        evaluate.setFeedbackContent(dto.getFeedbackContent());
        evaluate.setFeedbackPictures(dto.getFeedbackPictures());
        evaluate.setFeedbackTypeId(dto.getFeedbackTypeId());
        xpOrderEvaluateService.save(evaluate);
    }
@@ -821,37 +825,38 @@
        if (pricing == null) {
            throw new ServiceException("当前城市未配置定价规则", I18nKeyConstant.ORDER_PRICING_NOT_EXISTS);
        }
        Long id = pricing.getId();
        Integer pricingType = pricing.getPricingType();
        String basicPricingJson = pricing.getBasicPricingJson();
        String startingFareJson = pricing.getStartingFareJson();
        String dynamicPricingJson = pricing.getDynamicPricingJson();
        String priceRule = pricing.getPriceRule();
        // 根据计价规则计算费用
        BigDecimal startMoney = BigDecimal.ZERO;// 起步价
        BigDecimal mileageMoney = BigDecimal.ZERO;// 里程费
        BigDecimal durationMoney = BigDecimal.ZERO;// 时长费
        BigDecimal waitMoney = BigDecimal.ZERO;// 等待费
        BigDecimal longDistancemoney = BigDecimal.ZERO;// 远途费
        BigDecimal redPacketMoney = BigDecimal.ZERO;// 红包抵扣金额
        BigDecimal couponMoney = BigDecimal.ZERO;// 优惠券抵扣金额
        if (pricingType == 1) {
//        Long id = pricing.getId();
//        Integer pricingType = pricing.getPricingType();
//        String basicPricingJson = pricing.getBasicPricingJson();
//        String startingFareJson = pricing.getStartingFareJson();
//        String dynamicPricingJson = pricing.getDynamicPricingJson();
//        String priceRule = pricing.getPriceRule();
//        // 根据计价规则计算费用
//        BigDecimal startMoney = BigDecimal.ZERO;// 起步价
//        BigDecimal mileageMoney = BigDecimal.ZERO;// 里程费
//        BigDecimal durationMoney = BigDecimal.ZERO;// 时长费
//        BigDecimal waitMoney = BigDecimal.ZERO;// 等待费
//        BigDecimal longDistancemoney = BigDecimal.ZERO;// 远途费
//        BigDecimal redPacketMoney = BigDecimal.ZERO;// 红包抵扣金额
//        BigDecimal couponMoney = BigDecimal.ZERO;// 优惠券抵扣金额
//        if (pricingType == 1) {
//
//        } else {
//
//        }
//        if (org.springframework.util.StringUtils.hasLength(basicPricingJson)) {
//
//        }
//        if (org.springframework.util.StringUtils.hasLength(startingFareJson)) {
//
//        }
//        if (org.springframework.util.StringUtils.hasLength(dynamicPricingJson)) {
//
//        }
//        if (org.springframework.util.StringUtils.hasLength(priceRule)) {
//
//        }
        } else {
        }
        if (org.springframework.util.StringUtils.hasLength(basicPricingJson)) {
        }
        if (org.springframework.util.StringUtils.hasLength(startingFareJson)) {
        }
        if (org.springframework.util.StringUtils.hasLength(dynamicPricingJson)) {
        }
        if (org.springframework.util.StringUtils.hasLength(priceRule)) {
        }
        // 计算完价格后 挑选优惠券
        GetUserCouponDto getUserCouponDto = new GetUserCouponDto();
        getUserCouponDto.setUserId(Long.valueOf(uid));