调整车辆代码结构

master
DongZeLiang 2023-12-04 11:26:57 +08:00
parent 212b71fe96
commit 6ba8a8b35d
5 changed files with 74 additions and 45 deletions

View File

@ -99,11 +99,11 @@ public class VechileServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
updateWrapper.set(Vehicle::getRemainingBattery, vehicle.getRemainingBattery()); updateWrapper.set(Vehicle::getRemainingBattery, vehicle.getRemainingBattery());
updateWrapper.set(Vehicle::getTotalMileage, vehicle.getTotalMileage()); updateWrapper.set(Vehicle::getTotalMileage, vehicle.getTotalMileage());
updateWrapper.eq(Vehicle::getVin, vehicle.getVin()); updateWrapper.eq(Vehicle::getVin, vehicle.getVin());
boolean update = this.update(updateWrapper); try {
if (update){ this.update(updateWrapper);
syncSuccessSum.incrementAndGet(); syncSuccessSum.incrementAndGet();
log.debug("车辆:[{}] - 数据同步成功 - 电池容量:[{}毫安] 总公里数量:[{}KM]", vehicle.getVin(), vehicle.getRemainingBattery(), vehicle.getTotalMileage()); log.debug("车辆:[{}] - 数据同步成功 - 电池容量:[{}毫安] 总公里数量:[{}KM]", vehicle.getVin(), vehicle.getRemainingBattery(), vehicle.getTotalMileage());
}{ }catch (Exception exception){
log.error("车辆:[{}] - 数据同步失败 - 电池容量:[{}毫安] 总公里数量:[{}KM]", vehicle.getVin(), vehicle.getRemainingBattery(), vehicle.getTotalMileage()); log.error("车辆:[{}] - 数据同步失败 - 电池容量:[{}毫安] 总公里数量:[{}KM]", vehicle.getVin(), vehicle.getRemainingBattery(), vehicle.getTotalMileage());
} }
}); });

View File

@ -64,7 +64,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
vehicleInstance.setVehicle(vehicle); vehicleInstance.setVehicle(vehicle);
vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicle)); vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicle));
LocalContainer.setVehicleInstance(vehicleInstance); LocalContainer.setVehicleInstance(vehicleInstance);
log.info("构建车辆对象: [{}]", vehicle.getVin()); log.debug("构建车辆对象: [{}]", vehicle.getVin());
} }
/** /**
@ -214,14 +214,22 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
throw new RuntimeException("一键执行的任务正在进行中,请勿再次发布一键执行任务"); throw new RuntimeException("一键执行的任务正在进行中,请勿再次发布一键执行任务");
} }
new Thread(() -> { new Thread(() -> {
try {
unifiedStatus.set(Boolean.FALSE); unifiedStatus.set(Boolean.FALSE);
try {
// 筛选出离线车辆并使用并行流进行上线操作 // 筛选出离线车辆并使用并行流进行上线操作
LocalContainer.getOfflineVehicleInstance() LocalContainer.getOfflineVehicleInstance()
.stream() .stream()
.parallel() .parallel()
.map(VehicleInstance::getVin) .map(VehicleInstance::getVin)
.forEach(this::vehicleClientInit); .forEach(this::vehicleClientInit);
}catch (Exception exception){
log.error("车辆一件上线报错:{}", exception.getMessage(), exception);
}
unifiedStatus.set(Boolean.TRUE); unifiedStatus.set(Boolean.TRUE);
}catch (Exception exception){
}
}).start(); }).start();
} }
@ -235,6 +243,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
} }
new Thread(() -> { new Thread(() -> {
unifiedStatus.set(Boolean.FALSE); unifiedStatus.set(Boolean.FALSE);
try {
// 筛选出在线车辆使用并行流操作先停止车辆上报动作再进行车辆离线操作 // 筛选出在线车辆使用并行流操作先停止车辆上报动作再进行车辆离线操作
LocalContainer.getOnlineVehicleInstance() LocalContainer.getOnlineVehicleInstance()
.stream() .stream()
@ -243,6 +252,9 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
vehicleInstance.stopSend(); vehicleInstance.stopSend();
vehicleInstance.closeClient(); vehicleInstance.closeClient();
}); });
}catch (Exception exception){
log.error("车辆一键离线报错:{}", exception.getMessage(), exception);
}
unifiedStatus.set(Boolean.TRUE); unifiedStatus.set(Boolean.TRUE);
}).start(); }).start();
} }
@ -260,6 +272,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
throw new RuntimeException("还没有车辆上线,请先让车辆上线"); throw new RuntimeException("还没有车辆上线,请先让车辆上线");
} }
new Thread(() -> { new Thread(() -> {
try {
unifiedStatus.set(Boolean.FALSE); unifiedStatus.set(Boolean.FALSE);
// 先一键重置路径 // 先一键重置路径
this.unifiedPositionPri (); this.unifiedPositionPri ();
@ -275,6 +288,10 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
} }
vehicleInstance.startSend(); vehicleInstance.startSend();
}); });
}catch (Exception exception){
log.error("车辆一键上报报错:{}", exception.getMessage(), exception);
}
unifiedStatus.set(Boolean.TRUE); unifiedStatus.set(Boolean.TRUE);
}).start(); }).start();
@ -290,7 +307,11 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
} }
new Thread(() -> { new Thread(() -> {
unifiedStatus.set(Boolean.FALSE); unifiedStatus.set(Boolean.FALSE);
try {
this.unifiedPositionPri(); this.unifiedPositionPri();
}catch (Exception exception){
log.error("车辆一键重置路径报错:{}", exception.getMessage(), exception);
}
unifiedStatus.set(Boolean.TRUE); unifiedStatus.set(Boolean.TRUE);
}).start(); }).start();
} }
@ -330,12 +351,16 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
throw new RuntimeException("一键执行的任务正在进行中,请勿再次发布一键执行任务"); throw new RuntimeException("一键执行的任务正在进行中,请勿再次发布一键执行任务");
} }
new Thread(() -> { new Thread(() -> {
try {
unifiedStatus.set(Boolean.FALSE); unifiedStatus.set(Boolean.FALSE);
LocalContainer.getOnlineVehicleInstance() LocalContainer.getOnlineVehicleInstance()
.stream() .stream()
.parallel() .parallel()
.forEach(VehicleInstance::stopSend); .forEach(VehicleInstance::stopSend);
unifiedStatus.set(Boolean.TRUE); unifiedStatus.set(Boolean.TRUE);
}catch (Exception exception){
log.error("车辆一键取消上报报错:{}", exception.getMessage(), exception);
}
}).start(); }).start();
} }

View File

@ -140,7 +140,7 @@ public class VehicleInstance {
options.setKeepAliveInterval(60); options.setKeepAliveInterval(60);
// 连接 // 连接
client.connect(options); client.connect(options);
log.info("车辆:[{}] 客户端初始化成功连接配置:{}", getVin(), log.debug("车辆:[{}] 客户端初始化成功连接配置:{}", getVin(),
JSONObject.toJSONString(this.mqttProperties)); JSONObject.toJSONString(this.mqttProperties));
} catch (MqttException e) { } catch (MqttException e) {
log.error("车辆:[{}] 客户端初始化异常", getVin(), e); log.error("车辆:[{}] 客户端初始化异常", getVin(), e);
@ -168,7 +168,7 @@ public class VehicleInstance {
this.client.disconnect(); this.client.disconnect();
// 关闭连接 // 关闭连接
this.client.close(); this.client.close();
log.info("车辆:[{}] 客户端下线成功", getVin()); log.debug("车辆:[{}] 客户端下线成功", getVin());
} catch (MqttException e) { } catch (MqttException e) {
log.error("车辆:[{}] 客户端关闭异常:[{}]",getVin(), e.getMessage(), e); log.error("车辆:[{}] 客户端关闭异常:[{}]",getVin(), e.getMessage(), e);
} }

View File

@ -46,7 +46,7 @@ public class VehicleConfiguration implements ApplicationRunner {
Page<Vehicle> vehiclePage = vehicleService.page(new Page<>(page++, pageSize)); Page<Vehicle> vehiclePage = vehicleService.page(new Page<>(page++, pageSize));
List<Vehicle> vehicleList = vehiclePage.getRecords(); List<Vehicle> vehicleList = vehiclePage.getRecords();
vehicleList.forEach(vehicleInstanceService::init); vehicleList.forEach(vehicleInstanceService::init);
log.info("第[{}]页,[{}]条", page, vehicleList.size()); log.debug("第[{}]页,[{}]条", page, vehicleList.size());
if (vehicleList.size() < pageSize){ if (vehicleList.size() < pageSize){
break; break;
} }

View File

@ -59,6 +59,9 @@ mybatis-plus:
logging: logging:
level: level:
com.muyu: DEBUG com.muyu: DEBUG
com.muyu.service: INFO
com.muyu.mapper: INFO
com.muyu.vehicle: INFO
root: INFO root: INFO
org: org:
springframework: springframework:
@ -78,6 +81,7 @@ forest:
variables: variables:
adminHost: ${mqtt.admin.host} adminHost: ${mqtt.admin.host}
adminTopicUri: ${mqtt.admin.topic-uri} adminTopicUri: ${mqtt.admin.topic-uri}
log-enabled: false
# 服务器配置 # 服务器配置
mqtt: mqtt: