2024年6月18日 新增获取出行价格获取接口
This commit is contained in:
parent
4e1c3ef488
commit
7e9c4b59d3
|
@ -0,0 +1,90 @@
|
|||
package com.sqx.common.utils.baidu;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.setting.dialect.Props;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName BaiduCommon
|
||||
* @Description TODO
|
||||
* @Author bai
|
||||
* @Date 2024/6/17 下午8:22
|
||||
* @Version 1.0
|
||||
**/
|
||||
public class BaiduCommon {
|
||||
|
||||
//接口版本
|
||||
public static final String VERSION = "1";
|
||||
|
||||
//接口前缀
|
||||
public static final String BASE_PREFIX_PATH = "https://pns.baidubce.com/cloud/api/v";
|
||||
|
||||
//接口前缀
|
||||
|
||||
//拼接后的完整接口前缀
|
||||
public static final String BASE_PATH = BASE_PREFIX_PATH + VERSION;
|
||||
|
||||
//绑定
|
||||
public static final String API_AXB_BINDING = BASE_PATH + "/axb/binding";
|
||||
|
||||
//解绑
|
||||
public static final String API_AXB_UNBINDING = BASE_PATH + "/axb/unbinding";
|
||||
|
||||
//转绑
|
||||
public static final String API_AXB_CHANGE_BINDING = BASE_PATH + "/axb/changeBinding";
|
||||
|
||||
public static String genSigned(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getUTCDate(){
|
||||
DateTime now = DateTime.now();
|
||||
return DateUtil.format(now, DatePattern.UTC_PATTERN);
|
||||
}
|
||||
|
||||
//发出请求
|
||||
public static String baseSendHttp(String url, Map<String, String> headerMap, String json) {
|
||||
return HttpRequest
|
||||
.post(url)
|
||||
.headerMap(headerMap, true)
|
||||
//.form(paramMap)
|
||||
.body(json)
|
||||
.execute()
|
||||
.body();
|
||||
}
|
||||
|
||||
public static Map<String, String> getBaseHeaderMap(){
|
||||
Map<String, String> baseHeaderMap = Maps.newHashMap();
|
||||
baseHeaderMap.put("Authorization","bce-auth-v{1}/{accessKeyId}/{timestamp}/{expirationPeriodInSeconds}/{signedHeaders}/{signature}");
|
||||
|
||||
// version是正整数。
|
||||
// timestamp是生成签名时的UTC时间。
|
||||
// expirationPeriodInSeconds表示签名有效期限。
|
||||
// signedHeaders是签名算法中涉及到的头域列表。头域名之间用分号(;)分隔,如host;x-bce-date。列表按照字典序排列。(本API签名仅使用host和x-bce-date两个header)
|
||||
// signature是256位签名的十六进制表示,由64个小写字母组成。
|
||||
|
||||
baseHeaderMap.put("Content-Type","application/json; charset=utf-8");
|
||||
baseHeaderMap.put("x-bce-date", getUTCDate());//2019-10-30T10:55:26Z
|
||||
return baseHeaderMap;
|
||||
}
|
||||
|
||||
public static JSON sendHttpToJson(String url, Map<String, Object> paramMap){
|
||||
//
|
||||
Props props = new Props("test.properties");
|
||||
props.getStr("1111");
|
||||
return JSONUtil.parse(baseSendHttp(url, getBaseHeaderMap(), JSONUtil.toJsonStr(paramMap)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -215,11 +215,11 @@ public class CommonMapUtils {
|
|||
/**
|
||||
* 根据开始位置和结束位置根据出行方式获取米
|
||||
* @param mapType
|
||||
* @param tripWay
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param toLongitude 经度 116.307490
|
||||
* @param toLatitude 纬度 39.984154
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject calcTaxiMoney(MapEnum mapType,Integer tripWay, String longitude, String latitude, String toLongitude, String toLatitude, String city, String cityCode){
|
||||
|
@ -287,11 +287,11 @@ public class CommonMapUtils {
|
|||
|
||||
/**
|
||||
* 根据开始位置和结束位置根据出行方式获取米
|
||||
* @param tripWay
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param toLongitude 经度 116.307490
|
||||
* @param toLatitude 纬度 39.984154
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject calcTaxiMoneyInfo(Integer tripWay, String longitude, String latitude, String toLongitude, String toLatitude, String city, String cityCode){
|
||||
|
@ -348,5 +348,22 @@ public class CommonMapUtils {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询距离 (米)
|
||||
* @param tripWay (2:驾车/出租,其他值:公交)
|
||||
* @param longitude 经度 116.307490
|
||||
* @param latitude 纬度 39.984154
|
||||
* @param toLongitude 经度 116.307490
|
||||
* @param toLatitude 纬度 39.984154
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject calcTaxiMoneyInfo(Integer tripWay, String longitude, String latitude, String toLongitude, String toLatitude) {
|
||||
JSONObject mapAdRes = CommonMapUtils.getLocationToAdInfo(longitude, latitude);
|
||||
String cityName = mapAdRes.getString("city");
|
||||
String cityCode = mapAdRes.getString("adcode");
|
||||
return calcTaxiMoneyInfo(tripWay, longitude, latitude, toLongitude, toLatitude, cityName, cityCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -152,10 +152,7 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
|
|||
}
|
||||
|
||||
//获取城市名称
|
||||
JSONObject mapAdRes = CommonMapUtils.getLocationToAdInfo(longitude, latitude);
|
||||
String cityName = mapAdRes.getString("city");
|
||||
String cityCode = mapAdRes.getString("adcode");
|
||||
JSONObject mapRes = CommonMapUtils.calcTaxiMoneyInfo(artificer.getTripWay(), longitude, latitude, artificer.getLongitude(), artificer.getLatitude(), cityName, cityCode);//根据出行方式计算距离
|
||||
JSONObject mapRes = CommonMapUtils.calcTaxiMoneyInfo(artificer.getTripWay(), longitude, latitude, artificer.getLongitude(), artificer.getLatitude());//根据出行方式计算距离
|
||||
|
||||
//判断技师的出行方式
|
||||
if (artificer.getTripWay() == null || artificer.getTripWay() == 1) {
|
||||
|
|
|
@ -2,8 +2,10 @@ package com.sqx.modules.common.enums;
|
|||
|
||||
import com.sqx.modules.common.utils.CommonConfigUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum CommonEnum {
|
||||
|
||||
NONE(null,null,null,null),
|
||||
|
@ -32,7 +34,9 @@ public enum CommonEnum {
|
|||
/**白天时段从n开始~n结束*/
|
||||
V3_TRAVEL_CONF_DAY(445, "v3_travel_conf", "白天时段从n开始~n结束", "2"),
|
||||
/**夜间时段从n开始~n结束(留空自动计算)*/
|
||||
V3_TRAVEL_CONF_NIGHT(446, "v3_travel_conf", "夜间时段从n开始~n结束(留空自动计算)", ",");
|
||||
V3_TRAVEL_CONF_NIGHT(446, "v3_travel_conf", "夜间时段从n开始~n结束(留空自动计算)", ","),
|
||||
|
||||
V3_TRAVEL_CONF_IS_FIXED(447, "v3_travel_conf", "出行配置使用动态价格", "true");
|
||||
|
||||
private final Integer key;
|
||||
|
||||
|
@ -42,13 +46,6 @@ public enum CommonEnum {
|
|||
|
||||
private final String defValue;
|
||||
|
||||
CommonEnum(Integer key, String defCondition, String defName, String defValue) {
|
||||
this.key = key;
|
||||
this.defCondition = defCondition;
|
||||
this.defName = defName;
|
||||
this.defValue = defValue;
|
||||
}
|
||||
|
||||
// private boolean defValueIsEmpty() {
|
||||
// return CommonConfigUtil.defValueIsEmpty(this.defValue);
|
||||
// }
|
||||
|
@ -84,6 +81,7 @@ public enum CommonEnum {
|
|||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GroupKeyEnum {
|
||||
|
||||
/**
|
||||
|
@ -131,17 +129,15 @@ public enum CommonEnum {
|
|||
V3_TRAVEL_CONF_DAYLIGHT_SAVING_TIME.getKey(),
|
||||
V3_TRAVEL_CONF_WINTER_TIME.getKey(),
|
||||
V3_TRAVEL_CONF_DAY.getKey(),
|
||||
V3_TRAVEL_CONF_NIGHT.getKey()
|
||||
V3_TRAVEL_CONF_NIGHT.getKey(),
|
||||
V3_TRAVEL_CONF_IS_FIXED.getKey()
|
||||
});
|
||||
|
||||
private final Integer[] values;
|
||||
|
||||
GroupKeyEnum(Integer[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GroupConditionEnum {
|
||||
|
||||
V3_ORDER_FORM("v3_order_form"),
|
||||
|
@ -149,8 +145,5 @@ public enum CommonEnum {
|
|||
V3_TRAVEL_CONF("v3_travel_conf");
|
||||
|
||||
private final String value;
|
||||
GroupConditionEnum(String value){
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,18 @@ public class CommonConfigUtil {
|
|||
return Double.valueOf(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为boolean类型
|
||||
* @param value 转换的值
|
||||
* @return 转换后的值
|
||||
*/
|
||||
public static boolean getBooleanValue(String value) {
|
||||
if(defValueIsEmpty(value)) return false;
|
||||
return Boolean.getBoolean(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取数组,默认按,分隔
|
||||
* @param value 转换的值
|
||||
|
|
|
@ -86,5 +86,12 @@ public class TravelConfController {
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/calcTravelPrice")
|
||||
@ApiOperation("获取出行价格")
|
||||
public Result calcTravelPrice(Long artificerId, String toLongitude, String toLatitude){
|
||||
return Result.success().put("data", service.calcTravelPrice(artificerId, toLongitude, toLatitude));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package com.sqx.modules.travelconf.enums;
|
||||
|
||||
import com.sqx.modules.common.utils.CommonConfigUtil;
|
||||
import com.sqx.modules.travelconf.entity.TravelConf;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
public class TravelEnum {
|
||||
|
||||
|
@ -11,6 +10,7 @@ public class TravelEnum {
|
|||
* 价格类型
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum PricingType {
|
||||
|
||||
/***
|
||||
|
@ -23,10 +23,25 @@ public class TravelEnum {
|
|||
TRENDS(2);
|
||||
|
||||
private final Integer value;
|
||||
}
|
||||
|
||||
PricingType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
/**
|
||||
* 固定价格类型
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum FixedType {
|
||||
|
||||
/**
|
||||
* 往返
|
||||
*/
|
||||
RETURN(1),
|
||||
/**
|
||||
* 单程
|
||||
*/
|
||||
ONE_WAY(2);
|
||||
|
||||
private final Integer value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,6 +49,7 @@ public class TravelEnum {
|
|||
* 出行方式
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum TravelType {
|
||||
|
||||
/***
|
||||
|
@ -50,16 +66,13 @@ public class TravelEnum {
|
|||
FREE(3);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
TravelType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 时令
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SeasonsType {
|
||||
|
||||
/***
|
||||
|
@ -72,16 +85,13 @@ public class TravelEnum {
|
|||
WINTER_TIME(2);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
SeasonsType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 时段
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum TimeIntervalType {
|
||||
|
||||
/***
|
||||
|
@ -94,10 +104,6 @@ public class TravelEnum {
|
|||
NIGHT(2);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
TimeIntervalType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@ package com.sqx.modules.travelconf.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.modules.travelconf.entity.TravelConf;
|
||||
import com.sqx.modules.travelconf.vo.TravelPriceVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
public interface TravelConfService extends IService<TravelConf> {
|
||||
|
@ -11,11 +13,10 @@ public interface TravelConfService extends IService<TravelConf> {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param pricingType 价格类型(1:固定价格,2:动态价格)
|
||||
* @param travelType 出行方式(1:免费,2:出租,3:公共交通)
|
||||
* @return
|
||||
*/
|
||||
TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Date businessTime);
|
||||
TravelConf getConfByAccordingCondition(Integer travelType, Date businessTime);
|
||||
|
||||
/**
|
||||
* 根据类型获取出行配置
|
||||
|
@ -27,4 +28,24 @@ public interface TravelConfService extends IService<TravelConf> {
|
|||
*/
|
||||
TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Integer seasonsType, Integer timeIntervalType);
|
||||
|
||||
/**
|
||||
* 按ID获取出行价格
|
||||
* @param artificerId
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @return
|
||||
*/
|
||||
TravelPriceVo calcTravelPrice(Long artificerId, String toLongitude, String toLatitude);
|
||||
|
||||
/**
|
||||
* 最终获取出行价格
|
||||
* @param _travelType
|
||||
* @param freeKilometers
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param toLongitude
|
||||
* @param toLatitude
|
||||
* @return
|
||||
*/
|
||||
TravelPriceVo calcTravelPrice(Integer _travelType, BigDecimal freeKilometers, String longitude, String latitude, String toLongitude, String toLatitude);
|
||||
}
|
||||
|
|
|
@ -2,9 +2,14 @@ package com.sqx.modules.travelconf.service.impl;
|
|||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.exception.SqxException;
|
||||
import com.sqx.map.CommonMapUtils;
|
||||
import com.sqx.modules.artificer.entity.Artificer;
|
||||
import com.sqx.modules.artificer.service.ArtificerService;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.enums.CommonEnum;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
|
@ -13,9 +18,11 @@ import com.sqx.modules.travelconf.dao.TravelConfDao;
|
|||
import com.sqx.modules.travelconf.entity.TravelConf;
|
||||
import com.sqx.modules.travelconf.enums.TravelEnum;
|
||||
import com.sqx.modules.travelconf.service.TravelConfService;
|
||||
import com.sqx.modules.travelconf.vo.TravelPriceVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -28,20 +35,36 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
@Autowired
|
||||
private CommonInfoService commonInfoService;
|
||||
|
||||
@Autowired
|
||||
private ArtificerService artificerService;
|
||||
|
||||
@Override
|
||||
public TravelConf getConfByAccordingCondition(Integer pricingType, Integer travelType, Date businessTime) {
|
||||
public TravelConf getConfByAccordingCondition(Integer travelType, Date businessTime) {
|
||||
//为空则使用当前系统时间
|
||||
if(businessTime == null) businessTime = DateUtil.date();
|
||||
|
||||
//价格类型
|
||||
Integer pricingType;
|
||||
//时令
|
||||
Integer seasonsType = null;
|
||||
Integer seasonsType;
|
||||
//时段
|
||||
Integer timeIntervalType = null;
|
||||
Integer timeIntervalType;
|
||||
|
||||
//从配置文件中取出时间配置(包含很多个)
|
||||
Map<Integer,CommonInfo> commonInfoMap = commonInfoService.getMapByCondition(CommonEnum.GroupConditionEnum.V3_TRAVEL_CONF.getValue());
|
||||
|
||||
//价格类型
|
||||
CommonInfo pricingTypeConfig = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_IS_FIXED.getKey());
|
||||
|
||||
if(pricingTypeConfig == null) {
|
||||
//throw new SqxException("无法找到出行配置,请联系管理员!");
|
||||
pricingType = TravelEnum.PricingType.TRENDS.getValue();
|
||||
}else if(CommonConfigUtil.getBooleanValue(pricingTypeConfig.getValue())){
|
||||
pricingType = TravelEnum.PricingType.TRENDS.getValue();
|
||||
} else {
|
||||
pricingType = TravelEnum.PricingType.FIXED.getValue();
|
||||
}
|
||||
|
||||
//夏令时段
|
||||
CommonInfo daylightSavingTime = commonInfoMap.get(CommonEnum.V3_TRAVEL_CONF_DAYLIGHT_SAVING_TIME.getKey());
|
||||
//冬令时段
|
||||
|
@ -112,7 +135,7 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
}
|
||||
}else{
|
||||
//双方混合判断
|
||||
//TODO 前台无法创建 23:00:00-12:00:00的数据,直接甩出错误或者忽略
|
||||
//前台无法创建 23:00:00-12:00:00的数据,直接甩出错误或者忽略
|
||||
throw new SqxException("请清空夜间时间配置配置,请联系管理员!");
|
||||
}
|
||||
return getConfByAccordingCondition(pricingType, travelType, seasonsType, timeIntervalType);
|
||||
|
@ -158,4 +181,79 @@ public class TravelConfServiceImpl extends ServiceImpl<TravelConfDao, TravelConf
|
|||
}
|
||||
return conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TravelPriceVo calcTravelPrice(Long artificerId, String toLongitude, String toLatitude) {
|
||||
Artificer artificerInfo = artificerService.getById(artificerId);
|
||||
|
||||
Integer travelType = 1;//TODO 现在没有字段后补
|
||||
BigDecimal freeKilometers = new BigDecimal(0);//TODO 现在没有字段后补
|
||||
String longitude = artificerInfo.getLongitude();
|
||||
String latitude = artificerInfo.getLatitude();
|
||||
return calcTravelPrice(travelType, freeKilometers, longitude, latitude, toLongitude, toLatitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TravelPriceVo calcTravelPrice(Integer _travelType, BigDecimal freeKilometers, String longitude, String latitude, String toLongitude, String toLatitude){
|
||||
TravelPriceVo vo = new TravelPriceVo();
|
||||
|
||||
Date now = DateTime.now();
|
||||
//按条件取配置,
|
||||
TravelConf conf = getConfByAccordingCondition(_travelType, now);
|
||||
vo.setConf(conf);
|
||||
|
||||
Integer pricingType = conf.getPricingType();
|
||||
Integer fixedType = conf.getFixedType();
|
||||
Integer travelType = conf.getTravelType();
|
||||
//Integer seasonsType = conf.getSeasonsType();
|
||||
Integer timeIntervalType = conf.getTimeIntervalType();
|
||||
|
||||
//加载距离米数
|
||||
//类型转换
|
||||
int tripWay = 2;
|
||||
if(TravelEnum.TravelType.MASS_TRANSIT.getValue().equals(travelType)) {
|
||||
tripWay = 1;
|
||||
}
|
||||
JSONObject distanceJson = CommonMapUtils.calcTaxiMoneyInfo(tripWay, longitude, latitude, toLongitude, toLatitude);
|
||||
//公里数
|
||||
Integer distances = distanceJson.getInteger("distance");
|
||||
vo.setDistances(distances);
|
||||
|
||||
//转换为公里数
|
||||
BigDecimal kilometerNum = NumberUtil.mul(distances, new BigDecimal("1000"));
|
||||
vo.setKilometerNum(NumberUtil.decimalFormat("0.00", kilometerNum));
|
||||
|
||||
if(TravelEnum.PricingType.FIXED.getValue().equals(pricingType)) {
|
||||
//固定的
|
||||
BigDecimal fixedPrice = conf.getFixedPrice();//单程
|
||||
if(TravelEnum.FixedType.RETURN.getValue().equals(fixedType)) {
|
||||
//往返
|
||||
fixedPrice = NumberUtil.mul(fixedPrice, 2);
|
||||
}
|
||||
//最终价格
|
||||
vo.setTravelPrice(NumberUtil.decimalFormat("0.00", fixedPrice));
|
||||
}else if(TravelEnum.PricingType.TRENDS.getValue().equals(pricingType)){
|
||||
//动态的
|
||||
BigDecimal nightTravelExpenses = new BigDecimal("0");//白天
|
||||
if(TravelEnum.TimeIntervalType.NIGHT.getValue().equals(timeIntervalType)) {
|
||||
//夜间
|
||||
nightTravelExpenses = conf.getNightTravelExpenses();
|
||||
}
|
||||
|
||||
//免费公里数
|
||||
//freeKilometers
|
||||
//起步价
|
||||
BigDecimal startingPrice = conf.getStartingPrice();
|
||||
//每公里价格
|
||||
BigDecimal pricePerKilometer = conf.getPricePerKilometer();
|
||||
|
||||
//最终价格
|
||||
//计算公式为【起步价 + 夜间出行费 + ((公里数 - 免费公里数) * 每公里价格)= 最终价格】
|
||||
BigDecimal travelPrice = NumberUtil.add(startingPrice, nightTravelExpenses, NumberUtil.mul(NumberUtil.sub(kilometerNum, freeKilometers), pricePerKilometer));
|
||||
vo.setTravelPrice(NumberUtil.decimalFormat("0.00", travelPrice));
|
||||
}
|
||||
return vo;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.sqx.modules.travelconf.vo;
|
||||
|
||||
import com.sqx.modules.travelconf.entity.TravelConf;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassName TravelPriceVo
|
||||
* @Description TODO
|
||||
* @Author bai
|
||||
* @Date 2024/6/18 下午10:10
|
||||
* @Version 1.0
|
||||
**/
|
||||
@Data
|
||||
public class TravelPriceVo {
|
||||
|
||||
/**出行价格*/
|
||||
String travelPrice;
|
||||
|
||||
/**出行距离(米)*/
|
||||
Integer distances;
|
||||
|
||||
/**出行距离(公里)*/
|
||||
String kilometerNum;
|
||||
|
||||
/**出行配置具体参数*/
|
||||
TravelConf conf;
|
||||
}
|
Loading…
Reference in New Issue