package com.stylefeng.guns.modular.taxi.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
|
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
|
import com.stylefeng.guns.modular.system.dao.*;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.*;
|
import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
|
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
|
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Isolation;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
@Service
|
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
public class OrderTaxiServiceImpl extends ServiceImpl<OrderTaxiMapper, OrderTaxi> implements IOrderTaxiService {
|
|
@Resource
|
private OrderTaxiMapper orderTaxiMapper;
|
|
@Autowired
|
private IDriverService driverService;
|
@Autowired
|
private ICompanyService companyService;
|
|
@Autowired
|
private IUserRedPacketRecordService userRedPacketRecordService;
|
@Resource
|
private SystemPriceMapper systemPriceMapper;
|
@Autowired
|
private PushUtil pushUtil;
|
|
@Autowired
|
private GDMapElectricFenceUtil gdMapElectricFenceUtil;
|
@Autowired
|
private ITransactionDetailsService transactionDetailsService;
|
@Autowired
|
private GDFalconUtil gdFalconUtil;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private IOrderPositionService orderPositionService;
|
|
@Autowired
|
private ISystemNoticeService systemNoticeService;
|
|
@Autowired
|
private ChinaMobileUtil chinaMobileUtil;
|
|
@Autowired
|
private GeodesyUtil geodesyUtil;
|
|
@Resource
|
private RegionMapper regionMapper;
|
|
@Autowired
|
private GDMapGeocodingUtil gdMapGeocodingUtil;
|
|
@Autowired
|
private IOrderPrivateCarService orderPrivateCarService;
|
|
@Resource
|
private UserInfoMapper userInfoMapper;
|
|
@Resource
|
private TUseMoneyMapper useMoneyMapper;
|
|
|
@Autowired
|
private TransactionDetailsMapper transactionDetailsMapper;
|
|
|
|
|
|
/**
|
* 获取司机端首页订单列表
|
* @param state 1=服务中,2=待服务(30分钟定义预约)
|
* @param driverId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryOrderList(Integer state, Integer driverId) throws Exception {
|
return orderTaxiMapper.queryOrderList(state, driverId);
|
}
|
|
|
/**
|
* 获取司机端我的订单列表
|
* @param state 1=全部,2=待支付,3=已取消
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryMyAllOrder(Integer state, Integer uid) throws Exception {
|
return orderTaxiMapper.queryMyAllOrder(state, uid);
|
}
|
|
|
/**
|
* 获取订单数据
|
* @param state
|
* @param driverId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<OrderTaxi> query(Integer driverId, Integer...state) throws Exception {
|
List<Integer> integers = Arrays.asList(state);
|
return orderTaxiMapper.query(integers, driverId);
|
}
|
|
|
/**
|
* 获取司机抢单页面的订单详情
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public Map<String, Object> queryPushOrder(Integer orderId) throws Exception {
|
return orderTaxiMapper.queryPushOrder(orderId);
|
}
|
|
|
@Autowired
|
private ALiSendSms aLiSendSms;
|
|
|
@Autowired
|
private ICarService carService;
|
@Resource
|
private DriverWorkMapper driverWorkMapper;
|
/**
|
* 抢单操作
|
* @param orderId
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public synchronized ResultUtil grabOrder(Integer orderId, Integer uid) throws Exception {
|
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
|
//处理摆渡车的情况
|
if(orderTaxi.getType() == 2){
|
//查看用户下的摆渡车是否已被人抢了
|
List<OrderTaxi> list = this.selectList(
|
new EntityWrapper<OrderTaxi>()
|
.eq("type", 2)
|
.eq("userId", orderTaxi.getUserId())
|
.ne("state", 1)
|
.eq("crossCityOrderId", orderTaxi.getCrossCityOrderId())
|
.eq("place", orderTaxi.getPlace())
|
);
|
List<OrderPrivateCar> list1 = orderPrivateCarService.selectList(
|
new EntityWrapper<OrderPrivateCar>()
|
.eq("type", 2)
|
.eq("userId", orderTaxi.getUserId())
|
.ne("state", 1)
|
.eq("crossCityOrderId", orderTaxi.getCrossCityOrderId())
|
.eq("place", orderTaxi.getPlace())
|
);
|
if(list.size() > 0 || list1.size() > 0){
|
return ResultUtil.error("手速有点慢哦,订单已被抢啦!");
|
}
|
}
|
|
if(orderTaxi.getState() == 9){
|
return ResultUtil.error("订单已取消");
|
}
|
if(orderTaxi.getState() != 1){
|
return ResultUtil.error("手速有点慢哦,订单已被抢啦!");
|
}
|
Driver driver = driverService.selectById(uid);
|
|
orderTaxi.setDriverId(uid);
|
orderTaxi.setCarId(driver.getCarId());
|
orderTaxi.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
|
driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
|
orderTaxi.setState(2);
|
orderTaxi.setSnatchOrderTime(new Date());
|
|
//调用高德创建轨迹
|
// String s = gdFalconUtil.selectTerminal(driver.getPhone());
|
// String track = gdFalconUtil.createTrack(s);
|
// orderTaxi.setTrackId(track);
|
if (orderTaxi.getAudioLinkUrl()!=null){
|
// List<TUseMoney> money = useMoneyMapper.selectList(null);
|
Company company = companyService.selectById(driver.getCompanyId());
|
orderTaxi.setState(9);
|
driver.setState(2);
|
// driver.setBalance(driver.getBalance() - company.getFixedDeduction());
|
|
if(Objects.isNull(company)){
|
company = companyService.selectById(driver.getCompanyId());
|
}
|
// 平台收入
|
double money;
|
if(orderTaxi.getOrderSource() == 2 || orderTaxi.getOrderSource() == 3){
|
double v = company.getPercentageDeduction() / 100;
|
money = v * orderTaxi.getOrderMoney();
|
}else {
|
money = company.getFixedDeduction();
|
}
|
driver.setBalance(driver.getBalance() - money);
|
// 新增扣除使用费记录
|
transactionDetailsService.saveData(driver.getId(), "软件使用费", money, 2, 1, 2, 6, orderTaxi.getId(),company.getId());
|
|
driverService.updateById(driver);
|
Car car = carService.selectById(driver.getCarId());
|
// String s = MsgUtil.SendDriverPost(orderTaxi.getPassengersPhone(), car.getCarLicensePlate(),driver.getName(), driver.getPhone());
|
// String s = aLiSendSms.sendSms(orderTaxi.getPassengersPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" +car.getCarLicensePlate() + "\"}");
|
// System.err.println("====电话回调==="+s);
|
SMSUtil.send(orderTaxi.getPassengersPhone(), "您的订单已被司机" + driver.getName() + "接单,联系电话" + driver.getPhone() + "车牌号" + car.getCarLicensePlate() + "请耐心等待。", "2431012312845");
|
}
|
|
//调用移动的小号接口
|
/*Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
|
Region region = regionMapper.query(geocode.get("districtCode"));
|
Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1)));
|
if(String.valueOf(map.get("code")).equals("200")){
|
orderTaxi.setTelX(map.get("telX"));
|
orderTaxi.setBindId(map.get("bindId"));
|
}*/
|
|
this.updateById(orderTaxi);
|
|
if(orderTaxi.getType() == 2){
|
List<OrderTaxi> list = this.selectList(
|
new EntityWrapper<OrderTaxi>()
|
.eq("type", 2)
|
.eq("userId", orderTaxi.getUserId())
|
.ne("state", 1)
|
.eq("crossCityOrderId", orderTaxi.getCrossCityOrderId())
|
.eq("place", orderTaxi.getPlace())
|
);
|
List<OrderPrivateCar> list1 = orderPrivateCarService.selectList(
|
new EntityWrapper<OrderPrivateCar>()
|
.eq("type", 2)
|
.eq("userId", orderTaxi.getUserId())
|
.ne("state", 1)
|
.eq("crossCityOrderId", orderTaxi.getCrossCityOrderId())
|
.eq("place", orderTaxi.getPlace())
|
);
|
for(OrderTaxi orderTaxi1 : list){
|
orderTaxi1.setState(10);
|
this.updateById(orderTaxi1);
|
}
|
for(OrderPrivateCar orderPrivateCar : list1){
|
orderPrivateCar.setState(10);
|
orderPrivateCarService.updateById(orderPrivateCar);
|
}
|
}
|
|
//如果是预约单,则不修改司机为服务中
|
if(orderTaxi.getOrderType() == 2 && orderTaxi.getTravelTime().getTime() < System.currentTimeMillis() + 600000){
|
//修改司机为服务中
|
driver.setState(3);
|
driverService.updateById(driver);
|
}
|
|
//推送相关代码------------------start----------------
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState());
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState());
|
if(orderTaxi.getType() == 2){
|
pushUtil.pushFerryOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, 2);
|
System.err.println("----------------------------------推送摆渡订单-----------------------------");
|
}
|
}
|
}).start();
|
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushDriverPosition(orderId, 2);
|
}
|
}).start();
|
|
systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId());
|
systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId());
|
//发送短信
|
try{
|
UserInfo userInfo = userInfoMapper.selectById(orderTaxi.getUserId());
|
Car car = carService.selectById(orderTaxi.getCarId());
|
// String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" + car.getCarLicensePlate() + "\"}");
|
SMSUtil.send(userInfo.getPhone(), "您的订单已被司机" + driver.getName() + "接单,联系电话" + driver.getPhone() + "车牌号" + car.getCarLicensePlate() + "请耐心等待。", "2431012312845");
|
|
}catch (Exception e){
|
|
}
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 抢单操作(车载端)
|
* @param orderId
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public synchronized ResultUtil grabOrder_(Integer orderId, Integer uid) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(orderTaxi.getState() == 9){
|
return ResultUtil.error("订单已取消");
|
}
|
if(orderTaxi.getState() != 1){
|
return ResultUtil.error("手速有点慢哦,订单已被抢啦!");
|
}
|
Driver driver = driverService.selectById(uid);
|
orderTaxi.setDriverId(uid);
|
orderTaxi.setCarId(driver.getCarId());
|
orderTaxi.setCompanyId(driver.getFranchiseeId() != null && driver.getFranchiseeId() != 0 ? driver.getFranchiseeId() : (
|
driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
|
orderTaxi.setState(2);
|
Date date = new Date();
|
orderTaxi.setSnatchOrderTime(date);
|
orderTaxi.setSetOutTime(date);
|
orderTaxi.setArriveTime(date);
|
orderTaxi.setStartServiceTime(date);
|
orderTaxi.setBoardingTime(date);
|
|
String value = redisUtil.getValue("DRIVER" + uid);
|
if(ToolUtil.isNotEmpty(value)){
|
String[] split = value.split(",");
|
Map<String, String> geocode1 = gdMapGeocodingUtil.geocode(split[0], split[1]);
|
orderTaxi.setBoardingAddress(geocode1.get("address"));
|
orderTaxi.setBoardingLon(Double.valueOf(split[0]));
|
orderTaxi.setBoardingLat(Double.valueOf(split[1]));
|
}
|
|
//调用高德创建轨迹
|
String s = gdFalconUtil.selectTerminal(driver.getPhone());
|
String track = gdFalconUtil.createTrack(s);
|
orderTaxi.setTrackId(track);
|
|
//调用移动的小号接口 TODO 车载端使用真实号码
|
// Map<String, String> geocode = gdMapGeocodingUtil.geocode(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString());
|
// Region region = regionMapper.query(geocode.get("districtCode"));
|
// Map<String, String> map = chinaMobileUtil.midAxbBindSend(orderTaxi.getPassengersPhone(), driver.getPhone(), Integer.valueOf(region.getCitycode().substring(1)));
|
//// if(String.valueOf(map.get("code")).equals("200")){
|
//// orderTaxi.setTelX(map.get("telX"));
|
//// orderTaxi.setBindId(map.get("bindId"));
|
//// }
|
|
this.updateById(orderTaxi);
|
|
//如果是预约单,则不修改司机为服务中
|
if(orderTaxi.getOrderType() != 2 || (orderTaxi.getOrderType() == 2 && orderTaxi.getTravelTime().getTime() < System.currentTimeMillis() + 600000)){
|
//修改司机为服务中
|
driver.setState(3);
|
driverService.updateById(driver);
|
}
|
|
//推送相关代码------------------start----------------
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, orderTaxi.getState());
|
pushUtil.pushOrderState(2, orderTaxi.getDriverId(), orderTaxi.getId(), 2, orderTaxi.getState());
|
}
|
}).start();
|
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushDriverPosition(orderId, 2);
|
}
|
}).start();
|
|
systemNoticeService.addSystemNotice(2, "您已成功抢得出租车订单,请及时联系客户!", orderTaxi.getDriverId());
|
systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId());
|
//发送短信
|
try{
|
UserInfo userInfo = userInfoMapper.selectById(orderTaxi.getUserId());
|
Car car = carService.selectById(orderTaxi.getCarId());
|
// String sData = aLiSendSms.sendSms(userInfo.getPhone(), "SMS_476900230", "{\"code1\":\"" + driver.getName() + "\",\"code2\":\"" + driver.getPhone() + "\",\"code3\":\"" + car.getCarLicensePlate() + "\"}");
|
SMSUtil.send(userInfo.getPhone(), "您的订单已被司机" + driver.getName() + "接单,联系电话" + driver.getPhone() + "车牌号" + car.getCarLicensePlate() + "请耐心等待。", "2431012312845");
|
|
}catch (Exception e){
|
|
}
|
|
return ResultUtil.success();
|
}
|
|
|
|
|
|
/**
|
* 获取订单详情页(服务中的页面)
|
* @param orderId
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public Map<String, Object> queryOrderInfo(Integer orderId) throws Exception {
|
return orderTaxiMapper.queryOrderInfo(orderId);
|
}
|
/**
|
* 走订单流程操作
|
* @param orderId
|
* @param state
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
switch (state){
|
case 3://出发前往预约点
|
orderTaxi.setState(3);
|
orderTaxi.setSetOutTime(new Date());
|
systemNoticeService.addSystemNotice(1, "司机已出发,请耐心等待", orderTaxi.getUserId());
|
break;
|
case 4://到达预约点,等待客户上车
|
orderTaxi.setState(4);
|
orderTaxi.setArriveTime(new Date());
|
systemNoticeService.addSystemNotice(1, "司机已到达您设置的预约地点,请及时上车", orderTaxi.getUserId());
|
break;
|
case 5://开始服务
|
orderTaxi.setBoardingLon(lon);
|
orderTaxi.setBoardingLat(lat);
|
orderTaxi.setBoardingAddress(address);
|
orderTaxi.setBoardingTime(new Date());
|
orderTaxi.setState(5);
|
orderTaxi.setStartServiceTime(new Date());
|
|
pushUtil.pushDriverPosition(orderTaxi.getId(), 2);//主动推送司机定位
|
break;
|
case 6://结束服务
|
orderTaxi.setGetoffLon(lon);
|
orderTaxi.setGetoffLat(lat);
|
orderTaxi.setGetoffAddress(address);
|
orderTaxi.setGetoffTime(new Date());
|
orderTaxi.setEndServiceTime(new Date());
|
orderTaxi.setState(6);
|
//回滚司机状态为空闲
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
driver.setState(2);
|
driverService.updateById(driver);
|
|
pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据
|
systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId());
|
break;
|
}
|
this.updateById(orderTaxi);
|
|
// TODO: 2020/6/5 推送状态
|
OrderTaxi finalOrderTaxi = orderTaxi;
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
}
|
}).start();
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 确认费用操作
|
* @param orderId
|
* @param type
|
* @param travelFee
|
* @param parkingFee
|
* @param crossingFee
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil confirmFees(Integer orderId, Integer type, Double travelFee, Double parkingFee, Double crossingFee) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(2 == type && orderTaxi.getPayManner()==3){
|
orderTaxi.setState(9);
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
|
Company company = companyService.selectById(driver.getFranchiseeId());
|
if(Objects.isNull(company)){
|
company = companyService.selectById(driver.getCompanyId());
|
}
|
TransactionDetails transactionDetails = new TransactionDetails();
|
driver.setBalance(driver.getBalance() - company.getFixedDeduction());
|
transactionDetails.setMoney(company.getFixedDeduction());
|
// 新增扣除使用费记录
|
transactionDetails.setUserId(driver.getId());
|
transactionDetails.setInsertTime(new Date());
|
transactionDetails.setRemark("软件使用费");
|
transactionDetails.setState(2);
|
transactionDetails.setType(1);
|
transactionDetails.setUserType(2);
|
transactionDetails.setOrderType(6);
|
transactionDetails.setOrderId(orderTaxi.getId());
|
transactionDetailsMapper.insert(transactionDetails);
|
driverService.updateById(driver);
|
}
|
//打表计费,直接订单完成支付,
|
if(2 == type && orderTaxi.getPayManner()==2){
|
orderTaxi = this.setMoney2(orderTaxi, parkingFee, crossingFee);
|
//在线上计费的基础上随机加0.01-1的金额
|
Double orderMoney = orderTaxi.getOrderMoney() + (new BigDecimal(Math.random()).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
orderTaxi.setState(8);
|
orderTaxi.setOrderMoney(orderMoney);
|
orderTaxi.setPayMoney(orderMoney);
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
|
Company company = companyService.selectById(driver.getFranchiseeId());
|
if(Objects.isNull(company)){
|
company = companyService.selectById(driver.getCompanyId());
|
}
|
TransactionDetails transactionDetails = new TransactionDetails();
|
Double meterPrintingFee = company.getMeterPrintingFee();
|
Double laveBusinessMoney = driver.getLaveBusinessMoney();
|
Double laveActivityMoney = driver.getLaveActivityMoney();
|
if(null != laveBusinessMoney && laveBusinessMoney.compareTo(meterPrintingFee) >= 0){
|
driver.setLaveBusinessMoney(new BigDecimal(laveBusinessMoney).subtract(new BigDecimal(meterPrintingFee)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}else if(null != laveActivityMoney && laveActivityMoney.compareTo(meterPrintingFee) >= 0){
|
driver.setLaveActivityMoney(new BigDecimal(laveActivityMoney).subtract(new BigDecimal(meterPrintingFee)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
driver.setBalance(driver.getBalance() - meterPrintingFee);
|
transactionDetails.setMoney(meterPrintingFee);
|
// 新增扣除使用费记录
|
transactionDetails.setUserId(driver.getId());
|
transactionDetails.setInsertTime(new Date());
|
transactionDetails.setRemark("软件使用费");
|
transactionDetails.setState(2);
|
transactionDetails.setType(1);
|
transactionDetails.setUserType(2);
|
transactionDetails.setOrderType(6);
|
transactionDetails.setOrderId(orderTaxi.getId());
|
transactionDetailsMapper.insert(transactionDetails);
|
driverService.updateById(driver);
|
}
|
//线上计费,计算费用后修改为待支付
|
if(1 == type && orderTaxi.getPayManner()==1){
|
orderTaxi = this.setMoney2(orderTaxi, crossingFee, crossingFee);
|
orderTaxi.setState(7);
|
}
|
this.updateById(orderTaxi);
|
|
OrderTaxi finalOrderTaxi = orderTaxi;
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
}
|
}).start();
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 确认费用(车载端)
|
* @param orderId
|
* @param type
|
* @param travelFee
|
* @param lon
|
* @param lat
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil confirmFees_(Integer orderId, Integer type, Double travelFee, Double lon, Double lat, String address) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(orderTaxi.getState() == 5){//服务中才能确认费用
|
orderTaxi.setPayManner(type);
|
orderTaxi = this.setMoney(orderTaxi, travelFee, 0D, 0D);
|
orderTaxi.setState(7);
|
orderTaxi.setGetoffLon(lon);
|
orderTaxi.setGetoffLat(lat);
|
orderTaxi.setGetoffAddress(address);
|
orderTaxi.setGetoffTime(new Date());
|
orderTaxi.setEndServiceTime(new Date());
|
|
this.updateById(orderTaxi);
|
|
pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据
|
systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId());
|
|
//回滚司机状态为空闲
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
driver.setState(2);
|
driverService.updateById(driver);
|
|
OrderTaxi finalOrderTaxi = orderTaxi;
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
}
|
}).start();
|
//添加定时任务6分钟司机不确认收款自动完成支付(仅车载端),6分钟之内司机无法接单
|
String vehicle = redisUtil.getValue("VEHICLE");
|
JSONArray jsonArray = new JSONArray();
|
if(ToolUtil.isNotEmpty(vehicle)){
|
jsonArray = JSON.parseArray(vehicle);
|
}
|
jsonArray.add(orderTaxi.getDriverId());
|
redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识
|
|
TimerTask timerTask = new TimerTask() {
|
@Override
|
public void run() {
|
OrderTaxi orderTaxi1 = OrderTaxiServiceImpl.this.selectById(orderId);
|
if(orderTaxi1.getState() == 7){//如果是待支付
|
orderTaxi1.setPayManner(2);//其他方式支付
|
orderTaxi1.setRedPacketMoney(0D);
|
orderTaxi1.setCouponMoney(0D);
|
orderTaxi1.setDiscount(0D);
|
orderTaxi1.setDiscountMoney(0D);
|
orderTaxi1.setPayMoney(orderTaxi1.getOrderMoney());
|
orderTaxi1.setState(8);
|
OrderTaxiServiceImpl.this.updateById(orderTaxi1);
|
|
String vehicle = redisUtil.getValue("VEHICLE");
|
if(ToolUtil.isNotEmpty(vehicle)){
|
JSONArray jsonArray = JSON.parseArray(vehicle);
|
for(int i = 0; i < jsonArray.size(); i++){
|
if(jsonArray.getInteger(i).compareTo(orderTaxi1.getDriverId()) == 0){
|
jsonArray.remove(i);
|
break;
|
}
|
}
|
redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
|
}
|
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi1.getUserId(), orderId, 2, 8);
|
pushUtil.pushOrderState(2, orderTaxi1.getDriverId(), orderId, 2, 8);
|
}
|
}).start();
|
}
|
}
|
};
|
Timer timer = new Timer();
|
timer.schedule(timerTask, 6 * 60 * 1000);
|
}
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 司机确认费用(车载端)不管之前数据状态直接修改到待支付(流程断网情况的处理流程)
|
* @param orderId
|
* @param type
|
* @param travelFee
|
* @param lon
|
* @param lat
|
* @param address
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil confirmFees$(Integer orderId, Integer type, Double travelFee, Double lon, Double lat, String address) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
orderTaxi.setPayManner(type);
|
orderTaxi = this.setMoney(orderTaxi, travelFee, 0D, 0D);
|
orderTaxi.setState(7);
|
orderTaxi.setGetoffLon(lon);
|
orderTaxi.setGetoffLat(lat);
|
orderTaxi.setGetoffAddress(address);
|
orderTaxi.setGetoffTime(new Date());
|
orderTaxi.setEndServiceTime(new Date());
|
|
this.updateById(orderTaxi);
|
|
pushUtil.removeTask(orderId, 2);//删除定时任务,结束推送数据
|
systemNoticeService.addSystemNotice(1, "司机已结束本次行程,谢谢使用", orderTaxi.getUserId());
|
|
//回滚司机状态为空闲
|
Driver driver = driverService.selectById(orderTaxi.getDriverId());
|
driver.setState(2);
|
driverService.updateById(driver);
|
|
OrderTaxi finalOrderTaxi = orderTaxi;
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState());
|
}
|
}).start();
|
|
//添加定时任务6分钟司机不确认收款自动完成支付(仅车载端),6分钟之内司机无法接单
|
String vehicle = redisUtil.getValue("VEHICLE");
|
JSONArray jsonArray = new JSONArray();
|
if(ToolUtil.isNotEmpty(vehicle)){
|
jsonArray = JSON.parseArray(vehicle);
|
}
|
jsonArray.add(orderTaxi.getDriverId());
|
redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());//添加司机不能接单标识
|
|
TimerTask timerTask = new TimerTask() {
|
@Override
|
public void run() {
|
OrderTaxi orderTaxi1 = OrderTaxiServiceImpl.this.selectById(orderId);
|
if(orderTaxi1.getState() == 7){//如果是待支付
|
orderTaxi1.setPayManner(2);//其他方式支付
|
orderTaxi1.setRedPacketMoney(0D);
|
orderTaxi1.setCouponMoney(0D);
|
orderTaxi1.setDiscount(0D);
|
orderTaxi1.setDiscountMoney(0D);
|
orderTaxi1.setPayMoney(orderTaxi1.getOrderMoney());
|
orderTaxi1.setState(8);
|
OrderTaxiServiceImpl.this.updateById(orderTaxi1);
|
|
String vehicle = redisUtil.getValue("VEHICLE");
|
if(ToolUtil.isNotEmpty(vehicle)){
|
JSONArray jsonArray = JSON.parseArray(vehicle);
|
for(int i = 0; i < jsonArray.size(); i++){
|
if(jsonArray.getInteger(i).compareTo(orderTaxi1.getDriverId()) == 0){
|
jsonArray.remove(i);
|
break;
|
}
|
}
|
redisUtil.setStrValue("VEHICLE", jsonArray.toJSONString());
|
}
|
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
pushUtil.pushOrderState(1, orderTaxi1.getUserId(), orderId, 2, 8);
|
pushUtil.pushOrderState(2, orderTaxi1.getDriverId(), orderId, 2, 8);
|
}
|
}).start();
|
}
|
}
|
};
|
Timer timer = new Timer();
|
timer.schedule(timerTask, 6 * 60 * 1000);
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 计算已服务的实时里程
|
* @param orderId
|
* @param lon
|
* @param lat
|
*/
|
@Override
|
public boolean calculateMileage(Integer orderId, String lon, String lat) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(null == orderTaxi){
|
System.err.println("订单数据异常:" + orderId);
|
return false;
|
}
|
if(orderTaxi.getState() != 5){
|
return false;
|
}
|
OrderPosition orderPosition = orderPositionService.queryNew(orderId, 2);
|
String now = lon + "," + lat;
|
String old = null;
|
if(null != orderPosition){
|
old = orderPosition.getLon() + "," + orderPosition.getLat();
|
}else{
|
orderTaxi.setMileage(0D);
|
this.updateById(orderTaxi);
|
return true;//第一条数据不作处理,直接存储
|
}
|
// Map<String, String> distance = gdMapElectricFenceUtil.getDistance(now, old, 0);//直线距离
|
Map<String, Double> distance = geodesyUtil.getDistance(now, old);
|
if(null != distance){
|
Double distance1 = distance.get("WGS84");
|
if(Double.valueOf(distance1) > 50 && orderTaxi.getState() == 5){//大于50米表示在移动,且正在服务中的时候存入里程
|
orderTaxi.setMileage(new BigDecimal(orderTaxi.getMileage()).add(new BigDecimal(distance1)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
this.updateById(orderTaxi);
|
return true;
|
}
|
return false;
|
}else{
|
System.err.println("调用高德计算距离出错");
|
}
|
return false;
|
}
|
|
|
/**
|
* 获取所有快到期的预约单(出行时间在30分钟内)
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<OrderTaxi> queryMaturity() throws Exception {
|
return orderTaxiMapper.queryMaturity();
|
}
|
|
|
/**
|
* 获取订单完成后30分钟的数据
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<OrderTaxi> taskMidAxbUnBindSend() throws Exception {
|
return orderTaxiMapper.taskMidAxbUnBindSend();
|
}
|
|
@Override
|
public Map<String, Object> queryMoneyInfo(Integer orderId) throws Exception {
|
OrderTaxi orderTaxi = this.selectById(orderId);
|
if(orderTaxi.getState() == 5 || orderTaxi.getState() == 6){//服务中的时候获取实时费用数据
|
if(orderTaxi.getPayManner() == 2){//其他支付,不需要操作,直接完成订单
|
orderTaxi = this.setMoney1(orderTaxi, 0D, 0D, 0D);
|
}else if(orderTaxi.getPayManner() == 1){
|
orderTaxi = this.setMoney2(orderTaxi, 0D, 0D);
|
}else {
|
// 无
|
}
|
}
|
|
// 查询平台服务费
|
TransactionDetails transactionDetails = transactionDetailsService.selectOne(new EntityWrapper<TransactionDetails>()
|
.eq("orderId", orderId)
|
.eq("orderType", 6)
|
.last("LIMIT 1"));
|
|
Map<String, Object> map = new HashMap<>();
|
map.put("orderMoney", orderTaxi.getOrderMoney());//订单金额
|
map.put("startMileage", orderTaxi.getStartMileage());//起步价
|
map.put("startMoney", orderTaxi.getStartMoney());//起步价
|
map.put("mileageKilometers", orderTaxi.getMileageKilometers());//里程费
|
map.put("mileageMoney", orderTaxi.getMileageMoney());//里程费
|
map.put("duration", orderTaxi.getDuration());//时长费
|
map.put("durationMoney", orderTaxi.getDurationMoney());//时长费
|
map.put("wait", orderTaxi.getWait());//等待费
|
map.put("waitMoney", orderTaxi.getWaitMoney());//等待费
|
map.put("longDistance", orderTaxi.getLongDistance());//远途费
|
map.put("longDistanceMoney", orderTaxi.getLongDistanceMoney());//远途费
|
map.put("parkMoney", orderTaxi.getParkMoney());//停车费
|
map.put("roadTollMoney", orderTaxi.getRoadTollMoney());//过路费
|
map.put("redPacketMoney", orderTaxi.getRedPacketMoney());//红包抵扣金额
|
map.put("couponMoney", orderTaxi.getCouponMoney());//优惠券抵扣金额
|
map.put("discountMoney", orderTaxi.getDiscountMoney());//折扣抵扣金额
|
map.put("discount", orderTaxi.getDiscount());//折扣
|
if(Objects.isNull(transactionDetails)){
|
map.put("platformFee", 0);//折扣
|
}else {
|
map.put("platformFee", transactionDetails.getMoney());//折扣
|
}
|
return map;
|
}
|
|
/**
|
* 计算价格
|
* @param orderTaxi
|
* @param parkingFee
|
* @param crossingFee
|
* @return
|
* @throws Exception
|
*/
|
public OrderTaxi setMoney1(OrderTaxi orderTaxi, Double travelFee, Double parkingFee, Double crossingFee) throws Exception{
|
|
if (travelFee!=null){
|
String s = travelFee.toString();
|
BigDecimal trave = new BigDecimal(s);
|
orderTaxi.setTravelMoney(trave.setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
}else{
|
orderTaxi.setTravelMoney(0.0);
|
|
}
|
if (parkingFee!=null){
|
String s1 = parkingFee.toString();
|
BigDecimal parking = new BigDecimal(s1);
|
orderTaxi.setParkMoney(parking.setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
}else{
|
orderTaxi.setParkMoney(0.0);
|
|
}
|
if (crossingFee!=null){
|
String s2 = crossingFee.toString();
|
|
BigDecimal crossing = new BigDecimal(s2);
|
orderTaxi.setRoadTollMoney(crossing.setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
}else{
|
orderTaxi.setRoadTollMoney(0.0);
|
}
|
BigDecimal sum = new BigDecimal(null == travelFee ? 0 : travelFee).add(new BigDecimal(null == parkingFee ? 0 : parkingFee))
|
.add(new BigDecimal(null == crossingFee ? 0 : crossingFee)).add(new BigDecimal(null == orderTaxi.getTipMoney() ? 0 : orderTaxi.getTipMoney()));
|
orderTaxi.setOrderMoney(sum.setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
return orderTaxi;
|
}
|
|
/**
|
* 计算价格
|
* @param orderTaxi
|
* @param parkingFee
|
* @param crossingFee
|
* @return
|
* @throws Exception
|
*/
|
public OrderTaxi setMoney2(OrderTaxi orderTaxi, Double parkingFee, Double crossingFee) throws Exception {
|
Map<String, Object> query1 = systemPriceMapper.query1(orderTaxi.getCompanyId(), 2);
|
//开始根据不同的方式计算金额
|
double amount = 0;
|
JSONObject jsonObject = JSON.parseObject(String.valueOf(query1.get("content")));
|
//乘车类型(1=独享,2=一口价,3=拼车)
|
double d = (null == orderTaxi.getMileage() ? 0D : orderTaxi.getMileage());
|
System.out.println("行驶里程数"+d);
|
//在价格区间按照一口价算,不在区间按实时价格算
|
System.out.println("不在区间====================");
|
orderTaxi = calculationPrice(orderTaxi,jsonObject,jsonObject.getLongValue("num29"),jsonObject.getDouble("num30"),parkingFee,crossingFee);
|
System.out.println("返回订单数据"+orderTaxi);
|
return orderTaxi;
|
}
|
|
public OrderTaxi calculationPrice(OrderTaxi OrderTaxi,JSONObject rule, long wait,Double waitMoney, Double parkingFee, Double crossingFee) throws Exception {
|
double amount = 0.0;
|
//等待费
|
Date date = new Date();
|
if(OrderTaxi.getEndServiceTime()==null)OrderTaxi.setEndServiceTime(date);
|
double d = (null == OrderTaxi.getMileage() ? 0D : OrderTaxi.getMileage()) / 1000;//实际公里
|
double t = ((OrderTaxi.getEndServiceTime().getTime() - OrderTaxi.getStartServiceTime().getTime()) / 60000) + 1;//实际时间(不满一分钟按一分钟算)
|
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 w = ((OrderTaxi.getStartServiceTime().getTime() - OrderTaxi.getArriveTime().getTime()) / 60000) + 1;//等待分钟(不满一分钟按一分钟算)
|
double w1 = (w - wait) < 0 ? 0 : new BigDecimal(w - wait).setScale(0, BigDecimal.ROUND_UP).doubleValue();//超出等待时间的时间
|
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") && d < rule.getDouble("num7")){
|
yt1 = rule.getDouble("num18") * d;
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
if(d > rule.getDouble("num9") && d < rule.getDouble("num10")){
|
yt1 = rule.getDouble("num18") * rule.getDouble("num7");
|
yt2 = rule.getDouble("num19") * (d - rule.getDouble("num9"));
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num9")) ? d - rule.getDouble("num9") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
if(d > rule.getDouble("num12")){
|
yt1 = rule.getDouble("num18") * rule.getDouble("num7");
|
yt2 = rule.getDouble("num19") * (rule.getDouble("num10") - rule.getDouble("num9"));
|
yt3 = rule.getDouble("num20") * (d - rule.getDouble("num12"));
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num12")) ? d - rule.getDouble("num12") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
// amount = rule.getDouble("num15") + (d1 * rule.getDouble("num16")) + (t1 * rule.getDouble("num17")) + (w1 * waitMoney) + yt1 + yt2 + yt3;
|
OrderTaxi.setStartMileage(rule.getDouble("num2"));
|
OrderTaxi.setStartMoney(rule.getDouble("num15"));//起步价
|
OrderTaxi.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setMileageMoney(new BigDecimal(d1 * rule.getDouble("num16")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
|
OrderTaxi.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setDurationMoney(new BigDecimal(t1 * rule.getDouble("num17")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
|
OrderTaxi.setWait(new BigDecimal(w1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setWaitMoney(new BigDecimal(w1 * waitMoney).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//等待费
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
|
OrderTaxi.setParkMoney(Objects.isNull(parkingFee)?0D:parkingFee);//停车费
|
OrderTaxi.setRoadTollMoney(Objects.isNull(crossingFee)?0D:crossingFee);//过路费
|
OrderTaxi.setRedPacketMoney(0D);//红包抵扣
|
OrderTaxi.setCouponMoney(0D);//优惠券抵扣
|
OrderTaxi.setDiscount(0D);//优惠抵扣
|
OrderTaxi.setPayMoney(0D);//支付金额
|
amount = OrderTaxi.getStartMoney() + OrderTaxi.getMileageMoney() +
|
OrderTaxi.getDurationMoney() + OrderTaxi.getWaitMoney() + OrderTaxi.getLongDistanceMoney();
|
OrderTaxi.setOrderMoney(amount+OrderTaxi.getParkMoney()+OrderTaxi.getRoadTollMoney());
|
}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") && d < rule.getDouble("num7")){
|
yt1 = rule.getDouble("num26") * d;
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
if(d > rule.getDouble("num9") && d < rule.getDouble("num10")){
|
yt1 = rule.getDouble("num26") * rule.getDouble("num7");
|
yt2 = rule.getDouble("num27") * (d - rule.getDouble("num9"));
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num9")) ? d - rule.getDouble("num9") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
if(d > rule.getDouble("num12")){
|
yt1 = rule.getDouble("num26") * rule.getDouble("num7");
|
yt2 = rule.getDouble("num27") * (rule.getDouble("num10") - rule.getDouble("num9"));
|
yt3 = rule.getDouble("num28") * (d - rule.getDouble("num12"));
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num12")) ? d - rule.getDouble("num12") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
// amount = rule.getDouble("num23") + (d1 * rule.getDouble("num24")) + (t1 * rule.getDouble("num25")) + (w1 * waitMoney) + yt1 + yt2 + yt3;
|
OrderTaxi.setStartMileage(rule.getDouble("num2"));
|
OrderTaxi.setStartMoney(rule.getDouble("num23"));//起步价
|
OrderTaxi.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setMileageMoney(new BigDecimal(d1 * rule.getDouble("num24")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
|
OrderTaxi.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setDurationMoney(new BigDecimal(t1 * rule.getDouble("num25")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
|
OrderTaxi.setWait(new BigDecimal(w1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setWaitMoney(new BigDecimal(w1 * waitMoney).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//等待费
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
|
OrderTaxi.setParkMoney(Objects.isNull(parkingFee)?0D:parkingFee);//停车费
|
OrderTaxi.setRoadTollMoney(Objects.isNull(crossingFee)?0D:crossingFee);//过路费
|
OrderTaxi.setRedPacketMoney(0D);//红包抵扣
|
OrderTaxi.setCouponMoney(0D);//优惠券抵扣
|
OrderTaxi.setDiscount(0D);//优惠抵扣
|
OrderTaxi.setPayMoney(0D);//支付金额
|
// amount = new BigDecimal(OrderTaxi.getStartMoney())
|
// .add(new BigDecimal(OrderTaxi.getMileageMoney()))
|
// .add(new BigDecimal(OrderTaxi.getDurationMoney()))
|
// .add(new BigDecimal(OrderTaxi.getWaitMoney()))
|
// .add(new BigDecimal(OrderTaxi.getLongDistanceMoney()));
|
// OrderTaxi.setOrderMoney(amount.add(new BigDecimal(parkingFee)).add(new BigDecimal(parkingFee)).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());
|
amount = OrderTaxi.getStartMoney() + OrderTaxi.getMileageMoney() +
|
OrderTaxi.getDurationMoney() + OrderTaxi.getWaitMoney() + OrderTaxi.getLongDistanceMoney();
|
OrderTaxi.setOrderMoney(amount+OrderTaxi.getParkMoney()+OrderTaxi.getRoadTollMoney());
|
}else{
|
//其他时间段的计算
|
if(d > rule.getDouble("num6") && d < rule.getDouble("num7")){
|
yt1 = rule.getDouble("num8") * d;
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
if(d > rule.getDouble("num9") && d < rule.getDouble("num10")){
|
yt1 = rule.getDouble("num8") * rule.getDouble("num7");
|
yt2 = rule.getDouble("num11") * (d - rule.getDouble("num9"));
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num9")) ? d - rule.getDouble("num9") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
if(d > rule.getDouble("num12")){
|
yt1 = rule.getDouble("num8") * rule.getDouble("num7");
|
yt2 = rule.getDouble("num11") * (rule.getDouble("num10") - rule.getDouble("num9"));
|
yt3 = rule.getDouble("num13") * (d - rule.getDouble("num12"));
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num12")) ? d - rule.getDouble("num12") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
// amount = rule.getDouble("num1") + (d1 * rule.getDouble("num4")) + (t1 * rule.getDouble("num5")) + (w1 * waitMoney) + yt1 + yt2 + yt3;
|
OrderTaxi.setStartMileage(rule.getDouble("num2"));
|
OrderTaxi.setStartMoney(rule.getDouble("num1"));//起步价
|
OrderTaxi.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setMileageMoney(new BigDecimal(d1 * rule.getDouble("num4")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//里程费
|
OrderTaxi.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setDurationMoney(new BigDecimal(t1 * rule.getDouble("num5")).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//时长费
|
OrderTaxi.setWait(new BigDecimal(w1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setWaitMoney(new BigDecimal(w1 * waitMoney).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//等待费
|
// OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setLongDistance(new BigDecimal((d > rule.getDouble("num6")) ? d - rule.getDouble("num6") : 0).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
OrderTaxi.setLongDistanceMoney(new BigDecimal(yt1 + yt2 + yt3).setScale(2, BigDecimal.ROUND_DOWN).doubleValue());//远途费
|
OrderTaxi.setParkMoney(Objects.isNull(parkingFee)?0D:parkingFee);//停车费
|
OrderTaxi.setRoadTollMoney(Objects.isNull(crossingFee)?0D:crossingFee);//过路费
|
OrderTaxi.setRedPacketMoney(0D);//红包抵扣
|
OrderTaxi.setCouponMoney(0D);//优惠券抵扣
|
OrderTaxi.setDiscount(0D);//优惠抵扣
|
OrderTaxi.setPayMoney(0D);//支付金额
|
amount = OrderTaxi.getStartMoney() + OrderTaxi.getMileageMoney() +
|
OrderTaxi.getDurationMoney() + OrderTaxi.getWaitMoney() + OrderTaxi.getLongDistanceMoney();
|
OrderTaxi.setOrderMoney(amount+OrderTaxi.getParkMoney()+OrderTaxi.getRoadTollMoney());
|
}
|
}
|
return OrderTaxi;
|
}
|
/**
|
* 计算费用
|
* @param orderTaxi
|
* @param travelFee
|
* @param parkingFee
|
* @param crossingFee
|
* @return
|
*/
|
public OrderTaxi setMoney(OrderTaxi orderTaxi, Double travelFee, Double parkingFee, Double crossingFee) throws Exception{
|
orderTaxi.setTravelMoney(travelFee);
|
orderTaxi.setParkMoney(parkingFee);
|
orderTaxi.setRoadTollMoney(crossingFee);
|
BigDecimal sum = new BigDecimal(travelFee).add(new BigDecimal(parkingFee)).add(new BigDecimal(crossingFee)).add(new BigDecimal(orderTaxi.getTipMoney()));
|
orderTaxi.setOrderMoney(sum.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
return orderTaxi;
|
}
|
}
|