From 49b8de3a8447b1766dec1eeb160044e8e302d8b2 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期五, 13 三月 2026 21:14:03 +0800
Subject: [PATCH] 处理结束行程一口价
---
xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/XpPricingUtil.java | 689 +++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 568 insertions(+), 121 deletions(-)
diff --git a/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/XpPricingUtil.java b/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/XpPricingUtil.java
index fc09f3f..a7e3c07 100644
--- a/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/XpPricingUtil.java
+++ b/xp-robotaxi-order-boot/src/main/java/com/xiaopeng/order/utils/XpPricingUtil.java
@@ -1,129 +1,576 @@
-//package com.xiaopeng.order.utils;
-//
-//import com.alibaba.fastjson.JSONArray;
-//import com.alibaba.fastjson.JSONObject;
-//import com.xiaopeng.api.dto.order.GetOrderNumDto;
-//import com.xiaopeng.api.feignClient.order.XpOrderClient;
-//import com.xiaopeng.api.vo.order.XpPricingCardVo;
-//import com.xiaopeng.common.core.domain.R;
-//import com.xiaopeng.common.redis.service.RedisService;
-//import com.xiaopeng.order.service.IXpOrderService;
-//import com.xiaopeng.order.utils.holiday.HolidayUtil;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.stereotype.Component;
-//
-//import java.math.BigDecimal;
-//import java.math.RoundingMode;
-//import java.util.Calendar;
-//import java.util.Date;
-//import java.util.concurrent.TimeUnit;
-//
-///**
-// * 计算价格的工具类
-// */
-//@Slf4j
-//@Component
-//public class XpPricingUtil {
-//
-// @Autowired
-// private HolidayUtil holidayUtil;
-//
-// @Autowired
-// private RedisService redisService;
-// @Autowired
-// private IXpOrderService orderService;
-//
-// /**
-// * 获取起步里程
-// *
-// * @param startingFareJsonStr
-// * @return
-// */
-// public static Integer getStartMileage(String startingFareJsonStr) {
-// Date date = new Date();
-// JSONArray startingFareJson = JSONObject.parseArray(startingFareJsonStr);
-// 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()) {
-// Integer mileage = startingFare.getInteger("num4");
-// return mileage;
-// }
-// }
-// return null;
-// }
+package com.xiaopeng.order.utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.xiaopeng.api.dto.order.GetOrderNumDto;
+import com.xiaopeng.api.feignClient.order.XpOrderClient;
+import com.xiaopeng.api.vo.order.XpPricingCardVo;
+import com.xiaopeng.common.core.domain.R;
+import com.xiaopeng.common.redis.service.RedisService;
+import com.xiaopeng.order.utils.holiday.HolidayUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 计算价格的工具类
+ */
+@Slf4j
+@Component
+public class XpPricingUtil {
+
+ @Autowired
+ private HolidayUtil holidayUtil;
+
+ @Autowired
+ private RedisService redisService;
+
+ @Autowired
+ private XpOrderClient xpOrderClient;
+
+
+ /**
+ * 获取起步里程
+ * @param startingFareJsonStr
+ * @return
+ */
+ public static Integer getStartMileage(String startingFareJsonStr) {
+ Date date = new Date();
+ JSONArray startingFareJson = JSONObject.parseArray(startingFareJsonStr);
+ 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()) {
+ Integer mileage = startingFare.getInteger("num4");
+ return mileage;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * 计算一口价
+ */
+ public XpPricingCardVo calculationFixedPrice(String uid, JSONObject rule, JSONArray startingFareJson, double distance, double 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(new GetOrderNumDto(timeStr,openCityId));
+ 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;
+
+ double realDistance = distance;//实际公里
+ double realTime = duration ;//实际时间
+ 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 startPrice = rule.getDouble("num1");
+
+ // 超出公里数价格
+ Double distancePrice = new BigDecimal(rule.getDouble("num4") * exceedDistance).setScale(2,RoundingMode.HALF_UP).doubleValue();
+
+ // 超出时间价格
+ Double durationPrice = new BigDecimal(rule.getDouble("num5") * exceedTime).setScale(2,RoundingMode.HALF_UP).doubleValue();
+
+ startPrice = new BigDecimal(startPrice).multiply(BigDecimal.valueOf(priceRate)).setScale(2, RoundingMode.HALF_UP).doubleValue();
+
+ xpPricingCardVo.setStartPrice(startPrice);
+ xpPricingCardVo.setDistancePrice(distancePrice);
+ xpPricingCardVo.setDurationPrice(durationPrice);
+ xpPricingCardVo.setTotalPrice(startPrice + distancePrice + durationPrice);
+ // 里程
+ xpPricingCardVo.setDistance(realDistance);
+ xpPricingCardVo.setDuration(realTime);
+
+ return xpPricingCardVo;
+ }
+
+ /**
+ * 计算基础价格
+ * @param rule 基础规则
+ * @param distance 里程
+ * @param duration 时间
+ * @param wait 时间
+ * @param waitMoney 等待费
+ * @param openCityId 开通城市id
+ * @param isDynamicPriceStatus 是否开启动态调价
+ * @return
+ * @throws Exception
+ */
+ public XpPricingCardVo calculationPrice(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(new GetOrderNumDto(timeStr,openCityId));
+ 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("num6", startingFare.get("num4"));
+
+ 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(LocalDate.now());
+ if (holiday) {
+ if (realDistance > rule.getDouble("num6") && realDistance < rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num32") * (realDistance - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num32") * (rule.getDouble("num7") - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+ if (realDistance > rule.getDouble("num9") && realDistance < rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num33") * (realDistance - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num33") * (rule.getDouble("num10") - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+ if (realDistance > rule.getDouble("num12")) {
+ longDistanceThree = rule.getDouble("num34") * (realDistance - rule.getDouble("num12"));
+ longDistanceThree = new BigDecimal(longDistanceThree).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ amount = rule.getDouble("num29") + new BigDecimal(exceedDistance * rule.getDouble("num30")).setScale(2,RoundingMode.HALF_UP).doubleValue() + new BigDecimal(exceedTime * rule.getDouble("num31")).setScale(2,RoundingMode.HALF_UP).doubleValue() + (wait * waitMoney) + longDistanceOne + longDistanceTwo + longDistanceThree;
+
+
+ // 起步价
+ xpPricingCardVo.setStartPrice(rule.getDouble("num29"));
+ // 时间段
+ xpPricingCardVo.setTime("节假日");
+
+
+ // 里程
+ xpPricingCardVo.setDistance(realDistance);
+
+ // 里程费
+ double distancePrice = (exceedDistance * rule.getDouble("num30")) + longDistanceOne + longDistanceTwo + longDistanceThree;
+ distancePrice = new BigDecimal(distancePrice).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ 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") && realDistance < rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num18") * (realDistance - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num18") * (rule.getDouble("num7") - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+ if (realDistance > rule.getDouble("num9") && realDistance < rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num19") * (realDistance - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num19") * (rule.getDouble("num10") - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+ if (realDistance > rule.getDouble("num12")) {
+ longDistanceThree = rule.getDouble("num20") * (realDistance - rule.getDouble("num12"));
+ longDistanceThree = new BigDecimal(longDistanceThree).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ amount = rule.getDouble("num15") + new BigDecimal(exceedDistance * rule.getDouble("num16")).setScale(2,RoundingMode.HALF_UP).doubleValue() + new BigDecimal(exceedTime * rule.getDouble("num17")).setScale(2,RoundingMode.HALF_UP).doubleValue() + (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;
+ distancePrice = new BigDecimal(distancePrice).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ 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") && realDistance < rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num26") * (realDistance - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num26") * (rule.getDouble("num7") - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+
+ if (realDistance > rule.getDouble("num9") && realDistance < rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num27") * (realDistance - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num27") * (rule.getDouble("num10") - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+ if (realDistance > rule.getDouble("num12")) {
+ longDistanceThree = rule.getDouble("num28") * (realDistance - rule.getDouble("num12"));
+ longDistanceThree = new BigDecimal(longDistanceThree).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ amount = rule.getDouble("num23") + new BigDecimal(exceedDistance * rule.getDouble("num24")).setScale(2,RoundingMode.HALF_UP).doubleValue() + new BigDecimal(exceedTime * rule.getDouble("num25")).setScale(2,RoundingMode.HALF_UP).doubleValue() + (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;
+ distancePrice = new BigDecimal(distancePrice).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ xpPricingCardVo.setDistancePrice(distancePrice);
+
+ // 时长
+ xpPricingCardVo.setDuration(realTime);
+
+ // 时长费
+ xpPricingCardVo.setDurationPrice((exceedTime * rule.getDouble("num25")));
+
+ } else {
+ //其他时间段的计算
+ if (realDistance > rule.getDouble("num6") && realDistance < rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num8") * (realDistance - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num7")) {
+ longDistanceOne = rule.getDouble("num8") * (rule.getDouble("num7") - rule.getDouble("num6"));
+ longDistanceOne = new BigDecimal(longDistanceOne).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+
+
+ if (realDistance > rule.getDouble("num9") && realDistance < rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num11") * (realDistance - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ if (realDistance > rule.getDouble("num10")) {
+ longDistanceTwo = rule.getDouble("num11") * (rule.getDouble("num10") - rule.getDouble("num9"));
+ longDistanceTwo = new BigDecimal(longDistanceTwo).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+
+
+ if (realDistance > rule.getDouble("num12")) {
+ longDistanceThree = rule.getDouble("num13") * (realDistance - rule.getDouble("num12"));
+ longDistanceThree = new BigDecimal(longDistanceThree).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ }
+ amount = rule.getDouble("num1") + new BigDecimal(exceedDistance * rule.getDouble("num4")).setScale(2,RoundingMode.HALF_UP).doubleValue() + new BigDecimal(exceedTime * rule.getDouble("num5")).setScale(2,RoundingMode.HALF_UP).doubleValue() + (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;
+ distancePrice = new BigDecimal(distancePrice).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ xpPricingCardVo.setDistancePrice(distancePrice);
+
+ // 时长
+ xpPricingCardVo.setDuration(realTime);
+
+ // 时长费
+ xpPricingCardVo.setDurationPrice((exceedTime * rule.getDouble("num5")));
+
+ }
+ }
+ }
+
+ // 订单总额
+ Double startPrice = xpPricingCardVo.getStartPrice();
+ amount=new BigDecimal(amount).setScale(2,RoundingMode.HALF_UP).doubleValue();
+ // 先减去起步价重新计算
+ 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;
+ }
+ /**
+ * 行程结束后计算费用
+ * @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) {
//
//
-// /**
-// * 计算基础价格
-// * @param uid 用户id
-// * @param rule 基础规则
-// * @param distance 里程
-// * @param duration 时间
-// * @param isDynamicPriceStatus 是否开启动态调价
-// *
-// * @param openCityId 开通城市id
-// * @return
-// * @throws Exception
-// */
-// public XpPricingCardVo calculationPrice(String uid, JSONObject rule,
-// JSONArray startingFareJson,
-// String dynamicPricingJson,
-// Integer isDynamicPriceStatus,
-// double distance,
-// long duration,
-// Long openCityId) {
// // 默认费率1
-// double priceRate = 1;
-// if (isDynamicPriceStatus == 1) {
+// double priceRate=1;
+// if(isDynamicPriceStatus==1){
// // 先判断是否已经调价过了
// Object userDynamicPriceObj = redisService.getCacheObject("USER_DYNAMIC_PRICE_" + openCityId + "_" + uid);
-// if (userDynamicPriceObj != null) {
+// if(userDynamicPriceObj!=null){
// // 是否调价过了
// priceRate = Double.parseDouble(userDynamicPriceObj.toString());
-// } else {
+// }else {
// // 没有调过
// //是否触发动态调价 redis获取
// Object dynamicPriceObj = redisService.getCacheObject("DYNAMIC_PRICE_" + openCityId);
-// if (dynamicPriceObj != null) {
+// if(dynamicPriceObj!=null){
// JSONObject jsonObject = JSONObject.parseObject(dynamicPricingJson);
// // 触发动态调价
// // value=时间
// String timeStr = dynamicPriceObj.toString();
// // 判断当前距离这个时间范围的新增订单数(排除取消) / 上浮数量 算出应该增加的价格率
-// Integer num = orderService.getOrderNum(new GetOrderNumDto(timeStr, openCityId));
-// // 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();
+// 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);
// }
-// // 冷却时间
-// Integer time = getOrderNum(jsonObject, 6);
-// // 触发调价了
-// redisService.setCacheObject("USER_DYNAMIC_PRICE_" + openCityId + "_" + uid, priceRate, time.longValue(), TimeUnit.MINUTES);
// }
//
// }
// }
//
// }
+//
//
//
// XpPricingCardVo xpPricingCardVo = new XpPricingCardVo();
@@ -207,6 +654,7 @@
//
// // 时长
// xpPricingCardVo.setDuration(realTime);
+//
// // 时长费
// xpPricingCardVo.setDurationPrice((exceedTime * rule.getDouble("num31")));
//
@@ -349,25 +797,24 @@
// // 先减去起步价重新计算
// amount = amount - startPrice;
// // 动态计算费用
-// startPrice = new BigDecimal(startPrice).multiply(new BigDecimal(priceRate)).setScale(2, RoundingMode.HALF_UP).doubleValue();
-// 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;
// }
-//
-//
-//
-// /**
-// * 获取配置 4每X单 5上升X% 6冷却
-// *
-// * @param rule
-// * @param num
-// * @return
-// */
-// private Integer getOrderNum(JSONObject rule, int num) {
-// Integer param = rule.getInteger("num" + num);
-// return param;
-// }
-//}
+
+
+ /**
+ * 获取配置 4每X单 5上升X% 6冷却
+ *
+ * @param rule
+ * @param num
+ * @return
+ */
+ private Integer getOrderNum(JSONObject rule, int num) {
+ Integer param = rule.getInteger("num" + num);
+ return param;
+ }
+}
--
Gitblit v1.7.1