fix():修改BUG
parent
135448c504
commit
67a64a51bb
17
pom.xml
17
pom.xml
|
@ -96,5 +96,20 @@
|
|||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>vehicle-simulation-${version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -52,6 +52,7 @@ public class VehicleInstance {
|
|||
/**
|
||||
* 路径队列
|
||||
*/
|
||||
@Builder.Default
|
||||
private LinkedBlockingQueue<PositionModel> positionQueue = new LinkedBlockingQueue<>();
|
||||
/**
|
||||
* 车辆
|
||||
|
@ -81,7 +82,7 @@ public class VehicleInstance {
|
|||
/**
|
||||
* 链接上报
|
||||
*/
|
||||
private MqttClient client = null;
|
||||
private MqttClient client;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -98,6 +99,14 @@ public class VehicleInstance {
|
|||
return this.vehicleInfo.getVin();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前车辆所属租户信息
|
||||
* @return 租户ID
|
||||
*/
|
||||
public String getTenantId(){
|
||||
return this.vehicleInfo.getTenantId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param msg 消息
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.muyu.vehicle.core;
|
||||
|
||||
import com.muyu.system.handle.SystemHandler;
|
||||
import com.muyu.vehicle.VehicleInstance;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
|
@ -14,10 +15,26 @@ import java.util.Map;
|
|||
*/
|
||||
public class LocalContainer {
|
||||
|
||||
private static final Map<String, Map<String, VehicleInstance>> tenantVehicleDataMap
|
||||
= new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 车辆容器
|
||||
* 通过租户ID获取租户下车辆
|
||||
* @param tenantId 租户ID
|
||||
* @return 车辆内容
|
||||
*/
|
||||
public static final Map<String, VehicleInstance> vehicleDataMap = new HashMap<>();
|
||||
public static Map<String, VehicleInstance> getVehicleDataMap(String tenantId) {
|
||||
return tenantVehicleDataMap
|
||||
.computeIfAbsent(tenantId, k -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认获取档期啊租户下车辆
|
||||
* @return 车辆内容
|
||||
*/
|
||||
public static Map<String, VehicleInstance> getTenantVehicleDataMap() {
|
||||
return getVehicleDataMap(SystemHandler.getTenantId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加车辆
|
||||
|
@ -28,6 +45,7 @@ public class LocalContainer {
|
|||
}
|
||||
public static void setVehicleInstance(VehicleInstance vehicleInstance){
|
||||
String vin = vehicleInstance.getVehicleInfo().getVin();
|
||||
Map<String, VehicleInstance> vehicleDataMap = getVehicleDataMap(vehicleInstance.getTenantId());
|
||||
if (!vehicleDataMap.containsKey(vin)) {
|
||||
vehicleDataMap.put(vin, vehicleInstance);
|
||||
}
|
||||
|
@ -39,6 +57,7 @@ public class LocalContainer {
|
|||
* @return 车辆实例
|
||||
*/
|
||||
public static VehicleInstance getVehicleInstance(String vin){
|
||||
Map<String, VehicleInstance> vehicleDataMap = getTenantVehicleDataMap();
|
||||
return vehicleDataMap.get(vin);
|
||||
}
|
||||
|
||||
|
@ -47,10 +66,12 @@ public class LocalContainer {
|
|||
* @return
|
||||
*/
|
||||
public static long total () {
|
||||
Map<String, VehicleInstance> vehicleDataMap = getTenantVehicleDataMap();
|
||||
return vehicleDataMap.size();
|
||||
}
|
||||
|
||||
public static Collection<VehicleInstance> getVehicleInstanceAll () {
|
||||
Map<String, VehicleInstance> vehicleDataMap = getTenantVehicleDataMap();
|
||||
return vehicleDataMap.values();
|
||||
}
|
||||
|
||||
|
@ -60,6 +81,7 @@ public class LocalContainer {
|
|||
* @return 在线车辆集合
|
||||
*/
|
||||
public static List<VehicleInstance> getOnlineVehicleInstance(){
|
||||
Map<String, VehicleInstance> vehicleDataMap = getTenantVehicleDataMap();
|
||||
return vehicleDataMap.values().stream().filter(VehicleInstance::isOnline).toList();
|
||||
}
|
||||
/**
|
||||
|
@ -78,6 +100,7 @@ public class LocalContainer {
|
|||
* @return 离线车辆集合
|
||||
*/
|
||||
public static List<VehicleInstance> getOfflineVehicleInstance(){
|
||||
Map<String, VehicleInstance> vehicleDataMap = getTenantVehicleDataMap();
|
||||
return vehicleDataMap.values().stream().filter(vehicleInstance -> !vehicleInstance.isOnline()).toList();
|
||||
}
|
||||
|
||||
|
@ -86,6 +109,7 @@ public class LocalContainer {
|
|||
* @param vin 车辆VIN
|
||||
*/
|
||||
public static void removeByVin(String vin) {
|
||||
Map<String, VehicleInstance> vehicleDataMap = getTenantVehicleDataMap();
|
||||
vehicleDataMap.remove(vin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,8 +62,6 @@ public class VehicleConfiguration implements ApplicationRunner {
|
|||
*/
|
||||
@PreDestroy
|
||||
public void destroy(){
|
||||
|
||||
|
||||
log.info("数据库同步");
|
||||
vehicleInfoService.syncDb();
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ import com.muyu.vehicle.VehicleInstance;
|
|||
import com.muyu.vehicle.core.LocalContainer;
|
||||
import com.muyu.web.domain.model.OverviewModel;
|
||||
import com.muyu.web.service.OverviewService;
|
||||
import com.muyu.web.service.VehicleInstanceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -27,7 +25,7 @@ public class OverviewServiceImpl implements OverviewService {
|
|||
@Override
|
||||
public OverviewModel overview () {
|
||||
// 车辆实例对象
|
||||
Collection<VehicleInstance> instanceList = LocalContainer.vehicleDataMap.values();
|
||||
Collection<VehicleInstance> instanceList = LocalContainer.getTenantVehicleDataMap().values();
|
||||
|
||||
|
||||
return OverviewModel.builder()
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.web.service.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.system.handle.SystemHandler;
|
||||
import com.muyu.web.domain.VehicleInfo;
|
||||
import com.muyu.web.mapper.VehicleInfoMapper;
|
||||
import com.muyu.web.service.VehicleInstanceService;
|
||||
|
@ -65,6 +66,7 @@ public class VechileInfoServiceImpl extends ServiceImpl<VehicleInfoMapper, Vehic
|
|||
} else {
|
||||
LambdaQueryWrapper<VehicleInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(VehicleInfo::getVin, vin);
|
||||
queryWrapper.eq(VehicleInfo::getTenantId, SystemHandler.getTenantId());
|
||||
long count = this.count(queryWrapper);
|
||||
if (count == 1) {
|
||||
errorMsg.append("vin[").append(vin).append("]").append("已经存在\n");
|
||||
|
|
|
@ -70,7 +70,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
*/
|
||||
@Override
|
||||
public PageList<VehicleInstanceResp> queryList (VehicleInstanceListReq vehicleInstanceListReq) {
|
||||
Stream<VehicleInstance> stream = LocalContainer.vehicleDataMap.values()
|
||||
Stream<VehicleInstance> stream = LocalContainer.getTenantVehicleDataMap().values()
|
||||
.stream();
|
||||
if (StringUtils.isNotBlank(vehicleInstanceListReq.getVin())){
|
||||
stream = stream.filter(vehicleInstance ->
|
||||
|
@ -116,7 +116,9 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
|||
Result<MqttServerModel> result = clientAdmin.getVehicleLoadAddr(connectionReq);
|
||||
if (result.getCode() != 200){
|
||||
log.error("车辆:[{}],申请上线异常:[{}]", vin, result.getMsg());
|
||||
throw new RuntimeException("远程服务器没有【"+vin+"】车辆");
|
||||
throw new RuntimeException(
|
||||
String.format("车辆:[%s],申请上线异常:[%s]", vin, result.getMsg())
|
||||
);
|
||||
}
|
||||
MqttServerModel mqttServerModel = result.getData();
|
||||
MqttProperties mqttProperties = MqttProperties.builder()
|
||||
|
|
Loading…
Reference in New Issue