Pu Zhibing
2024-10-21 f08b7e95bc941a72d4a7b7bc64c2086ed53f1565
DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/smallLogistics/server/impl/OrderLogisticsServiceImpl.java
@@ -18,6 +18,7 @@
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.GoogleMap.ReverseGeocodeVo;
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;
@@ -192,9 +193,10 @@
            orderLogistics.setTripId(UUIDUtil.getRandomCode());
        }
        String value = redisUtil.getValue("DRIVER" + driver.getId());
        String tripId = redisUtil.getValue("trip" + orderLogistics.getUserId());
        if(ToolUtil.isNotEmpty(value)) {
            String[] split = value.split(",");
            DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]));
            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));
@@ -252,27 +254,63 @@
        }
    
        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());
            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());
                    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(5000L);
                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    }
                    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();
                boolean createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderLogistics.getTripId(),
                        orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
                if(!createTrip){
                    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());
                        if(createTrip){
                            break;
                        }
                        try {
                            Thread.sleep(5000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }else{
                //开始修改行程数据
                boolean updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null);
                if(!updateTrip){
                    for (int i = 0; i < 5; i++) {
                        updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null);
                        if(updateTrip){
                            break;
                        }
                        try {
                            Thread.sleep(5000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }).start();
        
@@ -346,13 +384,18 @@
     * @param state
     * @param lon
     * @param lat
     * @param address
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String address, String pickUpCode, Integer language, Integer uid) throws Exception {
    public ResultUtil process(Integer orderId, Integer state, Double lon, Double lat, String pickUpCode, Integer language, Integer uid) throws Exception {
        OrderLogistics orderLogistics = this.selectById(orderId);
        String tripId = redisUtil.getValue("trip" + orderLogistics.getUserId());
        ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(lat, lon, tripId);
        if(null == reverseGeocode){
            return ResultUtil.error(language == 1 ? "无效的经纬度" : language == 2 ? "Invalid longitude and latitude" : "Longitude et latitude non valides");
        }
        String address = reverseGeocode.getAddress();
        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");
        }
@@ -410,10 +453,19 @@
        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);
            boolean updateTrip = fleetEngineUtil.updateTrip(finalTripStatus, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null);
            if(!updateTrip){
                for (int i = 0; i < 5; i++) {
                    updateTrip = fleetEngineUtil.updateTrip(finalTripStatus, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null);
                    if(updateTrip){
                        break;
                    }
                    try {
                        Thread.sleep(5000L);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }).start();
        
@@ -656,11 +708,11 @@
            }
            EmailUtil.send(userInfo.getEmail(), language == 1 ? "取件码邮件" : language == 2 ? "Pickup code" : "Code de ramassage",  document.html());
            //开始生成pdf收据和html收据
            File file = new File("/usr/local/nginx/html/files/html/");
            File file = new File("/home/igotechgh/nginx/html/files/html/");
            if(!file.exists()){
                file.mkdirs();
            }
            file = new File("/usr/local/nginx/html/files/html/code_" + orderId + ".html");
            file = new File("/home/igotechgh/nginx/html/files/html/code_" + orderId + ".html");
            if(!file.exists()){
                file.createNewFile();
            }
@@ -669,7 +721,7 @@
            fileWriter.flush();
            fileWriter.close();
            String link ="http://182.160.16.251:81/files/html/code_" + orderId + ".html";
            String link ="https://igo.i-go.group/files/html/code_" + orderId + ".html";
            TEmail tEmail = new TEmail();
            tEmail.setLink(link);
            tEmail.setUserId(userInfo.getId());
@@ -724,12 +776,21 @@
            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);
            boolean updateTrip = fleetEngineUtil.updateTrip(null, null, null, orderLogistics.getTripId(),
                    null, null, orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
            if(!updateTrip){
                for (int i = 0; i < 5; i++) {
                    updateTrip = fleetEngineUtil.updateTrip(null, null, null, orderLogistics.getTripId(),
                            null, null, orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
                    if(updateTrip){
                        break;
                    }
                    try {
                        Thread.sleep(5000L);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
        orderLogistics.setDestinationLon("");
@@ -1091,12 +1152,20 @@
        //上报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();
            log.warn("行程结束:{}   {}", System.currentTimeMillis(), finalOrderLogistics.getTripId());
            boolean reportBillableEvent = fleetEngineUtil.reportBillableEvent(finalOrderLogistics.getTripId());
            if(!reportBillableEvent){
                for (int i = 0; i < 5; i++) {
                    reportBillableEvent = fleetEngineUtil.reportBillableEvent(finalOrderLogistics.getTripId());
                    if(reportBillableEvent){
                        break;
                    }
                    try {
                        Thread.sleep(5000L);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }).start();
        return ResultUtil.success();