package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.modular.system.dao.ServerCarModelMapper;
|
import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
|
import com.stylefeng.guns.modular.system.model.Company;
|
import com.stylefeng.guns.modular.system.model.OpenCity;
|
import com.stylefeng.guns.modular.system.model.ServerCarModel;
|
import com.stylefeng.guns.modular.system.model.SystemPriceCity;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
|
import com.stylefeng.guns.modular.system.util.GDMapGeocodingUtil;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
|
import com.stylefeng.guns.modular.system.warpper.ServerCarModelWarpper;
|
import lombok.Data;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.*;
|
|
|
@Service
|
public class ServerCarModelServiceImpl extends ServiceImpl<ServerCarModelMapper, ServerCarModel> implements IServerCarModelService {
|
|
@Resource
|
private ServerCarModelMapper serverCarModelMapper;
|
|
@Resource
|
private ISystemPriceCityService systemPriceCityService;
|
|
@Resource
|
private SystemPriceMapper systemPriceMapper;
|
|
@Autowired
|
private GDMapElectricFenceUtil gdMapElectricFenceUtil;
|
|
@Autowired
|
private GDMapGeocodingUtil gdMapGeocodingUtil;
|
|
@Autowired
|
private ICompanyCityService companyCityService;
|
|
@Autowired
|
private IOpenCityService openCityService;
|
|
@Autowired
|
private IOpenCityBusinessService openCityBusinessService;
|
|
|
/**
|
* 根据起点和终点获取车型
|
* @param startLonLat
|
* @param endLonLat
|
* @param type 业务类型
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil<List<ServerCarModelWarpper>> queryServerCarModel(String startLonLat, String endLonLat, Integer type) throws Exception {
|
//查找与起点匹配的企业(经营范围)
|
Map<String, String> geocode = gdMapGeocodingUtil.geocode(startLonLat.split(",")[0], startLonLat.split(",")[1]);
|
Company query = companyCityService.query(geocode.get("districtCode"));
|
if(null == query){
|
return ResultUtil.error("起点暂无企业提供服务", new ArrayList<>());
|
}
|
if(type == 1 && query.getIsSpe() == 2){
|
return ResultUtil.success(new ArrayList<>());
|
}
|
|
Map<String, String> distance = gdMapElectricFenceUtil.getDistance(startLonLat, endLonLat, 1);
|
if (null == distance) {
|
return ResultUtil.error("获取预估距离出错", new ArrayList<>());
|
}
|
String distance1 = distance.get("distance");//距离(米)
|
double distance1_ = Double.valueOf(distance1).doubleValue();
|
String duration = distance.get("duration");//时间(秒)
|
long duration_ = Long.valueOf(duration).longValue();
|
OpenCity openCity = openCityService.openCity1(geocode.get("districtCode"));
|
if(null == openCity){
|
return ResultUtil.error("起点暂未开通");
|
}
|
|
//专车车型
|
List<ServerCarModelWarpper> price = new ArrayList<>();
|
List<BaseWarpper> baseWarppers = openCityBusinessService.queryBusinessById(openCity.getId());
|
Optional<BaseWarpper> first = baseWarppers.stream().filter(s->s.getId() == 1).findFirst();
|
if(first.isPresent()){
|
price = this.getPrice(query.getId(), distance1_, duration_, 0, 1, geocode);
|
}
|
|
//出租车车型
|
ServerCarModelWarpper serverCarModelWarpper = null;
|
first = baseWarppers.stream().filter(s->s.getId() == 2).findFirst();
|
if(first.isPresent()){
|
serverCarModelWarpper = this.getTextPrice(query.getId(), distance1_, duration_, 0, 2, geocode);
|
if(serverCarModelWarpper!=null){
|
price.add(serverCarModelWarpper);
|
}
|
}
|
return ResultUtil.success(price);
|
}
|
|
|
/**
|
* 获取业务类型对应的所有服务车型
|
*
|
* @param type
|
* @return
|
*/
|
@Override
|
public List<Map<String, Object>> queryServerCarModels(Integer type) {
|
return serverCarModelMapper.queryServerCarModel(type);
|
}
|
|
/**
|
* 快捷叫车无终点,只返回可选车辆信息,不计算预估价格。
|
*
|
* @param startLonLat 起点经纬度
|
* @return 车辆信息
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil<List<ServerCarModelWarpper>> queryQuickCallServerCarModel(String startLonLat) throws Exception {
|
Map<String, String> geocode = gdMapGeocodingUtil.geocode(startLonLat.split(",")[0], startLonLat.split(",")[1]);
|
Company query = companyCityService.query(geocode.get("districtCode"));
|
if (null == query) {
|
return ResultUtil.error("起点暂无企业提供服务", new ArrayList<>());
|
}
|
OpenCity openCity = openCityService.openCity1(geocode.get("districtCode"));
|
if (null == openCity) {
|
return ResultUtil.error("起点暂未开通", new ArrayList<>());
|
}
|
List<BaseWarpper> baseWarppers = openCityBusinessService.queryBusinessById(openCity.getId());
|
List<ServerCarModelWarpper> data = new ArrayList<>();
|
Optional<BaseWarpper> privateCarBusiness = baseWarppers.stream().filter(s -> s.getId() == 1).findFirst();
|
if (privateCarBusiness.isPresent() && !Integer.valueOf(2).equals(query.getIsSpe())) {
|
data.addAll(this.getPrice(query.getId(), 0, 0, 0, 1, geocode));
|
}
|
Optional<BaseWarpper> taxiBusiness = baseWarppers.stream().filter(s -> s.getId() == 2).findFirst();
|
if (taxiBusiness.isPresent() && !Integer.valueOf(2).equals(query.getIsTaxi())) {
|
ServerCarModelWarpper taxiWarpper = this.getTextPrice(query.getId(), 0, 0, 0, 2, geocode);
|
if (taxiWarpper != null) {
|
data.add(taxiWarpper);
|
}
|
}
|
// 快捷叫车不能参与拼车合单,前端不展示拼车选项。
|
for (ServerCarModelWarpper warpper : data) {
|
warpper.setMileage(0D);
|
warpper.setDuration(0D);
|
warpper.setPc_check(0);
|
}
|
return ResultUtil.success(data);
|
}
|
|
|
/**
|
* 计算价格
|
*
|
* @param companyId
|
* @param distance
|
* @param duration
|
* @param wait
|
* @param type
|
* @return
|
* @throws Exception
|
*/
|
public List<ServerCarModelWarpper> getPrice(Integer companyId, double distance, long duration, long wait, Integer type, Map<String, String> geocode) throws Exception {
|
System.err.println("预估里程:" + distance);
|
System.err.println("预估时间:" + duration);
|
String provinceCode = geocode.get("provinceCode");
|
String cityCode = geocode.get("cityCode");
|
String districtCode = geocode.get("districtCode");
|
//获取匹配的城市价格配置
|
SystemPriceCity systemPriceCity = systemPriceCityService.queryOne(provinceCode, cityCode, districtCode);
|
System.err.println("获取匹配的城市价格配置:" + systemPriceCity);
|
if (null == systemPriceCity) {
|
return new ArrayList<>();
|
}
|
List<Map<String, Object>> list = serverCarModelMapper.queryServerCarModel(type);
|
System.err.println("获取匹配的城市价格配置111:" + list);
|
List<ServerCarModelWarpper> data = new ArrayList<>();
|
for (Map<String, Object> map : list) {
|
Map<String, Object> query1 = systemPriceMapper.query(companyId, type, Integer.valueOf(map.get("id").toString()), systemPriceCity.getId());
|
if (null == query1) {//排除没有设置价格的车型
|
continue;
|
}
|
//开始根据不同的方式计算金额
|
double amount = 0;
|
if (type == 1) {//专车
|
double d = distance / 1000;//实际公里
|
double t = duration / 60;//实际时间
|
JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费
|
Double waitMoney = jsonObject.getDouble("num2");
|
JSONObject contentPutOne = JSON.parseObject(query1.get("contentPutOne").toString());//一人拼成
|
JSONObject contentNotOne = JSON.parseObject(query1.get("contentNotOne").toString());//一人未拼成
|
JSONObject contentPutTwo = JSON.parseObject(query1.get("contentPutTwo").toString());//2人拼成
|
JSONObject contentNotTwo = JSON.parseObject(query1.get("contentNotTwo").toString());//2人未拼成
|
JSONObject contentPutThree = JSON.parseObject(query1.get("contentPutThree").toString());//3人拼成
|
JSONObject contentNotThree = JSON.parseObject(query1.get("contentNotThree").toString());//3人未拼成
|
JSONObject contentExclusive = JSON.parseObject(query1.get("contentExclusive").toString());//独享
|
JSONObject contentPrice = JSON.parseObject(query1.get("contentPrice").toString());//一口价
|
//一口价
|
ServerCarModelWarpper serverCarModelWarpper = ServerCarModelWarpper.getServerCarModelWarpper(map);
|
serverCarModelWarpper.setFareTypeNote1(query1.get("fareTypeNote1").toString());
|
serverCarModelWarpper.setFareTypeNote2(query1.get("fareTypeNote2").toString());
|
serverCarModelWarpper.setFareTypeNote3(query1.get("fareTypeNote3").toString());
|
serverCarModelWarpper.setContentPutOne(contentPutOne);
|
serverCarModelWarpper.setContentNotOne(contentNotOne);
|
|
serverCarModelWarpper.setContentPutTwo(contentPutTwo);
|
serverCarModelWarpper.setContentNotTwo(contentNotTwo);
|
|
serverCarModelWarpper.setContentPutThree(contentPutThree);
|
serverCarModelWarpper.setContentNotThree(contentNotThree);
|
|
|
serverCarModelWarpper.setContentExclusive(contentExclusive);
|
serverCarModelWarpper.setContentPrice(contentPrice);
|
serverCarModelWarpper.setWaitPrice(jsonObject);
|
|
serverCarModelWarpper.setAmount(this.calculationPrice(contentExclusive, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setBuyNowAmount(this.calculationPrice(contentPrice, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setPutTogetherOneAmount(this.calculationPrice(contentPutOne, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setNotAssembledOneAmount(this.calculationPrice(contentNotOne, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setPutTogetherTwoAmount(this.calculationPrice(contentPutTwo, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setNotAssembledTwoAmount(this.calculationPrice(contentNotTwo, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setPutTogetherThreeAmount(this.calculationPrice(contentPutThree, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setNotAssembledThreeAmount(this.calculationPrice(contentNotThree, distance, duration, wait, waitMoney));
|
serverCarModelWarpper.setMileage(d);
|
serverCarModelWarpper.setDuration(t);
|
serverCarModelWarpper.setIsOpen(Integer.parseInt(query1.get("isOpen").toString()));
|
serverCarModelWarpper.setIsOpenExclusive(Integer.parseInt(query1.get("isOpenExclusive").toString()));
|
serverCarModelWarpper.setIsOpenPrice(Integer.parseInt(query1.get("isOpenPrice").toString()));
|
String isCheck = map.get("isCheck").toString();
|
String[] split = isCheck.split(",");
|
serverCarModelWarpper.setDx_check(Integer.valueOf(split[0]));
|
serverCarModelWarpper.setYkj_check(Integer.valueOf(split[1]));
|
serverCarModelWarpper.setPc_check(Integer.valueOf(split[2]));
|
data.add(serverCarModelWarpper);
|
}
|
}
|
return data;
|
}
|
|
|
public ServerCarModelWarpper getTextPrice(Integer companyId, double distance, long duration, long wait, Integer type, Map<String, String> geocode) throws Exception {
|
String provinceCode = geocode.get("provinceCode");
|
String cityCode = geocode.get("cityCode");
|
String districtCode = geocode.get("districtCode");
|
//获取匹配的城市价格配置
|
SystemPriceCity systemPriceCity = systemPriceCityService.queryOne(provinceCode, cityCode, districtCode);
|
if (null == systemPriceCity) {
|
return null;
|
}
|
Map<String, Object> query1 = systemPriceMapper.query(companyId, type, null, systemPriceCity.getId());
|
if (null == query1) {//排除没有设置价格的车型
|
return null;
|
}
|
Map<String, Object> map = new HashMap<>();
|
double d = distance / 1000;//实际公里
|
double t = duration / 60;//实际时间
|
JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());//等待费
|
Double num1 = jsonObject.getDouble("num1");
|
Double num2 = jsonObject.getDouble("num2");
|
JSONArray mileageList = jsonObject.getJSONArray("mileageList");
|
Double num4 = jsonObject.getDouble("num4");
|
Double num5 = jsonObject.getDouble("num5");
|
String num6 = jsonObject.getString("num6");
|
Double num7 = jsonObject.getDouble("num7");
|
Double num8 = jsonObject.getDouble("num8");
|
|
String[] split = num6.split(" - ");
|
Integer time1 = Integer.valueOf(split[0].replace(":", ""));
|
Integer time2 = Integer.valueOf(split[1].replace(":", ""));
|
long start_date = 0;
|
long end_date = 0;
|
if(time1.compareTo(time2) > 0){
|
//跨天
|
String[] split1 = split[1].split(":");
|
Calendar calendar = Calendar.getInstance();
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1);
|
calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0]));
|
calendar.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
|
calendar.set(Calendar.SECOND, 59);
|
end_date = calendar.getTimeInMillis();
|
|
String[] split2 = split[0].split(":");
|
calendar = Calendar.getInstance();
|
calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split2[0]));
|
calendar.set(Calendar.MINUTE, Integer.valueOf(split2[1]));
|
calendar.set(Calendar.SECOND, 0);
|
start_date = calendar.getTimeInMillis();
|
}else{
|
String[] split1 = split[1].split(":");
|
Calendar calendar = Calendar.getInstance();
|
calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0]));
|
calendar.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
|
calendar.set(Calendar.SECOND, 59);
|
end_date = calendar.getTimeInMillis();
|
|
String[] split2 = split[0].split(":");
|
calendar = Calendar.getInstance();
|
calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split2[0]));
|
calendar.set(Calendar.MINUTE, Integer.valueOf(split2[1]));
|
calendar.set(Calendar.SECOND, 0);
|
start_date = calendar.getTimeInMillis();
|
}
|
|
Double amount = 0D;
|
if (System.currentTimeMillis() > start_date && System.currentTimeMillis() <= end_date) {
|
amount = num7;
|
BigDecimal multiply = BigDecimal.ZERO;
|
BigDecimal yt = BigDecimal.ZERO;
|
if (d > num8) {
|
|
if(null != mileageList){
|
List<MileageObject> list = new ArrayList<>();
|
for (int i = 0; i < mileageList.size(); i++) {
|
MileageObject mileageObject = mileageList.getObject(i, MileageObject.class);
|
list.add(mileageObject);
|
}
|
//根据配置的里程倒序排序
|
list.sort(new Comparator<MileageObject>() {
|
@Override
|
public int compare(MileageObject o1, MileageObject o2) {
|
return o1.getMileage().compareTo(o2.getMileage()) * -1;
|
}
|
});
|
//计算每个阶段的增加费用
|
Double last = new BigDecimal(d).setScale(0, RoundingMode.DOWN).doubleValue();
|
for (int i = 0; i < list.size(); i++) {
|
Double mileage = list.get(i).getMileage();
|
Double price = list.get(i).getPrice();
|
if(d > mileage){
|
if(last <= num2){
|
break;
|
}
|
multiply = multiply.add((new BigDecimal(last).subtract(new BigDecimal(mileage))).multiply(new BigDecimal(price)));
|
last = mileage;
|
}
|
}
|
}
|
if (d > num4) {
|
yt = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5));
|
}
|
amount = new BigDecimal(num7).add(multiply).add(yt).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
|
}
|
map.put("qibujia", num7);
|
map.put("lichengfei", multiply.doubleValue());
|
map.put("yuantufei", yt.doubleValue());
|
map.put("zongfeiyong", amount);
|
} else {
|
amount = num1;
|
BigDecimal multiply = BigDecimal.ZERO;
|
BigDecimal yt = BigDecimal.ZERO;
|
if (d > num2) {
|
if(null != mileageList){
|
List<MileageObject> list = new ArrayList<>();
|
for (int i = 0; i < mileageList.size(); i++) {
|
MileageObject mileageObject = mileageList.getObject(i, MileageObject.class);
|
list.add(mileageObject);
|
}
|
//根据配置的里程倒序排序
|
list.sort(new Comparator<MileageObject>() {
|
@Override
|
public int compare(MileageObject o1, MileageObject o2) {
|
return o1.getMileage().compareTo(o2.getMileage()) * -1;
|
}
|
});
|
//计算每个阶段的增加费用
|
Double last = new BigDecimal(d).setScale(0, RoundingMode.DOWN).doubleValue();
|
for (int i = 0; i < list.size(); i++) {
|
Double mileage = list.get(i).getMileage();
|
Double price = list.get(i).getPrice();
|
if(d > mileage){
|
if(last <= num2){
|
break;
|
}
|
multiply = multiply.add((new BigDecimal(last).subtract(new BigDecimal(mileage))).multiply(new BigDecimal(price)));
|
last = mileage;
|
}
|
}
|
}
|
|
if (d > num4) {
|
yt = new BigDecimal(d).subtract(new BigDecimal(num4)).multiply(new BigDecimal(num5));
|
}
|
amount = new BigDecimal(num1).add(multiply).add(yt).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
|
}
|
map.put("qibujia", num1);
|
map.put("lichengfei", multiply.doubleValue());
|
map.put("yuantufei", yt.doubleValue());
|
map.put("zongfeiyong", amount);
|
}
|
List<Map<String, Object>> list = serverCarModelMapper.queryServerCarModel(4);
|
String isCheck = "0";
|
if(list.size() > 0){
|
Map<String, Object> objectMap = list.get(0);
|
isCheck = objectMap.get("isCheck").toString();
|
}
|
ServerCarModelWarpper serverCarModelWarpper = new ServerCarModelWarpper();
|
serverCarModelWarpper.setId(0);
|
serverCarModelWarpper.setName("出租车");
|
serverCarModelWarpper.setAmount(map);
|
serverCarModelWarpper.setDx_check(Integer.valueOf(isCheck));
|
serverCarModelWarpper.setContentPutOne(new JSONObject());
|
serverCarModelWarpper.setContentNotOne(new JSONObject());
|
serverCarModelWarpper.setContentPutTwo(new JSONObject());
|
serverCarModelWarpper.setContentNotTwo(new JSONObject());
|
serverCarModelWarpper.setContentPutThree(new JSONObject());
|
serverCarModelWarpper.setContentNotThree(new JSONObject());
|
serverCarModelWarpper.setContentExclusive(jsonObject);
|
serverCarModelWarpper.setContentPrice(new JSONObject());
|
|
return serverCarModelWarpper;
|
}
|
|
/**
|
* 专车费用计算
|
*/
|
public Map<String, Object> calculationPrice(JSONObject rule, double distance, long duration, long wait, Double waitMoney) throws Exception {
|
System.err.println("专车费计算参数1:" + rule);
|
System.err.println("专车费计算参数2:" + distance);
|
System.err.println("专车费计算参数3:" + duration);
|
System.err.println("专车费计算参数4:" + wait);
|
System.err.println("专车费计算参数5:" + waitMoney);
|
|
Map<String, Object> map = new HashMap<>();
|
Date date = new Date();
|
|
double d = distance / 1000; // 实际公里
|
double t = duration / 60; // 实际分钟
|
double d1 = Math.max(0, d - rule.getDouble("num2")); // 超出起步里程
|
double t1 = Math.max(0, t - rule.getDouble("num3")); // 超出起步时间
|
|
// 从 num14 开始,每 7 个为一组,动态匹配时间区间
|
// 每组结构:numI=时间区间, numI+1=起步价, numI+2=里程费, numI+3=时间费,
|
// numI+4=远途1费率, numI+5=远途2费率, numI+6=远途3费率
|
int startIndex = 14;
|
boolean matched = false;
|
|
while (rule.containsKey("num" + startIndex)) {
|
String timeRangeKey = "num" + startIndex;
|
String timeRange = rule.getString(timeRangeKey);
|
|
// 确保后续6个参数都存在,否则跳出
|
if (!rule.containsKey("num" + (startIndex + 6))) {
|
break;
|
}
|
|
// 解析时间区间,兼容 "HH:mm - HH:mm" 和 "HH:mm-HH:mm" 两种格式
|
String[] parts = timeRange.split("\\s*-\\s*");
|
if (parts.length != 2) {
|
startIndex += 7;
|
continue;
|
}
|
|
try {
|
Calendar rangeStart = parseTimeToCalendar(date, parts[0].trim());
|
Calendar rangeEnd = parseTimeToCalendar(date, parts[1].trim());
|
|
boolean inRange;
|
if (rangeStart.before(rangeEnd)) {
|
// 同日区间,例如 "08:00 - 10:00"
|
inRange = date.getTime() > rangeStart.getTimeInMillis()
|
&& date.getTime() < rangeEnd.getTimeInMillis();
|
} else {
|
// 跨午夜区间,例如 "20:00 - 02:00"
|
inRange = date.getTime() > rangeStart.getTimeInMillis()
|
|| date.getTime() < rangeEnd.getTimeInMillis();
|
}
|
|
if (inRange) {
|
double qibujia = rule.getDouble("num" + (startIndex + 1));
|
double lchengLv = rule.getDouble("num" + (startIndex + 2));
|
double schangLv = rule.getDouble("num" + (startIndex + 3));
|
double yt1Lv = rule.getDouble("num" + (startIndex + 4));
|
double yt2Lv = rule.getDouble("num" + (startIndex + 5));
|
double yt3Lv = rule.getDouble("num" + (startIndex + 6));
|
|
buildResult(map, rule, d, d1, t1, wait, waitMoney,
|
qibujia, lchengLv, schangLv, yt1Lv, yt2Lv, yt3Lv);
|
matched = true;
|
break;
|
}
|
} catch (Exception e) {
|
// 时间解析失败时跳过该组,继续下一组
|
}
|
|
startIndex += 7;
|
}
|
|
// 没有任何时间区间匹配,使用基础时段费率(num1 ~ num13)
|
if (!matched) {
|
buildResult(map, rule, d, d1, t1, wait, waitMoney,
|
rule.getDouble("num1"),
|
rule.getDouble("num4"),
|
rule.getDouble("num5"),
|
rule.getDouble("num8"),
|
rule.getDouble("num11"),
|
rule.getDouble("num13"));
|
}
|
return map;
|
}
|
|
/**
|
* 将 "HH:mm" 字符串解析为当天对应的 Calendar 实例
|
*/
|
private Calendar parseTimeToCalendar(Date baseDate, String hhmm) {
|
String[] hm = hhmm.split(":");
|
Calendar cal = Calendar.getInstance();
|
cal.setTime(baseDate);
|
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hm[0]));
|
cal.set(Calendar.MINUTE, Integer.parseInt(hm[1]));
|
cal.set(Calendar.SECOND, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
return cal;
|
}
|
|
/**
|
* 计算远途费和总价并写入 map
|
*/
|
private void buildResult(Map<String, Object> map, JSONObject rule,
|
double d, double d1, double t1,
|
long wait, Double waitMoney,
|
double qibujia, double lchengLv, double schangLv,
|
double yt1Lv, double yt2Lv, double yt3Lv) {
|
|
double yt1 = d > rule.getDouble("num6") ? yt1Lv * (d - rule.getDouble("num6")) : 0;
|
double yt2 = d > rule.getDouble("num9") ? yt2Lv * (d - rule.getDouble("num9")) : 0;
|
double yt3 = d > rule.getDouble("num12") ? yt3Lv * (d - rule.getDouble("num12")) : 0;
|
|
double lichengfei = d1 * lchengLv;
|
double schangfei = t1 * schangLv;
|
double dengdaifei = wait * waitMoney;
|
double yuantufei = yt1 + yt2 + yt3;
|
double total = qibujia + lichengfei + schangfei + dengdaifei + yuantufei;
|
|
map.put("qibujia", qibujia);
|
map.put("lichengfei", lichengfei);
|
map.put("shichangfei", schangfei);
|
map.put("dengdaifei", dengdaifei);
|
map.put("yuantufei", yuantufei);
|
map.put("zongfeiyong", total);
|
}
|
|
|
/**
|
* 专车计算逻辑用上面的新方法(这个方法废弃)
|
*/
|
@Deprecated
|
public Map<String, Object> calculationPriceBack(JSONObject rule, double distance, long duration, long wait, Double waitMoney) throws Exception {
|
Map<String, Object> map = new HashMap<>();
|
//等待费
|
Date date = new Date();
|
double d = distance / 1000;//实际公里
|
double t = duration / 60;//实际时间
|
double d1 = (d - rule.getDouble("num2")) < 0 ? 0 : d - rule.getDouble("num2");//超出起步里程的公里
|
double t1 = (t - rule.getDouble("num3")) < 0 ? 0 : t - rule.getDouble("num3");//超过起步分钟数的时间
|
double yt1 = 0;//远途1段
|
double yt2 = 0;//远途2段
|
double yt3 = 0;//远途3段
|
|
|
//夜间服务处理逻辑
|
Calendar s = Calendar.getInstance();
|
s.setTime(date);
|
s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[0]));
|
s.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[0].split(":")[1]));
|
|
Calendar e = Calendar.getInstance();
|
e.setTime(date);
|
e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[0]));
|
e.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num14").split(" - ")[1].split(":")[1]));
|
|
if (date.getTime() > s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()) {
|
if (d > rule.getDouble("num6")) {
|
yt1 = rule.getDouble("num18") * (d - rule.getDouble("num6"));
|
}
|
if (d > rule.getDouble("num9")) {
|
yt2 = rule.getDouble("num19") * (d - rule.getDouble("num9"));
|
}
|
if (d > rule.getDouble("num12")) {
|
yt3 = rule.getDouble("num20") * (d - rule.getDouble("num12"));
|
}
|
double amount = rule.getDouble("num15") + (d1 * rule.getDouble("num16")) + (t1 * rule.getDouble("num17")) + (wait * waitMoney) + yt1 + yt2 + yt3;
|
map.put("qibujia", rule.getDouble("num15"));
|
map.put("lichengfei", d1 * rule.getDouble("num16"));
|
map.put("shichangfei", t1 * rule.getDouble("num17"));
|
map.put("dengdaifei", wait * waitMoney);
|
map.put("yuantufei", yt1 + yt2 + yt3);
|
map.put("zongfeiyong", amount);
|
}else{
|
Calendar s1 = Calendar.getInstance();
|
s1.setTime(date);
|
s1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[0]));
|
s1.set(Calendar.MINUTE, Integer.valueOf(rule.getString("num21").split(" - ")[0].split(":")[1]));
|
|
Calendar e1 = Calendar.getInstance();
|
e1.setTime(date);
|
e1.set(Calendar.HOUR_OF_DAY, Integer.valueOf(rule.getString("num21").split(" - ")[1].split(":")[0]));
|
e1.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() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis()) || (date.getTime() > s2.getTimeInMillis() && date.getTime() < e2.getTimeInMillis())) {
|
if (d > rule.getDouble("num6")) {
|
yt1 = rule.getDouble("num26") * (d - rule.getDouble("num6"));
|
}
|
if (d > rule.getDouble("num9")) {
|
yt2 = rule.getDouble("num27") * (d - rule.getDouble("num9"));
|
}
|
if (d > rule.getDouble("num12")) {
|
yt3 = rule.getDouble("num28") * (d - rule.getDouble("num12"));
|
}
|
double amount = rule.getDouble("num23") + (d1 * rule.getDouble("num24")) + (t1 * rule.getDouble("num25")) + (wait * waitMoney) + yt1 + yt2 + yt3;
|
map.put("qibujia", rule.getDouble("num23"));
|
map.put("lichengfei", d1 * rule.getDouble("num24"));
|
map.put("shichangfei", t1 * rule.getDouble("num25"));
|
map.put("dengdaifei", wait * waitMoney);
|
map.put("yuantufei", yt1 + yt2 + yt3);
|
map.put("zongfeiyong", amount);
|
}else{
|
//其他时间段的计算
|
if (d > rule.getDouble("num6")) {
|
yt1 = rule.getDouble("num8") * (d - rule.getDouble("num6"));
|
}
|
if (d > rule.getDouble("num9")) {
|
yt2 = rule.getDouble("num11") * (d - rule.getDouble("num9"));
|
}
|
if (d > rule.getDouble("num12")) {
|
yt3 = rule.getDouble("num13") * (d - rule.getDouble("num12"));
|
}
|
double amount = rule.getDouble("num1") + (d1 * rule.getDouble("num4")) + (t1 * rule.getDouble("num5")) + (wait * waitMoney) + yt1 + yt2 + yt3;
|
map.put("qibujia", rule.getDouble("num1"));
|
map.put("lichengfei", d1 * rule.getDouble("num4"));
|
map.put("shichangfei", t1 * rule.getDouble("num5"));
|
map.put("dengdaifei", wait * waitMoney);
|
map.put("yuantufei", yt1 + yt2 + yt3);
|
map.put("zongfeiyong", amount);
|
}
|
}
|
return map;
|
}
|
|
|
@Data
|
public static class MileageObject{
|
private Double mileage;
|
private Double price;
|
|
}
|
}
|