无关风月
2024-08-12 53ff6ea7033a550d89368aa3c52377bf2184c5f4
DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -11,22 +11,25 @@
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.system.dao.CarMapper;
import com.stylefeng.guns.modular.system.dao.RegionMapper;
import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
import com.stylefeng.guns.modular.system.dao.UserInfoMapper;
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.system.util.GoogleMap.DistancematrixVo;
import com.stylefeng.guns.modular.system.util.GoogleMap.FleetEngineUtil;
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
import com.stylefeng.guns.modular.system.util.itextpdf.HtmlToPdfUtils;
import com.stylefeng.guns.modular.system.util.quartz.QuartzUtil;
import com.stylefeng.guns.modular.system.util.quartz.jobs.OrderTimeOutJob;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import org.apache.shiro.util.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.quartz.JobDataMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -45,9 +48,14 @@
@Service
public class OrderLogisticsServiceImpl extends ServiceImpl<OrderLogisticsMapper, OrderLogistics> implements IOrderLogisticsService {
    Logger log = LoggerFactory.getLogger(this.getClass());
    @Resource
    private OrderLogisticsMapper orderLogisticsMapper;
    @Resource
    private IOrderCancelService orderCancelService;
    @Autowired
    private IDriverService driverService;
@@ -115,6 +123,24 @@
    
    @Resource
    private SystemPriceMapper systemPriceMapper;
    @Autowired
    private FleetEngineUtil fleetEngineUtil;
    @Resource
    private CarModelMapper carModelMapper;
    @Autowired
    private ICarService carService;
    @Autowired
    private ISysOvertimeService sysOvertimeService;
    @Resource
    private ICancleOrderService cancleOrderService;
    @Autowired
    private IOrderPositionService orderPositionService;
@@ -154,6 +180,7 @@
        if(orderLogistics.getState() != 1){
            return ResultUtil.error(language == 1 ? "手速有点慢哦,订单已被抢啦" : language == 2 ? "Too slow, order was snatched!" : "Trop lent, l’ordre a été arraché!");
        }
        Driver driver = driverService.selectById(uid);
        orderLogistics.setDriverId(uid);
        orderLogistics.setCarId(driver.getCarId());
@@ -161,35 +188,100 @@
                driver.getCompanyId() != null && driver.getCompanyId() != 0 ? driver.getCompanyId() : 1));
        orderLogistics.setState(2);
        orderLogistics.setSnatchOrderTime(new Date());
        if(!StringUtils.hasLength(orderLogistics.getTripId())){
            orderLogistics.setTripId(UUIDUtil.getRandomCode());
        }
        String value = redisUtil.getValue("DRIVER" + driver.getId());
        if(ToolUtil.isNotEmpty(value)) {
            String[] split = value.split(",");
            DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]));
            //超时时间
            long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
            orderLogistics.setEstimateArriveTime(new Date(timeOut));
            orderLogistics.setEstimateArriveMileage(distancematrix.getDistance());
        }
        this.updateById(orderLogistics);
        //修改司机为服务中
        driver.setState(3);
        driverService.updateById(driver);
    
        /**
         * 超时用户取消不收费的提醒
         *   即时单:预估到达预约点时间 + 配置不收费的时间 > 当前时间 (只弹一次)
         *
         * 超时用户取消订单后需要弹给司机提醒弹框,超时时间 = 当前时间 - 行程时间 - 配置不收费的时间
         *
         * 定时提醒弹框
         *   司机只要开始超时且还未到达预约点,则需要定时提醒
         */
    
        //todo 待翻译
        //添加定时任务(普通任务)
        ReminderRules reminderRules = reminderRulesService.selectOne(new EntityWrapper<ReminderRules>().eq("companyId", driver.getCompanyId()));
        SysOvertime reminderRules = sysOvertimeService.selectOne(new EntityWrapper<SysOvertime>().eq("companyId", driver.getCompanyId()));
        if(null != reminderRules){
            JSONObject jsonObject = JSON.parseObject(reminderRules.getContent());
            long packageTimeoutReminderInterval = jsonObject.getInteger("packageTimeoutReminderInterval") * 60000L;
            long m = (System.currentTimeMillis() - orderLogistics.getSnatchOrderTime().getTime()) / 60000;
            CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", driver.getCompanyId()));
            Integer driverTimeout = JSON.parseObject(cancleOrder.getContent()).getInteger("driverTimeout");
            //超时时间
            long timeOut = orderLogistics.getEstimateArriveTime().getTime() + (driverTimeout * 60000);
            //乘客取消不收费提醒
            JobDataMap jobDataMap = new JobDataMap();
            jobDataMap.put("driverId", uid);
            jobDataMap.put("timeOutType", 1);
            jobDataMap.put("orderId", orderLogistics.getId());
            jobDataMap.put("orderType", 4);
            jobDataMap.put("describe", "您的打车订单已超时" + m + "分钟,请抓紧!");
            jobDataMap.put("language", language);
            jobDataMap.put("timeOut", timeOut);
            jobDataMap.put("driverTimeout", driverTimeout);
            jobDataMap.put("describe", language == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language == 2 ? "Reminder You are overdue for " + driverTimeout + " minutes The subscriber could cancel the order for free Confirm" : "Rappel Vous êtes en retard de " + driverTimeout + " minutes L’abonné peut annuler la commande gratuitement Confirmer");
            QuartzUtil.addSimpleQuartzTask(
                    new OrderTimeOutJob().buildQuartzJob(UUIDUtil.getRandomCode(5) + "_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap)
                    , new Date(packageTimeoutReminderInterval), packageTimeoutReminderInterval, -1);
                    new OrderTimeOutJob().buildQuartzJob("1_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap)
                    , new Date(timeOut), timeOut, 0);
            //超时循环提醒
            jobDataMap = new JobDataMap();
            jobDataMap.put("driverId", uid);
            jobDataMap.put("timeOutType", 3);
            jobDataMap.put("orderId", orderLogistics.getId());
            jobDataMap.put("orderType", 4);
            jobDataMap.put("language", language);
            jobDataMap.put("timeOut", orderLogistics.getEstimateArriveTime().getTime());
            jobDataMap.put("driverTimeout", driverTimeout);
            jobDataMap.put("describe", "");
            QuartzUtil.addSimpleQuartzTask(
                    new OrderTimeOutJob().buildQuartzJob("3_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap)
                    , orderLogistics.getEstimateArriveTime(), reminderRules.getCar() * 60000, -1);
        }
        new Thread(()->{
            try {
                Car car = carService.selectById(orderLogistics.getCarId());
                if(!StringUtils.hasLength(car.getVehicleId())){
                    car.setVehicleId(UUIDUtil.getRandomCode());
                    carService.updateById(car);
                }
                String trip = fleetEngineUtil.getTrip(orderLogistics.getTripId());
                if(ToolUtil.isEmpty(trip)){
                    String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
                    if(ToolUtil.isEmpty(vehicles)){
                        CarModel carModel = carModelMapper.selectById(car.getCarModelId());
                        fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                    }
                    fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderLogistics.getTripId(),
                            orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(),  orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
                }else{
                    //开始修改行程数据
                    fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
        
        //推送相关代码------------------start----------------
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
            }
        }).start();
@@ -212,11 +304,28 @@
    @Override
    public Map<String, Object> queryOrderInfo(Integer language, Integer orderId) throws Exception {
        Map<String, Object> map = orderLogisticsMapper.queryOrderInfo(orderId);
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(null != map.get("travelTime_")){
            String travelTime_ = map.get("travelTime_").toString();
            map.put("travelTime_", DateUtil.conversionFormat1(language, travelTime_));
        }
        Integer orderState = Integer.valueOf(map.get("orderState").toString());
        if(orderState == 12){
            OrderCancel orderCancel = orderCancelService.selectOne(new EntityWrapper<OrderCancel>().eq("orderId", orderId)
                    .eq("orderType", 4).eq("state", 1).orderBy("insertTime desc limit 0, 1"));
            if(null != orderCancel){
                map.put("cancelPayMoney", orderCancel.getMoney());
            }
        }
        map.put("cancelUser", language == 1 ? "用户" : language == 2 ? "The client" : "Le client");
        map.put("timeOutCancel", 0);
        if(null != orderLogistics.getEstimateArriveTime()){
            CancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<CancleOrder>().eq("companyId", orderLogistics.getCompanyId()));
            JSONObject jsonObject = JSON.parseObject(cancleOrder.getContent());
            int driverTimeout = jsonObject.getIntValue("driverTimeout");
            long timeOutCancel = orderLogistics.getEstimateArriveTime().getTime() + driverTimeout;
            map.put("timeOutCancel", timeOutCancel);
        }
        return map;
    }
@@ -241,8 +350,11 @@
     * @throws Exception
     */
    @Override
    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address, String pickUpCode, Integer language) throws Exception {
    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address, String pickUpCode, Integer language, Integer uid) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(!uid.equals(orderLogistics.getDriverId())){
            return ResultUtil.error(language == 1 ? "操作失败,请刷新订单" : language == 2 ? "Operation failed, please refresh the order" : "L’opération a échoué, veuillez actualiser la commande");
        }
        if(orderLogistics.getState().compareTo(state) == 0){
            return ResultUtil.error(language == 1 ? "不能重复操作" : language == 2 ? "Unable to recur operate" : "Impossible de récurrence des opérer");
        }
@@ -254,19 +366,22 @@
        }
        List<OrderLogisticsSpread> orderLogisticsId = spreadService.selectList(new EntityWrapper<OrderLogisticsSpread>().eq("orderLogisticsId", orderLogistics.getId()).eq("payType",4));
        String tripStatus = "UNKNOWN_TRIP_STATUS";
        switch (state){
            case 3://出发前往预约点
                orderLogistics.setState(3);
                orderLogistics.setSetOutTime(new Date());
                systemNoticeService.addSystemNotice(1, language == 1 ? "司机已出发,请耐心等待" : language == 2 ? "The driver is on the way, please wait." : "Le chauffeur est en route. Veuillez patienter.", orderLogistics.getUserId());
                pushUtil.pushDriverPosition(orderId, 4);
                tripStatus = "ENROUTE_TO_PICKUP";
                break;
            case 4://到达预约点,等待客户上车
                orderLogistics.setState(4);
                orderLogistics.setArriveTime(new Date());
                systemNoticeService.addSystemNotice(1, language == 1 ? "司机已到达您设置的预约地点。" : language == 2 ? "The driver has arrived at the reserved location." : "Le chauffeur est arrivé à l'endroit prévu.", orderLogistics.getUserId());
                tripStatus = "ARRIVED_AT_PICKUP";
                break;
            case 5://开始服务
                orderLogistics.setBoardingLon(lon);
@@ -275,6 +390,7 @@
                orderLogistics.setBoardingTime(new Date());
                orderLogistics.setState(5);
                orderLogistics.setStartServiceTime(new Date());
                tripStatus = "ENROUTE_TO_DROPOFF";
                break;
            case 6://结束服务
                orderLogistics.setGetoffLon(lon);
@@ -283,16 +399,29 @@
                orderLogistics.setGetoffTime(new Date());
                orderLogistics.setEndServiceTime(new Date());
                orderLogistics.setState(6);
                tripStatus = "COMPLETE";
                break;
        }
        this.updateById(orderLogistics);
        Driver driver = driverService.selectById(orderLogistics.getDriverId());
        String finalTripStatus = tripStatus;
        new Thread(()->{
            Car car = carMapper.selectById(driver.getCarId());
            //修改行程数据
            try {
                fleetEngineUtil.updateTrip(finalTripStatus, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }).start();
        
        // TODO: 2020/6/5 推送状态
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
            }
        }).start();
        
@@ -338,8 +467,8 @@
    }
    @Override
    public List<Map<String, Object>> queryOrderList(Integer driverId, Integer language) throws Exception {
        List<Map<String, Object>> list = orderLogisticsMapper.queryOrderList(driverId, language);
    public List<Map<String, Object>> queryOrderList(Integer state, Integer driverId, Integer language) throws Exception {
        List<Map<String, Object>> list = orderLogisticsMapper.queryOrderList(state, driverId, language);
        for (Map<String, Object> map : list) {
            if(null != map.get("time")){
                String time = map.get("time").toString();
@@ -427,8 +556,8 @@
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState());
                pushUtil.pushOrderState(1, orderLogistics.getUserId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
                pushUtil.pushOrderState(2, orderLogistics.getDriverId(), orderLogistics.getId(), orderLogistics.getType(), orderLogistics.getState(), 0, "");
            }
        }).start();
@@ -593,6 +722,14 @@
            orderLogistics.setEndLon(Double.valueOf(orderLogistics.getDestinationLon()));
            orderLogistics.setEndLat(Double.valueOf(orderLogistics.getDestinationLat()));
            orderLogistics.setEndAddress(orderLogistics.getDestination());
            //修改google地图行程终点
            try {
                fleetEngineUtil.updateTrip(null, null, null, orderLogistics.getTripId(),
                        null, null, orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        orderLogistics.setDestinationLon("");
        orderLogistics.setDestination("");
@@ -611,8 +748,9 @@
    @Override
    public Map<String, Object> queryMoneyInfo(Integer orderId) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(orderLogistics.getState() == 5){//服务中的时候获取实时费用数据
        if(orderLogistics.getState() == 6){//服务中的时候获取实时费用数据
            this.setMoney(orderLogistics, 0D, 0D);
            orderLogistics.setOrderMoney(orderLogistics.getOrderMoney() + orderLogistics.getPriceDifference());
        }
    
        Map<String, Object> map = new HashMap<>();
@@ -788,8 +926,8 @@
            }
            amount = num25 + (d1 * num26) + (t1 * num27) + (w1 * num7) + yt1 + yt2 + yt3;
            orderLogistics.setStartMileage(num2);
            orderLogistics.setStartDuration((int)(num3.doubleValue()));
            orderLogistics.setStartMoney(num25);//起步价
            orderLogistics.setStartDuration((int)(num3.doubleValue()));
            orderLogistics.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            orderLogistics.setMileageMoney(new BigDecimal(d1 * num26).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());//里程费
            orderLogistics.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
@@ -805,14 +943,6 @@
            orderLogistics.setDiscount(0D);//优惠抵扣
            orderLogistics.setPayMoney(0D);//支付金额
            orderLogistics.setOrderMoney(new BigDecimal(amount + parkingFee + crossingFee).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
            orderLogistics.setMoneyType(3);
            if((date.getTime() > s1.getTimeInMillis() && date.getTime() < e1.getTimeInMillis())){
                orderLogistics.setMoneyTime(num23);
            }else{
                orderLogistics.setMoneyTime(num24);
            }
            return orderLogistics;
        }
        
@@ -834,8 +964,8 @@
        }
        amount = num1 + (d1 * num4) + (t1 * num5) + (w1 * num7) + yt1 + yt2 + yt3;
        orderLogistics.setStartMileage(num2);
        orderLogistics.setStartDuration((int)(num3.doubleValue()));
        orderLogistics.setStartMoney(num1);//起步价
        orderLogistics.setStartDuration((int)(num3.doubleValue()));
        orderLogistics.setMileageKilometers(new BigDecimal(d1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
        orderLogistics.setMileageMoney(new BigDecimal(d1 * num4).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());//里程费
        orderLogistics.setDuration(new BigDecimal(t1).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
@@ -852,7 +982,6 @@
        orderLogistics.setPayMoney(0D);//支付金额
        orderLogistics.setOrderMoney(new BigDecimal(amount + parkingFee + crossingFee).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
    
        orderLogistics.setMoneyType(1);
        return orderLogistics;
    }
    
@@ -868,8 +997,14 @@
     * @throws Exception
     */
    @Override
    public ResultUtil confirmFees(Integer language, Integer orderId, Integer type, Double parkingFee, Double crossingFee) throws Exception {
    public ResultUtil confirmFees(Integer language, Integer orderId, Integer type, Double parkingFee, Double crossingFee, Integer uid) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(!uid.equals(orderLogistics.getDriverId())){
            return ResultUtil.error(language == 1 ? "操作失败,请刷新订单" : language == 2 ? "Operation failed, please refresh the order" : "L’opération a échoué, veuillez actualiser la commande");
        }
        if(6 != orderLogistics.getState()){
            return ResultUtil.error(language == 1 ? "操作失败,请刷新订单" : language == 2 ? "Operation failed, please refresh the order" : "L’opération a échoué, veuillez actualiser la commande");
        }
        if(orderLogistics.getArriveTime()==null){
            orderLogistics.setArriveTime(orderLogistics.getStartServiceTime());
        }
@@ -887,7 +1022,6 @@
            if(userInfo.getFreeMoney().doubleValue()>0d){
                if(orderLogistics.getOrderMoney()<=userInfo.getFreeMoney().doubleValue()){
                    orderLogistics.setState(8);
                    orderLogistics.setIsFree(2);
                    //添加已收入明细
                    Company company = companyService.selectById(orderLogistics.getCompanyId());
                    Double speMoney = company.getSpeMoney();
@@ -933,7 +1067,9 @@
        
        
        pushUtil.removeTask(orderId, 4);//删除定时任务,结束推送数据
        systemNoticeService.addSystemNotice(1, language == 1 ? "司机已结束本次行程,谢谢使用" : language == 2 ?
        UserInfo userInfo = userInfoMapper.selectById(orderLogistics.getUserId());
        Integer language1 = userInfo.getLanguage();
        systemNoticeService.addSystemNotice(1, language1 == 1 ? "司机已结束本次行程,谢谢使用" : language1 == 2 ?
                "The driver has finished the trip,thank you for using I-GO" : "Le chauffeur a terminé le trajet, merci d'utiliser I-GO", orderLogistics.getUserId());
        
        //回滚司机状态为空闲
@@ -945,10 +1081,67 @@
        new Thread(new Runnable() {
            @Override
            public void run() {
                pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 4, finalOrderTaxi.getState());
                pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 4, finalOrderTaxi.getState());
                pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 4, finalOrderTaxi.getState(), 0, "");
                pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 4, finalOrderTaxi.getState(), 0, "");
            }
        }).start();
        //上报google
        OrderLogistics finalOrderLogistics = orderLogistics;
        new Thread(()->{
            try {
                fleetEngineUtil.reportBillableEvent(finalOrderLogistics.getTripId());
                log.warn("上报时间:{},tripid:{},created_at:{},completed_at:{}", System.currentTimeMillis(), finalOrderLogistics.getTripId(),
                        finalOrderLogistics.getInsertTime().getTime(), finalOrderLogistics.getEndServiceTime().getTime());
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
        return ResultUtil.success();
    }
    /**
     * 计算已服务的实时里程
     * @param orderId
     * @param lon
     * @param lat
     */
    @Override
    public boolean calculateMileage(Integer orderId, String lon, String lat) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        if(orderLogistics.getState() == 2){
            return false;
        }
        OrderPosition orderPosition = orderPositionService.queryNew(orderId, 4);
        String now = lon + "," + lat;
        String old = null;
        if(null != orderPosition){
            old = orderPosition.getLon() + "," + orderPosition.getLat();
        }else{
            orderLogistics.setToStartPointMileage(0D);
            orderLogistics.setMileage(0D);
            this.updateById(orderLogistics);
            return true;//第一条数据不作处理,直接存储
        }
        Map<String, Double> distance = GeodesyUtil.getDistance(now, old);
        if(null != distance){
            Double distance1 = distance.get("WGS84");
            if(distance1 > 50 &&  Arrays.asList(3, 4).contains(orderLogistics.getState())){//大于50米表示在移动
                orderLogistics.setToStartPointMileage(new BigDecimal(orderLogistics.getToStartPointMileage()).add(new BigDecimal(distance1)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                this.updateById(orderLogistics);
                return true;
            }
            if(distance1 > 50 && orderLogistics.getState()==5){//大于50米表示在移动
                orderLogistics.setMileage(new BigDecimal(orderLogistics.getMileage()).add(new BigDecimal(distance1)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
                this.updateById(orderLogistics);
                return true;
            }
            return false;
        }else{
            System.err.println("调用高德计算距离出错");
        }
        return false;
    }
}