Pu Zhibing
6 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/specialTrain/TReassignController.java
@@ -1,31 +1,45 @@
package com.stylefeng.guns.modular.system.controller.specialTrain;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.controller.util.PushUtil;
import com.stylefeng.guns.modular.system.dao.LineShiftDriverMapper;
import com.stylefeng.guns.modular.system.dao.OrderCancelMapper;
import com.stylefeng.guns.modular.system.dao.TCarModelMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.HttpRequestUtil;
import com.stylefeng.guns.modular.system.util.PushURL;
import com.stylefeng.guns.modular.system.util.ResultUtil;
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.*;
import com.stylefeng.guns.modular.system.util.quartz.QuartzUtil;
import com.stylefeng.guns.modular.system.util.quartz.jobs.OrderTimeOutJob;
import org.apache.shiro.util.StringUtils;
import org.quartz.JobDataMap;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -42,6 +56,9 @@
    @Autowired
    private ITReassignService tReassignService;
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private ITOrderPrivateCarService itOrderPrivateCarService;
@@ -78,8 +95,34 @@
    @Autowired
    private ITOrderLogisticsService orderLogisticsService;
    @Autowired
    private ITPubTransactionDetailsService itPubTransactionDetailsService;
    @Resource
    private QuartzUtil quartzUtil;
    @Resource
    private FleetEngineUtil fleetEngineUtil;
    @Resource
    private TCarModelMapper carModelMapper;
    @Resource
    private ITCarService carService;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private ITSysOverTimeService sysOvertimeService;
    @Resource
    private ITSysCancleOrderService cancleOrderService;
    @Resource
    private ITSystemNoticeService systemNoticeService;
    /**
     * 跳转到专车改派管理首页
@@ -97,7 +140,6 @@
        return PREFIX + "cross.html";
    }
    /**
     * 跳转到小件物流改派管理首页
     */
@@ -105,7 +147,6 @@
    public String smallPieceLogistics() {
        return PREFIX + "smallPieceLogistics.html";
    }
    /**
     * 跳转到添加专车改派管理
@@ -143,7 +184,7 @@
        model.addAttribute("tReassignId",tReassignId);
        return PREFIX + "tReassign_reassignmentCross.html";
    }
    /**
     * 跳转到修改跨城改派管理
     */
@@ -151,6 +192,14 @@
    public String tReassign_reassignmentSmall(@PathVariable Integer tReassignId, Model model) {
        model.addAttribute("tReassignId",tReassignId);
        return PREFIX + "tReassign_reassignmentSmall.html";
    }
    @RequestMapping("/lookDetail/{id}")
    public String lookDetail(@PathVariable Integer id, Model model) {
        TReassign tReassign = tReassignService.selectById(id);
        String str = tReassign.getReason();
        model.addAttribute("str",str);
        return "/system/tComplaint/lookDetail.html";
    }
    /**
@@ -203,7 +252,6 @@
        return super.packForBT(page);
    }
    /**
     * 获取跨城改派管理列表
     */
@@ -229,7 +277,6 @@
        return super.packForBT(page);
    }
    /**
     * 选择司机列表
     */
@@ -241,7 +288,7 @@
        TReassign reassign = tReassignService.selectById(orderId);
        TOrderPrivateCar privateCar = itOrderPrivateCarService.selectById(reassign.getOrderId());
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getCanSelectPrivateCarDriverList(page,privateCar.getCompanyId(),name,phone));
        page.setRecords(tReassignService.getCanSelectPrivateCarDriverList(page,privateCar.getServerCarModelId(),privateCar.getDriverId(),name,phone));
        return super.packForBT(page);
    }
@@ -262,7 +309,6 @@
        return super.packForBT(page);
    }
    /**
     * 选择司机列表
     */
@@ -274,10 +320,9 @@
        TReassign reassign = tReassignService.selectById(orderId);
        TOrderLogistics tOrderLogistics = orderLogisticsService.selectById(reassign.getOrderId());
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getCanSelectSmallDriverList(page,tOrderLogistics.getCompanyId(), tOrderLogistics.getType(),name,phone));
        page.setRecords(tReassignService.getCanSelectSmallDriverList(page,tOrderLogistics.getServerCarModelId(), tOrderLogistics.getDriverId(), tOrderLogistics.getType(),name,phone));
        return super.packForBT(page);
    }
    /**
     * 操作专车改派管理
@@ -326,6 +371,7 @@
            Map<String,String> map = new HashMap<>();
            map.put("id", tOrderPrivateCar.getId().toString());
            map.put("orderType", "1");
            map.put("from", "admin");
            String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
            System.out.println("专车取消:【orderId="+tOrderPrivateCar.getId().toString()+"】,调用接口:"+result);
        }
@@ -349,9 +395,6 @@
//        itPubTransactionDetailsService.insert(details);
        return SUCCESS_TIP;
    }
    @Autowired
    private ITPubTransactionDetailsService itPubTransactionDetailsService;
    /**
     * 操作跨城改派管理
@@ -417,6 +460,7 @@
                Map<String,String> map = new HashMap<>();
                map.put("id", orderCrossCity.getId().toString());
                map.put("orderType", "3");
                map.put("from", "admin");
                String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
                System.out.println("跨城出行取消:【orderId="+orderCrossCity.getId().toString()+"】,调用接口:"+result);
@@ -552,27 +596,28 @@
            Map<String,String> map = new HashMap<>();
            map.put("id", tOrderLogistics.getId().toString());
            map.put("orderType", tOrderLogistics.getType().toString());
            map.put("from", "admin");
            String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
            System.out.println("小件物流取消:【orderId="+tOrderLogistics.getId().toString()+"】,调用接口:"+result);
        }
        //返回驾驶员处罚金
        TDriver originalDriver = itDriverService.selectById(tReassign.getOriginalDriverId());
        originalDriver.setBalance(originalDriver.getBalance().add(new BigDecimal(tReassign.getMoney())));
        itDriverService.updateById(originalDriver);
        //增加交易明细
        TPubTransactionDetails details = new TPubTransactionDetails();
        details.setUserId(originalDriver.getId());
        details.setInsertTime(new Date());
        details.setRemark("【小件物流】:改派失败或订单取消");
        details.setMoney(new BigDecimal(tReassign.getMoney()));
        details.setState(1);
        details.setType(1);
        details.setUserType(2);
        details.setOrderType(tReassign.getOrderType());
        details.setOrderId(tReassign.getOrderId());
        itPubTransactionDetailsService.insert(details);
//        //返回驾驶员处罚金
//        TDriver originalDriver = itDriverService.selectById(tReassign.getOriginalDriverId());
//        originalDriver.setBalance(originalDriver.getBalance().add(new BigDecimal(tReassign.getMoney())));
//        itDriverService.updateById(originalDriver);
//
//        //增加交易明细
//        TPubTransactionDetails details = new TPubTransactionDetails();
//        details.setUserId(originalDriver.getId());
//        details.setInsertTime(new Date());
//        details.setRemark("【小件物流】:改派失败或订单取消");
//        details.setMoney(new BigDecimal(tReassign.getMoney()));
//        details.setState(1);
//        details.setType(1);
//        details.setUserType(2);
//        details.setOrderType(tReassign.getOrderType());
//        details.setOrderId(tReassign.getOrderId());
//        itPubTransactionDetailsService.insert(details);
        return SUCCESS_TIP;
    }
@@ -583,40 +628,303 @@
    @RequestMapping(value = "/selectDriver")
    @ResponseBody
    public Object selectDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) {
        //修改订单
        TReassign tReassign = tReassignService.selectById(orderId);
        TOrderPrivateCar tOrderPrivateCar = itOrderPrivateCarService.selectById(tReassign.getOrderId());
        //修改之前司机状态 -- 空闲
        TDriver oldDriver = itDriverService.selectById(tReassign.getOriginalDriverId());
        oldDriver.setState(2);
        itDriverService.updateById(oldDriver);
        //查找司机对象
        TDriver nowDriver = itDriverService.selectById(driverId);
        nowDriver.setState(3);
        itDriverService.updateById(nowDriver);
        //修改专车订单
        tOrderPrivateCar.setState(tOrderPrivateCar.getOldState());
        tOrderPrivateCar.setDriverId(driverId);
        tOrderPrivateCar.setCarId(nowDriver.getCarId());
        itOrderPrivateCarService.updateById(tOrderPrivateCar);
        //修改专车改派订单
        tReassign.setNowDriverId(driverId);
        tReassign.setNowCarId(nowDriver.getCarId());
        tReassign.setState(3);
        tReassign.setCompleteTime(new Date());
        tReassignService.updateById(tReassign);
        //增加推送
        Map<String,String> map = new HashMap<>();
        map.put("orderId", tOrderPrivateCar.getId().toString());
        map.put("orderType", "1");
        String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map);
        System.out.println("专车改派:【orderId="+tOrderPrivateCar.getId().toString()+"】,调用接口:"+result);
        return SUCCESS_TIP;
        try {
            //修改订单
            TReassign tReassign = tReassignService.selectById(orderId);
            TOrderPrivateCar orderPrivateCar = itOrderPrivateCarService.selectById(tReassign.getOrderId());
            String tripId = redisUtil.getValue("trip" + orderPrivateCar.getUserId());
            TDriver driver = itDriverService.selectById(orderPrivateCar.getDriverId());
            TDriver driver1 = itDriverService.selectById(driverId);
            String text = "";
            tReassign.setState(3);
            tReassign.setNowDriverId(driver1.getId());
            tReassign.setNowCarId(driver1.getCarId());
            tReassign.setCompleteTime(new Date());
            tReassignService.updateById(tReassign);
            Integer language1 = driver1.getLanguage();
            switch (language1){
                case 1:
                    text = "收到新的打车订单,从" + orderPrivateCar.getStartAddress() + "出发,全程约" + orderPrivateCar.getEstimatedMileage() + "公里";
                    break;
                case 2:
                    text = "Received a new ride order, starting from " + orderPrivateCar.getStartAddress() + ", the whole journey is about " + orderPrivateCar.getEstimatedMileage() + "kilometre";
                    break;
                case 3:
                    text = "Reçu une nouvelle commande de course, à partir de " + orderPrivateCar.getStartAddress() + ", le trajet complet est d’environ " + orderPrivateCar.getEstimatedMileage();
                    break;
            }
            String audioUrl = "";
            String fileName = "pushOrder" + orderPrivateCar.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3";
            try {
                audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            //定时任务删除语音文件
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    try {
                        // 使用Runtime执行命令
                        Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName);
                        // 读取命令的输出
                        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        String line;
                        while ((line = reader.readLine()) != null) {
                            System.out.println(line);
                        }
                        // 等待命令执行完成
                        process.waitFor();
                        // 关闭流
                        reader.close();
                    } catch (IOException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 30000);
            orderPrivateCar.setDriverId(driver1.getId());
            orderPrivateCar.setCarId(driver1.getCarId());
            orderPrivateCar.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : (
                    driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1));
            orderPrivateCar.setSnatchOrderTime(new Date());
            orderPrivateCar.setState(orderPrivateCar.getOldState());
            orderPrivateCar.setOldState(null);
            if(!StringUtils.hasLength(orderPrivateCar.getTripId())){
                orderPrivateCar.setTripId(UUIDUtil.getRandomCode());
            }
            if(orderPrivateCar.getOrderType() == 1){
                String value = redisUtil.getValue("DRIVER" + driver1.getId());
                if(ToolUtil.isNotEmpty(value)) {
                    String[] split = value.split(",");
                    DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]), tripId);
                    //超时时间
                    long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
                    orderPrivateCar.setEstimateArriveTime(new Date(timeOut));
                    orderPrivateCar.setEstimateArriveMileage(distancematrix.getDistance());
                }
            }
            itOrderPrivateCarService.updateAllColumnById(orderPrivateCar);
            driver1.setState(3);
            itDriverService.updateById(driver1);
            driver.setState(2);
            itDriverService.updateById(driver);
            //检查google车辆信息或者添加新的车辆信息
            TCar car = carService.selectById(orderPrivateCar.getCarId());
            if(ToolUtil.isEmpty(car.getVehicleId())){
                car.setVehicleId(UUIDUtil.getRandomCode());
                carService.updateById(car);
            }
            String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
            if(ToolUtil.isEmpty(vehicles)){
                TCarModel carModel = carModelMapper.selectById(car.getCarModelId());
                boolean createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                if(!createVehicles){
                    for (int i = 0; i < 5; i++) {
                        createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                        if(createVehicles){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            //修改google订单信息或者创建新的行程
            String trip = fleetEngineUtil.getTrip(orderPrivateCar.getTripId());
            if(ToolUtil.isEmpty(trip)){
                JSONObject createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderPrivateCar.getTripId(),
                        orderPrivateCar.getStartLat().toString(), orderPrivateCar.getStartLon().toString(),  orderPrivateCar.getEndLat().toString(), orderPrivateCar.getEndLon().toString());
                JSONObject error = createTrip.getJSONObject("error");
                if(null != error){
                    for (int i = 0; i < 5; i++) {
                        createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderPrivateCar.getTripId(),
                                orderPrivateCar.getStartLat().toString(), orderPrivateCar.getStartLon().toString(),  orderPrivateCar.getEndLat().toString(), orderPrivateCar.getEndLon().toString());
                        error = createTrip.getJSONObject("error");
                        String tripStatus = createTrip.getString("tripStatus");
                        if(null == error && "NEW".equals(tripStatus)){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }else{
                //开始修改行程数据
                boolean updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null, orderPrivateCar.getId(), 1);
                if(!updateTrip){
                    for (int i = 0; i < 5; i++) {
                        updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null, orderPrivateCar.getId(), 1);
                        if(updateTrip){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            //删除定时任务
            quartzUtil.deleteQuartzTask("1_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_1_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_2_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("3_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
            /**
             * 超时用户取消不收费的提醒
             *   预约单:行程时间 + 配置不收费的时间 > 当前时间 (只弹一次)
             *   即时单:预估到达预约点时间 + 配置不收费的时间 > 当前时间 (只弹一次)
             *
             * 超时用户取消订单后需要弹给司机提醒弹框,超时时间 = 当前时间 - 行程时间 - 配置不收费的时间
             *
             * 定时提醒弹框
             *   司机只要开始超时且还未到达预约点,则需要定时提醒
             *
             * 预约单需要提前xx分钟提醒司机需要接乘客,过后每隔xx分钟提醒一次。超时后停止提醒
             */
            //添加定时任务(普通任务)
            TSysOverTime reminderRules = sysOvertimeService.selectOne(new EntityWrapper<TSysOverTime>().eq("companyId", driver1.getCompanyId()));
            if(null != reminderRules){
                TSysCancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<TSysCancleOrder>().eq("companyId", driver1.getCompanyId()));
                Integer driverTimeout = JSON.parseObject(cancleOrder.getContent()).getInteger("driverTimeout");
                //即时单
                if(orderPrivateCar.getOrderType() == 1){
                    //超时时间
                    long timeOut = orderPrivateCar.getEstimateArriveTime().getTime() + (driverTimeout * 60 * 1000);
                    //乘客取消不收费提醒
                    JobDataMap jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 1);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", timeOut);
                    jobDataMap.put("driverTimeout", driverTimeout);
                    jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 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(OrderTimeOutJob.class, "1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(timeOut), timeOut, 0);
                    //超时循环提醒
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 3);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", orderPrivateCar.getEstimateArriveTime().getTime());
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", "");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "3_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , orderPrivateCar.getEstimateArriveTime(), reminderRules.getCar() * 60000, -1);
                }else{
                    //超时时间
                    long timeOut = orderPrivateCar.getTravelTime().getTime() + (driverTimeout * 60000);
                    //乘客取消不收费提醒
                    JobDataMap jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 1);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", timeOut);
                    jobDataMap.put("driverTimeout", driverTimeout);
                    jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 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(OrderTimeOutJob.class, "1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(timeOut), timeOut, 0);
                    TUser userInfo = userService.selectById(orderPrivateCar.getUserId());
                    //预约单出发首次提醒
                    long travelTime = orderPrivateCar.getTravelTime().getTime() - reminderRules.getReserveTime() * 60000;
                    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 2);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", timeOut);
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", language1 == 1 ? "您将于" + sdf.format(orderPrivateCar.getTravelTime()) + "去接" + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName())  + ",请准时!" :
                            language1 == 2 ? "You are going to pick up " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " at " + sdf.format(orderPrivateCar.getTravelTime()) + ", please be on time. " :
                                    "Vous allez chercher " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " à " + sdf.format(orderPrivateCar.getTravelTime()) + ", s’il vous plaît soyez à l’heure.");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "2_1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(travelTime), travelTime, 0);
                    //预约单出发循环提醒
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 2);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", orderPrivateCar.getTravelTime().getTime());
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", language1 == 1 ? "您将于" + sdf.format(orderPrivateCar.getTravelTime()) + "去接" + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName())  + ",请准时!" :
                            language1 == 2 ? "You are going to pick up " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " at " + sdf.format(orderPrivateCar.getTravelTime()) + ", please be on time. " :
                                    "Vous allez chercher " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " à " + sdf.format(orderPrivateCar.getTravelTime()) + ", s’il vous plaît soyez à l’heure.");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "2_2_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(travelTime + reminderRules.getReserveNext() * 60000), reminderRules.getReserveNext() * 60000, -1);
                    //超时循环提醒
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 3);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", orderPrivateCar.getTravelTime().getTime());
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", "");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "3_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , orderPrivateCar.getTravelTime(), reminderRules.getCar() * 60000, -1);
                }
            }
            //推送相关代码------------------start----------------
            String finalAudioUrl = audioUrl;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderReassign(orderPrivateCar.getUserId(), 1, orderPrivateCar.getId(), 1, "");
                    pushUtil.pushOrderReassign(orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, finalAudioUrl);
                }
            }).start();
            Integer language2 = userService.selectById(orderPrivateCar.getUserId()).getLanguage();
            systemNoticeService.addSystemNotice(2, language1 == 1 ? "您已成功抢得打车订单,请及时联系客户!" :
                    language1 == 2 ? "You have grabbed the ride order, please contact the client timely."
                            : "Vous avez saisi la commande de course, veuillez contacter le client en temps opportun.", orderPrivateCar.getDriverId());
            systemNoticeService.addSystemNotice(1, language2 == 1 ? "您的订单已指派给" + driver1.getFirstName() + "师傅,请保持电话畅通!" :
                    language2 == 2 ? "Your order has been assigned to the driver- " + driver1.getFirstName() + ", please keep your line on."
                            : "Votre commande a été attribuée au chauffeur- " + driver1.getFirstName() + ", S'il vous plaît, restez en ligne.", orderPrivateCar.getUserId());
            return SUCCESS_TIP;
        }catch (Exception e){
            e.printStackTrace();
        }
        return ERROR;
    }
    /**
@@ -728,6 +1036,7 @@
        Map<String,String> map = new HashMap<>();
        map.put("orderId", tOrderCrossCity.getId().toString());
        map.put("orderType", "3");
        map.put("from", "admin");
        String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map);
        System.out.println("跨城出行改派:【orderId="+tOrderCrossCity.getId().toString()+"】,调用接口:"+result);
        return SUCCESS_TIP;
@@ -741,28 +1050,236 @@
    @ResponseBody
    public Object selectSmallDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) {
        //修改订单
        TReassign tReassign = tReassignService.selectById(orderId);
        TOrderLogistics tOrderLogistics = orderLogisticsService.selectById(tReassign.getOrderId());
        TDriver nowDriver = itDriverService.selectById(driverId);
        //修改专车订单
        tOrderLogistics.setState(tOrderLogistics.getOldState());
        tOrderLogistics.setDriverId(driverId);
        tOrderLogistics.setCarId(nowDriver.getCarId());
        orderLogisticsService.updateById(tOrderLogistics);
        tReassign.setNowDriverId(driverId);
        tReassign.setNowCarId(nowDriver.getCarId());
        tReassign.setState(3);
        tReassign.setCompleteTime(new Date());
        tReassignService.updateById(tReassign);
        //增加推送
        Map<String,String> map = new HashMap<>();
        map.put("orderId", tOrderLogistics.getId().toString());
        map.put("orderType", tOrderLogistics.getType().toString());
        String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map);
        System.out.println("小件物流改派:【orderId="+tOrderLogistics.getId().toString()+"】,调用接口:"+result);
        return SUCCESS_TIP;
        try {
            TReassign tReassign = tReassignService.selectById(orderId);
            TOrderLogistics orderLogistics = orderLogisticsService.selectById(tReassign.getOrderId());
            String tripId = redisUtil.getValue("trip" + orderLogistics.getUserId());
            TDriver driver = itDriverService.selectById(orderLogistics.getDriverId());
            TDriver driver1 = itDriverService.selectById(driverId);
            tReassign.setState(3);
            tReassign.setNowDriverId(driver1.getId());
            tReassign.setNowCarId(driver1.getCarId());
            tReassign.setCompleteTime(new Date());
            tReassignService.updateById(tReassign);
            String text = "";
            Integer language1 = driver1.getLanguage();
            switch (language1){
                case 1:
                    text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
                    break;
                case 2:
                    text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
                    break;
                case 3:
                    text = "Reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage();
                    break;
            }
            String audioUrl = "";
            String fileName = null;
            try {
                fileName = "pushOrder" + driver1.getId() + UUIDUtil.getRandomCode(5) + ".mp3";
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            try {
                audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            //定时任务删除语音文件
            String finalFileName = fileName;
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    try {
                        // 使用Runtime执行命令
                        Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + finalFileName);
                        // 读取命令的输出
                        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        String line;
                        while ((line = reader.readLine()) != null) {
                            System.out.println(line);
                        }
                        // 等待命令执行完成
                        process.waitFor();
                        // 关闭流
                        reader.close();
                    } catch (IOException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 30000);
            orderLogistics.setDriverId(driver1.getId());
            orderLogistics.setCarId(driver1.getCarId());
            orderLogistics.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : (
                    driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1));
            orderLogistics.setState(orderLogistics.getOldState());
            orderLogistics.setOldState(null);
            orderLogistics.setSnatchOrderTime(new Date());
            if(!StringUtils.hasLength(orderLogistics.getTripId())){
                orderLogistics.setTripId(UUIDUtil.getRandomCode());
            }
            String value = redisUtil.getValue("DRIVER" + driver1.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]), tripId);
                //超时时间
                long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
                orderLogistics.setEstimateArriveTime(new Date(timeOut));
                orderLogistics.setEstimateArriveMileage(distancematrix.getDistance());
            }
            orderLogisticsService.updateAllColumnById(orderLogistics);
            //修改司机为服务中
            driver1.setState(3);
            itDriverService.updateById(driver1);
            driver.setState(2);
            itDriverService.updateById(driver);
            //检查google车辆信息或者添加新的车辆信息
            TCar car = carService.selectById(orderLogistics.getCarId());
            if(ToolUtil.isEmpty(car.getVehicleId())){
                car.setVehicleId(UUIDUtil.getRandomCode());
                carService.updateById(car);
            }
            String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
            if(ToolUtil.isEmpty(vehicles)){
                TCarModel carModel = carModelMapper.selectById(car.getCarModelId());
                boolean createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                if(!createVehicles){
                    for (int i = 0; i < 5; i++) {
                        createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                        if(createVehicles){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            //修改google订单信息或者创建新的行程
            String trip = fleetEngineUtil.getTrip(orderLogistics.getTripId());
            if(ToolUtil.isEmpty(trip)){
                JSONObject createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderLogistics.getTripId(),
                        orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
                JSONObject error = createTrip.getJSONObject("error");
                if(null != error){
                    for (int i = 0; i < 5; i++) {
                        createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderLogistics.getTripId(),
                                orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
                        error = createTrip.getJSONObject("error");
                        String tripStatus = createTrip.getString("tripStatus");
                        if(null == error && "NEW".equals(tripStatus)){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }else{
                //开始修改行程数据
                boolean updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null, orderLogistics.getId(), 4);
                if(!updateTrip){
                    for (int i = 0; i < 5; i++) {
                        updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null, orderLogistics.getId(), 4);
                        if(updateTrip){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
            //删除定时任务
            quartzUtil.deleteQuartzTask("1_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_1_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_2_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("3_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
            /**
             * 超时用户取消不收费的提醒
             *   即时单:预估到达预约点时间 + 配置不收费的时间 > 当前时间 (只弹一次)
             *
             * 超时用户取消订单后需要弹给司机提醒弹框,超时时间 = 当前时间 - 行程时间 - 配置不收费的时间
             *
             * 定时提醒弹框
             *   司机只要开始超时且还未到达预约点,则需要定时提醒
             */
            //添加定时任务(普通任务)
            TSysOverTime reminderRules = sysOvertimeService.selectOne(new EntityWrapper<TSysOverTime>().eq("companyId", driver1.getCompanyId()));
            if(null != reminderRules){
                TSysCancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<TSysCancleOrder>().eq("companyId", driver1.getCompanyId()));
                Integer driverTimeout = JSON.parseObject(cancleOrder.getContent()).getInteger("driverTimeout");
                //超时时间
                long timeOut = orderLogistics.getEstimateArriveTime().getTime() + (driverTimeout * 60 * 1000);
                //乘客取消不收费提醒
                JobDataMap jobDataMap = new JobDataMap();
                jobDataMap.put("driverId", driver1.getId());
                jobDataMap.put("timeOutType", 1);
                jobDataMap.put("orderId", orderLogistics.getId());
                jobDataMap.put("orderType", 4);
                jobDataMap.put("language", language1);
                jobDataMap.put("timeOut", timeOut);
                jobDataMap.put("driverTimeout", driverTimeout);
                jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 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(OrderTimeOutJob.class, "1_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap
                        , new Date(timeOut), timeOut, 0);
                //超时循环提醒
                jobDataMap = new JobDataMap();
                jobDataMap.put("driverId", driver1.getId());
                jobDataMap.put("timeOutType", 3);
                jobDataMap.put("orderId", orderLogistics.getId());
                jobDataMap.put("orderType", 4);
                jobDataMap.put("language", language1);
                jobDataMap.put("timeOut", orderLogistics.getEstimateArriveTime().getTime());
                jobDataMap.put("driverTimeout", driverTimeout);
                jobDataMap.put("describe", "");
                quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "3_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap
                        , orderLogistics.getEstimateArriveTime(), reminderRules.getCar() * 60000, -1);
            }
            //推送相关代码------------------start----------------
            String finalAudioUrl = audioUrl;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderReassign(orderLogistics.getUserId(), 1, orderLogistics.getId(), 4, "");
                    pushUtil.pushOrderReassign(orderLogistics.getDriverId(), 2, orderLogistics.getId(), 4, finalAudioUrl);
                }
            }).start();
            Integer language2 = userService.selectById(orderLogistics.getUserId()).getLanguage();
            systemNoticeService.addSystemNotice(2, language1 == 1 ? "您已成功抢得包裹订单,请及时联系客户!" :
                    language1 == 2 ? "You have grabbed the delivery order, please contact the client timely."
                            : "Vous avez saisi la commande du livraison. Veuillez contacter le client en temps opportun.", orderLogistics.getDriverId());
            systemNoticeService.addSystemNotice(1, language2 == 1 ? "您的订单已指派给" + driver1.getFirstName() + "师傅,请保持电话畅通!" :
                    language2 == 2 ? "Your order has been assigned to the driver- " + driver1.getFirstName() + ", please keep your line on."
                            : "Votre commande a été attribuée au chauffeur- " + driver1.getFirstName() + ", S'il vous plaît, restez en ligne.", orderLogistics.getUserId());
            return SUCCESS_TIP;
        }catch (Exception e){
            e.printStackTrace();
        }
        return ERROR;
    }
}