增加车辆实例操作业务层
parent
53216b6918
commit
3915ad1b5d
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.service;
|
||||
|
||||
import com.muyu.domain.Vehicle;
|
||||
|
||||
/**
|
||||
* @author DongZeLiang
|
||||
* @version 1.0
|
||||
* @description 车辆实例业务层
|
||||
* @date 2023/11/22
|
||||
*/
|
||||
public interface VehicleInstanceService {
|
||||
|
||||
/**
|
||||
* 根据车辆生成车辆实例
|
||||
* @param vehicle 车辆信息
|
||||
*/
|
||||
public void init(Vehicle vehicle);
|
||||
|
||||
/**
|
||||
* 初始化链接客户端
|
||||
* @param vin 车辆VIN
|
||||
*/
|
||||
public void initClient(String vin);
|
||||
}
|
|
@ -33,4 +33,6 @@ public class VechileServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
|||
List<Vehicle> vehicleList = Stream.generate(Vehicle::gen).limit(sum).toList();
|
||||
this.saveBatch(vehicleList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package com.muyu.service.impl;
|
||||
|
||||
import com.muyu.domain.Vehicle;
|
||||
import com.muyu.service.VehicleInstanceService;
|
||||
import com.muyu.vehicle.VehicleInstance;
|
||||
import com.muyu.vehicle.core.LocalContainer;
|
||||
import com.muyu.vehicle.model.VehicleData;
|
||||
import com.muyu.vehicle.model.properties.MqttProperties;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author DongZeLiang
|
||||
* @version 1.0
|
||||
* @description 车辆实例业务实现层
|
||||
* @date 2023/11/22
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||
/**
|
||||
* 根据车辆生成车辆实例
|
||||
*
|
||||
* @param vehicle 车辆信息
|
||||
*/
|
||||
@Override
|
||||
public void init(Vehicle vehicle) {
|
||||
VehicleInstance vehicleInstance = new VehicleInstance();
|
||||
vehicleInstance.setVehicle(vehicle);
|
||||
vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicle));
|
||||
LocalContainer.setVehicleInstance(vehicleInstance);
|
||||
log.info("构建车辆对象: [{}]", vehicle.getVin());
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化链接客户端
|
||||
*
|
||||
* @param vin 车辆VIN
|
||||
*/
|
||||
@Override
|
||||
public void initClient(String vin) {
|
||||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
||||
MqttProperties mqttProperties = MqttProperties.builder()
|
||||
.broker("tcp://fluxmq.muyu.icu:1883")
|
||||
.topic("test")
|
||||
.clientId(vin)
|
||||
.build();
|
||||
vehicleInstance.setMqttProperties(mqttProperties);
|
||||
vehicleInstance.initCline();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
}
|
|
@ -38,10 +38,10 @@ public class Test {
|
|||
log.info("开始生成VIN");
|
||||
long genVinStartTime = System.currentTimeMillis();
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("VIN12345678912345");
|
||||
// for (int i = 0; i < 1; i++) {
|
||||
// list.add(VehicleUtils.genVin());
|
||||
// }
|
||||
// list.add("VIN12345678912345");
|
||||
for (int i = 0; i < 100; i++) {
|
||||
list.add(VehicleUtils.genVin());
|
||||
}
|
||||
log.info("生成VIN结束:[{}MS]", System.currentTimeMillis()-genVinStartTime);
|
||||
log.info("开始创建车辆");
|
||||
long initVehicleStartTime = System.currentTimeMillis();
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.muyu.vehicle.thread.VehicleThread;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
|
@ -38,6 +39,7 @@ import static com.muyu.common.SystemConstant.*;
|
|||
@Data
|
||||
@Log4j2
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleInstance {
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.vehicle.core;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.muyu.domain.Vehicle;
|
||||
import com.muyu.service.VehicleInstanceService;
|
||||
import com.muyu.service.VehicleService;
|
||||
import com.muyu.vehicle.VehicleInstance;
|
||||
import com.muyu.vehicle.model.VehicleData;
|
||||
|
@ -29,7 +30,9 @@ public class VehicleConfiguration implements ApplicationRunner {
|
|||
|
||||
private final VehicleService vehicleService;
|
||||
|
||||
public VehicleInstance init(Vehicle vehicle){
|
||||
private final VehicleInstanceService vehicleInstanceService;
|
||||
|
||||
/*public VehicleInstance init(Vehicle vehicle){
|
||||
log.info("构建车辆对象: [{}]", vehicle.getVin());
|
||||
VehicleInstance vehicleInstance = new VehicleInstance(
|
||||
MqttProperties.builder()
|
||||
|
@ -44,7 +47,7 @@ public class VehicleConfiguration implements ApplicationRunner {
|
|||
vehicleInstance.initCline();
|
||||
log.info("构建车辆客户端: [{}]", vehicle.getVin());
|
||||
return vehicleInstance;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 初始化加载汽车数据到内存当中
|
||||
|
@ -56,9 +59,7 @@ public class VehicleConfiguration implements ApplicationRunner {
|
|||
while (true){
|
||||
Page<Vehicle> vehiclePage = vehicleService.page(new Page<>(page++, pageSize));
|
||||
List<Vehicle> vehicleList = vehiclePage.getRecords();
|
||||
vehicleList.stream()
|
||||
.map(this::init)
|
||||
.forEach(LocalContainer::setVehicleInstance);
|
||||
vehicleList.forEach(vehicleInstanceService::init);
|
||||
log.info("第[{}]页,[{}]条", page, vehicleList.size());
|
||||
if (vehicleList.size() < pageSize){
|
||||
break;
|
||||
|
@ -68,7 +69,7 @@ public class VehicleConfiguration implements ApplicationRunner {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void run (ApplicationArguments args) throws Exception {
|
||||
public void run (ApplicationArguments args) {
|
||||
this.vehiclePageInit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
create table if not exists vehicle (
|
||||
`vin` char (50) primary key not null,
|
||||
`vin` char (17) primary key not null,
|
||||
`remaining_battery` DOUBLE not null,
|
||||
`total_mileage` DOUBLE not null,
|
||||
`battery_level` DOUBLE not null,
|
||||
|
|
Loading…
Reference in New Issue