Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
|
4a8406d4b7 | |
|
ebf78f9b14 | |
|
dd08255e8d | |
|
3bff2fa630 | |
|
824c2118dd | |
|
d3810706f5 | |
|
ad84ffb8c2 | |
|
fa64eefa03 |
|
@ -0,0 +1,35 @@
|
||||||
|
<?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-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>cloud-common-kafka</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.kafka</groupId>
|
||||||
|
<artifactId>kafka-clients</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.muyu.common.kafka.config;
|
||||||
|
|
||||||
|
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||||
|
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||||
|
import org.apache.kafka.common.serialization.Deserializer;
|
||||||
|
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka 消息的消费者 配置类
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class KafkaConsumerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public KafkaConsumer kafkaConsumer() {
|
||||||
|
Map<String, Object> configs = new HashMap<>();
|
||||||
|
//kafka服务端的IP和端口,格式:(ip:port)
|
||||||
|
configs.put("bootstrap.servers", "60.204.221.52:9092");
|
||||||
|
//开启consumer的偏移量(offset)自动提交到Kafka
|
||||||
|
configs.put("enable.auto.commit", true);
|
||||||
|
//consumer的偏移量(offset) 自动提交的时间间隔,单位毫秒
|
||||||
|
configs.put("auto.commit.interval", 5000);
|
||||||
|
//在Kafka中没有初始化偏移量或者当前偏移量不存在情况
|
||||||
|
//earliest, 在偏移量无效的情况下, 自动重置为最早的偏移量
|
||||||
|
//latest, 在偏移量无效的情况下, 自动重置为最新的偏移量
|
||||||
|
//none, 在偏移量无效的情况下, 抛出异常.
|
||||||
|
configs.put("auto.offset.reset", "latest");
|
||||||
|
//请求阻塞的最大时间(毫秒)
|
||||||
|
configs.put("fetch.max.wait", 500);
|
||||||
|
//请求应答的最小字节数
|
||||||
|
configs.put("fetch.min.size", 1);
|
||||||
|
//心跳间隔时间(毫秒)
|
||||||
|
configs.put("heartbeat-interval", 3000);
|
||||||
|
//一次调用poll返回的最大记录条数
|
||||||
|
configs.put("max.poll.records", 500);
|
||||||
|
//指定消费组
|
||||||
|
configs.put("group.id", KafkaConstants.KafkaGrop);
|
||||||
|
//指定key使用的反序列化类
|
||||||
|
Deserializer keyDeserializer = new StringDeserializer();
|
||||||
|
//指定value使用的反序列化类
|
||||||
|
Deserializer valueDeserializer = new StringDeserializer();
|
||||||
|
//创建Kafka消费者
|
||||||
|
KafkaConsumer kafkaConsumer = new KafkaConsumer(configs, keyDeserializer, valueDeserializer);
|
||||||
|
return kafkaConsumer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.muyu.common.kafka.config;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
|
import org.apache.kafka.common.serialization.Serializer;
|
||||||
|
import org.apache.kafka.common.serialization.StringSerializer;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka 消息的生产者 配置类
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class KafkaProviderConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public KafkaProducer kafkaProducer() {
|
||||||
|
Map<String, Object> configs = new HashMap<>();
|
||||||
|
//#kafka服务端的IP和端口,格式:(ip:port)
|
||||||
|
configs.put("bootstrap.servers", "47.116.173.119:9092");
|
||||||
|
//客户端发送服务端失败的重试次数
|
||||||
|
configs.put("retries", 2);
|
||||||
|
//多个记录被发送到同一个分区时,生产者将尝试将记录一起批处理成更少的请求.
|
||||||
|
//此设置有助于提高客户端和服务器的性能,配置控制默认批量大小(以字节为单位)
|
||||||
|
configs.put("batch.size", 16384);
|
||||||
|
//生产者可用于缓冲等待发送到服务器的记录的总内存字节数(以字节为单位)
|
||||||
|
configs.put("buffer-memory", 33554432);
|
||||||
|
//生产者producer要求leader节点在考虑完成请求之前收到的确认数,用于控制发送记录在服务端的持久化
|
||||||
|
//acks=0,设置为0,则生产者producer将不会等待来自服务器的任何确认.该记录将立即添加到套接字(socket)缓冲区并视为已发送.在这种情况下,无法保证服务器已收到记录,并且重试配置(retries)将不会生效(因为客户端通常不会知道任何故障),每条记录返回的偏移量始终设置为-1.
|
||||||
|
//acks=1,设置为1,leader节点会把记录写入本地日志,不需要等待所有follower节点完全确认就会立即应答producer.在这种情况下,在follower节点复制前,leader节点确认记录后立即失败的话,记录将会丢失.
|
||||||
|
//acks=all,acks=-1,leader节点将等待所有同步复制副本完成再确认记录,这保证了只要至少有一个同步复制副本存活,记录就不会丢失.
|
||||||
|
configs.put("acks", "-1");
|
||||||
|
//指定key使用的序列化类
|
||||||
|
Serializer keySerializer = new StringSerializer();
|
||||||
|
//指定value使用的序列化类
|
||||||
|
Serializer valueSerializer = new StringSerializer();
|
||||||
|
//创建Kafka生产者
|
||||||
|
KafkaProducer kafkaProducer = new KafkaProducer(configs, keySerializer, valueSerializer);
|
||||||
|
return kafkaProducer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.muyu.common.kafka.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 胡杨
|
||||||
|
* @date: 2024/7/10
|
||||||
|
* @Description: kafka常量
|
||||||
|
* @Version 1.0.0
|
||||||
|
*/
|
||||||
|
public class KafkaConstants {
|
||||||
|
|
||||||
|
public final static String KafkaTopic = "kafka_topic";
|
||||||
|
|
||||||
|
public final static String KafkaGrop = "kafka_grop";
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
com.muyu.common.kafka.config.KafkaConsumerConfig
|
||||||
|
com.muyu.common.kafka.config.KafkaProviderConfig
|
|
@ -21,6 +21,7 @@
|
||||||
<module>cloud-common-xxl</module>
|
<module>cloud-common-xxl</module>
|
||||||
<module>cloud-common-rabbit</module>
|
<module>cloud-common-rabbit</module>
|
||||||
<module>cloud-common-saas</module>
|
<module>cloud-common-saas</module>
|
||||||
|
<module>cloud-common-kafka</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-common</artifactId>
|
<artifactId>cloud-common</artifactId>
|
||||||
|
|
|
@ -66,16 +66,16 @@
|
||||||
<artifactId>cloud-common-log</artifactId>
|
<artifactId>cloud-common-log</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--apache.kafka<-->
|
||||||
<!-- XllJob定时任务 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>org.apache.kafka</groupId>
|
||||||
<artifactId>cloud-common-xxl</artifactId>
|
<artifactId>kafka-clients</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>org.eclipse.paho</groupId>
|
||||||
<artifactId>cloud-common-rabbit</artifactId>
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
|
<version>1.2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- MuYu Common System-->
|
<!-- MuYu Common System-->
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
package com.muyu.car;
|
package com.muyu.car;
|
||||||
|
|
||||||
|
import com.muyu.car.service.CarMessageService;
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableCaching
|
||||||
public class CarApplication {
|
public class CarApplication {
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
SpringApplication.run(CarApplication.class,args);
|
SpringApplication.run(CarApplication.class,args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.muyu.car.config;
|
||||||
|
|
||||||
|
public class kafka {
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.car.controller;
|
package com.muyu.car.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.muyu.car.domain.CarMessage;
|
import com.muyu.car.domain.CarMessage;
|
||||||
import com.muyu.car.service.CarMessageService;
|
import com.muyu.car.service.CarMessageService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
@ -7,10 +8,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
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 javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -29,8 +27,8 @@ public class CarMessageController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/selectCarMessageList")
|
@PostMapping("/selectCarMessageList")
|
||||||
@Operation(summary = "报文模板展示列表")
|
@Operation(summary = "报文模板展示列表")
|
||||||
public Result<List<CarMessage>> selectCarMessageList(){
|
public Result<List<CarMessage>> selectCarMessageList(Integer carMessageCartype){
|
||||||
List<CarMessage> carMessages = carMessageService.selectCarMessageList();
|
List<CarMessage> carMessages = carMessageService.selectCarMessageList(carMessageCartype);
|
||||||
return Result.success(carMessages);
|
return Result.success(carMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,58 +64,22 @@ public class CarMessageController {
|
||||||
return Result.success(updateCarMessage,"修改成功");
|
return Result.success(updateCarMessage,"修改成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试分割字符
|
||||||
|
*/
|
||||||
|
@PostMapping("/inciseCarMessage")
|
||||||
|
@Operation(summary = "解析报文处理", description = "解析报文测试")
|
||||||
|
public Result<JSONObject> inciseCarMessage(@RequestParam(name = "testString") String testString){
|
||||||
|
JSONObject carMessage = carMessageService.inciseCarMessage(testString);
|
||||||
|
return Result.success(carMessage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试分割字符
|
* 测试分割字符
|
||||||
*/
|
*/
|
||||||
public class MessageParser{
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String message = "01,02,03," +
|
|
||||||
"04,05,06,07,08,09," +
|
|
||||||
"10,11,12,13,14,15,16" +
|
|
||||||
",17,18,19,20,21,22,23," +
|
|
||||||
"24,25,26,27,28,29,30" +
|
|
||||||
",31,32,33,34,35,36,37," +
|
|
||||||
"38,39,40,41,42,43,44,45," +
|
|
||||||
"46";
|
|
||||||
|
|
||||||
|
|
||||||
String[] split = message.split(",");
|
|
||||||
for (int i = 0; i < split.length; i++) {
|
|
||||||
System.out.println(split[i]);
|
|
||||||
if(i == 0){
|
|
||||||
System.out.println("开始");
|
|
||||||
}else if(i == split.length - 1){
|
|
||||||
System.out.println("结束");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(split.length);
|
|
||||||
System.out.println(message.length());
|
|
||||||
|
|
||||||
System.out.println(message.substring(0,1));
|
|
||||||
System.out.println(message.substring(1,2));
|
|
||||||
System.out.println(message.substring(2,3));
|
|
||||||
System.out.println(message.substring(3,4));
|
|
||||||
System.out.println(message.substring(4,5));
|
|
||||||
System.out.println(message.substring(5,6));
|
|
||||||
System.out.println(message.substring(6,7));
|
|
||||||
System.out.println(message.substring(7,8));
|
|
||||||
System.out.println(message.substring(8,9));
|
|
||||||
System.out.println(message.substring(9,10));
|
|
||||||
System.out.println(message.substring(10,11));
|
|
||||||
System.out.println(message.substring(11,12));
|
|
||||||
System.out.println(message.substring(12,13));
|
|
||||||
System.out.println(message.substring(13,14));
|
|
||||||
System.out.println(message.substring(14,15));
|
|
||||||
System.out.println(message.substring(15,16));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.muyu.car.controller;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.Packettemplate;
|
||||||
|
import com.muyu.car.domain.req.PackettemplateAddReq;
|
||||||
|
import com.muyu.car.service.PackertemplateService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@RequestMapping("/packettemplate")
|
||||||
|
@RestController
|
||||||
|
@Tag(name = "报文模板车系分类")
|
||||||
|
public class PackettemplateController {
|
||||||
|
@Resource
|
||||||
|
public PackertemplateService packertemplateService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
*/
|
||||||
|
@PostMapping("/selectAll")
|
||||||
|
@Operation(summary = "报文车系查询")
|
||||||
|
public List<Packettemplate> selectAll(){
|
||||||
|
List<Packettemplate> packettemplates = packertemplateService.selectAll();
|
||||||
|
log.info(packettemplates);
|
||||||
|
return packettemplates;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*/
|
||||||
|
@PostMapping("/addPackert")
|
||||||
|
@Operation(summary = "添加分类模板")
|
||||||
|
public Result addPackert(PackettemplateAddReq packettemplateAddReq){
|
||||||
|
Result result = packertemplateService.addPackert(packettemplateAddReq);
|
||||||
|
log.info(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.muyu.car.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
@TableName(value = "报文模板分类实体类" , autoResultMap = true)
|
||||||
|
public class Packettemplate {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板分类id
|
||||||
|
*/
|
||||||
|
private Integer packetTemplateId;
|
||||||
|
/**
|
||||||
|
* 报文模板分类车型外键
|
||||||
|
*/
|
||||||
|
private Integer packetTemplateCartype;
|
||||||
|
/**
|
||||||
|
* 报文模板分类联报文表外键
|
||||||
|
*/
|
||||||
|
private Integer packetTemplateCarmessage;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.car.domain.req;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
public class PackettemplateAddReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模板分类车型外键
|
||||||
|
*/
|
||||||
|
private Integer packetTemplateCartype;
|
||||||
|
/**
|
||||||
|
* 报文模板分类联报文表外键
|
||||||
|
*/
|
||||||
|
private Integer packetTemplateCarmessage;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.muyu.car.domain.resp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.bouncycastle.crypto.Digest;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Tag(
|
||||||
|
name = "测试代码行",
|
||||||
|
description = "车INdsa"
|
||||||
|
)
|
||||||
|
public class CarINdsa {
|
||||||
|
|
||||||
|
private Long testmessageId;
|
||||||
|
private String testmessagename;
|
||||||
|
private Integer testmessagetodo;
|
||||||
|
private String testmessageagon;
|
||||||
|
private Integer testmessagetest;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private Date dayend;
|
||||||
|
private String testmessagehid;
|
||||||
|
private Integer testmessageyou;
|
||||||
|
private Digest testmessageertug;
|
||||||
|
private String testmessagebug;
|
||||||
|
private Integer testmessagedata;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,99 +0,0 @@
|
||||||
package com.muyu.car.domain.resp;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public class CarReq {
|
|
||||||
|
|
||||||
private String EatImagtion;
|
|
||||||
private String imgTion;
|
|
||||||
private String EatIma6ion;
|
|
||||||
private String EatImagtFformion;
|
|
||||||
private String EatTailImagtion;
|
|
||||||
private String EatImagertion;
|
|
||||||
private String EatImagtodoion;
|
|
||||||
private String EatasImagtion;
|
|
||||||
private String EatImageartion;
|
|
||||||
private String imagtionId;
|
|
||||||
private String Eagtion;
|
|
||||||
private String EatImag;
|
|
||||||
private String tImag;
|
|
||||||
private String agtizyRon;
|
|
||||||
private String EatImagcdtion;
|
|
||||||
private String agtigagtion;
|
|
||||||
private String EatImfhgdfagtion;
|
|
||||||
private String EffatImagtion;
|
|
||||||
private String EatImadfggtion;
|
|
||||||
private String EatImagfgtion;
|
|
||||||
private String EatImaggdtion;
|
|
||||||
private String EatImagdfgtion;
|
|
||||||
private String EatImfdgadfggtion;
|
|
||||||
private String EatIfdgmagtion;
|
|
||||||
private String EatIfdgfgmagtion;
|
|
||||||
private String EatImagdffggtion;
|
|
||||||
private String EatImaggfdtion;
|
|
||||||
private String EatImagtigon;
|
|
||||||
private String EatImagtbjion;
|
|
||||||
private String EatImagt_fdgion;
|
|
||||||
private String EatrgImagtion;
|
|
||||||
private String EatIdgmagtion;
|
|
||||||
private String EatImafggtion;
|
|
||||||
private String EgatImgagtion;
|
|
||||||
private String EatImggagtion;
|
|
||||||
private String EatImagfdgtion;
|
|
||||||
private String EatdfgImadfggtion;
|
|
||||||
private String EatIgdmagtion;
|
|
||||||
private String EatImagd;
|
|
||||||
private String EatdfgImagtion;
|
|
||||||
private String EatIgfgmagtion;
|
|
||||||
private String EatIsdmagtion;
|
|
||||||
private String EatfImagtion;
|
|
||||||
private String EadatImagtion;
|
|
||||||
private String EatdgImagtion;
|
|
||||||
private String EatdImagtion;
|
|
||||||
private String EatIafmagtion;
|
|
||||||
private String EatIagffmagtion;
|
|
||||||
private String EatgsImagtion;
|
|
||||||
private String EatasdImagtion;
|
|
||||||
private String EatIadmagtion;
|
|
||||||
private String EatadImagtion;
|
|
||||||
private String EatIcvmagtion;
|
|
||||||
private String EatImagtfion;
|
|
||||||
private String EatImagation;
|
|
||||||
private String EatImfagtion;
|
|
||||||
private String EatImagyution;
|
|
||||||
private Integer other;
|
|
||||||
private Integer othjjer;
|
|
||||||
private Integer otmkdowedher;
|
|
||||||
private Integer desother;
|
|
||||||
private Integer otsmkeher;
|
|
||||||
private Integer othsmer;
|
|
||||||
private Integer oedednjihyther;
|
|
||||||
private Integer othhuer;
|
|
||||||
private Integer othmkjoer;
|
|
||||||
private Integer othnjiu8er;
|
|
||||||
private Integer othhubhyer;
|
|
||||||
private Integer othejkihjur;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,14 +2,17 @@ package com.muyu.car.mapper;
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.car.domain.CarInformation;
|
import com.muyu.car.domain.CarInformation;
|
||||||
|
import com.muyu.car.domain.CarMessage;
|
||||||
import com.muyu.car.domain.req.CarInformationAddReq;
|
import com.muyu.car.domain.req.CarInformationAddReq;
|
||||||
import com.muyu.car.domain.req.CarInformationListReq;
|
import com.muyu.car.domain.req.CarInformationListReq;
|
||||||
import com.muyu.car.domain.req.CarInformationUpdReq;
|
import com.muyu.car.domain.req.CarInformationUpdReq;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
|
@Tag(name = "车辆基础信息表")
|
||||||
public interface CarInformationMapper {
|
public interface CarInformationMapper {
|
||||||
/**
|
/**
|
||||||
* 企业车辆管理列表
|
* 企业车辆管理列表
|
||||||
|
@ -64,5 +67,4 @@ public interface CarInformationMapper {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.muyu.car.mapper;
|
package com.muyu.car.mapper;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.CarInformation;
|
||||||
import com.muyu.car.domain.CarMessage;
|
import com.muyu.car.domain.CarMessage;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -12,7 +14,7 @@ public interface CarMessageMapper {
|
||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<CarMessage> selectCarMessageList();
|
List<CarMessage> selectCarMessageList(@Param("carMessageCartype")Integer carMessageCartype);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,4 +33,24 @@ public interface CarMessageMapper {
|
||||||
*/
|
*/
|
||||||
Integer updateCarMessage(CarMessage carMessage);
|
Integer updateCarMessage(CarMessage carMessage);
|
||||||
|
|
||||||
|
|
||||||
|
//报文切割
|
||||||
|
/**
|
||||||
|
* 查询报文ID
|
||||||
|
* @param carInformationVIN
|
||||||
|
* @return
|
||||||
|
* 根据车辆VIN值查列表
|
||||||
|
* 根据给定的车辆VIN号获取对应的车辆类型ID-->模板参数
|
||||||
|
*/
|
||||||
|
List<CarInformation> selectcarInformationType(String carInformationVIN);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*根据VIN查询报文作用哪个车辆类型
|
||||||
|
*/
|
||||||
|
Long selectcarMessageCartype(String carInformationVIN);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.muyu.car.mapper;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.Packettemplate;
|
||||||
|
import com.muyu.car.domain.req.PackettemplateAddReq;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
@Tag(name = "保温分类表")
|
||||||
|
public interface PackettemplateMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
*/
|
||||||
|
List<Packettemplate> selectAll();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*/
|
||||||
|
Integer addPackert(PackettemplateAddReq packettemplateAddReq);
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.car.service;
|
package com.muyu.car.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.muyu.car.domain.CarMessage;
|
import com.muyu.car.domain.CarMessage;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ public interface CarMessageService {
|
||||||
* @param
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<CarMessage> selectCarMessageList();
|
List<CarMessage> selectCarMessageList(Integer carMessageCartype);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +35,14 @@ public interface CarMessageService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分割字符串获取报文模板信息
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分割字符串获取报文信息
|
||||||
|
*/
|
||||||
|
JSONObject inciseCarMessage(String testString);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,9 @@ import com.muyu.car.mapper.CarInformationMapper;
|
||||||
import com.muyu.car.service.CarInformationService;
|
import com.muyu.car.service.CarInformationService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.apache.poi.ss.formula.functions.IDStarAlgorithm;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
|
@ -1,22 +1,39 @@
|
||||||
package com.muyu.car.service.Impl;
|
package com.muyu.car.service.Impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.muyu.car.domain.CarInformation;
|
||||||
import com.muyu.car.domain.CarMessage;
|
import com.muyu.car.domain.CarMessage;
|
||||||
|
import com.muyu.car.mapper.CarInformationMapper;
|
||||||
import com.muyu.car.mapper.CarMessageMapper;
|
import com.muyu.car.mapper.CarMessageMapper;
|
||||||
import com.muyu.car.service.CarMessageService;
|
import com.muyu.car.service.CarMessageService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Log4j2
|
||||||
public class CarMessageServiceImpl implements CarMessageService {
|
public class CarMessageServiceImpl implements CarMessageService {
|
||||||
@Resource
|
@Resource
|
||||||
private CarMessageMapper carMessageMapper;
|
private CarMessageMapper carMessageMapper;
|
||||||
|
@Resource
|
||||||
|
private CarInformationMapper carInformationMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String, Objects> redisTemplate;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CarMessage> selectCarMessageList() {
|
public List<CarMessage> selectCarMessageList(Integer carMessageCartype) {
|
||||||
return carMessageMapper.selectCarMessageList();
|
return carMessageMapper.selectCarMessageList(carMessageCartype);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,7 +65,67 @@ public class CarMessageServiceImpl implements CarMessageService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
|
Long selectcared = carMessageMapper.selectcarMessageCartype(substring);
|
||||||
|
//根据给定的vehicleVin(车辆VIN号)获取对应的模板信息
|
||||||
|
// List<CarInformation> carInformations = carMessageMapper.selectcarInformationType(substring);
|
||||||
|
//创建接受数据的数组
|
||||||
|
List<CarMessage> carMessagesList ;
|
||||||
|
|
||||||
|
try{
|
||||||
|
String redisKey = "carMessageList" + selectcared;
|
||||||
|
if (redisTemplate.hasKey(redisKey)){
|
||||||
|
List<Objects> list = redisTemplate.opsForList().range(redisKey , 0, -1);
|
||||||
|
carMessagesList =
|
||||||
|
list.stream().map(objects ->
|
||||||
|
JSON.parseObject(objects.toString(), CarMessage.class))
|
||||||
|
.toList();
|
||||||
|
log.info("Redis缓存查询成功");
|
||||||
|
}else {
|
||||||
|
carMessagesList = carMessageMapper.selectCarMessageList(Math.toIntExact(selectcared));
|
||||||
|
|
||||||
|
carMessagesList.forEach(
|
||||||
|
listReq -> redisTemplate.opsForList().rightPushAll(redisKey, (Collection<Objects>) listReq)
|
||||||
|
);
|
||||||
|
log.info("数据库查询成功");
|
||||||
|
}
|
||||||
|
log.info("获取失败,请重试");
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new RuntimeException("获取报文模板失败");
|
||||||
|
}
|
||||||
|
//判断报文模板 列表 不为空
|
||||||
|
if(carMessagesList.isEmpty()){
|
||||||
|
throw new RuntimeException("报文模版为空");
|
||||||
|
}
|
||||||
|
//存储报文模板解析后的数据
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
for (CarMessage carMessage : carMessagesList) {
|
||||||
|
//起始位下标
|
||||||
|
Integer startIndex = carMessage.getCarMessageStartIndex();
|
||||||
|
//结束位下标
|
||||||
|
Integer endIndex = carMessage.getCarMessageEndIndex();
|
||||||
|
//根据报文模板获取保温截取位置
|
||||||
|
String value = stringBuilder.substring(startIndex, endIndex);
|
||||||
|
//存入数据
|
||||||
|
jsonObject.put(carMessage.getMessageTypeName(), value);
|
||||||
|
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.muyu.car.service.Impl;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.Packettemplate;
|
||||||
|
import com.muyu.car.domain.req.PackettemplateAddReq;
|
||||||
|
import com.muyu.car.mapper.PackettemplateMapper;
|
||||||
|
import com.muyu.car.service.PackertemplateService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Log4j2
|
||||||
|
public class PackertemplateServiceImpl implements PackertemplateService {
|
||||||
|
@Resource
|
||||||
|
private PackettemplateMapper packettemplateMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*分类模板
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Packettemplate> selectAll() {
|
||||||
|
List<Packettemplate> packettemplates = packettemplateMapper.selectAll();
|
||||||
|
log.info("packettemplates:{}",packettemplates);
|
||||||
|
return packettemplates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 添加分类
|
||||||
|
*
|
||||||
|
* @param packettemplateAddReq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result addPackert(PackettemplateAddReq packettemplateAddReq) {
|
||||||
|
Integer addPackert = packettemplateMapper.addPackert(packettemplateAddReq);
|
||||||
|
if (addPackert > 0){
|
||||||
|
return Result.success(packettemplateAddReq , "添加成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.error(500, "添加失败");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.car.service;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.Packettemplate;
|
||||||
|
import com.muyu.car.domain.req.PackettemplateAddReq;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PackertemplateService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
*/
|
||||||
|
List<Packettemplate> selectAll();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*/
|
||||||
|
Result addPackert(PackettemplateAddReq packettemplateAddReq);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.muyu.car.test;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Kafka {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//配置kafka生产者
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.put("bootstrap.servers", "http://60.204.221.52:9092");
|
||||||
|
properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
|
||||||
|
properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
|
||||||
|
//创建kafka生产者
|
||||||
|
Producer<String, String> product = new KafkaProducer<>(properties);
|
||||||
|
String aa = "2345678";
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("aa", aa);
|
||||||
|
String jsonString = jsonObject.toString();
|
||||||
|
System.out.println("JSON内容是:" + jsonString);
|
||||||
|
try {
|
||||||
|
product.send(new ProducerRecord<>("nima", UUID.randomUUID().toString(), jsonString
|
||||||
|
));
|
||||||
|
System.out.println("消费的数据内容为:" + jsonString);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
product.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,168 @@
|
||||||
|
package com.muyu.car.test;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.muyu.car.domain.CarMessage;
|
||||||
|
import com.muyu.car.mapper.CarMessageMapper;
|
||||||
|
import com.muyu.car.service.CarMessageService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class MQTT {
|
||||||
|
@Resource
|
||||||
|
private CarMessageService carMessageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CarMessageMapper carMessageMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String,Objects> redisTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KafkaProducer<String,String> kafkaProducer;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
// 设置消息主题
|
||||||
|
String topic = "vehicle";
|
||||||
|
// 设置消息内容
|
||||||
|
String content = "Message from MqttPublishSample";
|
||||||
|
// 设置消息质量等级
|
||||||
|
int qos = 2;
|
||||||
|
// 设置MQTT代理服务器地址
|
||||||
|
String broker = "tcp://106.15.136.7:1883";
|
||||||
|
// 设置客户端ID
|
||||||
|
String clientId = "JavaSample";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 创建MQTT客户端实例,第三个参数为空,表示使用默认的持久化策略
|
||||||
|
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||||
|
// 创建连接选项实例
|
||||||
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
|
// 设置连接选项,表示每次连接时都清除会话信息
|
||||||
|
connOpts.setCleanSession(true);
|
||||||
|
// 输出正在连接的代理服务器地址
|
||||||
|
System.out.println("Connecting to broker: "+broker);
|
||||||
|
// 连接MQTT代理服务器
|
||||||
|
sampleClient.connect(connOpts);
|
||||||
|
// 订阅指定主题
|
||||||
|
sampleClient.subscribe(topic,0);
|
||||||
|
// 设置回调函数,处理MQTT事件
|
||||||
|
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()));
|
||||||
|
String string = new String(mqttMessage.getPayload());
|
||||||
|
JSONObject object = carMessageService.inciseCarMessage(string);
|
||||||
|
System.out.println(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
Long selectcared = carMessageMapper.selectcarMessageCartype(substring);
|
||||||
|
//根据给定的vehicleVin(车辆VIN号)获取对应的模板信息
|
||||||
|
// List<CarInformation> carInformations = carMessageMapper.selectcarInformationType(substring);
|
||||||
|
//创建接受数据的数组
|
||||||
|
List<CarMessage> carMessagesList ;
|
||||||
|
|
||||||
|
try{
|
||||||
|
String redisKey = "carMessageList" + selectcared;
|
||||||
|
if (redisTemplate.hasKey(redisKey)){
|
||||||
|
List<Objects> list = redisTemplate.opsForList().range(redisKey , 0, -1);
|
||||||
|
carMessagesList =
|
||||||
|
list.stream().map(objects ->
|
||||||
|
JSON.parseObject(objects.toString(), CarMessage.class))
|
||||||
|
.toList();
|
||||||
|
log.info("Redis缓存查询成功");
|
||||||
|
}else {
|
||||||
|
carMessagesList = carMessageMapper.selectCarMessageList(Math.toIntExact(selectcared));
|
||||||
|
|
||||||
|
carMessagesList.forEach(
|
||||||
|
listReq -> redisTemplate.opsForList().rightPushAll(redisKey, (Collection<Objects>) listReq)
|
||||||
|
);
|
||||||
|
log.info("数据库查询成功");
|
||||||
|
}
|
||||||
|
log.info("获取失败,请重试");
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new RuntimeException("获取报文模板失败");
|
||||||
|
}
|
||||||
|
//判断报文模板 列表 不为空
|
||||||
|
if(carMessagesList.isEmpty()){
|
||||||
|
throw new RuntimeException("报文模版为空");
|
||||||
|
}
|
||||||
|
//存储报文模板解析后的数据
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
for (CarMessage carMessage : carMessagesList) {
|
||||||
|
//起始位下标
|
||||||
|
Integer startIndex = carMessage.getCarMessageStartIndex();
|
||||||
|
//结束位下标
|
||||||
|
Integer endIndex = carMessage.getCarMessageEndIndex();
|
||||||
|
//根据报文模板获取保温截取位置
|
||||||
|
String value = stringBuilder.substring(startIndex, endIndex);
|
||||||
|
//存入数据
|
||||||
|
jsonObject.put(carMessage.getMessageTypeName(), value);
|
||||||
|
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 处理消息发送完成事件
|
||||||
|
@Override
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||||
|
// 输出消息是否成功发送完成
|
||||||
|
System.out.println("deliveryComplete---------" + iMqttDeliveryToken.isComplete());
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -104,6 +104,8 @@
|
||||||
FROM `car_information`
|
FROM `car_information`
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<insert id="addCarInformation">
|
<insert id="addCarInformation">
|
||||||
INSERT INTO `car_information`
|
INSERT INTO `car_information`
|
||||||
(
|
(
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
|
|
||||||
<mapper namespace="com.muyu.car.mapper.CarMessageMapper">
|
<mapper namespace="com.muyu.car.mapper.CarMessageMapper">
|
||||||
<resultMap id="carMessageResult" type="com.muyu.car.domain.CarMessage">
|
<resultMap id="carMessageResult" type="com.muyu.car.domain.CarMessage">
|
||||||
<result property="messageTypeId" column="message_type_id"/>
|
<result property="messageTypeId" column="message_type_id"/>
|
||||||
<result property="messageTypeCode" column="message_type_code"/>
|
<result property="messageTypeCode" column="message_type_code"/>
|
||||||
<result property="messageTypeName" column="message_type_name"/>
|
<result property="messageTypeName" column="message_type_name"/>
|
||||||
<result property="messageTypeBelongs" column="message_type_belongs"/>
|
<result property="messageTypeBelongs" column="message_type_belongs"/>
|
||||||
<result property="messageTypeClass" column="message_type_class"/>
|
<result property="messageTypeClass" column="message_type_class"/>
|
||||||
<result property="carMessageId" column="car_message_id"/>
|
<result property="carMessageId" column="car_message_id"/>
|
||||||
<result property="carMessageCartype" column="car_message_cartype"/>
|
<result property="carMessageCartype" column="car_message_cartype"/>
|
||||||
<result property="carMessageType" column="car_message_type"/>
|
<result property="carMessageType" column="car_message_type"/>
|
||||||
<result property="carMessageStartIndex" column="car_message_start_index"/>
|
<result property="carMessageStartIndex" column="car_message_start_index"/>
|
||||||
<result property="carMessageEndIndex" column="car_message_end_index"/>
|
<result property="carMessageEndIndex" column="car_message_end_index"/>
|
||||||
<result property="carMessageState" column= "car_message_state"/>
|
<result property="carMessageState" column= "car_message_state"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insertCarMessage">
|
<insert id="insertCarMessage">
|
||||||
|
@ -89,6 +89,46 @@
|
||||||
ON `car_message`.car_message_type = `car_message_type`.message_type_id
|
ON `car_message`.car_message_type = `car_message_type`.message_type_id
|
||||||
LEFT JOIN `car_type`
|
LEFT JOIN `car_type`
|
||||||
ON `car_message` .car_message_cartype = `car_type`.car_type_id
|
ON `car_message` .car_message_cartype = `car_type`.car_type_id
|
||||||
|
WHERE
|
||||||
|
`car_message`.car_message_cartype = #{carMessageCartype}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectcarInformationType" resultType="com.muyu.car.domain.CarInformation">
|
||||||
|
SELECT
|
||||||
|
car_information_VIN,
|
||||||
|
car_information_type,
|
||||||
|
car_type_id,
|
||||||
|
car_type_name,
|
||||||
|
car_message_id,
|
||||||
|
car_message_cartype,
|
||||||
|
car_message_type,
|
||||||
|
car_message_start_index,
|
||||||
|
car_message_end_index,
|
||||||
|
message_type_class,
|
||||||
|
car_message_state
|
||||||
|
FROM `car_information`
|
||||||
|
LEFT JOIN `car_type`
|
||||||
|
ON `car_information`. car_information_type
|
||||||
|
=`car_type`. car_type_id
|
||||||
|
LEFT JOIN `car_message`
|
||||||
|
ON `car_message`.car_message_cartype
|
||||||
|
=`car_type`. car_type_id
|
||||||
|
WHERE
|
||||||
|
`car_information`.car_information_VIN = #{carInformationVIN}
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectcarMessageCartype" resultType="java.lang.Long">
|
||||||
|
SELECT `car_information`.car_Information_Type
|
||||||
|
FROM `car_information`
|
||||||
|
WHERE `car_information`.car_information_VIN = #{carInformationVIN}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?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.car.mapper.PackettemplateMapper">
|
||||||
|
<resultMap id="PackertemplateResult" type="com.muyu.car.domain.Packettemplate">
|
||||||
|
<result property="packetTemplateId" column="packet_template_id"/>
|
||||||
|
<result property="packetTemplateCartype" column="packet_template_cartype"/>
|
||||||
|
<result property="packetTemplateCarmessage" column="packet_template_carmessage"/>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="packerResult">
|
||||||
|
select
|
||||||
|
*
|
||||||
|
from `packet_template`
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<insert id="addPackert">
|
||||||
|
INSERT INTO `packet_template`
|
||||||
|
( `packet_template_cartype`, `packet_template_carmessage`)
|
||||||
|
VALUES
|
||||||
|
( #{packetTemplateCartype}, #{packetTemplateCarmessage});
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectAll" resultType="com.muyu.car.domain.Packettemplate">
|
||||||
|
<include refid="packerResult"/>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -13,6 +13,7 @@
|
||||||
<module>cloud-modules-gen</module>
|
<module>cloud-modules-gen</module>
|
||||||
<module>cloud-modules-file</module>
|
<module>cloud-modules-file</module>
|
||||||
<module>cloud-modules-car</module>
|
<module>cloud-modules-car</module>
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-modules</artifactId>
|
<artifactId>cloud-modules</artifactId>
|
||||||
|
|
Loading…
Reference in New Issue