调整车辆代码结构
parent
212b71fe96
commit
6ba8a8b35d
|
@ -99,11 +99,11 @@ public class VechileServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
|||
updateWrapper.set(Vehicle::getRemainingBattery, vehicle.getRemainingBattery());
|
||||
updateWrapper.set(Vehicle::getTotalMileage, vehicle.getTotalMileage());
|
||||
updateWrapper.eq(Vehicle::getVin, vehicle.getVin());
|
||||
boolean update = this.update(updateWrapper);
|
||||
if (update){
|
||||
try {
|
||||
this.update(updateWrapper);
|
||||
syncSuccessSum.incrementAndGet();
|
||||
log.debug("车辆:[{}] - 数据同步成功 - 电池容量:[{}毫安] 总公里数量:[{}KM]", vehicle.getVin(), vehicle.getRemainingBattery(), vehicle.getTotalMileage());
|
||||
}{
|
||||
}catch (Exception exception){
|
||||
log.error("车辆:[{}] - 数据同步失败 - 电池容量:[{}毫安] 总公里数量:[{}KM]", vehicle.getVin(), vehicle.getRemainingBattery(), vehicle.getTotalMileage());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -64,7 +64,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
vehicleInstance.setVehicle(vehicle);
|
||||
vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicle));
|
||||
LocalContainer.setVehicleInstance(vehicleInstance);
|
||||
log.info("构建车辆对象: [{}]", vehicle.getVin());
|
||||
log.debug("构建车辆对象: [{}]", vehicle.getVin());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,14 +214,22 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
throw new RuntimeException("一键执行的任务正在进行中,请勿再次发布一键执行任务");
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
unifiedStatus.set(Boolean.FALSE);
|
||||
try {
|
||||
// 筛选出离线车辆并使用并行流进行上线操作
|
||||
LocalContainer.getOfflineVehicleInstance()
|
||||
.stream()
|
||||
.parallel()
|
||||
.map(VehicleInstance::getVin)
|
||||
.forEach(this::vehicleClientInit);
|
||||
}catch (Exception exception){
|
||||
log.error("车辆一件上线报错:{}", exception.getMessage(), exception);
|
||||
}
|
||||
unifiedStatus.set(Boolean.TRUE);
|
||||
}catch (Exception exception){
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
@ -235,6 +243,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
}
|
||||
new Thread(() -> {
|
||||
unifiedStatus.set(Boolean.FALSE);
|
||||
try {
|
||||
// 筛选出在线车辆使用并行流操作先停止车辆上报动作再进行车辆离线操作
|
||||
LocalContainer.getOnlineVehicleInstance()
|
||||
.stream()
|
||||
|
@ -243,6 +252,9 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
vehicleInstance.stopSend();
|
||||
vehicleInstance.closeClient();
|
||||
});
|
||||
}catch (Exception exception){
|
||||
log.error("车辆一键离线报错:{}", exception.getMessage(), exception);
|
||||
}
|
||||
unifiedStatus.set(Boolean.TRUE);
|
||||
}).start();
|
||||
}
|
||||
|
@ -260,6 +272,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
throw new RuntimeException("还没有车辆上线,请先让车辆上线");
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
unifiedStatus.set(Boolean.FALSE);
|
||||
// 先一键重置路径
|
||||
this.unifiedPositionPri ();
|
||||
|
@ -275,6 +288,10 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
}
|
||||
vehicleInstance.startSend();
|
||||
});
|
||||
}catch (Exception exception){
|
||||
log.error("车辆一键上报报错:{}", exception.getMessage(), exception);
|
||||
}
|
||||
|
||||
unifiedStatus.set(Boolean.TRUE);
|
||||
}).start();
|
||||
|
||||
|
@ -290,7 +307,11 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
}
|
||||
new Thread(() -> {
|
||||
unifiedStatus.set(Boolean.FALSE);
|
||||
try {
|
||||
this.unifiedPositionPri();
|
||||
}catch (Exception exception){
|
||||
log.error("车辆一键重置路径报错:{}", exception.getMessage(), exception);
|
||||
}
|
||||
unifiedStatus.set(Boolean.TRUE);
|
||||
}).start();
|
||||
}
|
||||
|
@ -330,12 +351,16 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
throw new RuntimeException("一键执行的任务正在进行中,请勿再次发布一键执行任务");
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
unifiedStatus.set(Boolean.FALSE);
|
||||
LocalContainer.getOnlineVehicleInstance()
|
||||
.stream()
|
||||
.parallel()
|
||||
.forEach(VehicleInstance::stopSend);
|
||||
unifiedStatus.set(Boolean.TRUE);
|
||||
}catch (Exception exception){
|
||||
log.error("车辆一键取消上报报错:{}", exception.getMessage(), exception);
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ public class VehicleInstance {
|
|||
options.setKeepAliveInterval(60);
|
||||
// 连接
|
||||
client.connect(options);
|
||||
log.info("车辆:[{}] 客户端初始化成功连接配置:{}", getVin(),
|
||||
log.debug("车辆:[{}] 客户端初始化成功连接配置:{}", getVin(),
|
||||
JSONObject.toJSONString(this.mqttProperties));
|
||||
} catch (MqttException e) {
|
||||
log.error("车辆:[{}] 客户端初始化异常", getVin(), e);
|
||||
|
@ -168,7 +168,7 @@ public class VehicleInstance {
|
|||
this.client.disconnect();
|
||||
// 关闭连接
|
||||
this.client.close();
|
||||
log.info("车辆:[{}] 客户端下线成功", getVin());
|
||||
log.debug("车辆:[{}] 客户端下线成功", getVin());
|
||||
} catch (MqttException e) {
|
||||
log.error("车辆:[{}] 客户端关闭异常:[{}]",getVin(), e.getMessage(), e);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class VehicleConfiguration implements ApplicationRunner {
|
|||
Page<Vehicle> vehiclePage = vehicleService.page(new Page<>(page++, pageSize));
|
||||
List<Vehicle> vehicleList = vehiclePage.getRecords();
|
||||
vehicleList.forEach(vehicleInstanceService::init);
|
||||
log.info("第[{}]页,[{}]条", page, vehicleList.size());
|
||||
log.debug("第[{}]页,[{}]条", page, vehicleList.size());
|
||||
if (vehicleList.size() < pageSize){
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,9 @@ mybatis-plus:
|
|||
logging:
|
||||
level:
|
||||
com.muyu: DEBUG
|
||||
com.muyu.service: INFO
|
||||
com.muyu.mapper: INFO
|
||||
com.muyu.vehicle: INFO
|
||||
root: INFO
|
||||
org:
|
||||
springframework:
|
||||
|
@ -78,6 +81,7 @@ forest:
|
|||
variables:
|
||||
adminHost: ${mqtt.admin.host}
|
||||
adminTopicUri: ${mqtt.admin.topic-uri}
|
||||
log-enabled: false
|
||||
|
||||
# 服务器配置
|
||||
mqtt:
|
||||
|
|
Loading…
Reference in New Issue