fix():车辆报文上报基于模板
parent
1bf4fc14a5
commit
2ac3ef27a6
|
@ -1,4 +1,4 @@
|
||||||
package com.muyu.config.cache;
|
package com.muyu.cache;
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Expiry;
|
import com.github.benmanes.caffeine.cache.Expiry;
|
||||||
import org.checkerframework.checker.index.qual.NonNegative;
|
import org.checkerframework.checker.index.qual.NonNegative;
|
||||||
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
* @Description: 缓存过期
|
* @Description: 缓存过期
|
||||||
* @Version: 1.0
|
* @Version: 1.0
|
||||||
*/
|
*/
|
||||||
public class CacheExpiry implements Expiry<String, ExpiryTime> {
|
public class CacheExpiry<K, V extends ExpiryTime> implements Expiry<K, ExpiryTime> {
|
||||||
/**
|
/**
|
||||||
* @param key 缓存键
|
* @param key 缓存键
|
||||||
* @param value 缓存值
|
* @param value 缓存值
|
||||||
|
@ -20,7 +20,7 @@ public class CacheExpiry implements Expiry<String, ExpiryTime> {
|
||||||
* @return 进入有效期前的时间长度,以纳秒为单位
|
* @return 进入有效期前的时间长度,以纳秒为单位
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long expireAfterCreate (String key, ExpiryTime value, long currentTime) {
|
public long expireAfterCreate (K key, ExpiryTime value, long currentTime) {
|
||||||
return TimeUnit.SECONDS.toNanos(value.getExpiryTime());
|
return TimeUnit.SECONDS.toNanos(value.getExpiryTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public class CacheExpiry implements Expiry<String, ExpiryTime> {
|
||||||
* @return 进入有效期前的时间长度,以纳秒为单位
|
* @return 进入有效期前的时间长度,以纳秒为单位
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long expireAfterUpdate (String key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
|
public long expireAfterUpdate (K key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
|
||||||
return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
|
return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ public class CacheExpiry implements Expiry<String, ExpiryTime> {
|
||||||
* @return 进入有效期前的时间长度,以纳秒为单位
|
* @return 进入有效期前的时间长度,以纳秒为单位
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long expireAfterRead (String key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
|
public long expireAfterRead (K key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
|
||||||
return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
|
return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.muyu.cache;
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存配置类
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class CaffeineConfig {
|
||||||
|
@Bean("loginUserCache")
|
||||||
|
public Cache<String, ? extends ExpiryTime> loginUserCache(){
|
||||||
|
CacheExpiry<String, ExpiryTime> cacheExpiry = new CacheExpiry<>();
|
||||||
|
return Caffeine.newBuilder()
|
||||||
|
.expireAfter(cacheExpiry)
|
||||||
|
.initialCapacity(128)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean("messageTemplateCache")
|
||||||
|
public Cache<Long, ? extends ExpiryTime> messageTemplateCache(){
|
||||||
|
CacheExpiry<Long, ExpiryTime> cacheExpiry = new CacheExpiry<>();
|
||||||
|
return Caffeine.newBuilder()
|
||||||
|
.expireAfter(cacheExpiry)
|
||||||
|
.initialCapacity(128)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.muyu.config.cache;
|
package com.muyu.cache;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.muyu.cache.model;
|
||||||
|
|
||||||
|
import com.muyu.cache.ExpiryTime;
|
||||||
|
import com.muyu.web.domain.MessageTemplate;
|
||||||
|
import com.muyu.web.domain.MessageTemplateValue;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: DongZeLiang
|
||||||
|
* @date: 2024/9/25
|
||||||
|
* @Description: 模板报文模型
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class MessageTemplateCacheModel extends ExpiryTime {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Long key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文名称
|
||||||
|
*/
|
||||||
|
private String messageName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板值集合
|
||||||
|
*/
|
||||||
|
private List<MessageTemplateValue> messageTemplateValueList;
|
||||||
|
|
||||||
|
public static MessageTemplateCacheModel messageTemplateBuild(
|
||||||
|
MessageTemplate messageTemplate, Function<Long,List<MessageTemplateValue>> function) {
|
||||||
|
return MessageTemplateCacheModel.builder()
|
||||||
|
.key(messageTemplate.getId())
|
||||||
|
.messageName(messageTemplate.getMessageName())
|
||||||
|
.messageTemplateValueList(function.apply(messageTemplate.getId()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,23 +0,0 @@
|
||||||
package com.muyu.config.cache;
|
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存配置类
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class CaffeineConfig {
|
|
||||||
@Bean("loginUserCache")
|
|
||||||
public Cache<String, ? extends ExpiryTime> caffeineCache(){
|
|
||||||
CacheExpiry cacheExpiry = new CacheExpiry();
|
|
||||||
return Caffeine.newBuilder()
|
|
||||||
.expireAfter(cacheExpiry)
|
|
||||||
//初始容量为100
|
|
||||||
.initialCapacity(128)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
package com.muyu.vehicle.core;
|
package com.muyu.config.runner;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
|
import com.muyu.cache.model.MessageTemplateCacheModel;
|
||||||
import com.muyu.config.tenant.CustomTenantHandler;
|
import com.muyu.config.tenant.CustomTenantHandler;
|
||||||
|
import com.muyu.vehicle.VehicleInstance;
|
||||||
|
import com.muyu.vehicle.core.LocalContainer;
|
||||||
import com.muyu.web.common.pool.FixedThreadPool;
|
import com.muyu.web.common.pool.FixedThreadPool;
|
||||||
import com.muyu.web.common.pool.ScheduledThreadPool;
|
import com.muyu.web.common.pool.ScheduledThreadPool;
|
||||||
import com.muyu.web.domain.VehicleInfo;
|
import com.muyu.web.domain.VehicleInfo;
|
||||||
|
import com.muyu.web.service.MessageTemplateService;
|
||||||
|
import com.muyu.web.service.MessageTemplateValueService;
|
||||||
import com.muyu.web.service.VehicleInfoService;
|
import com.muyu.web.service.VehicleInfoService;
|
||||||
import com.muyu.web.service.VehicleInstanceService;
|
import com.muyu.web.service.VehicleInstanceService;
|
||||||
import com.muyu.vehicle.VehicleInstance;
|
|
||||||
import jakarta.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
import lombok.AllArgsConstructor;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -18,21 +24,62 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 车辆
|
||||||
* @author DongZeLiang
|
* @author DongZeLiang
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @description 配置
|
* @description 车辆
|
||||||
* @date 2023/11/9
|
* @date 2023/11/9
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Configuration
|
@Configuration
|
||||||
@AllArgsConstructor
|
public class VehicleConfigRunner implements ApplicationRunner {
|
||||||
public class VehicleConfiguration implements ApplicationRunner {
|
|
||||||
|
|
||||||
private final VehicleInfoService vehicleInfoService;
|
@Autowired
|
||||||
|
private VehicleInfoService vehicleInfoService;
|
||||||
|
|
||||||
private final VehicleInstanceService vehicleInstanceService;
|
@Autowired
|
||||||
|
private VehicleInstanceService vehicleInstanceService;
|
||||||
|
|
||||||
private final CustomTenantHandler customTenantHandler;
|
@Autowired
|
||||||
|
private CustomTenantHandler customTenantHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板缓存
|
||||||
|
*/
|
||||||
|
@Resource(name = "messageTemplateCache")
|
||||||
|
private Cache<Long, MessageTemplateCacheModel> messageTemplateCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板业务类
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private MessageTemplateService messageTemplateService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板业务值类
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private MessageTemplateValueService messageTemplateValueService;
|
||||||
|
|
||||||
|
|
||||||
|
public void initMessageTemplate() {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
log.info("开始初始化加载报文模板---------------");
|
||||||
|
messageTemplateService
|
||||||
|
.list()
|
||||||
|
.stream()
|
||||||
|
.map(messageTemplate -> MessageTemplateCacheModel.messageTemplateBuild(messageTemplate, messageTemplateValueService::valueListByMsgId))
|
||||||
|
.filter(model -> {
|
||||||
|
log.info(
|
||||||
|
"过滤校验报文模板[{}-{}] 报文值个数-[{}个] -- {}",
|
||||||
|
model.getKey(), model.getMessageName(), model.getMessageTemplateValueList().size(),
|
||||||
|
model.getMessageTemplateValueList().isEmpty() ? "不合格,已过滤" : "合格"
|
||||||
|
);
|
||||||
|
return model.getMessageTemplateValueList().isEmpty();
|
||||||
|
})
|
||||||
|
.forEach(model -> messageTemplateCache.put(model.getKey(), model));
|
||||||
|
log.info("结束初始化加载报文模板耗时:[{}MS]---------------", System.currentTimeMillis() - startTime);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化加载汽车数据到内存当中
|
* 初始化加载汽车数据到内存当中
|
||||||
|
@ -41,7 +88,6 @@ public class VehicleConfiguration implements ApplicationRunner {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
int page = 0, pageSize = 10;
|
int page = 0, pageSize = 10;
|
||||||
log.info("初始开始,批量从数据库当中加载数据到内存当中,每次[{}]条", pageSize);
|
log.info("初始开始,批量从数据库当中加载数据到内存当中,每次[{}]条", pageSize);
|
||||||
customTenantHandler.ignore();
|
|
||||||
while (true){
|
while (true){
|
||||||
Page<VehicleInfo> vehiclePage = vehicleInfoService.page(new Page<>(page++, pageSize));
|
Page<VehicleInfo> vehiclePage = vehicleInfoService.page(new Page<>(page++, pageSize));
|
||||||
List<VehicleInfo> vehicleInfoList = vehiclePage.getRecords();
|
List<VehicleInfo> vehicleInfoList = vehiclePage.getRecords();
|
||||||
|
@ -51,13 +97,15 @@ public class VehicleConfiguration implements ApplicationRunner {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
customTenantHandler.remove();
|
|
||||||
log.info("数据加载完成,耗时:{} MS", System.currentTimeMillis() - startTime);
|
log.info("数据加载完成,耗时:{} MS", System.currentTimeMillis() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run (ApplicationArguments args) {
|
public void run (ApplicationArguments args) {
|
||||||
|
customTenantHandler.ignore();
|
||||||
|
this.initMessageTemplate();
|
||||||
this.vehiclePageInit();
|
this.vehiclePageInit();
|
||||||
|
customTenantHandler.remove();
|
||||||
// 提交给线程池 一分钟 执行一次
|
// 提交给线程池 一分钟 执行一次
|
||||||
// ThreadPool.submit(new Thread(vehicleService::syncDb), 30);
|
// ThreadPool.submit(new Thread(vehicleService::syncDb), 30);
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package com.muyu.system.domain;
|
package com.muyu.system.domain;
|
||||||
|
|
||||||
import com.muyu.config.cache.ExpiryTime;
|
import com.muyu.cache.ExpiryTime;
|
||||||
import com.muyu.system.properties.ServerConfigProperties;
|
import com.muyu.system.properties.ServerConfigProperties;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package com.muyu.vehicle;
|
package com.muyu.vehicle;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.muyu.cache.model.MessageTemplateCacheModel;
|
||||||
|
import com.muyu.system.enums.MessageTemplateValueType;
|
||||||
import com.muyu.vehicle.model.VehicleData;
|
import com.muyu.vehicle.model.VehicleData;
|
||||||
import com.muyu.vehicle.model.properties.MqttProperties;
|
import com.muyu.vehicle.model.properties.MqttProperties;
|
||||||
import com.muyu.vehicle.thread.VehicleThread;
|
import com.muyu.vehicle.thread.VehicleThread;
|
||||||
import com.muyu.web.common.SystemConstant;
|
import com.muyu.web.common.SystemConstant;
|
||||||
import com.muyu.web.common.pool.ScheduledThreadPool;
|
import com.muyu.web.common.pool.ScheduledThreadPool;
|
||||||
|
import com.muyu.web.domain.MessageTemplateValue;
|
||||||
import com.muyu.web.domain.VehicleInfo;
|
import com.muyu.web.domain.VehicleInfo;
|
||||||
import com.muyu.web.domain.model.PositionModel;
|
import com.muyu.web.domain.model.PositionModel;
|
||||||
import com.muyu.web.utils.CalculateCheckDigit;
|
import com.muyu.web.utils.CalculateCheckDigit;
|
||||||
|
@ -24,6 +27,7 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
@ -59,6 +63,12 @@ public class VehicleInstance {
|
||||||
* 车辆
|
* 车辆
|
||||||
*/
|
*/
|
||||||
private VehicleInfo vehicleInfo;
|
private VehicleInfo vehicleInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板
|
||||||
|
*/
|
||||||
|
private MessageTemplateCacheModel messageTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实例数据
|
* 实例数据
|
||||||
*/
|
*/
|
||||||
|
@ -207,24 +217,6 @@ public class VehicleInstance {
|
||||||
log.info("车辆:{} 设置路径成功", this.getVin());
|
log.info("车辆:{} 设置路径成功", this.getVin());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化线程
|
|
||||||
*/
|
|
||||||
/*public void initVehicleThread() {
|
|
||||||
if (this.positionCode == null){
|
|
||||||
throw new RuntimeException("车辆["+getVin()+"]未选中路径");
|
|
||||||
}
|
|
||||||
if (!isOnline()){
|
|
||||||
throw new RuntimeException("车辆["+getVin()+"]未和服务器建立链接");
|
|
||||||
}
|
|
||||||
VehicleThread vehicleThread = new VehicleThread();
|
|
||||||
vehicleThread.setVehicleInstance(this);
|
|
||||||
this.setVehicleThread(vehicleThread);
|
|
||||||
ScheduledFuture<?> scheduledFuture = ScheduledThreadPool.submit(vehicleThread);
|
|
||||||
this.setScheduledFuture(scheduledFuture);
|
|
||||||
log.info("初始化车辆上报模拟线程开始:[{}]", this.getVin());
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束发送
|
* 结束发送
|
||||||
*/
|
*/
|
||||||
|
@ -305,9 +297,34 @@ public class VehicleInstance {
|
||||||
.setScale(2, RoundingMode.HALF_UP).toString()
|
.setScale(2, RoundingMode.HALF_UP).toString()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
vehicleData.imitateBase();
|
List<MessageTemplateValue> messageTemplateValueList
|
||||||
vehicleData.imitateMotor();
|
= this.messageTemplate.getMessageTemplateValueList();
|
||||||
vehicleData.imitateBatteryPack();
|
for (MessageTemplateValue messageTemplateValue : messageTemplateValueList) {
|
||||||
|
String valueType = messageTemplateValue.getValueType();
|
||||||
|
MessageTemplateValueType messageTemplateValueType
|
||||||
|
= MessageTemplateValueType.valueOf(valueType);
|
||||||
|
switch (messageTemplateValueType){
|
||||||
|
// 固定值
|
||||||
|
case FIXED -> {
|
||||||
|
String fixedValue = messageTemplateValue.getFixedValue();
|
||||||
|
String[] split = fixedValue.split(",");
|
||||||
|
vehicleData.putData(messageTemplateValue.getCode(), split[0]);
|
||||||
|
}
|
||||||
|
// 区间值
|
||||||
|
case INTERVAL -> {
|
||||||
|
vehicleData.putData(
|
||||||
|
messageTemplateValue.getCode(),
|
||||||
|
vehicleData.getValue(
|
||||||
|
vehicleData.genValue(
|
||||||
|
messageTemplateValue.getMinValue(),
|
||||||
|
messageTemplateValue.getMaxValue()
|
||||||
|
),
|
||||||
|
messageTemplateValue.getLength()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -318,4 +335,33 @@ public class VehicleInstance {
|
||||||
this.vehicleData.setGear(gear);
|
this.vehicleData.setGear(gear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String imitateDataAndMsg () {
|
||||||
|
this.imitateData();
|
||||||
|
List<MessageTemplateValue> messageTemplateValueList
|
||||||
|
= this.messageTemplate.getMessageTemplateValueList();
|
||||||
|
StringBuilder elBuilder = new StringBuilder();
|
||||||
|
messageTemplateValueList.stream()
|
||||||
|
.filter(MessageTemplateValue::isEl)
|
||||||
|
.sorted(Comparator.comparing(MessageTemplateValue::getStartLocation))
|
||||||
|
.forEach(value -> {
|
||||||
|
String elValue = value.getElValue();
|
||||||
|
// TODO 获取EL报文
|
||||||
|
});
|
||||||
|
StringBuilder fixedBuilder = new StringBuilder();
|
||||||
|
messageTemplateValueList.stream()
|
||||||
|
.filter(MessageTemplateValue::isFixed)
|
||||||
|
.sorted(Comparator.comparing(MessageTemplateValue::getStartLocation))
|
||||||
|
.forEach(value -> {
|
||||||
|
// TODO 获取固定报文
|
||||||
|
});
|
||||||
|
|
||||||
|
StringBuilder intervalBuilder = new StringBuilder();
|
||||||
|
messageTemplateValueList.stream()
|
||||||
|
.filter(MessageTemplateValue::isInterval)
|
||||||
|
.sorted(Comparator.comparing(MessageTemplateValue::getStartLocation))
|
||||||
|
.forEach(value -> {
|
||||||
|
// TODO 获取随机报文
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,9 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.HashMap;
|
||||||
import static com.muyu.web.utils.VehicleUtils.genValue;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 牧鱼
|
* @author 牧鱼
|
||||||
|
@ -26,10 +27,6 @@ public class VehicleData {
|
||||||
* VIN
|
* VIN
|
||||||
*/
|
*/
|
||||||
private String vin;
|
private String vin;
|
||||||
/**
|
|
||||||
* 行驶路线
|
|
||||||
*/
|
|
||||||
private String drivingRoute;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 经度
|
* 经度
|
||||||
|
@ -51,21 +48,6 @@ public class VehicleData {
|
||||||
*/
|
*/
|
||||||
private BigDecimal mileage;
|
private BigDecimal mileage;
|
||||||
|
|
||||||
/**
|
|
||||||
* 总电压
|
|
||||||
*/
|
|
||||||
private String voltage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 总电流
|
|
||||||
*/
|
|
||||||
private String current;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 绝缘电阻
|
|
||||||
*/
|
|
||||||
private String resistance;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 档位
|
* 档位
|
||||||
*/
|
*/
|
||||||
|
@ -73,320 +55,43 @@ public class VehicleData {
|
||||||
private String gear = "P";
|
private String gear = "P";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加速踏板行程值
|
* 电池剩余电量
|
||||||
*/
|
*/
|
||||||
private String accelerationPedal;
|
private BigDecimal remainingBattery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 制动踏板行程值
|
* 电池电量
|
||||||
*/
|
*/
|
||||||
private String brakePedal;
|
private BigDecimal batteryLevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 燃料消耗率
|
* 燃料消耗率
|
||||||
*/
|
*/
|
||||||
private String fuelConsumptionRate;
|
private String fuelConsumptionRate;
|
||||||
|
|
||||||
/**
|
private Map<String, String> dataMap = new HashMap<String, String>();
|
||||||
* 电机控制器温度
|
|
||||||
*/
|
|
||||||
private String motorControllerTemperature;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 电机转速
|
* 存放值
|
||||||
|
* @param key
|
||||||
|
* @param value
|
||||||
*/
|
*/
|
||||||
private String motorSpeed;
|
public void putData(String key, String value) {
|
||||||
|
dataMap.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 电机转矩
|
* 获取值
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
private String motorTorque;
|
public String getData(String key) {
|
||||||
|
return dataMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public String genValue(double start, double end) {
|
||||||
* 电机温度
|
Random random = new Random();
|
||||||
*/
|
return String.valueOf(random.nextDouble() * (end - start) + start);
|
||||||
private String motorTemperature;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 电机电压
|
|
||||||
*/
|
|
||||||
private String motorVoltage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 电机电流
|
|
||||||
*/
|
|
||||||
private String motorCurrent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动力电池剩余电量SOC
|
|
||||||
*/
|
|
||||||
private BigDecimal remainingBattery;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 电池总容量
|
|
||||||
*/
|
|
||||||
private BigDecimal batteryLevel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当前状态允许的最大反馈功率
|
|
||||||
*/
|
|
||||||
private String maximumFeedbackPower;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 当前状态允许最大放电功率
|
|
||||||
*/
|
|
||||||
private String maximumDischargePower;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BMS自检计数器
|
|
||||||
*/
|
|
||||||
private String selfCheckCounter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动力电池充放电电流
|
|
||||||
*/
|
|
||||||
private String totalBatteryCurrent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动力电池负载端总电压V3
|
|
||||||
*/
|
|
||||||
private String totalBatteryVoltage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单次最大电压
|
|
||||||
*/
|
|
||||||
private String singleBatteryMaxVoltage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单体电池最低电压
|
|
||||||
*/
|
|
||||||
private String singleBatteryMinVoltage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单体电池最高温度
|
|
||||||
*/
|
|
||||||
private String singleBatteryMaxTemperature;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单体电池最低温度
|
|
||||||
*/
|
|
||||||
private String singleBatteryMinTemperature;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动力电池可用容量
|
|
||||||
*/
|
|
||||||
private String availableBatteryCapacity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int vehicleStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 充电状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int chargingStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 运行状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int operatingStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SOC
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int socStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 可充电储能装置工作状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int chargingEnergyStorageStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 驱动电机状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int driveMotorStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定位是否有效
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int positionStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* EAS(汽车防盗系统)状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int easStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PTC(电动加热器)状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int ptcStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* EPS(电动助力系统)状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int epsStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ABS(防抱死)状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int absStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MCU(电机/逆变器)状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int mcuStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动力电池加热状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int heatingStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动力电池当前状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int batteryStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动力电池保温状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int batteryInsulationStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DCDC(电力交换系统)状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int dcdcStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CHG(充电机)状态
|
|
||||||
*/
|
|
||||||
@Builder.Default
|
|
||||||
private int chgStatus = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆状态 报文
|
|
||||||
*/
|
|
||||||
private String vehicleStatusMsg;
|
|
||||||
/**
|
|
||||||
* 智能硬件 报文
|
|
||||||
*/
|
|
||||||
private String smartHardwareMsg;
|
|
||||||
/**
|
|
||||||
* 电池报文
|
|
||||||
*/
|
|
||||||
private String batteryMsg;
|
|
||||||
|
|
||||||
public String getMsg(){
|
|
||||||
//第一位VIN
|
|
||||||
return vin +
|
|
||||||
// 当前时间戳
|
|
||||||
System.currentTimeMillis() +
|
|
||||||
//第二位经度 longitude latitude
|
|
||||||
getValue(longitude, 11) +
|
|
||||||
//第三位维度 longitude latitude
|
|
||||||
getValue(latitude, 10) +
|
|
||||||
//车速
|
|
||||||
getValue(speed, 6) +
|
|
||||||
//总里程
|
|
||||||
getValue(mileage == null ? "" : mileage.toString(), 11) +
|
|
||||||
// 总电压
|
|
||||||
getValue(voltage, 6) +
|
|
||||||
//总电流
|
|
||||||
getValue(current, 5) +
|
|
||||||
//绝缘电阻 79 - 87
|
|
||||||
getValue(resistance, 9) +
|
|
||||||
//档位
|
|
||||||
(gear == null ? "D" : gear) +
|
|
||||||
// 加速踏板行程值
|
|
||||||
getValue(accelerationPedal, 2) +
|
|
||||||
// 制动踏板行程值
|
|
||||||
getValue(brakePedal, 2) +
|
|
||||||
// 燃料消耗率
|
|
||||||
getValue(fuelConsumptionRate, 5) +
|
|
||||||
//电机控制器温度
|
|
||||||
getValue(motorControllerTemperature, 6) +
|
|
||||||
//电机转速
|
|
||||||
getValue(motorSpeed, 5) +
|
|
||||||
//点击转矩
|
|
||||||
getValue(motorTorque, 4) +
|
|
||||||
//电机温度
|
|
||||||
getValue(motorTemperature, 6) +
|
|
||||||
//电机电压
|
|
||||||
getValue(motorVoltage, 5) +
|
|
||||||
//电机电流
|
|
||||||
getValue(motorCurrent, 8) +
|
|
||||||
//动力电池剩余电量SOC
|
|
||||||
getValue(remainingBattery == null ? "" : remainingBattery.toString(), 6) +
|
|
||||||
//当前状态允许的最大反馈功率
|
|
||||||
getValue(maximumFeedbackPower, 6) +
|
|
||||||
//当前状态允许最大放电功率
|
|
||||||
getValue(maximumDischargePower, 6) +
|
|
||||||
//BMS自检计数器
|
|
||||||
getValue(selfCheckCounter, 2) +
|
|
||||||
//动力电池充放电电流
|
|
||||||
getValue(totalBatteryCurrent, 5) +
|
|
||||||
//动力电池负载端总电压V3
|
|
||||||
getValue(totalBatteryVoltage, 6) +
|
|
||||||
//单次最大电压
|
|
||||||
getValue(singleBatteryMaxVoltage, 4) +
|
|
||||||
//单体电池最低电压
|
|
||||||
getValue(singleBatteryMinVoltage, 4) +
|
|
||||||
//单体电池最高温度
|
|
||||||
getValue(singleBatteryMaxTemperature, 6) +
|
|
||||||
//单体电池最低温度
|
|
||||||
getValue(singleBatteryMinTemperature, 6) +
|
|
||||||
//动力电池可用容量
|
|
||||||
getValue(availableBatteryCapacity, 6) +
|
|
||||||
//车辆状态
|
|
||||||
vehicleStatus +
|
|
||||||
//充电状态
|
|
||||||
chargingStatus +
|
|
||||||
//运行状态
|
|
||||||
operatingStatus +
|
|
||||||
//SOC
|
|
||||||
socStatus +
|
|
||||||
//可充电储能装置工作状态
|
|
||||||
chargingEnergyStorageStatus +
|
|
||||||
//驱动电机状态
|
|
||||||
driveMotorStatus +
|
|
||||||
//定位是否有效
|
|
||||||
positionStatus +
|
|
||||||
//EAS
|
|
||||||
easStatus +
|
|
||||||
//PTC
|
|
||||||
ptcStatus +
|
|
||||||
//EPS
|
|
||||||
epsStatus +
|
|
||||||
//ABS
|
|
||||||
absStatus +
|
|
||||||
//MCU
|
|
||||||
mcuStatus +
|
|
||||||
//动力电池加热状态
|
|
||||||
heatingStatus +
|
|
||||||
//动力电池当前状态
|
|
||||||
batteryStatus +
|
|
||||||
//动力电池保温状态
|
|
||||||
batteryInsulationStatus +
|
|
||||||
//DCDC
|
|
||||||
dcdcStatus +
|
|
||||||
//CHG
|
|
||||||
chgStatus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue(String val , int valLength){
|
public String getValue(String val , int valLength){
|
||||||
|
@ -413,126 +118,6 @@ public class VehicleData {
|
||||||
.remainingBattery(vehicleInfo.getRemainingBattery())
|
.remainingBattery(vehicleInfo.getRemainingBattery())
|
||||||
.batteryLevel(vehicleInfo.getBatteryLevel())
|
.batteryLevel(vehicleInfo.getBatteryLevel())
|
||||||
.mileage(vehicleInfo.getTotalMileage())
|
.mileage(vehicleInfo.getTotalMileage())
|
||||||
.vehicleStatus(1)
|
|
||||||
.chargingStatus(1)
|
|
||||||
.operatingStatus(1)
|
|
||||||
.socStatus(1)
|
|
||||||
.chargingEnergyStorageStatus(1)
|
|
||||||
.driveMotorStatus(1)
|
|
||||||
.positionStatus(1)
|
|
||||||
.easStatus(1)
|
|
||||||
.ptcStatus(1)
|
|
||||||
.epsStatus(1)
|
|
||||||
.absStatus(1)
|
|
||||||
.mcuStatus(1)
|
|
||||||
.heatingStatus(1)
|
|
||||||
.batteryStatus(1)
|
|
||||||
.batteryInsulationStatus(1)
|
|
||||||
.dcdcStatus(1)
|
|
||||||
.chgStatus(1)
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 模拟基础项
|
|
||||||
*/
|
|
||||||
public void imitateBase(){
|
|
||||||
// 总电压
|
|
||||||
this.voltage = genValue(110, 750);
|
|
||||||
// 总电流
|
|
||||||
this.current = genValue(3, 50);
|
|
||||||
// 绝缘电阻
|
|
||||||
this.resistance = genValue(0,30000);
|
|
||||||
// 加速踏板行程值
|
|
||||||
this.accelerationPedal = genValue(0, 10);
|
|
||||||
// 制动踏板行程值
|
|
||||||
this.brakePedal = genValue(0, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模拟电机数据
|
|
||||||
*/
|
|
||||||
public void imitateMotor(){
|
|
||||||
// 电机控制器温度
|
|
||||||
this.motorControllerTemperature = genValue(0, 100);
|
|
||||||
// 电机转速
|
|
||||||
this.motorSpeed = genValue(0, 99999);
|
|
||||||
// 电机转矩
|
|
||||||
this.motorTorque = genValue(0, 1000);
|
|
||||||
// 电机温度
|
|
||||||
this.motorTemperature = genValue(0, 150);
|
|
||||||
// 电机电压
|
|
||||||
this.motorVoltage = genValue(110, 300);
|
|
||||||
// 电机电流
|
|
||||||
this.motorCurrent = genValue(0, 15000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模拟电池包数据
|
|
||||||
*/
|
|
||||||
public void imitateBatteryPack(){
|
|
||||||
// 当前状态允许的最大反馈功率
|
|
||||||
this.maximumFeedbackPower = genValue(0, 100);
|
|
||||||
// 当前状态允许最大放电功率
|
|
||||||
this.maximumDischargePower = genValue(0, 100);
|
|
||||||
// BMS自检计数器
|
|
||||||
this.selfCheckCounter = genValue(0, 15);
|
|
||||||
// 动力电池充放电电流
|
|
||||||
this.totalBatteryCurrent = genValue(0, 15);
|
|
||||||
// 动力电池负载端总电压V3
|
|
||||||
this.totalBatteryVoltage = genValue(220, 750);
|
|
||||||
// 单体电池最高电压
|
|
||||||
this.singleBatteryMaxVoltage = genValue(3, 5);
|
|
||||||
// 单体电池最低电压
|
|
||||||
this.singleBatteryMinVoltage = genValue(3, 5);
|
|
||||||
// 单体电池最高温度
|
|
||||||
this.singleBatteryMaxTemperature = genValue(0, 100);
|
|
||||||
// 单体电池最低温度
|
|
||||||
this.singleBatteryMinTemperature = genValue(0, 100);
|
|
||||||
// 动力电池可用容量
|
|
||||||
this.availableBatteryCapacity = genValue(0,100 );
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
车辆状态
|
|
||||||
vehicleStatus;
|
|
||||||
充电状态
|
|
||||||
chargingStatus;
|
|
||||||
运行状态
|
|
||||||
operatingStatus;
|
|
||||||
SOC
|
|
||||||
socStatus;
|
|
||||||
可充电储能装置工作状态
|
|
||||||
chargingEnergyStorageStatus;
|
|
||||||
驱动电机状态
|
|
||||||
driveMotorStatus;
|
|
||||||
定位是否有效
|
|
||||||
positionStatus;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
EAS(汽车防盗系统)状态
|
|
||||||
easStatus;
|
|
||||||
PTC(电动加热器)状态
|
|
||||||
ptcStatus;
|
|
||||||
EPS(电动助力系统)状态
|
|
||||||
epsStatus;
|
|
||||||
ABS(防抱死)状态
|
|
||||||
absStatus;
|
|
||||||
MCU(电机/逆变器)状态
|
|
||||||
mcuStatus;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
动力电池加热状态
|
|
||||||
heatingStatus;
|
|
||||||
动力电池当前状态
|
|
||||||
batteryStatus;
|
|
||||||
动力电池保温状态
|
|
||||||
batteryInsulationStatus;
|
|
||||||
DCDC(电力交换系统)状态
|
|
||||||
dcdcStatus;
|
|
||||||
CHG(充电机)状态
|
|
||||||
chgStatus;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,7 @@ public class VehicleThread implements Runnable {
|
||||||
try {
|
try {
|
||||||
if (!isStop){
|
if (!isStop){
|
||||||
log.info("{} - 上报数据", this.vehicleInstance.getVin());
|
log.info("{} - 上报数据", this.vehicleInstance.getVin());
|
||||||
this.vehicleInstance.imitateData();
|
this.vehicleInstance.sendMsg( this.vehicleInstance.imitateDataAndMsg());
|
||||||
this.vehicleInstance.sendMsg(
|
|
||||||
this.vehicleInstance.getVehicleData().getMsg()
|
|
||||||
);
|
|
||||||
}else {
|
}else {
|
||||||
log.info("终止模拟和上报:[{}]", this.vehicleInstance.getVin());
|
log.info("终止模拟和上报:[{}]", this.vehicleInstance.getVin());
|
||||||
vehicleInstance.cancelExecution();
|
vehicleInstance.cancelExecution();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.muyu.web.domain;
|
package com.muyu.web.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.muyu.system.enums.MessageTemplateValueType;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -79,4 +80,16 @@ public class MessageTemplateValue {
|
||||||
* 数据最大范围
|
* 数据最大范围
|
||||||
*/
|
*/
|
||||||
private Double maxValue;
|
private Double maxValue;
|
||||||
|
|
||||||
|
public boolean isEl () {
|
||||||
|
return MessageTemplateValueType.EL.code().equals(valueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInterval () {
|
||||||
|
return MessageTemplateValueType.INTERVAL.code().equals(valueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFixed () {
|
||||||
|
return MessageTemplateValueType.FIXED.code().equals(valueType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.muyu.web.service;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.web.domain.MessageTemplateValue;
|
import com.muyu.web.domain.MessageTemplateValue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: DongZeLiang
|
* @Author: DongZeLiang
|
||||||
* @date: 2024-9-18
|
* @date: 2024-9-18
|
||||||
|
@ -11,4 +13,10 @@ import com.muyu.web.domain.MessageTemplateValue;
|
||||||
*/
|
*/
|
||||||
public interface MessageTemplateValueService extends IService<MessageTemplateValue> {
|
public interface MessageTemplateValueService extends IService<MessageTemplateValue> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过报文模板ID获取报文值集合
|
||||||
|
* @param msgId 模板ID
|
||||||
|
* @return 报文值集合
|
||||||
|
*/
|
||||||
|
List<MessageTemplateValue> valueListByMsgId (Long msgId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package com.muyu.web.service.impl;
|
package com.muyu.web.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.muyu.web.domain.MessageTemplateValue;
|
import com.muyu.web.domain.MessageTemplateValue;
|
||||||
import com.muyu.web.mapper.MessageTemplateValueMapper;
|
import com.muyu.web.mapper.MessageTemplateValueMapper;
|
||||||
import com.muyu.web.service.MessageTemplateValueService;
|
import com.muyu.web.service.MessageTemplateValueService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: DongZeLiang
|
* @Author: DongZeLiang
|
||||||
* @date: 2024/9/18
|
* @date: 2024/9/18
|
||||||
|
@ -16,4 +19,19 @@ import org.springframework.stereotype.Service;
|
||||||
public class MessageTemplateValueServiceImpl
|
public class MessageTemplateValueServiceImpl
|
||||||
extends ServiceImpl<MessageTemplateValueMapper, MessageTemplateValue>
|
extends ServiceImpl<MessageTemplateValueMapper, MessageTemplateValue>
|
||||||
implements MessageTemplateValueService {
|
implements MessageTemplateValueService {
|
||||||
|
/**
|
||||||
|
* 通过报文模板ID获取报文值集合
|
||||||
|
*
|
||||||
|
* @param msgId 模板ID
|
||||||
|
*
|
||||||
|
* @return 报文值集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<MessageTemplateValue> valueListByMsgId (Long msgId) {
|
||||||
|
return this.list(
|
||||||
|
new LambdaQueryWrapper<>(){{
|
||||||
|
this.eq(MessageTemplateValue::getMessageId, msgId);
|
||||||
|
}}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.web.service.impl;
|
package com.muyu.web.service.impl;
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
|
import com.muyu.cache.model.MessageTemplateCacheModel;
|
||||||
import com.muyu.vehicle.VehicleInstance;
|
import com.muyu.vehicle.VehicleInstance;
|
||||||
import com.muyu.vehicle.api.ClientAdmin;
|
import com.muyu.vehicle.api.ClientAdmin;
|
||||||
import com.muyu.vehicle.api.req.VehicleConnectionReq;
|
import com.muyu.vehicle.api.req.VehicleConnectionReq;
|
||||||
|
@ -19,6 +21,7 @@ import com.muyu.web.service.PositionRouteService;
|
||||||
import com.muyu.web.service.VehicleInstanceService;
|
import com.muyu.web.service.VehicleInstanceService;
|
||||||
import com.muyu.web.utils.MD5Util;
|
import com.muyu.web.utils.MD5Util;
|
||||||
import com.muyu.web.utils.ReflectUtils;
|
import com.muyu.web.utils.ReflectUtils;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -45,6 +48,12 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ClientAdmin clientAdmin;
|
private ClientAdmin clientAdmin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板缓存
|
||||||
|
*/
|
||||||
|
@Resource(name = "messageTemplateCache")
|
||||||
|
private Cache<Long, MessageTemplateCacheModel> messageTemplateCache;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据车辆生成车辆实例
|
* 根据车辆生成车辆实例
|
||||||
|
@ -56,6 +65,9 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
VehicleInstance vehicleInstance = new VehicleInstance();
|
VehicleInstance vehicleInstance = new VehicleInstance();
|
||||||
vehicleInstance.setVehicleInfo(vehicleInfo);
|
vehicleInstance.setVehicleInfo(vehicleInfo);
|
||||||
vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicleInfo));
|
vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicleInfo));
|
||||||
|
vehicleInstance.setMessageTemplate(
|
||||||
|
messageTemplateCache.getIfPresent(vehicleInfo.getMessageTemplateId())
|
||||||
|
);
|
||||||
LocalContainer.setVehicleInstance(vehicleInstance);
|
LocalContainer.setVehicleInstance(vehicleInstance);
|
||||||
log.debug("构建车辆对象: [{}]", vehicleInfo.getVin());
|
log.debug("构建车辆对象: [{}]", vehicleInfo.getVin());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue