From cf286d48f9e14ce4185112397ec1fcc835f3e316 Mon Sep 17 00:00:00 2001 From: Number7 <1845377266@qq.com> Date: Thu, 10 Oct 2024 09:26:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat():=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=A2=84=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud-auth/src/main/resources/bootstrap.yml | 2 +- .../many/datasource/ManyDataSource.java | 6 - .../src/main/resources/bootstrap.yml | 2 +- cloud-modules/cloud-event/pom.xml | 12 ++ .../muyu/event/consumer/MessageConsumer.java | 21 +-- .../muyu/event/service/IncidentService.java | 16 ++ .../service/impl/IncidentServiceImpl.java | 160 ++++++++++++++++++ .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../muyu/template/config/MqttConfigure.java | 1 - .../src/main/java/com/muyu/template/test.java | 3 +- .../src/main/resources/bootstrap.yml | 62 +++++++ .../src/main/resources/bootstrap.yml | 2 +- .../java/com/muyu/server/SaasApplication.java | 2 - .../src/main/resources/bootstrap.yml | 2 +- 17 files changed, 270 insertions(+), 29 deletions(-) create mode 100644 cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java create mode 100644 cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java create mode 100644 cloud-modules/cloud-modules-template/src/main/resources/bootstrap.yml diff --git a/cloud-auth/src/main/resources/bootstrap.yml b/cloud-auth/src/main/resources/bootstrap.yml index 57dca73..7561373 100644 --- a/cloud-auth/src/main/resources/bootstrap.yml +++ b/cloud-auth/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # Spring spring: application: diff --git a/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java b/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java index 04bf3b3..cf5c81b 100644 --- a/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java +++ b/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java @@ -1,5 +1,4 @@ package com.muyu.cloud.common.many.datasource; - import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; @@ -22,12 +21,10 @@ import org.springframework.boot.ApplicationRunner; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; - /** * @Author: DongZeLiang * @date: 2024/6/3 @@ -62,7 +59,6 @@ public class ManyDataSource implements ApplicationRunner{ return null; } } - // private List dataPrimarySourceInfoList(){ // List list = new ArrayList<>(); // list.add( @@ -74,7 +70,6 @@ public class ManyDataSource implements ApplicationRunner{ // ); // return list; // } - @Bean public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) { // 企业列表 企业CODE,端口,IP @@ -93,7 +88,6 @@ public class ManyDataSource implements ApplicationRunner{ dynamicDataSource.setDefineTargetDataSources(dataSourceMap); return dynamicDataSource; } - @Override public void run(ApplicationArguments args) { DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class); diff --git a/cloud-gateway/src/main/resources/bootstrap.yml b/cloud-gateway/src/main/resources/bootstrap.yml index de95a70..77dc05c 100644 --- a/cloud-gateway/src/main/resources/bootstrap.yml +++ b/cloud-gateway/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # Spring spring: diff --git a/cloud-modules/cloud-event/pom.xml b/cloud-modules/cloud-event/pom.xml index cae475e..25957cc 100644 --- a/cloud-modules/cloud-event/pom.xml +++ b/cloud-modules/cloud-event/pom.xml @@ -114,6 +114,18 @@ com.muyu cloud-common-rabbit + + com.muyu.common + saas-common + 3.6.3 + compile + + + com.muyu + saas-cache + 3.6.3 + compile + diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java index 3cb39c0..ed71470 100644 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java @@ -1,9 +1,7 @@ package com.muyu.event.consumer; - - - import com.alibaba.fastjson2.JSONObject; import com.muyu.event.basic.EventPublisher; +import com.muyu.event.service.IncidentService; import lombok.extern.log4j.Log4j2; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -11,14 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; - import java.time.Duration; import java.util.Collections; import java.util.List; - import static org.bouncycastle.asn1.x500.style.RFC4519Style.l; - -/** +/* * kafka监听 * @author 刘武 * @package:com.muyu.event.consumer @@ -36,12 +31,13 @@ public class MessageConsumer implements ApplicationRunner { private final String topic="four_car"; + @Autowired + private IncidentService incidentService; @Override public void run(ApplicationArguments args) throws Exception { List list = Collections.singletonList(topic); consumer.subscribe(list); - while (true){ ConsumerRecords consumerRecords = consumer.poll(Duration.ofMillis(100)); consumerRecords.forEach(record -> { @@ -49,9 +45,14 @@ public class MessageConsumer implements ApplicationRunner { JSONObject jsonObject = JSONObject.parseObject(value); log.info("value:{}",value); // eventPublisher.publishEvent(jsonObject); + try { + //预警 + incidentService.warnEventProcess(jsonObject); + + } catch (Exception e) { + throw new RuntimeException(e); + } }); - - } } } diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java new file mode 100644 index 0000000..4f60079 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java @@ -0,0 +1,16 @@ +package com.muyu.event.service; + +import com.alibaba.fastjson2.JSONObject; + +/** + * @author liuxinyue + * @Package:com.muyu.event.service + * @name:IncidentService + * @Date:2024/10/9 15:02 + */ +public interface IncidentService { + + void warnEventProcess(JSONObject jsonObject) throws Exception; + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java new file mode 100644 index 0000000..fb90eb9 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java @@ -0,0 +1,160 @@ +package com.muyu.event.service.impl; +import com.alibaba.fastjson2.JSONObject; +import com.muyu.cache.MessageTemplateTypeCacheService; +import com.muyu.cache.SysCarCacheService; +import com.muyu.cache.WarnRuleCacheService; +import com.muyu.cache.WarnStrategyCacheService; +import com.muyu.common.domain.MessageTemplateType; +import com.muyu.common.domain.SysCar; +import com.muyu.common.domain.resp.SysCarVo; +import com.muyu.common.domain.resp.WarnRuleResp; +import com.muyu.common.domain.resp.WarnStrategyResp; +import com.muyu.event.consumer.MessageConsumer; +import com.muyu.event.service.IncidentService; +import lombok.extern.log4j.Log4j2; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; +import java.util.stream.Collectors; +/** + * @author liuxinyue + * @Package:com.muyu.event.service.impl + * @name:IncidentServiceImpl + * @Date:2024/10/9 15:02 + */ +@Log4j2 +@Service +public class IncidentServiceImpl implements IncidentService { + private static int DURATION_SECONDS = 5; + private static List receivedStrings = new ArrayList<>(); + private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + private static int elapsedSeconds = 0; + private static String file="elapsed"; + private static List messageTemplateTypes=null; + private static Long msgTypeId=null; + //滑窗时间 + private static Long slideTime=null; + //增长率 + private static Long slideFrequency=null; + //预警策略 + @Resource + private WarnStrategyCacheService warnStrategyCacheService; + //车辆 + @Resource + private SysCarCacheService sysCarCacheService; + //预警规则 + @Resource + private WarnRuleCacheService warnRuleCacheService; + //报文模版 + @Resource + private MessageTemplateTypeCacheService messageTemplateTypeCacheService; + + private final String topic="four_car"; + + @Autowired + private MessageConsumer messageConsumer; + + @Autowired + public KafkaConsumer consumer; + + @Override + public void warnEventProcess(JSONObject jsonObject) throws Exception { + + receivedStrings.add(jsonObject); + //协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings + //根据这个车辆VIN查询出他对应的车辆类型 + String carVin=null; + //报文模版的ID + Integer templateId=null; + for (JSONObject receivedString : receivedStrings) { + carVin = (String) receivedString.get("carVin"); + } + SysCar carByVin = null; + List carVoList = sysCarCacheService.get(sysCarCacheService.keyPre()); + Map carMap = carVoList.stream() + .collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity())); + //获取到了这个车辆的信息 + carByVin = carMap.get(carVin); + //获取到这辆车绑定的报文模版 + templateId=carByVin.getTemplateId(); + //这个是这辆车对应的所有策略 + List carWithWarnStrategyList=null; + List warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre()); + for (WarnStrategyResp warnStrategyResp : warnStrategyResps) { + if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){ + carWithWarnStrategyList.add(warnStrategyResp); + } + } + //该车对应的所有预警规则 + List warnRuleResp=null; + List warnRuleResps = warnRuleCacheService.get(warnRuleCacheService.keyPre()); + for (WarnStrategyResp warnStrategyResp : carWithWarnStrategyList) { + for (WarnRuleResp ruleResp : warnRuleResps) { + if(warnStrategyResp.getId().equals(ruleResp.getStrategyId())){ + warnRuleResp.add(ruleResp); + } + } + } + //报文模版 + messageTemplateTypes = messageTemplateTypeCacheService.get(messageTemplateTypeCacheService.keyPre()); + for (WarnRuleResp ruleResp : warnRuleResp) { + //每一个规则他绑定了报文模版里面对应的一个配置 比如:电池,或者车速 + msgTypeId = ruleResp.getMsgTypeId(); + //将规则中对应的滑窗时间赋值为DURATION_SECONDS + DURATION_SECONDS = Math.toIntExact(ruleResp.getSlideTime()); + slideFrequency = ruleResp.getSlideFrequency(); + } + // 定义一个任务,每秒执行一次 + Runnable task = new Runnable() { + @Override + public void run() { + // 清理超过的数据 + cleanUpOldStrings(); + // 检查超速条件 + checkForSpeeding(); + } + }; + // 每隔1秒执行一次任务 + scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS); + } + // 清理超过60秒的数据 + private static void cleanUpOldStrings() { + long currentTime = System.currentTimeMillis(); + receivedStrings.removeIf(jsonObject -> + currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS) + ); + } + // 检查是否有超速情况 + private static void checkForSpeeding() { + if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回 + for (int i = 0; i < receivedStrings.size(); i++) { + JSONObject current = receivedStrings.get(i); + JSONObject next = receivedStrings.get(i + 1); + for (MessageTemplateType messageTemplateType : messageTemplateTypes) { + if(messageTemplateType.getMessageTemplateTypeId().equals(msgTypeId)){ + Short currentElapsed = current.getShort(messageTemplateType.getMessageField()); + Short nextElapsed = next.getShort(messageTemplateType.getMessageField()); + if (nextElapsed > currentElapsed + slideFrequency) { + log.info("出错啦,出错啦,您的"+messageTemplateType.getMessageField()+"不正常,请检查!!!"); + } + } + } + } + } + + + +} diff --git a/cloud-modules/cloud-event/src/main/resources/bootstrap.yml b/cloud-modules/cloud-event/src/main/resources/bootstrap.yml index 1bc0fa4..a3e909a 100644 --- a/cloud-modules/cloud-event/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-event/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: 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 3a1eb6a..0b5c562 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: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # 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 c5e8cb9..a70108e 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: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: 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 afe1a22..84b2bf9 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: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java index 9802526..9eb42bd 100644 --- a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java @@ -104,7 +104,6 @@ public class MqttConfigure { me.printStackTrace(); } } - public JSONObject messageParsing(String templateMessage) { //给一个JSON对象 JSONObject jsonObject = new JSONObject(); diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/test.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/test.java index ad62d51..753bc2e 100644 --- a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/test.java +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/test.java @@ -50,6 +50,7 @@ public class test { //报文模版 @Resource private MessageTemplateTypeCacheService messageTemplateTypeCacheService; + public void main(String[] args) { //协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings //根据这个车辆VIN查询出他对应的车辆类型 @@ -107,7 +108,6 @@ public class test { // 每隔1秒执行一次任务 scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS); } - // 清理超过60秒的数据 private static void cleanUpOldStrings() { long currentTime = System.currentTimeMillis(); @@ -115,7 +115,6 @@ public class test { currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS) ); } - // 检查是否有超速情况 private static void checkForSpeeding() { if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回 diff --git a/cloud-modules/cloud-modules-template/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-template/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..1ff0cd8 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/resources/bootstrap.yml @@ -0,0 +1,62 @@ +# Tomcat +server: + port: 15277 + +# nacos线上地址 +nacos: + addr: 47.101.53.251:8848 + user-name: nacos + password: nacos + namespace: lxy +# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all +# Spring +spring: + mvc: + pathmatch: + matching-strategy: ant_path_matcher + amqp: + deserialization: + trust: + all: true + main: + allow-bean-definition-overriding: true + application: + # 应用名称 + name: cloud-template + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + config: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + # 系统共享配置 + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # 系统环境Config共享配置 + - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # xxl-job 配置文件 + - application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + +logging: + level: + com.muyu.system.mapper: DEBUG diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-vehiclegateway/src/main/resources/bootstrap.yml index b027b47..4eecbb4 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # Spring spring: diff --git a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/SaasApplication.java b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/SaasApplication.java index 7186808..4d2fd21 100644 --- a/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/SaasApplication.java +++ b/cloud-modules/saas/saas-server/src/main/java/com/muyu/server/SaasApplication.java @@ -1,6 +1,4 @@ package com.muyu.server; - - import com.muyu.common.security.annotation.EnableMyFeignClients; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/cloud-modules/saas/saas-server/src/main/resources/bootstrap.yml b/cloud-modules/saas/saas-server/src/main/resources/bootstrap.yml index faf0576..0ee7641 100644 --- a/cloud-modules/saas/saas-server/src/main/resources/bootstrap.yml +++ b/cloud-modules/saas/saas-server/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: yzl + namespace: lxy # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: From 1a62dd6f961ff75d24dc27b53183b3f45133c995 Mon Sep 17 00:00:00 2001 From: SuiXxx <1752599835@qq.com> Date: Thu, 10 Oct 2024 17:20:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat():=E8=BD=AE=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud-modules-vehiclegateway/pom.xml | 7 +++ .../java/com/muyu/vehicle/ManageInstance.java | 11 +++- .../muyu/vehicle/config/CloseInstance.java | 20 ++++++++ .../muyu/vehicle/config/CreateExchange.java | 5 ++ .../muyu/vehicle/config/SelectInstance.java | 3 +- .../controller/CarInstanceController.java | 5 +- .../vehicle/mapper/VehicleConnectMapper.java | 4 +- .../service/VehicleConnectService.java | 2 +- .../impl/VehicleConnectServiceImpl.java | 51 +++++++++++++++++-- .../resources/mapper/VehicleConnectMapper.xml | 15 ++++++ 10 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 cloud-modules/cloud-modules-vehiclegateway/src/main/resources/mapper/VehicleConnectMapper.xml diff --git a/cloud-modules/cloud-modules-vehiclegateway/pom.xml b/cloud-modules/cloud-modules-vehiclegateway/pom.xml index 112b41e..1150791 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/pom.xml +++ b/cloud-modules/cloud-modules-vehiclegateway/pom.xml @@ -91,6 +91,13 @@ cloud-common-rabbit + + + redis.clients + jedis + 5.0.2 + + org.springframework.boot spring-boot-autoconfigure diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java index c8457c5..66c4d37 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/ManageInstance.java @@ -14,6 +14,7 @@ import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -30,10 +31,12 @@ public class ManageInstance implements ApplicationRunner { @Autowired private RedisService redisService; + + /** * 镜像ID */ - public static final String IMAGE_ID = "m-uf6ffgkry85fwu4znr6s"; + public static final String IMAGE_ID = "m-uf62k8zpy0ga35jnmkwt"; /** * 实例类型 @@ -57,6 +60,8 @@ public class ManageInstance implements ApplicationRunner { public static final String INSTANCE_CHARGE_TY = "PostPaid"; public static List generateInstance() throws Exception { + + // 创建阿里云ECS客户端 // 创建ECS客户端对象,用于后续调用ECS相关API Client client = CreateClient.createClient(); @@ -118,16 +123,18 @@ public class ManageInstance implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { List list = generateInstance(); + ArrayList ipList = new ArrayList<>(); log.info("创建实例成功"); log.info("正在加载实例"); Thread.sleep(30000); List instanceInfos = SelectInstance.selectInstance(list); log.info("实例信息查询成功"); for (InstanceInfo instanceInfo : instanceInfos) { + ipList.add(instanceInfo.getIpAddress()); redisService.setCacheObject("FourInstanceIdKey:"+instanceInfo.getInstanceId(),instanceInfo); } + redisService.setCacheList("FourIpList",ipList); System.out.println("实例信息:"+instanceInfos); - log.info("实例信息:", JSONObject.toJSONString(instanceInfos)); } } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CloseInstance.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CloseInstance.java index dd6ab92..e98b6e9 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CloseInstance.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CloseInstance.java @@ -8,13 +8,17 @@ import com.aliyun.tea.TeaException; import com.aliyun.teaopenapi.models.Config; import com.aliyun.teautil.Common; import com.aliyun.teautil.models.RuntimeOptions; +import com.muyu.common.redis.service.RedisService; import com.muyu.vehicle.utils.CreateClient; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; +import redis.clients.jedis.Jedis; import java.util.ArrayList; +import java.util.Set; /** * 删除实例信息 @@ -23,6 +27,8 @@ import java.util.ArrayList; @Component @Log4j2 public class CloseInstance implements DisposableBean{ + @Autowired + private RedisService redisService; /** * description : @@ -33,6 +39,7 @@ public class CloseInstance implements DisposableBean{ */ public static void delInstance() throws Exception { + // 创建ECS客户端对象,用于后续调用ECS相关API Client client = CreateClient.createClient(); @@ -95,6 +102,19 @@ public class CloseInstance implements DisposableBean{ public void destroy() throws Exception { log.info("开始删除实例"); delInstance(); + redisService.deleteObject("FourIpList"); + // 连接到Redis服务器 + Jedis jedis = new Jedis("47.116.173.119", 6379); + // 指定要删除的文件夹(命名空间) + String namespace = "FourInstanceIdKey:"; + // 获取所有以namespace为前缀的键 + Set keys = jedis.keys(namespace + "*"); + // 如果存在键,则删除它们 + if (keys.size() > 0) { + jedis.del(keys.toArray(new String[0])); + } + // 关闭连接 + jedis.close(); } } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CreateExchange.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CreateExchange.java index eb7436b..49804f8 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CreateExchange.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/CreateExchange.java @@ -9,10 +9,15 @@ import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; +/** + * 创建交换机 + */ @Log4j2 @Component public class CreateExchange implements ApplicationRunner { + + @Autowired private ConnectionFactory connectionFactory; diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java index e2048d7..b1b33d2 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/config/SelectInstance.java @@ -29,7 +29,9 @@ import java.util.List; @Log4j2 public class SelectInstance { + public static List selectInstance(List instanceIds) throws Exception { + // 创建ECS客户端对象,用于后续调用ECS相关API Client client = CreateClient.createClient(); ArrayList instanceInfos = new ArrayList<>();// 实例基础信息 @@ -56,7 +58,6 @@ public class SelectInstance { list.add(instanceInfo); } System.out.println("实例信息:"+list); - log.info("实例信息:",list); return list; } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java index 0ba1477..c7f621b 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/controller/CarInstanceController.java @@ -17,10 +17,11 @@ public class CarInstanceController { @PostMapping("/receiveMsg") - public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){ + public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){ log.info("=======>"+vehicleConnectionReq); Result connect = vehicleConnectService.getConnect(vehicleConnectionReq); - return Result.success(connect); + MqttServerModel data = connect.getData(); + return Result.success(data); } } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/mapper/VehicleConnectMapper.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/mapper/VehicleConnectMapper.java index 50af952..f81af09 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/mapper/VehicleConnectMapper.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/mapper/VehicleConnectMapper.java @@ -3,10 +3,12 @@ package com.muyu.vehicle.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.muyu.vehicle.domain.req.VehicleConnectionReq; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; @Mapper public interface VehicleConnectMapper extends BaseMapper { - VehicleConnectionReq selectByVehicleVin(String vin); + Integer insertVehicleConnection(VehicleConnectionReq vehicleConnectionReq); + VehicleConnectionReq selectByVehicleVin(@Param("vin") String vin); } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/VehicleConnectService.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/VehicleConnectService.java index cf276da..9db7c6b 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/VehicleConnectService.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/VehicleConnectService.java @@ -7,6 +7,6 @@ import com.muyu.vehicle.domain.req.VehicleConnectionReq; public interface VehicleConnectService extends IService { - Result getConnect(VehicleConnectionReq vehicleConnectionReq); + Result getConnect(VehicleConnectionReq vehicleConnectionReq); } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/VehicleConnectServiceImpl.java b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/VehicleConnectServiceImpl.java index 340c273..6c28922 100644 --- a/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/VehicleConnectServiceImpl.java +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/java/com/muyu/vehicle/service/impl/VehicleConnectServiceImpl.java @@ -3,20 +3,31 @@ package com.muyu.vehicle.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.muyu.common.core.domain.Result; +import com.muyu.common.redis.service.RedisService; +import com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil; +import com.muyu.rabbitmq.producer.RabbitMQProducerUtil; import com.muyu.vehicle.domain.MqttServerModel; import com.muyu.vehicle.domain.req.VehicleConnectionReq; import com.muyu.vehicle.mapper.VehicleConnectMapper; import com.muyu.vehicle.service.VehicleConnectService; import lombok.extern.log4j.Log4j2; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service @Log4j2 public class VehicleConnectServiceImpl extends ServiceImpl implements VehicleConnectService { @Autowired private VehicleConnectMapper vehicleConnectMapper; + @Autowired private RedisService redisService; + + @Autowired + private RabbitMQProducerUtil rabbitMQProducerUtil; + @Override public Result getConnect(VehicleConnectionReq vehicleConnectionReq) { log.info("车辆连接信息:{}", vehicleConnectionReq); @@ -24,13 +35,43 @@ public class VehicleConnectServiceImpl extends ServiceImpl 0) { log.info("车辆预上线成功"); }else { - log.info("车辆已预上线成功,禁止重复"); + log.info("车辆预上线失败"); + } + rabbitMQProducerUtil.basicSendMessage("SendVin",vehicleConnectionReq.getVehicleVin()); + //从redis获取信息 + // 获取名为 "ipList" 的列表 + List ipList = redisService.getCacheList("FourIpList"); + if (ipList.isEmpty()) { + return null; + } + + // 获取当前使用的索引位置 + String indexStr = redisService.getCacheObject("currentIndex"); + int index = indexStr!= null? Integer.parseInt(indexStr) : 0; + String selectedIp = ipList.get(index); + // 获取该 IP 的使用次数 + String countStr = redisService.getCacheMapValue("ipCounts", selectedIp); + log.info("IP:[{}]车辆连接数:[{}]",selectedIp,countStr); + int count = countStr!= null? Integer.parseInt(countStr) : 0; + if (count < 6) { + // 使用次数加一 + count++; + redisService.setCacheMapValue("ipCounts", selectedIp, String.valueOf(count)); + // 更新索引 + index = (index + 1) % ipList.size(); + redisService.setCacheObject("currentIndex", String.valueOf(index)); + MqttServerModel mqttServerModel = new MqttServerModel("tcp://" + selectedIp.substring(1, selectedIp.length() - 1) + ":1883", "vehicle"); + return Result.success(mqttServerModel); + } else { + // 如果使用次数达到 6 次,跳过该 IP 并更新索引 + index = (index + 1) % ipList.size(); + redisService.setCacheObject("currentIndex", String.valueOf(index)); + return getConnect(vehicleConnectionReq); } - return null; } } diff --git a/cloud-modules/cloud-modules-vehiclegateway/src/main/resources/mapper/VehicleConnectMapper.xml b/cloud-modules/cloud-modules-vehiclegateway/src/main/resources/mapper/VehicleConnectMapper.xml new file mode 100644 index 0000000..684912d --- /dev/null +++ b/cloud-modules/cloud-modules-vehiclegateway/src/main/resources/mapper/VehicleConnectMapper.xml @@ -0,0 +1,15 @@ + + + + + + INSERT INTO `four`.`vehicle_connection` ( `vehicle_vin`, `timestamp`, `username`, `nonce`, `password`) VALUES + (#{vehicleVin},#{timestamp},#{username},#{nonce},#{password}) + + + + From 2308d974be8bc4431a361daddf2b3ff9af88a091 Mon Sep 17 00:00:00 2001 From: Number7 <1845377266@qq.com> Date: Thu, 10 Oct 2024 19:53:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix():=E6=95=B0=E6=8D=AE=E9=A2=84=E8=AD=A6?= =?UTF-8?q?=E7=BC=96=E5=86=99=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud-common/cloud-common-kafka/pom.xml | 4 -- .../muyu/event/consumer/MessageConsumer.java | 19 +++++--- .../event/listener/AddDatabaseListener.java | 7 --- .../muyu/event/service/IncidentService.java | 1 + .../service/impl/IncidentServiceImpl.java | 48 +++++++++++++------ .../muyu/template/config/MqttConfigure.java | 1 - .../java/com/muyu/common/domain/SysCar.java | 3 +- 7 files changed, 47 insertions(+), 36 deletions(-) diff --git a/cloud-common/cloud-common-kafka/pom.xml b/cloud-common/cloud-common-kafka/pom.xml index abe86fc..3b47731 100644 --- a/cloud-common/cloud-common-kafka/pom.xml +++ b/cloud-common/cloud-common-kafka/pom.xml @@ -33,9 +33,5 @@ com.muyu cloud-common-core - - - - diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java index 5caad0b..7caad4b 100644 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java @@ -1,7 +1,7 @@ package com.muyu.event.consumer; - import com.alibaba.fastjson2.JSONObject; import com.muyu.event.basic.EventPublisher; +import com.muyu.event.service.IncidentService; import lombok.extern.log4j.Log4j2; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -9,13 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; - import java.time.Duration; import java.util.Collections; import java.util.List; - import static org.bouncycastle.asn1.x500.style.RFC4519Style.l; - /** * kafka监听 * @author 刘武 @@ -29,16 +26,18 @@ public class MessageConsumer implements ApplicationRunner { @Autowired public KafkaConsumer consumer; - @Autowired + private EventPublisher eventPublisher; - private final String topic="four_car"; + private final String topic="kafka-topic"; + + @Autowired + private IncidentService incidentService; @Override public void run(ApplicationArguments args) throws Exception { List list = Collections.singletonList(topic); consumer.subscribe(list); - while (true){ ConsumerRecords consumerRecords = consumer.poll(Duration.ofMillis(100)); consumerRecords.forEach(record -> { @@ -46,6 +45,12 @@ public class MessageConsumer implements ApplicationRunner { JSONObject jsonObject = JSONObject.parseObject(value); log.info("value:{}",value); eventPublisher.publishEvent(jsonObject); + try { + incidentService.warnEventProcess(jsonObject); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); } } diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/listener/AddDatabaseListener.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/listener/AddDatabaseListener.java index 95e33bd..4d94fe6 100644 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/listener/AddDatabaseListener.java +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/listener/AddDatabaseListener.java @@ -1,13 +1,9 @@ package com.muyu.event.listener; - import com.alibaba.fastjson2.JSONObject; import com.muyu.event.basic.EventCustom; import com.muyu.event.basic.EventListener; - - import java.util.ArrayList; import java.util.List; - /** * 添加数据库事件 * @program: cloud-server @@ -29,9 +25,6 @@ public class AddDatabaseListener implements EventListener { values.add((String) value); }); - - - } @Override diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java index 4f60079..60c8c0e 100644 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/IncidentService.java @@ -12,5 +12,6 @@ public interface IncidentService { void warnEventProcess(JSONObject jsonObject) throws Exception; + void eventAlarmProcessing(JSONObject jsonObject) throws Exception; } diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java index fb90eb9..b205563 100644 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/IncidentServiceImpl.java @@ -1,11 +1,9 @@ package com.muyu.event.service.impl; import com.alibaba.fastjson2.JSONObject; -import com.muyu.cache.MessageTemplateTypeCacheService; -import com.muyu.cache.SysCarCacheService; -import com.muyu.cache.WarnRuleCacheService; -import com.muyu.cache.WarnStrategyCacheService; +import com.muyu.cache.*; import com.muyu.common.domain.MessageTemplateType; import com.muyu.common.domain.SysCar; +import com.muyu.common.domain.SysCarFault; import com.muyu.common.domain.resp.SysCarVo; import com.muyu.common.domain.resp.WarnRuleResp; import com.muyu.common.domain.resp.WarnStrategyResp; @@ -38,6 +36,7 @@ import java.util.stream.Collectors; @Log4j2 @Service public class IncidentServiceImpl implements IncidentService { + private static int DURATION_SECONDS = 5; private static List receivedStrings = new ArrayList<>(); private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @@ -61,27 +60,23 @@ public class IncidentServiceImpl implements IncidentService { //报文模版 @Resource private MessageTemplateTypeCacheService messageTemplateTypeCacheService; - - private final String topic="four_car"; - + //kafka的主题名称 + private final String topic="kafka-topic"; @Autowired - private MessageConsumer messageConsumer; - - @Autowired - public KafkaConsumer consumer; - + private SysCarFaultCacheService sysCarFaultCacheService; @Override public void warnEventProcess(JSONObject jsonObject) throws Exception { - receivedStrings.add(jsonObject); //协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings //根据这个车辆VIN查询出他对应的车辆类型 String carVin=null; //报文模版的ID Integer templateId=null; + //取出这辆车的carVin for (JSONObject receivedString : receivedStrings) { carVin = (String) receivedString.get("carVin"); } + //这辆车的信息 SysCar carByVin = null; List carVoList = sysCarCacheService.get(sysCarCacheService.keyPre()); Map carMap = carVoList.stream() @@ -94,6 +89,7 @@ public class IncidentServiceImpl implements IncidentService { List carWithWarnStrategyList=null; List warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre()); for (WarnStrategyResp warnStrategyResp : warnStrategyResps) { + //策略中有绑定的车辆ID if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){ carWithWarnStrategyList.add(warnStrategyResp); } @@ -154,7 +150,29 @@ public class IncidentServiceImpl implements IncidentService { } } } + @Override + public void eventAlarmProcessing(JSONObject jsonObject) throws Exception { + String carVin = (String) jsonObject.get("carVin"); + //车辆缓存配置 + List carVoList = sysCarCacheService.get(sysCarCacheService.keyPre()); + //这辆车的信息 + SysCar carByVin = null; + Map carMap = carVoList.stream() + .collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity())); + //获取到了这个车辆的信息 + carByVin = carMap.get(carVin); + Long carTypeId = carByVin.getCarTypeId(); + //车辆绑定的报警规则 + List sysCarFaults = sysCarFaultCacheService.get(sysCarFaultCacheService.keyPre()); + //车辆的所有报警规则都重新存储在sysCarFaultList里面 + List sysCarFaultList=null; + SysCar finalCarByVin = carByVin; + sysCarFaults.forEach(sysCarFault -> { + if(sysCarFault.getCarTypeId().equals(carTypeId)){ + sysCarFaultList.add(sysCarFault); + } + }); + //报文模版 - - + } } diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java index 9eb42bd..1e130a3 100644 --- a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java @@ -160,7 +160,6 @@ public class MqttConfigure { log.info("发送kafka成功"); return jsonObject; } - //kafka发送消息 public void sendKafka(JSONObject jsonObject){ ProducerRecord stringStringProducerRecord = new ProducerRecord<>("four_car", jsonObject.toString()); diff --git a/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/SysCar.java b/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/SysCar.java index c40467d..bc2096f 100644 --- a/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/SysCar.java +++ b/cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/SysCar.java @@ -1,5 +1,4 @@ package com.muyu.common.domain; - import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -8,7 +7,6 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; - /** * 车辆管理表 * @author sx @@ -22,6 +20,7 @@ import lombok.NoArgsConstructor; @EqualsAndHashCode(callSuper = true) @TableName(value = "sys_car",autoResultMap = true) public class SysCar extends BaseEntity { + @TableId(value = "id",type = IdType.AUTO) private Long id; private String carVin;