From 735e7f56e0c636324e5fdc2d9b408eab4a6b5d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E6=AC=A3=E6=82=A6?= <2289014031@qq.com> Date: Mon, 30 Sep 2024 20:58:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E8=A7=A3=E6=9E=90:=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E8=A7=A3=E6=9E=90=E6=96=B9=E6=B3=95=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?kafka=E7=9A=84=E6=8A=95=E4=BA=A7,=E5=B9=B6=E6=8B=86=E5=85=A5?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=E7=9A=84=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud-auth/src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/banner.txt | 2 + .../src/main/resources/logback/dev.xml | 74 ++++++++ .../src/main/resources/logback/prod.xml | 81 +++++++++ .../src/main/resources/logback/test.xml | 81 +++++++++ .../main/java/com/muyu/domain/CarMessage.java | 10 +- .../main/java/com/muyu/domain/KafKaData.java | 17 ++ .../cloud-modules-enterprise-server/pom.xml | 18 +- .../com/muyu/server/feign/KafkaClient.java | 18 -- .../server/service/CarMessageService.java | 7 - .../service/impl/CarMessageServiceImpl.java | 8 - .../server/service/message/MessageDao.java | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../cloud-modules-protocolparsing/pom.xml | 102 +++++++++++ .../java/com/muyu/ProtocolApplication.java | 15 ++ .../muyu/controller/CarMessageController.java | 38 ++++ .../main/java/com/muyu/domain/CarMessage.java | 135 ++++++++++++++ .../java/com/muyu/domain/CarMessageType.java | 43 +++++ .../main/java/com/muyu/domain/KafKaData.java | 17 ++ .../com/muyu/domain/resp/CarMessageResp.java | 57 ++++++ .../main/java/com/muyu/feign/KafkaClient.java | 19 ++ .../com/muyu/mapper/CarInformationMapper.java | 24 +++ .../com/muyu/mapper/CarMessageMapper.java | 17 ++ .../com/muyu/mapper/CarMessagePlusMapper.java | 12 ++ .../com/muyu/mapper/CarMessageTypeMapper.java | 8 + .../src/main/java/com/muyu}/mqtt/Demo.java | 14 +- .../src/main/java/com/muyu/mqtt/MqttTest.java | 118 +++++++++++++ .../main/java/com/muyu/mqtt/ParsingMQTT.java | 166 ++++++++++++++++++ .../com/muyu/service/CarMessageService.java | 35 ++++ .../service/impl/CarMessageServiceImpl.java | 134 ++++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../src/main/resources/banner.txt | 2 + .../src/main/resources/logback/dev.xml | 74 ++++++++ .../src/main/resources/logback/prod.xml | 81 +++++++++ .../src/main/resources/logback/test.xml | 81 +++++++++ .../resources/mapper/CarMessageMapper.xml | 15 ++ .../src/main/resources/bootstrap.yml | 2 +- cloud-modules/pom.xml | 1 + .../src/main/resources/bootstrap.yml | 2 +- 42 files changed, 1476 insertions(+), 65 deletions(-) create mode 100644 cloud-modules/cloud-modules-carData/src/main/resources/banner.txt create mode 100644 cloud-modules/cloud-modules-carData/src/main/resources/logback/dev.xml create mode 100644 cloud-modules/cloud-modules-carData/src/main/resources/logback/prod.xml create mode 100644 cloud-modules/cloud-modules-carData/src/main/resources/logback/test.xml create mode 100644 cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/KafKaData.java delete mode 100644 cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/feign/KafkaClient.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/pom.xml create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/ProtocolApplication.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/controller/CarMessageController.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessage.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessageType.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/KafKaData.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/resp/CarMessageResp.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/feign/KafkaClient.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarInformationMapper.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageMapper.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessagePlusMapper.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageTypeMapper.java rename cloud-modules/{cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server => cloud-modules-protocolparsing/src/main/java/com/muyu}/mqtt/Demo.java (95%) create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/MqttTest.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/ParsingMQTT.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/CarMessageService.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/impl/CarMessageServiceImpl.java create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/resources/banner.txt create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/dev.xml create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/prod.xml create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/test.xml create mode 100644 cloud-modules/cloud-modules-protocolparsing/src/main/resources/mapper/CarMessageMapper.xml diff --git a/cloud-auth/src/main/resources/bootstrap.yml b/cloud-auth/src/main/resources/bootstrap.yml index 9a56e49..c286e94 100644 --- a/cloud-auth/src/main/resources/bootstrap.yml +++ b/cloud-auth/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 127.0.0.1:8848 user-name: nacos password: nacos - namespace: eight + namespace: xxy # Spring spring: application: diff --git a/cloud-gateway/src/main/resources/bootstrap.yml b/cloud-gateway/src/main/resources/bootstrap.yml index a9335ac..202ab69 100644 --- a/cloud-gateway/src/main/resources/bootstrap.yml +++ b/cloud-gateway/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 127.0.0.1:8848 user-name: nacos password: nacos - namespace: eight + namespace: xxy # Spring spring: diff --git a/cloud-modules/cloud-modules-carData/src/main/resources/banner.txt b/cloud-modules/cloud-modules-carData/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/cloud-modules/cloud-modules-carData/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/cloud-modules/cloud-modules-carData/src/main/resources/logback/dev.xml b/cloud-modules/cloud-modules-carData/src/main/resources/logback/dev.xml new file mode 100644 index 0000000..8f19f70 --- /dev/null +++ b/cloud-modules/cloud-modules-carData/src/main/resources/logback/dev.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-carData/src/main/resources/logback/prod.xml b/cloud-modules/cloud-modules-carData/src/main/resources/logback/prod.xml new file mode 100644 index 0000000..260f145 --- /dev/null +++ b/cloud-modules/cloud-modules-carData/src/main/resources/logback/prod.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-carData/src/main/resources/logback/test.xml b/cloud-modules/cloud-modules-carData/src/main/resources/logback/test.xml new file mode 100644 index 0000000..260f145 --- /dev/null +++ b/cloud-modules/cloud-modules-carData/src/main/resources/logback/test.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/CarMessage.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/CarMessage.java index 41df8b4..6de2217 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/CarMessage.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/CarMessage.java @@ -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 { */ - - - } diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/KafKaData.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/KafKaData.java new file mode 100644 index 0000000..66f4683 --- /dev/null +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-common/src/main/java/com/muyu/domain/KafKaData.java @@ -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; +} diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/pom.xml b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/pom.xml index b7bfbc8..7dde0dc 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/pom.xml +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/pom.xml @@ -28,6 +28,12 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + 1.2.2 + com.alibaba.cloud @@ -38,17 +44,6 @@ org.apache.kafka kafka-clients - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - 1.2.2 - com.alibaba.cloud @@ -103,7 +98,6 @@ com.muyu cloud-common-kafka 3.6.3 - compile diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/feign/KafkaClient.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/feign/KafkaClient.java deleted file mode 100644 index 24e4999..0000000 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/feign/KafkaClient.java +++ /dev/null @@ -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(); -// -// -//} diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/CarMessageService.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/CarMessageService.java index 598f6f7..8a194d7 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/CarMessageService.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/CarMessageService.java @@ -53,11 +53,4 @@ public interface CarMessageService extends IService { * 获取报文最终信息 */ JSONObject inciseCarMessage(String testString); - - - List selectCarMessageList(int i, int i1); - - - - } diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/impl/CarMessageServiceImpl.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/impl/CarMessageServiceImpl.java index 404db2d..b23e154 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/impl/CarMessageServiceImpl.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/impl/CarMessageServiceImpl.java @@ -110,14 +110,6 @@ public class CarMessageServiceImpl return null; } - @Override - public List selectCarMessageList(int id, int modelCode) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(CarMessage::getCarMessageId, id); - queryWrapper.eq(CarMessage::getCarMessageType, modelCode); - return this.list(queryWrapper); - } - //报文处理 diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/message/MessageDao.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/message/MessageDao.java index 8bf4173..afeb878 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/message/MessageDao.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/service/message/MessageDao.java @@ -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()); diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/resources/bootstrap.yml index 574393e..0616949 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/resources/bootstrap.yml @@ -4,7 +4,7 @@ server: # nacos线上地址 nacos: - addr: 127.0.0.1:8848 + addr: 159.75.188.178:8848 user-name: nacos password: nacos namespace: eight diff --git a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml index 2863945..b2d27b0 100644 --- a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 127.0.0.1:8848 user-name: nacos password: nacos - namespace: eight + namespace: xxy # Spring spring: diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml index 5735ae2..d00587b 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 127.0.0.1:8848 user-name: nacos password: nacos - namespace: eight + namespace: xxy # Spring spring: diff --git a/cloud-modules/cloud-modules-protocolparsing/pom.xml b/cloud-modules/cloud-modules-protocolparsing/pom.xml new file mode 100644 index 0000000..13b771d --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + com.muyu + cloud-modules + 3.6.3 + + + cloud-modules-protocolparsing + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + 1.2.2 + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + org.apache.kafka + kafka-clients + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + org.springframework.boot + spring-boot-starter-actuator + + + + com.mysql + mysql-connector-j + + + + com.muyu + cloud-common-datasource + + + + com.muyu + cloud-common-datascope + + + + com.muyu + cloud-common-log + + + + com.muyu + cloud-common-api-doc + + + com.muyu + cloud-modules-enterprise-common + 1.0.0 + + + com.github.yulichang + mybatis-plus-join-boot-starter + 1.4.13 + + + com.github.pagehelper + pagehelper + 6.0.0 + + + com.muyu + cloud-common-kafka + 3.6.3 + + + + 17 + 17 + UTF-8 + + + diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/ProtocolApplication.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/ProtocolApplication.java new file mode 100644 index 0000000..ce6cf59 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/ProtocolApplication.java @@ -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); + } +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/controller/CarMessageController.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/controller/CarMessageController.java new file mode 100644 index 0000000..ed34b86 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/controller/CarMessageController.java @@ -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 { + + + /** + * 测试分割字符 + */ + + + + + +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessage.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessage.java new file mode 100644 index 0000000..6de2217 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessage.java @@ -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 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 ; + */ + + +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessageType.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessageType.java new file mode 100644 index 0000000..7bc7b48 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/CarMessageType.java @@ -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 ; + +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/KafKaData.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/KafKaData.java new file mode 100644 index 0000000..66f4683 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/KafKaData.java @@ -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; +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/resp/CarMessageResp.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/resp/CarMessageResp.java new file mode 100644 index 0000000..e682ed0 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/domain/resp/CarMessageResp.java @@ -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 ; + +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/feign/KafkaClient.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/feign/KafkaClient.java new file mode 100644 index 0000000..c74984c --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/feign/KafkaClient.java @@ -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); + + +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarInformationMapper.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarInformationMapper.java new file mode 100644 index 0000000..1a1c380 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarInformationMapper.java @@ -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 { + + + /** + * 根据车辆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); +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageMapper.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageMapper.java new file mode 100644 index 0000000..b219bd9 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageMapper.java @@ -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 { + + + +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessagePlusMapper.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessagePlusMapper.java new file mode 100644 index 0000000..2e0981b --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessagePlusMapper.java @@ -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 selectCarMessageList(@Param("carMessageCartype") Integer carMessageCartype); +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageTypeMapper.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageTypeMapper.java new file mode 100644 index 0000000..3b65c1d --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mapper/CarMessageTypeMapper.java @@ -0,0 +1,8 @@ +package com.muyu.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.muyu.domain.CarMessageType; + + +public interface CarMessageTypeMapper extends MPJBaseMapper { +} diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/mqtt/Demo.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/Demo.java similarity index 95% rename from cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/mqtt/Demo.java rename to cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/Demo.java index 007c82e..c30d6db 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/server/mqtt/Demo.java +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/Demo.java @@ -1,15 +1,14 @@ -package com.muyu.server.mqtt; +package com.muyu.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 com.muyu.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; @@ -17,7 +16,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -@Component +//@Component public class Demo { @Resource private CarMessageService service; @@ -25,11 +24,10 @@ public class Demo { private KafkaProducer 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 broker = "tcp://60.204.221.52:1883"; String clientId = "JavaSample"; try { @@ -50,7 +48,7 @@ public class Demo { @Override public void messageArrived(String s, MqttMessage mqttMessage) throws Exception { - List list= service.selectCarMessageList(1,2); + List list= service.selectCarMessage(1); String str = new String( mqttMessage.getPayload() ); System.out.println(str); String[] test = str.split(" "); diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/MqttTest.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/MqttTest.java new file mode 100644 index 0000000..0f0f5de --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/MqttTest.java @@ -0,0 +1,118 @@ +package com.muyu.mqtt; + +import com.alibaba.fastjson2.JSONObject; +import com.muyu.common.kafka.constants.KafkaConstants; + +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 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 list = sysCarMessageService.selectCarMessage(1); + String string = new String(mqttMessage.getPayload()); + log.info(new String(mqttMessage.getPayload())); + List 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 producerRecord = new ProducerRecord<>(KafkaConstants.KafkaTopic, jsonString); + kafkaProducer.send(producerRecord); + log.info("kafka投产:{}", jsonString); +// HashMap 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(); + } + } +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/ParsingMQTT.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/ParsingMQTT.java new file mode 100644 index 0000000..c41f07b --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/mqtt/ParsingMQTT.java @@ -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 redisTemplate; +// +// @Autowired +// private KafkaClient remoteServiceClient; +// +// @Resource +// private KafkaProducer 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 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 byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin); +// Long templateId = byVehicleVin.getData(); +// List templateList; +// //从redis缓存中获取报文模板数据 +// try { +// String redisKey = RedisConstants.MESSAGE_TEMPLATE + templateId; +// if (redisTemplate.hasKey(redisKey)) { +// List list = redisTemplate.opsForList().range(redisKey, 0, -1); +// templateList = list.stream() +// .map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class)) +// .toList(); +// log.info("Redis缓存查询成功"); +// } else { +// Result> 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(); +// } +// } +// +// +// +// +// +//} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/CarMessageService.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/CarMessageService.java new file mode 100644 index 0000000..726ebae --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/CarMessageService.java @@ -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 { + + + + + //报文切割 + /** + * 分割字符串 + * 解析字符 + * 获取报文最终信息 + */ + JSONObject inciseCarMessage(String testString); + + + List selectCarMessageList(int modelCode); + + + List selectCarMessage(@Param("carMessageCartype") Integer carMessageCartype); + + + List selectCarMessageListAll(int i); +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/impl/CarMessageServiceImpl.java b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/impl/CarMessageServiceImpl.java new file mode 100644 index 0000000..a854c67 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/java/com/muyu/service/impl/CarMessageServiceImpl.java @@ -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 + implements CarMessageService { + @Resource + private CarMessageMapper carMessageMapper; + + @Resource + private CarMessagePlusMapper carMessagePlusMapper; + + @Resource + private CarInformationMapper carInformationMapper; + + + @Override + public List selectCarMessageList(int modelCode) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(CarMessage::getCarMessageCartype, modelCode); + return this.list(queryWrapper); + } + + @Override + public List selectCarMessage(Integer carMessageCartype) { + return carMessagePlusMapper.selectCarMessageList(carMessageCartype); + } + + @Override + public List selectCarMessageListAll(int i) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(CarMessage::getCarMessageCartype, i); + return this.list(queryWrapper); + } + + @Override + public JSONObject inciseCarMessage(String testString) { + return null; + } + + //报文处理 +// @Resource +// private RedisTemplate 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 messagesList ; +// +// try{ +// String redisKey = "carMessageList" + selectcared; +// +// if (redisTemplate.hasKey(redisKey)){ +// List 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; +// +// } + + + +} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ + diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/resources/banner.txt b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/dev.xml b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/dev.xml new file mode 100644 index 0000000..187e473 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/dev.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/prod.xml b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/prod.xml new file mode 100644 index 0000000..9f04f11 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/prod.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/test.xml b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/test.xml new file mode 100644 index 0000000..9f04f11 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/logback/test.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-protocolparsing/src/main/resources/mapper/CarMessageMapper.xml b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/mapper/CarMessageMapper.xml new file mode 100644 index 0000000..a86f278 --- /dev/null +++ b/cloud-modules/cloud-modules-protocolparsing/src/main/resources/mapper/CarMessageMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml index a0052fd..ac12bee 100644 --- a/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 127.0.0.1:8848 user-name: nacos password: nacos - namespace: eight + namespace: xxy # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: diff --git a/cloud-modules/pom.xml b/cloud-modules/pom.xml index 672d384..61c92c9 100644 --- a/cloud-modules/pom.xml +++ b/cloud-modules/pom.xml @@ -14,6 +14,7 @@ cloud-modules-gen cloud-modules-file cloud-modules-carData + cloud-modules-protocolparsing cloud-modules diff --git a/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml b/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml index 10e7fb8..a4fdef3 100644 --- a/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml +++ b/cloud-visual/cloud-visual-monitor/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 127.0.0.1:8848 user-name: nacos password: nacos - namespace: eight + namespace: xxy # Spring spring: