Compare commits
9 Commits
e46b6325c4
...
aeec2245c0
Author | SHA1 | Date |
---|---|---|
|
aeec2245c0 | |
|
6c2daa0d7e | |
|
5a64054615 | |
|
903fecc2cc | |
|
217ffd81ab | |
|
b2c16300f4 | |
|
b07b7a1d2d | |
|
057ad3ded5 | |
|
735e7f56e0 |
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: eight
|
||||
namespace: xxy
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: eight
|
||||
namespace: xxy
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.muyu.carData;
|
||||
|
||||
import com.muyu.carData.listener.MyListener;
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
|
@ -14,11 +16,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
*/
|
||||
@SpringBootApplication
|
||||
@EnableMyFeignClients
|
||||
@EnableCustomConfig
|
||||
@EnableAsync
|
||||
@EnableCaching
|
||||
public class CarDataApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(CarDataApplication.class);
|
||||
application.addListeners(new MyListener());
|
||||
application.run(args);
|
||||
SpringApplication.run(CarDataApplication.class,args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
package com.muyu.carData.config.lotdbconfig;
|
||||
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.Session;
|
||||
import org.apache.iotdb.session.SessionDataSet;
|
||||
import org.apache.iotdb.session.pool.SessionPool;
|
||||
import org.apache.iotdb.tsfile.read.common.Field;
|
||||
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -76,6 +83,66 @@ public class IotDBSessionConfig {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加操作
|
||||
* @param deviceId
|
||||
* @param time 时间戳
|
||||
* @param measurements
|
||||
* @param values 值
|
||||
*/
|
||||
public void execute(String deviceId,long time,List<String> measurements,List<String> values){
|
||||
if (CollectionUtils.isEmpty(measurements) && !CollectionUtils.isEmpty(values)){
|
||||
try {
|
||||
iotSession().insertAlignedRecord(deviceId,time,measurements,values);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询操作
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
public List<HashMap<String,Object>> executeQuery(String sql){
|
||||
logger.info("sql:{}",sql);
|
||||
List<HashMap<String,Object>> list = new ArrayList<>();
|
||||
|
||||
try {
|
||||
SessionDataSet sessionDataSet = iotSession().executeQueryStatement(sql);
|
||||
int fetchSize = sessionDataSet.getFetchSize();
|
||||
List<String> columnNames = sessionDataSet.getColumnNames();
|
||||
logger.info("columnNames:{}",columnNames);
|
||||
List<String> columnTypes = sessionDataSet.getColumnTypes();
|
||||
logger.info("columnTypes:{}",columnTypes);
|
||||
if (fetchSize > 0){
|
||||
while (sessionDataSet.hasNext()){
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
RowRecord next = sessionDataSet.next();
|
||||
List<Field> fields = next.getFields();
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
Field field = fields.get(i);
|
||||
String key = field.getStringValue();
|
||||
Object value = field.getObjectValue(field.getDataType());
|
||||
map.put(key,value);
|
||||
}
|
||||
list.add(map);
|
||||
}
|
||||
|
||||
sessionDataSet.closeOperationHandle();
|
||||
}
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import com.muyu.carData.util.CacheUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 车辆下线消费者
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.consumer
|
||||
* @Project:cloud-server-8
|
||||
* @name:CarOffConsumer
|
||||
* @Date:2024/10/4 14:30
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class CarOffConsumer {
|
||||
|
||||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(value = "CAR_OFFLINE",durable = "true"),
|
||||
exchange = @Exchange(value = "CAR_OFF_EXCHANGE",type = "fanout")
|
||||
))
|
||||
public void inline(String vin){
|
||||
log.info("车辆vin:{},车辆下线成功!开始消费...");
|
||||
cacheUtil.remove(vin);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import com.muyu.carData.util.CacheUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**车辆上线消费者
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.consumer
|
||||
* @Project:cloud-server-8
|
||||
* @name:CarOnlineConsumer
|
||||
* @Date:2024/10/4 14:27
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class CarOnlineConsumer {
|
||||
|
||||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(value = "CAR_ONLINE",durable = "true"),
|
||||
exchange = @Exchange(value = "ONLINE_EXCHANGE",type = "fanout")
|
||||
))
|
||||
public void online(String vin){
|
||||
log.info("车辆vin:{},已上线,开始消费",vin);
|
||||
}
|
||||
}
|
|
@ -1,19 +1,23 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
|
||||
import com.muyu.carData.pojo.Student;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.event.EventPublisher;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**卡夫卡消费者
|
||||
* @Author:张腾
|
||||
|
@ -24,33 +28,43 @@ import java.util.Collection;
|
|||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class MyKafkaConsumer implements InitializingBean {
|
||||
public class MyKafkaConsumer implements ApplicationRunner, ApplicationListener<ContextClosedEvent> {
|
||||
|
||||
@Autowired
|
||||
private KafkaConsumer kafkaConsumer;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher eventPublisher;
|
||||
|
||||
private final String topicName = "carJsons";
|
||||
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
log.info("启动线程开始监听topic:{}",topicName);
|
||||
Thread thread = new Thread(() -> {
|
||||
ThreadUtil.sleep(1000);
|
||||
Collection<String> topics = Lists.newArrayList(topicName);
|
||||
kafkaConsumer.subscribe(topics);
|
||||
while (true){
|
||||
ConsumerRecords<String,String> consumerRecords = kafkaConsumer.poll(Duration.ofMillis(1000));
|
||||
for (ConsumerRecord<String, String> consumerRecord : consumerRecords) {
|
||||
//从consumerRecord中获取消费数据
|
||||
String value = consumerRecord.value();
|
||||
log.info("从Kafka中消费的原始数据===============>>:{}",value);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("开始监听kafka-topic:{}",topicName);
|
||||
List<String> topics = Collections.singletonList(topicName);
|
||||
kafkaConsumer.subscribe(topics);
|
||||
|
||||
log.info("启动线程结束监听topic:{}",topicName);
|
||||
while (true){
|
||||
ConsumerRecords<String,String> consumerRecords = kafkaConsumer.poll(Duration.ofMillis(100));
|
||||
consumerRecords.forEach(record ->{
|
||||
executorService.submit(() -> handleRecord(record));
|
||||
log.info("数据为:{},消费成功!",record);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRecord(ConsumerRecord<String,String> record) {
|
||||
String value = record.value();
|
||||
JSONObject jsonObject = JSONObject.parseObject(value);
|
||||
eventPublisher.publishEvent(jsonObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent event) {
|
||||
log.info("关闭kafka和线程");
|
||||
kafkaConsumer.close();
|
||||
executorService.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
package com.muyu.carData.controller;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
|
@ -8,13 +9,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
*/
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:TestController
|
||||
* @Date:2024/9/26 23:56
|
||||
*/
|
||||
*//*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/testCache")
|
||||
@Log4j2
|
||||
|
@ -42,3 +45,4 @@ public class CacheController {
|
|||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
package com.muyu.carData.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
@ -9,13 +10,15 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
*/
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.testcontroller
|
||||
* @Project:cloud-server-8
|
||||
* @name:KafkaProducerController
|
||||
* @Date:2024/9/28 15:10
|
||||
*/
|
||||
*//*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/produce")
|
||||
@Log4j2
|
||||
|
@ -43,3 +46,4 @@ public class KafkaProducerController {
|
|||
|
||||
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -15,8 +15,12 @@ public class EsSaveEvent extends ApplicationEvent {
|
|||
private JSONObject data;
|
||||
|
||||
|
||||
public EsSaveEvent(JSONObject source) {
|
||||
public EsSaveEvent(Object source,JSONObject data) {
|
||||
super(source);
|
||||
this.data = source;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public JSONObject getData(){
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.carData.event;
|
||||
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
/** 事件监听接口
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.event
|
||||
* @Project:cloud-server-8
|
||||
* @name:EventListener
|
||||
* @Date:2024/10/4 10:39
|
||||
*/
|
||||
public interface EventListener extends ApplicationListener<EsSaveEvent> {
|
||||
|
||||
void onEvent(EsSaveEvent event);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.carData.event;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 策略发送事件
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.event
|
||||
* @Project:cloud-server-8
|
||||
* @name:EventPublisher
|
||||
* @Date:2024/10/4 10:40
|
||||
*/
|
||||
@Component
|
||||
public class EventPublisher implements ApplicationEventPublisherAware {
|
||||
|
||||
private ApplicationEventPublisher publisher;
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.publisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
public void publishEvent(JSONObject message){
|
||||
EsSaveEvent esSaveEvent = new EsSaveEvent(this, message);
|
||||
publisher.publishEvent(esSaveEvent);
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:CustomEventListener
|
||||
* @Date:2024/9/29 23:49
|
||||
*/
|
||||
@Component
|
||||
public class CustomEventListener {
|
||||
|
||||
@EventListener
|
||||
public void handMyEvent(EsSaveEvent event){
|
||||
//处理事件详情
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.config.lotdbconfig.IotDBSessionConfig;
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import com.muyu.carData.event.EventListener;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** 数据持久化事件
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:InsertIotDBListener
|
||||
* @Date:2024/10/6 9:25
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class InsertIotDBListener implements EventListener {
|
||||
@Override
|
||||
public void onEvent(EsSaveEvent event) {
|
||||
JSONObject jsonObject = event.getData();
|
||||
log.info("持久化:监听到数据:{}", jsonObject);
|
||||
List<String> keys = new ArrayList<>();
|
||||
List<String> values = new ArrayList<>();
|
||||
|
||||
jsonObject.forEach((key,value) -> {
|
||||
keys.add(key);
|
||||
values.add((String) value);
|
||||
});
|
||||
|
||||
IotDBSessionConfig iotDBSessionConfig = new IotDBSessionConfig();
|
||||
long time = System.currentTimeMillis();
|
||||
iotDBSessionConfig.execute("root.vehicle",time,keys,values);
|
||||
log.info("数据写入成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EsSaveEvent event) {
|
||||
onEvent(event);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
/**自定义监听器
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:MyListener
|
||||
* @Date:2024/9/29 21:18
|
||||
*/
|
||||
@Log4j2
|
||||
public class MyListener implements ApplicationListener<EsSaveEvent> {
|
||||
@Override
|
||||
public void onApplicationEvent(EsSaveEvent event) {
|
||||
log.info("监听到自定义事件........");
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.muyu.carData.pojo;
|
||||
|
||||
import com.muyu.carData.config.cacheconfig.ExpiryTime;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.pojo
|
||||
* @Project:cloud-server-8
|
||||
* @name:Student
|
||||
* @Date:2024/9/27 0:40
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Student extends ExpiryTime{
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 插入时间
|
||||
*/
|
||||
private long time = System.currentTimeMillis();
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.muyu.carData.pulisher;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**事件发布测试
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.pulisher
|
||||
* @Project:cloud-server-8
|
||||
* @name:CustomEventPublisher
|
||||
* @Date:2024/9/29 23:51
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class CustomEventPublisher {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
public void publish(JSONObject data){
|
||||
EsSaveEvent esSaveEvent = new EsSaveEvent(data);
|
||||
applicationEventPublisher.publishEvent(esSaveEvent);
|
||||
log.info("事件发布成功 - 消息是:{}",data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.carData.util;
|
||||
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 缓存工具类
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.util
|
||||
* @Project:cloud-server-8
|
||||
* @name:CacheUtil
|
||||
* @Date:2024/10/4 10:42
|
||||
*/
|
||||
@Component
|
||||
public class CacheUtil<T> {
|
||||
|
||||
private final Cache<String,T> cache;
|
||||
|
||||
public CacheUtil() {
|
||||
this.cache = Caffeine.newBuilder()
|
||||
.maximumSize(500L)
|
||||
.build();
|
||||
}
|
||||
|
||||
public T get(String key) {
|
||||
return (T)cache.getIfPresent(key);
|
||||
}
|
||||
|
||||
public void put(String key, T value) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
|
||||
public void remove(String key) {
|
||||
cache.invalidate(key);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import java.util.function.Supplier;
|
|||
|
||||
/**
|
||||
* 车辆报文模板实体类
|
||||
*
|
||||
* @author 17353
|
||||
*/
|
||||
@Data
|
||||
|
@ -18,7 +19,7 @@ import java.util.function.Supplier;
|
|||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Tag(name = "车辆报文模板实体类")
|
||||
@TableName(value = "car_message",autoResultMap = true)
|
||||
@TableName(value = "car_message", autoResultMap = true)
|
||||
public class CarMessage {
|
||||
//报文类型模块表
|
||||
/**
|
||||
|
@ -68,8 +69,11 @@ public class CarMessage {
|
|||
*/
|
||||
private Integer carMessageState;
|
||||
|
||||
private String carMessageName;
|
||||
|
||||
/**
|
||||
* 修改方法
|
||||
*
|
||||
* @param carMessage
|
||||
* @param supplier
|
||||
* @return
|
||||
|
@ -92,6 +96,7 @@ public class CarMessage {
|
|||
|
||||
/**
|
||||
* 添加方法
|
||||
*
|
||||
* @param carMessage
|
||||
* @return
|
||||
*/
|
||||
|
@ -127,7 +132,4 @@ public class CarMessage {
|
|||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class KafKaData {
|
||||
private String key;
|
||||
private String type;
|
||||
private String label;
|
||||
private String value;
|
||||
}
|
|
@ -28,6 +28,12 @@
|
|||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- mqttv3 -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -38,17 +44,6 @@
|
|||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
</dependency>
|
||||
<!--远调端Feign-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!-- mqttv3 -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -103,7 +98,6 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-kafka</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
//package com.muyu.server.feign;
|
||||
//
|
||||
//import org.springframework.cloud.openfeign.FeignClient;
|
||||
//import org.springframework.web.bind.annotation.GetMapping;
|
||||
//
|
||||
//@FeignClient(name = "cloud-modules-carData",value = "KafkaProducerController")
|
||||
//public abstract class KafkaClient {
|
||||
// /**
|
||||
// * 处理"/produceTest"的GET请求,用于执行特定的测试任务
|
||||
// * 此方法的具体实现将在子类中定义
|
||||
// * @return 返回类型为String,表示该方法的执行结果
|
||||
// * @return
|
||||
// */
|
||||
// @GetMapping("/produceTest")
|
||||
// public abstract String produceTest();
|
||||
//
|
||||
//
|
||||
//}
|
|
@ -1,105 +0,0 @@
|
|||
package com.muyu.server.mqtt;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||
import com.muyu.domain.CarMessage;
|
||||
import com.muyu.server.service.CarMessageService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@Component
|
||||
public class Demo {
|
||||
@Resource
|
||||
private CarMessageService service;
|
||||
@Resource
|
||||
private KafkaProducer<String, String> kafkaProducer;
|
||||
@PostConstruct
|
||||
public void test() {
|
||||
|
||||
String topic = "vehicle";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://106.15.136.7:1883";
|
||||
String clientId = "JavaSample";
|
||||
|
||||
try {
|
||||
// 第三个参数为空,默认持久化策略
|
||||
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
System.out.println("Connecting to broker: "+broker);
|
||||
sampleClient.connect(connOpts);
|
||||
sampleClient.subscribe(topic,0);
|
||||
sampleClient.setCallback(new MqttCallback() {
|
||||
// 连接丢失
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
|
||||
}
|
||||
// 连接成功
|
||||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
|
||||
List<CarMessage> list= service.selectCarMessageList(1,2);
|
||||
String str = new String( mqttMessage.getPayload() );
|
||||
System.out.println(str);
|
||||
String[] test = str.split(" ");
|
||||
String[] results = new String[list.size()];
|
||||
List<CompletableFuture<String>> futures = new ArrayList<>();
|
||||
for (CarMessage carmsg : list) {
|
||||
futures.add(CompletableFuture.supplyAsync(() -> {
|
||||
int startIndex = Integer.parseInt(String.valueOf(carmsg.getCarMessageStartIndex())) - 1;
|
||||
int endIndex = Integer.parseInt(String.valueOf(carmsg.getCarMessageEndIndex()));
|
||||
StringBuilder hexBuilder = new StringBuilder();
|
||||
for (int j = startIndex; j < endIndex; j++) {
|
||||
hexBuilder.append(test[j]);
|
||||
}
|
||||
// 创建16进制的对象
|
||||
String hex = hexBuilder.toString();
|
||||
// 转橙字符数组
|
||||
char[] result = new char[hex.length() / 2];
|
||||
for (int x = 0; x < hex.length(); x += 2) {
|
||||
// 先转十进制
|
||||
int high = Character.digit(hex.charAt(x), 16);
|
||||
// 转二进制
|
||||
int low = Character.digit(hex.charAt(x + 1), 16);
|
||||
// 转字符
|
||||
result[x / 2] = (char) ((high << 4) + low);
|
||||
}
|
||||
return new String(result);
|
||||
}));
|
||||
}
|
||||
for (int i = 0; i < futures.size(); i++) {
|
||||
results[i] = futures.get(i).get();
|
||||
}
|
||||
String jsonString = JSONObject.toJSONString( results );
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>( KafkaConstants.KafkaTopic, jsonString);
|
||||
kafkaProducer.send(producerRecord);
|
||||
}
|
||||
// 接收信息
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch(MqttException me) {
|
||||
System.out.println("reason "+me.getReasonCode());
|
||||
System.out.println("msg "+me.getMessage());
|
||||
System.out.println("loc "+me.getLocalizedMessage());
|
||||
System.out.println("cause "+me.getCause());
|
||||
System.out.println("excep "+me);
|
||||
me.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -53,11 +53,4 @@ public interface CarMessageService extends IService<CarMessage> {
|
|||
* 获取报文最终信息
|
||||
*/
|
||||
JSONObject inciseCarMessage(String testString);
|
||||
|
||||
|
||||
List<CarMessage> selectCarMessageList(int i, int i1);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -110,14 +110,6 @@ public class CarMessageServiceImpl
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CarMessage> selectCarMessageList(int id, int modelCode) {
|
||||
LambdaQueryWrapper<CarMessage> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CarMessage::getCarMessageId, id);
|
||||
queryWrapper.eq(CarMessage::getCarMessageType, modelCode);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//报文处理
|
||||
|
|
|
@ -26,7 +26,7 @@ public class MessageDao {
|
|||
}
|
||||
|
||||
public void sendMessage(Message message) throws Exception{
|
||||
String sql="INSERT INTO `eight`.`car_fault_message` (`id`, `sender`, `receiver`, `content`, `status`, `create_time`, `user_id`) " +
|
||||
String sql="INSERT INTO `xxy`.`car_fault_message` (`id`, `sender`, `receiver`, `content`, `status`, `create_time`, `user_id`) " +
|
||||
"VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
|
||||
try(PreparedStatement pstmt=connection.prepareStatement(sql)){
|
||||
pstmt.setString(1, message.getContent());
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: eight
|
||||
namespace: xxy
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: eight
|
||||
namespace: xxy
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-modules-protocolparsing</artifactId>
|
||||
<dependencies>
|
||||
<!--远调端Feign-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!-- mqttv3 -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!--apache.kafka<-->
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-log</artifactId>
|
||||
</dependency>
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.4.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-kafka</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class ProtocolApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ProtocolApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.controller;
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
import com.muyu.domain.CarMessage;
|
||||
import com.muyu.service.CarMessageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报文模板展示列表控制层
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/carMessage")
|
||||
@Tag(name = "信息报文模块" )
|
||||
public class CarMessageController {
|
||||
|
||||
|
||||
/**
|
||||
* 测试分割字符
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 车辆报文模板实体类
|
||||
*
|
||||
* @author 17353
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Tag(name = "车辆报文模板实体类")
|
||||
@TableName(value = "car_message", autoResultMap = true)
|
||||
public class CarMessage {
|
||||
//报文类型模块表
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
private Long messageTypeId;
|
||||
/**
|
||||
* 报文编码
|
||||
*/
|
||||
private String messageTypeCode;
|
||||
/**
|
||||
* 报文名称
|
||||
*/
|
||||
private String messageTypeName;
|
||||
/**
|
||||
* 报文所属类别
|
||||
*/
|
||||
private String messageTypeBelongs;
|
||||
|
||||
//报文拆分位置主表
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
private Long carMessageId;
|
||||
/**
|
||||
* 车辆类型外键
|
||||
*/
|
||||
private Integer carMessageCartype;
|
||||
/**
|
||||
* 车辆报文类型外键
|
||||
*/
|
||||
private Integer carMessageType;
|
||||
/**
|
||||
* 开始位下标
|
||||
*/
|
||||
private Integer carMessageStartIndex;
|
||||
/**
|
||||
* 结束位下标
|
||||
*/
|
||||
private Integer carMessageEndIndex;
|
||||
/**
|
||||
* 报文数据类型 (固定值 区间随机值)
|
||||
*/
|
||||
private String messageTypeClass;
|
||||
/**
|
||||
* 报文是否开启故障检测(0默认未开启 1开启)
|
||||
*/
|
||||
private Integer carMessageState;
|
||||
|
||||
private String carMessageName;
|
||||
|
||||
/**
|
||||
* 修改方法
|
||||
*
|
||||
* @param carMessage
|
||||
* @param supplier
|
||||
* @return
|
||||
*/
|
||||
public static CarMessage carMessageUpdBuilder(CarMessage carMessage, Supplier<Long> supplier) {
|
||||
return CarMessage.builder()
|
||||
.messageTypeId(supplier.get())
|
||||
.messageTypeCode(carMessage.messageTypeCode)
|
||||
.messageTypeName(carMessage.messageTypeName)
|
||||
.messageTypeBelongs(carMessage.messageTypeBelongs)
|
||||
.carMessageId(carMessage.carMessageId)
|
||||
.carMessageCartype(carMessage.carMessageCartype)
|
||||
.carMessageType(carMessage.carMessageType)
|
||||
.carMessageStartIndex(carMessage.carMessageStartIndex)
|
||||
.carMessageEndIndex(carMessage.carMessageEndIndex)
|
||||
.messageTypeClass(carMessage.messageTypeClass)
|
||||
.carMessageState(carMessage.carMessageState)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加方法
|
||||
*
|
||||
* @param carMessage
|
||||
* @return
|
||||
*/
|
||||
public static CarMessage carMessageAddBuilder(CarMessage carMessage) {
|
||||
return CarMessage.builder()
|
||||
.messageTypeCode(carMessage.messageTypeCode)
|
||||
.messageTypeName(carMessage.messageTypeName)
|
||||
.messageTypeBelongs(carMessage.messageTypeBelongs)
|
||||
.carMessageId(carMessage.carMessageId)
|
||||
.carMessageCartype(carMessage.carMessageCartype)
|
||||
.carMessageType(carMessage.carMessageType)
|
||||
.carMessageStartIndex(carMessage.carMessageStartIndex)
|
||||
.carMessageEndIndex(carMessage.carMessageEndIndex)
|
||||
.messageTypeClass(carMessage.messageTypeClass)
|
||||
.carMessageState(carMessage.carMessageState)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
private Long messageTypeId ;
|
||||
private String messageTypeCode ;
|
||||
private String messageTypeName ;
|
||||
private String messageTypeBelongs ;
|
||||
private String messageTypeClass ;
|
||||
private Long carMessageId ;
|
||||
private Integer carMessageCartype ;
|
||||
private Integer carMessageType ;
|
||||
private Integer carMessageStartIndex ;
|
||||
private Integer carMessageEndIndex ;
|
||||
private Integer carMessageState ;
|
||||
*/
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆报文所属类型
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.warn.domain.car
|
||||
* @Project:cloud-server-8
|
||||
* @name:CarMessage
|
||||
* @Date:2024/9/22 下午3:07
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tag(name = "车辆报文所属类型")
|
||||
@TableName(value = "car_message_type",autoResultMap = true)
|
||||
public class CarMessageType {
|
||||
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
private Integer messageTypeId ;
|
||||
/**
|
||||
* 报文编码
|
||||
*/
|
||||
private String messageTypeCode ;
|
||||
/**
|
||||
* 报文名称
|
||||
*/
|
||||
private String messageTypeName ;
|
||||
/**
|
||||
* 报文所属类别
|
||||
*/
|
||||
private String messageTypeBelongs ;
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class KafKaData {
|
||||
private String key;
|
||||
private String type;
|
||||
private String label;
|
||||
private String value;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.muyu.domain.resp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆报文信息(预警)响应对象
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.warn.domain.car
|
||||
* @Project:cloud-server-8
|
||||
* @name:resp
|
||||
* @Date:2024/9/22 下午7:12
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tag(name = "车辆报文信息")
|
||||
public class CarMessageResp {
|
||||
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
private Integer carMessageId ;
|
||||
/**
|
||||
* 车辆类型外键
|
||||
*/
|
||||
private Integer carMessageCartype ;
|
||||
/**
|
||||
* 车辆报文外键
|
||||
*/
|
||||
private Integer carMessageType ;
|
||||
/**
|
||||
* 报文名称
|
||||
*/
|
||||
private String messageTypeName ;
|
||||
/**
|
||||
* 开始位下标
|
||||
*/
|
||||
private Integer carMessageStartIndex ;
|
||||
/**
|
||||
* 结束位下标
|
||||
*/
|
||||
private Integer carMessageEndIndex ;
|
||||
/**
|
||||
* 报文数据类型 (固定值 区间随机值)
|
||||
*/
|
||||
private String messageTypeClass ;
|
||||
/**
|
||||
* 报文是否开启故障检测(0默认未开启 1开启)
|
||||
*/
|
||||
private Integer carMessageState ;
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.feign;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@FeignClient(name = "cloud-modules-carData")
|
||||
public interface KafkaClient {
|
||||
/**
|
||||
* 处理"/produceTest"的GET请求,用于执行特定的测试任务
|
||||
* 此方法的具体实现将在子类中定义
|
||||
* @return 返回类型为String,表示该方法的执行结果
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/produce/producer")
|
||||
public abstract String producerKafka(JSONObject data);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.mapper;
|
||||
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.muyu.domain.CarInformation;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* 车辆信息管理持久层
|
||||
*/
|
||||
@Mapper
|
||||
public interface CarInformationMapper extends MPJBaseMapper<CarInformation> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据车辆VIN码获取车辆类型(报文模板分类用的值)
|
||||
* @param carInformationVIN
|
||||
* @return
|
||||
*/
|
||||
@Select("SELECT `car_information`.car_Information_Type FROM `car_information` WHERE `car_information`.car_information_VIN = #{carInformationVIN}")
|
||||
Long selectcarMessageCartype(@Param("carInformationVIN") String carInformationVIN);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.muyu.domain.CarMessage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报文模板展示列表持久层
|
||||
*/
|
||||
@Mapper
|
||||
public interface CarMessageMapper extends MPJBaseMapper<CarMessage> {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.muyu.mapper;
|
||||
|
||||
import com.muyu.domain.CarMessage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@Mapper
|
||||
public interface CarMessagePlusMapper {
|
||||
|
||||
List<CarMessage> selectCarMessageList(@Param("carMessageCartype") Integer carMessageCartype);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.muyu.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.muyu.domain.CarMessageType;
|
||||
|
||||
|
||||
public interface CarMessageTypeMapper extends MPJBaseMapper<CarMessageType> {
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package com.muyu.mqtt;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import com.muyu.domain.CarMessage;
|
||||
import com.muyu.domain.KafKaData;
|
||||
import com.muyu.service.CarMessageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* mqtt
|
||||
*
|
||||
* @ClassName MqttTest
|
||||
* @Description
|
||||
* @Date 2024/9/28 23:49
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MqttTest {
|
||||
private static final Integer ID = 1;
|
||||
private static final Integer CODE = 1;
|
||||
|
||||
@Resource
|
||||
private KafkaProducer<String, String> kafkaProducer;
|
||||
@Resource
|
||||
private CarMessageService sysCarMessageService;
|
||||
|
||||
@PostConstruct
|
||||
public void Test() {
|
||||
String topic = "vehicle";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://60.204.221.52:1883";
|
||||
String clientId = "JavaSample";
|
||||
try {
|
||||
// 第三个参数为空,默认持久化策略
|
||||
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
System.out.println("Connecting to broker: " + broker);
|
||||
sampleClient.connect(connOpts);
|
||||
sampleClient.subscribe(topic, 0);
|
||||
sampleClient.setCallback(new MqttCallback() {
|
||||
// 连接丢失
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
// 连接成功
|
||||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
List<CarMessage> list = sysCarMessageService.selectCarMessage(1);
|
||||
String string = new String(mqttMessage.getPayload());
|
||||
log.info(new String(mqttMessage.getPayload()));
|
||||
List<KafKaData> kafKaDataList = new ArrayList<>();
|
||||
String[] test = string.split(" ");
|
||||
// String[] results = new String[list.size()];
|
||||
for (CarMessage carMessage : list) {
|
||||
int startIndex = Integer.parseInt(String.valueOf(carMessage.getCarMessageStartIndex())) - 1;
|
||||
int endIndex = Integer.parseInt(String.valueOf(carMessage.getCarMessageEndIndex()));
|
||||
StringBuilder hexBuilder = new StringBuilder();
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
hexBuilder.append(test[i]);
|
||||
}
|
||||
String hex = hexBuilder.toString();
|
||||
char[] result = new char[hex.length() / 2];
|
||||
for (int x = 0; x < hex.length(); x += 2) {
|
||||
int high = Character.digit(hex.charAt(x), 16);
|
||||
int low = Character.digit(hex.charAt(x + 1), 16);
|
||||
result[x / 2] = (char) ((high << 4) + low);
|
||||
}
|
||||
String value = new String(result);
|
||||
kafKaDataList.add(KafKaData.builder()
|
||||
.key(carMessage.getMessageTypeCode())
|
||||
.label(carMessage.getMessageTypeCode())
|
||||
.value(value)
|
||||
.type("String")
|
||||
.build());
|
||||
}
|
||||
String jsonString = JSONObject.toJSONString(kafKaDataList);
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>("carJsons", jsonString);
|
||||
kafkaProducer.send(producerRecord);
|
||||
log.info("kafka投产:{}", jsonString);
|
||||
// HashMap<String, String> stringStringHashMap = new HashMap<>();
|
||||
// kafKaDataList.forEach(data -> stringStringHashMap.put(data.getKey(), data.getValue()));
|
||||
// jsonString = JSONObject.toJSONString(stringStringHashMap);
|
||||
// System.out.println(jsonString);
|
||||
}
|
||||
|
||||
// 接收信息
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
} catch (MqttException me) {
|
||||
System.out.println("reason " + me.getReasonCode());
|
||||
System.out.println("msg " + me.getMessage());
|
||||
System.out.println("loc " + me.getLocalizedMessage());
|
||||
System.out.println("cause " + me.getCause());
|
||||
System.out.println("excep " + me);
|
||||
me.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
package com.muyu.mqtt;//package com.muyu.server.mqtt;
|
||||
//
|
||||
//import com.muyu.analysis.parsing.remote.RemoteClientService;
|
||||
//import com.muyu.common.core.constant.KafkaConstants;
|
||||
//import com.muyu.common.core.constant.RedisConstants;
|
||||
//import com.muyu.common.core.domain.Result;
|
||||
//import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||
//import com.muyu.server.feign.KafkaClient;
|
||||
//import jakarta.annotation.PostConstruct;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import cn.hutool.json.JSONObject;
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import lombok.extern.log4j.Log4j2;
|
||||
//import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
//import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
//import org.eclipse.paho.client.mqttv3.*;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.data.redis.core.RedisTemplate;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * 协议解析处理数据发送传送到队列
|
||||
// * @Author:李庆帅
|
||||
// * @Package:com.muyu.analysis.parsing.MQTT
|
||||
// * @Project:cloud-server
|
||||
// * @name:ParsingMQTT
|
||||
// * @Date:2024/9/29 16:08
|
||||
// */
|
||||
//@Log4j2
|
||||
//@Component
|
||||
//public class ParsingMQTT {
|
||||
//
|
||||
// @Resource
|
||||
// private RedisTemplate<String, Object> redisTemplate;
|
||||
//
|
||||
// @Autowired
|
||||
// private KafkaClient remoteServiceClient;
|
||||
//
|
||||
// @Resource
|
||||
// private KafkaProducer<String, String> kafkaProducer;
|
||||
//
|
||||
// /**
|
||||
// * 协议解析
|
||||
// */
|
||||
// @PostConstruct
|
||||
// public void mqttClient() {
|
||||
// String topic = "vehicle";
|
||||
// String broker = "tcp://106.15.136.7:1883";
|
||||
// String clientId = "JavaSample";
|
||||
//
|
||||
// try {
|
||||
// // 第三个参数为空,默认持久化策略
|
||||
// MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||
// MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
// connOpts.setCleanSession(true);
|
||||
// System.out.println("Connecting to broker: " + broker);
|
||||
// sampleClient.connect(connOpts);
|
||||
// sampleClient.subscribe(topic, 0);
|
||||
// sampleClient.setCallback(new MqttCallback() {
|
||||
// // 连接丢失
|
||||
// @Override
|
||||
// public void connectionLost(Throwable throwable) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // 连接成功
|
||||
// @Override
|
||||
// public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
// System.out.println(new String(mqttMessage.getPayload()));
|
||||
// JSONObject entries = this.protocolParsing(new String(mqttMessage.getPayload()));
|
||||
//
|
||||
// ProducerRecord<String, String> producerRecord = new ProducerRecord<>(KafkaConstants.MESSAGE_PARSING,
|
||||
// entries.toString() );
|
||||
// kafkaProducer.send(producerRecord);
|
||||
// log.info("解析之后的数据"+entries);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 协议解析
|
||||
// * @param messageStr
|
||||
// * @return
|
||||
// */
|
||||
// public JSONObject protocolParsing(String messageStr) {
|
||||
// //根据空格切割数据
|
||||
// String[] hexArray = messageStr.split(" ");
|
||||
// StringBuilder result = new StringBuilder();
|
||||
// //遍历十六进制数据转换为字符
|
||||
// for (String hex : hexArray) {
|
||||
// int decimal = Integer.parseInt(hex, 16);
|
||||
// result.append((char) decimal);
|
||||
// }
|
||||
// //取出车辆VIN码
|
||||
// String vehicleVin = result.substring(1, 18);
|
||||
// log.info("车辆VIN码: " + vehicleVin);
|
||||
// //根据车辆VIN码查询报文模板ID
|
||||
// Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
|
||||
// Long templateId = byVehicleVin.getData();
|
||||
// List<MessageValueListResp> templateList;
|
||||
// //从redis缓存中获取报文模板数据
|
||||
// try {
|
||||
// String redisKey = RedisConstants.MESSAGE_TEMPLATE + templateId;
|
||||
// if (redisTemplate.hasKey(redisKey)) {
|
||||
// List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
||||
// templateList = list.stream()
|
||||
// .map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
||||
// .toList();
|
||||
// log.info("Redis缓存查询成功");
|
||||
// } else {
|
||||
// Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.producerKafka(templateId);
|
||||
// templateList = byTemplateId.getData();
|
||||
// templateList.forEach(
|
||||
// listResp ->
|
||||
// redisTemplate.opsForList().rightPush(
|
||||
// redisKey, JSON.toJSONString(listResp)
|
||||
// )
|
||||
// );
|
||||
// log.info("数据库查询成功:"+byTemplateId);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.info("获取报文模板失败");
|
||||
// throw new RuntimeException("获取报文模板失败");
|
||||
// }
|
||||
// //判断报文模板列表不为空
|
||||
// if (templateList.isEmpty()) {
|
||||
// log.info("报文模版为空");
|
||||
// throw new RuntimeException("报文模版为空");
|
||||
// }
|
||||
// //存储报文模版解析后的数据
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// for (MessageValueListResp messageValue : templateList) {
|
||||
// //起始位下标
|
||||
// Integer startIndex = messageValue.getMessageStartIndex() - 1;
|
||||
// //结束位下标
|
||||
// Integer endIndex = messageValue.getMessageEndIndex();
|
||||
// //根据报文模版截取数据
|
||||
// String value = result.substring(startIndex, endIndex);
|
||||
// //存入数据
|
||||
// jsonObject.put(messageValue.getMessageLabel(), value);
|
||||
// }
|
||||
// return jsonObject;
|
||||
// }
|
||||
//
|
||||
// // 接收信息
|
||||
// @Override
|
||||
// public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// } catch (MqttException me) {
|
||||
// log.info("reason " + me.getReasonCode());
|
||||
// log.info("msg " + me.getMessage());
|
||||
// log.info("loc " + me.getLocalizedMessage());
|
||||
// log.info("cause " + me.getCause());
|
||||
// log.info("excep " + me);
|
||||
// me.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.CarMessage;
|
||||
import com.muyu.domain.resp.CarMessageResp;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报文模板展示列表业务层
|
||||
*/
|
||||
public interface CarMessageService extends IService<CarMessage> {
|
||||
|
||||
|
||||
|
||||
|
||||
//报文切割
|
||||
/**
|
||||
* 分割字符串
|
||||
* 解析字符
|
||||
* 获取报文最终信息
|
||||
*/
|
||||
JSONObject inciseCarMessage(String testString);
|
||||
|
||||
|
||||
List<CarMessage> selectCarMessageList(int modelCode);
|
||||
|
||||
|
||||
List<CarMessage> selectCarMessage(@Param("carMessageCartype") Integer carMessageCartype);
|
||||
|
||||
|
||||
List<CarMessage> selectCarMessageListAll(int i);
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package com.muyu.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.domain.CarMessage;
|
||||
|
||||
import com.muyu.domain.resp.CarMessageResp;
|
||||
import com.muyu.mapper.CarInformationMapper;
|
||||
import com.muyu.mapper.CarMessageMapper;
|
||||
import com.muyu.mapper.CarMessagePlusMapper;
|
||||
import com.muyu.service.CarMessageService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报文模板展示列表业务实现层
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class CarMessageServiceImpl
|
||||
extends ServiceImpl<CarMessageMapper, CarMessage>
|
||||
implements CarMessageService {
|
||||
@Resource
|
||||
private CarMessageMapper carMessageMapper;
|
||||
|
||||
@Resource
|
||||
private CarMessagePlusMapper carMessagePlusMapper;
|
||||
|
||||
@Resource
|
||||
private CarInformationMapper carInformationMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<CarMessage> selectCarMessageList(int modelCode) {
|
||||
LambdaQueryWrapper<CarMessage> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CarMessage::getCarMessageCartype, modelCode);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CarMessage> selectCarMessage(Integer carMessageCartype) {
|
||||
return carMessagePlusMapper.selectCarMessageList(carMessageCartype);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CarMessage> selectCarMessageListAll(int i) {
|
||||
LambdaQueryWrapper<CarMessage> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CarMessage::getCarMessageCartype, i);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject inciseCarMessage(String testString) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//报文处理
|
||||
// @Resource
|
||||
// private RedisTemplate<String ,Objects > redisTemplate;
|
||||
//
|
||||
// /**
|
||||
// * 报文解析
|
||||
// * @param testString
|
||||
// * @return
|
||||
// */
|
||||
// @Override
|
||||
// public JSONObject inciseCarMessage(String testString) {
|
||||
// //根据空格拆分切割数据字符串
|
||||
// String[] split = testString.split(" ");
|
||||
// StringBuilder stringBuilder = new StringBuilder();
|
||||
// for (String conversion : split) {
|
||||
// //将16进制字符串转换为对应的10进制
|
||||
// int inciseindex = Integer.parseInt(conversion, 16);
|
||||
// // 将10进制转换为对应的字符
|
||||
// stringBuilder.append((char) inciseindex);
|
||||
// }
|
||||
// //切取车辆VIN
|
||||
// String substring = stringBuilder.substring(1, 18);
|
||||
// log.info("车辆的VIN码:" + substring);
|
||||
// //根据给定的vehicleVin(车辆VIN号)获取对应的模板车辆分类carMessageCartype
|
||||
// String selectcared = carInformationMapper.selectcarMessageCartype(substring);
|
||||
// //创建接受数据的数组
|
||||
// List<CarMessage> messagesList ;
|
||||
//
|
||||
// try{
|
||||
// String redisKey = "carMessageList" + selectcared;
|
||||
//
|
||||
// if (redisTemplate.hasKey(redisKey)){
|
||||
// List<Objects> list = redisTemplate.opsForList().range(redisKey , 0, -1);
|
||||
// messagesList = list.stream()
|
||||
// .map(objects -> JSON.parseObject(objects.toString(), CarMessage.class))
|
||||
// .toList();
|
||||
// log.info("Redis缓存查询成功");
|
||||
// }else {
|
||||
// messagesList = carInformationMapper.selectcarMessageCartype(selectcared);
|
||||
//
|
||||
// messagesList.forEach(
|
||||
// listReq -> redisTemplate.opsForList().rightPushAll(redisKey, JSON.toString(listReq) )
|
||||
// );
|
||||
// log.info("数据库查询成功");
|
||||
// }
|
||||
// }catch(Exception e){
|
||||
// throw new RuntimeException("获取报文模板失败");
|
||||
// }
|
||||
// //判断报文模板 列表 不为空
|
||||
// if(messagesList.isEmpty()){
|
||||
// throw new RuntimeException("报文模版为空");
|
||||
// }
|
||||
// //存储报文模板解析后的数据
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// for (CarMessage carMessage : messagesList) {
|
||||
// //起始位下标
|
||||
// Integer startIndex = carMessage.getCarMessageStartIndex();
|
||||
// //结束位下标
|
||||
// Integer endIndex = carMessage.getCarMessageEndIndex();
|
||||
// //根据报文模板获取保温截取位置
|
||||
// String value = stringBuilder.substring(startIndex, endIndex);
|
||||
// //存入数据
|
||||
// jsonObject.put(carMessage.getMessageTypeName(), value);
|
||||
//
|
||||
// }
|
||||
// return jsonObject;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-electronic"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-electronic"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-electronic"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<!-- 1.在mybats的开发中namespace有特殊的意思,一定要是对应接口的全限定名通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)-->
|
||||
|
||||
<mapper namespace="com.muyu.mapper.CarMessagePlusMapper">
|
||||
|
||||
|
||||
<select id="selectCarMessageList" resultType="com.muyu.domain.CarMessage">
|
||||
select * from `car_message` where car_message_cartype = #{carMessageCartype}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: eight
|
||||
namespace: xxy
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<module>cloud-modules-gen</module>
|
||||
<module>cloud-modules-file</module>
|
||||
<module>cloud-modules-carData</module>
|
||||
<module>cloud-modules-protocolparsing</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: eight
|
||||
namespace: xxy
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
Loading…
Reference in New Issue