From f1c81c66b4ce666e61a3604e299ea41b874fa8b7 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期六, 08 二月 2025 17:57:52 +0800 Subject: [PATCH] 修改订单异常问题 --- DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java | 232 +++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 167 insertions(+), 65 deletions(-) diff --git a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java index feb3c96..0f911a0 100644 --- a/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java +++ b/DriverIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java @@ -1,6 +1,7 @@ package com.stylefeng.guns.modular.system.service.impl; import com.alibaba.fastjson.JSON; +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; @@ -33,7 +34,9 @@ import org.springframework.transaction.annotation.Transactional; 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.*; @@ -228,7 +231,7 @@ text = "Received a new ride order, starting from " + orderPrivateCar.getStartAddress() + ", the whole journey is about " + orderPrivateCar.getEstimatedMileage() + "kilometre"; break; case 3: - text = "J'ai reçu une nouvelle commande de course, à partir de " + orderPrivateCar.getStartAddress() + ", le trajet complet est d’environ " + orderPrivateCar.getEstimatedMileage() + "kilométrage"; + text = "Reçu une nouvelle commande de course, à partir de " + orderPrivateCar.getStartAddress() + ", le trajet complet est d’environ " + orderPrivateCar.getEstimatedMileage(); break; } @@ -243,14 +246,21 @@ new Timer().schedule(new TimerTask() { @Override public void run() { - Process process = null; try { - process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (process != null) { - process.destroy(); + // 使用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); @@ -283,6 +293,73 @@ driver.setState(2); driverService.updateById(driver); + + //检查google车辆信息或者添加新的车辆信息 + Car 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)){ + 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(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); + if(!updateTrip){ + for (int i = 0; i < 5; i++) { + updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null); + if(updateTrip){ + break; + } + try { + Thread.sleep(3000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + } + + //删除定时任务 QuartzUtil.deleteQuartzTask("1_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT"); @@ -410,30 +487,6 @@ } } - new Thread(()->{ - try { - Car car = carService.selectById(orderPrivateCar.getCarId()); - if(!StringUtils.hasLength(car.getVehicleId())){ - car.setVehicleId(UUIDUtil.getRandomCode()); - carService.updateById(car); - } - String trip = fleetEngineUtil.getTrip(orderPrivateCar.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, orderPrivateCar.getTripId(), - orderPrivateCar.getStartLat().toString(), orderPrivateCar.getStartLon().toString(), orderPrivateCar.getEndLat().toString(), orderPrivateCar.getEndLon().toString()); - } - //开始修改行程数据 - fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null); - }catch (Exception e){ - e.printStackTrace(); - } - }).start(); - //推送相关代码------------------start---------------- String finalAudioUrl = audioUrl; new Thread(new Runnable() { @@ -479,7 +532,7 @@ text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre"; break; case 3: - text = "J'ai reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage() + "kilométrage"; + text = "Reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage(); break; } @@ -494,14 +547,21 @@ new Timer().schedule(new TimerTask() { @Override public void run() { - Process process = null; try { - process = Runtime.getRuntime().exec("rm -rf /usr/local/nginx/html/files/audio/" + fileName); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (process != null) { - process.destroy(); + // 使用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); @@ -533,6 +593,72 @@ driver.setState(2); driverService.updateById(driver); + + //检查google车辆信息或者添加新的车辆信息 + Car 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)){ + 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(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); + 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(3000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + } + //删除定时任务 QuartzUtil.deleteQuartzTask("1_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT"); @@ -585,31 +711,7 @@ 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---------------- String finalAudioUrl = audioUrl; -- Gitblit v1.7.1