From 4f3466431b6ea9f16235a8021fca009b549f32e5 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 11 三月 2026 22:28:17 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/TaxiPricingDemoService.java | 107 ++++++++++++++++++++++++++++-------------------------
1 files changed, 56 insertions(+), 51 deletions(-)
diff --git a/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/TaxiPricingDemoService.java b/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/TaxiPricingDemoService.java
index 18d9cc3..a50c4d0 100644
--- a/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/TaxiPricingDemoService.java
+++ b/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/TaxiPricingDemoService.java
@@ -1,4 +1,6 @@
package com.xiaopeng.order.utils;
+import com.xiaopeng.order.utils.holiday.HolidayUtil;
+
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalTime;
@@ -11,21 +13,20 @@
*/
public class TaxiPricingDemoService {
+
public static void main(String[] args) {
PricingConfig config = setupMockConfig();
//
- Calendar cal = Calendar.getInstance();
- cal.set(2026, Calendar.APRIL, 11, 15, 49, 15);
- Date orderTime = cal.getTime();
+ Date orderTime = new Date();
//
// 模拟总里程 25.0 km,以触发多级远途加价
- double totalMillige = 9.148;
+ double totalMillige = 2.984;
// 模拟 GPS 轨迹点
List<GpsPoint> points = createMockGpsPoints(orderTime);
TaxiPricingService service = new TaxiPricingService();
- Map<String, BigDecimal> bill = service.calculateOrderPrice(orderTime, totalMillige, points, config);
+ Map<String, BigDecimal> bill = service.calculateOrderPrice(orderTime, totalMillige, points, config,0);
System.err.println("======= 订单计费账单 =======");
bill.forEach((detail, price) -> System.err.println(detail + ": " + price + " 元"));
@@ -40,12 +41,14 @@
}
+
+
public static class TaxiPricingService {
- public Map<String, BigDecimal> calculateOrderPrice(Date orderTime, double totalMileageKm, List<GpsPoint> points, PricingConfig config) {
+ public Map<String, BigDecimal> calculateOrderPrice(Date orderTime, double totalMileageKm, List<GpsPoint> points, PricingConfig config,Integer holiday) {
Map<String, BigDecimal> result = new LinkedHashMap<>();
BigDecimal totalMileage = BigDecimal.valueOf(totalMileageKm);
- PricingRule baseRule = config.findMatchedRule(orderTime);
+ PricingRule baseRule = config.findMatchedRule(orderTime,holiday);
result.put("起步价(" + baseRule.ruleName + ")"+"|"+baseRule.start+"-"+baseRule.end+"|"+baseRule.baseMin+"&"+baseRule.baseKm, baseRule.baseFare);
if (totalMileage.compareTo(baseRule.baseKm) <= 0) {
@@ -74,7 +77,7 @@
currentTotalM = currentTotalM.add(segM); // 累计当前已行驶的总里程
currentTotalMs = currentTotalMs.add(segMs); // 累计当前已行驶的总时间
- PricingRule activeRule = config.findMatchedRule(new Date(curr.getLocatetime()));
+ PricingRule activeRule = config.findMatchedRule(new Date(curr.getLocatetime()),holiday);
// 扣除起步额度逻辑
BigDecimal billM = BigDecimal.ZERO;
@@ -216,9 +219,11 @@
public List<PricingRule> normals = new ArrayList<>();
public List<LongRangeStep> longSteps = new ArrayList<>(); // 修改为区间列表
- public PricingRule findMatchedRule(Date date) {
+ public PricingRule findMatchedRule(Date date,Integer isHoliday) {
LocalTime t = date.toInstant().atZone(ZoneId.systemDefault()).toLocalTime();
- if (holiday.isMatch(t)) return holiday;
+ if (isHoliday==1){
+ return holiday;
+ }
for (PricingRule r : peaks) if (r.isMatch(t)) return r;
if (night.isMatch(t)) return night;
for (PricingRule r : normals) if (r.isMatch(t)) return r;
@@ -257,19 +262,19 @@
private static PricingConfig setupMockConfig() {
PricingConfig config = new PricingConfig();
- config.peaks.add(new PricingRule("高峰期", "04:00", "05:00", 15.0, 3.0, 10.0, 4, 4));
- config.peaks.add(new PricingRule("高峰期", "15:00", "16:00", 15.0, 3.0, 10.0, 4, 4));
- config.night = new PricingRule("夜间行驶", "20:04", "23:00", 15.0, 3.0, 10.0, 3, 3);
- config.holiday = new PricingRule("节假日", "18:47", "18:48", 18.0, 3.0, 5.0, 4, 2.0);
- config.normals.add(new PricingRule("普通时段", "00:00", "23:59", 10.0, 3.0, 10.0, 3, 3));
+ config.peaks.add(new PricingRule("高峰期", "04:00", "05:00", 15, 1, 10, 4, 4));
+ config.peaks.add(new PricingRule("高峰期", "15:00", "16:00", 15, 1, 10, 4, 4));
+ config.night = new PricingRule("夜间行驶", "20:04", "23:00", 15, 1, 10, 3, 3);
+ config.holiday = new PricingRule("节假日", "00:00", "23:59", 20, 1, 10, 4, 4);
+ config.normals.add(new PricingRule("普通时段", "00:00", "23:59", 10.0, 1, 10.0, 3, 3));
// --- 远途加价区间配置 (关键修改) ---
// 1. 超过 num1(12) 不足 num2(20), 加收 num3(1.2)
- config.longSteps.add(new LongRangeStep(5.0, 6.0, 1.2));
+ config.longSteps.add(new LongRangeStep(1, 3, 3));
// 2. 超过 num4(20) 不足 num5(35), 加收 num6(2.0)
- config.longSteps.add(new LongRangeStep(6.0, 7.0, 2.0));
+ config.longSteps.add(new LongRangeStep(3, 5, 5));
// 3. 超过 num7(35) 以后, 加收 num8(3.5) -> numEnd 传个极大值
- config.longSteps.add(new LongRangeStep(7.0, 8.0, 3.5));
+ config.longSteps.add(new LongRangeStep(5, 999999, 6));
return config;
}
@@ -296,39 +301,39 @@
list.add(new GpsPoint(162, startTs + 2 * 150 * 1000));
list.add(new GpsPoint(182, startTs + 2 * 160 * 1000));
list.add(new GpsPoint(132, startTs + 2 * 170 * 1000));
- list.add(new GpsPoint(142, startTs + 2 * 180 * 1000));
- list.add(new GpsPoint(262, startTs + 2 * 190 * 1000));
- list.add(new GpsPoint(242, startTs + 2 * 200 * 1000));
- list.add(new GpsPoint(282, startTs + 2 * 210 * 1000));
- list.add(new GpsPoint(222, startTs + 2 * 220 * 1000));
- list.add(new GpsPoint(212, startTs + 2 * 230 * 1000));
- list.add(new GpsPoint(142, startTs + 2 * 240 * 1000));
- list.add(new GpsPoint(262, startTs + 2 * 250 * 1000));
- list.add(new GpsPoint(169, startTs + 2 * 260 * 1000));
- list.add(new GpsPoint(170, startTs + 2 * 270 * 1000));
- list.add(new GpsPoint(180, startTs + 2 * 280 * 1000));
- list.add(new GpsPoint(165, startTs + 2 * 290 * 1000));
- list.add(new GpsPoint(180, startTs + 2 * 300 * 1000));
- list.add(new GpsPoint(198, startTs + 2 * 310 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 320 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 330 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 340 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 350 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 360 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 370 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 380 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 390 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 400 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 410 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 420 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 430 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 440 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 450 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 460 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 470 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 490 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 500 * 1000));
- list.add(new GpsPoint(182, startTs + 2 * 510 * 1000));
+ list.add(new GpsPoint(122, startTs + 2 * 180 * 1000));
+// list.add(new GpsPoint(262, startTs + 2 * 190 * 1000));
+// list.add(new GpsPoint(242, startTs + 2 * 200 * 1000));
+// list.add(new GpsPoint(282, startTs + 2 * 210 * 1000));
+// list.add(new GpsPoint(222, startTs + 2 * 220 * 1000));
+// list.add(new GpsPoint(212, startTs + 2 * 230 * 1000));
+// list.add(new GpsPoint(142, startTs + 2 * 240 * 1000));
+// list.add(new GpsPoint(262, startTs + 2 * 250 * 1000));
+// list.add(new GpsPoint(169, startTs + 2 * 260 * 1000));
+// list.add(new GpsPoint(170, startTs + 2 * 270 * 1000));
+// list.add(new GpsPoint(180, startTs + 2 * 280 * 1000));
+// list.add(new GpsPoint(165, startTs + 2 * 290 * 1000));
+// list.add(new GpsPoint(180, startTs + 2 * 300 * 1000));
+// list.add(new GpsPoint(198, startTs + 2 * 310 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 320 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 330 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 340 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 350 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 360 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 370 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 380 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 390 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 400 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 410 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 420 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 430 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 440 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 450 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 460 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 470 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 490 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 500 * 1000));
+// list.add(new GpsPoint(182, startTs + 2 * 510 * 1000));
// list.add(new GpsPoint(182, startTs + 2 * 520 * 1000));
// list.add(new GpsPoint(182, startTs + 2 * 530 * 1000));
// list.add(new GpsPoint(182, startTs + 2 * 540 * 1000));
--
Gitblit v1.7.1