Merge remote-tracking branch 'origin/dev' into dev.business
# Conflicts: # cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/EnterpriseController.java # cloud-modules/saas/saas-server/src/main/resources/bootstrap.ymldev.business^2
commit
d7fa72be80
|
@ -17,6 +17,11 @@
|
|||
<dependencies>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
|
@ -36,6 +41,11 @@
|
|||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-saas</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.muyu.auth.form.RegisterBody;
|
|||
import com.muyu.auth.service.SysFirmService;
|
||||
import com.muyu.auth.service.SysLoginService;
|
||||
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.JwtUtils;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
|
@ -14,6 +15,8 @@ import com.muyu.common.security.auth.AuthUtil;
|
|||
import com.muyu.common.security.service.TokenService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -32,6 +35,7 @@ import java.sql.Connection;
|
|||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* token 控制
|
||||
|
@ -51,6 +55,9 @@ public class TokenController {
|
|||
@Autowired
|
||||
private SysFirmService sysFirmService;
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@PostMapping("login")
|
||||
@Operation(summary = "登录", description = "登录")
|
||||
public Result<?> login (@RequestBody LoginBody form) {
|
||||
|
@ -120,6 +127,13 @@ public class TokenController {
|
|||
} else {
|
||||
log.warn("数据库 {} 创建成功", settlement.getDatabaseName());
|
||||
|
||||
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setCreateTime(new Date());
|
||||
sysUser.setUserName(settlement.getFirmName());
|
||||
sysUser.setDatabaseName(settlement.getDatabaseName());
|
||||
remoteUserService.addUser(sysUser, SecurityConstants.INNER);
|
||||
|
||||
// 切换到新的数据库连接
|
||||
Connection connection = null;
|
||||
try {
|
||||
|
|
|
@ -13,8 +13,10 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.ip.IpUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.Business;
|
||||
|
||||
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.common.system.domain.Business;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: four
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.kafka</groupId>-->
|
||||
<!-- <artifactId>kafka-clients</artifactId>-->
|
||||
<!-- <version>3.0.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.kafka</groupId>-->
|
||||
<!-- <artifactId>kafka-clients</artifactId>-->
|
||||
<!-- <version>3.0.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.muyu.common.kafka.config;
|
||||
|
||||
|
||||
|
||||
import com.muyu.common.core.constant.KafkaConstant;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
|
|
|
@ -49,8 +49,6 @@ public class KafkaProducerConfig {
|
|||
private String acks;
|
||||
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public KafkaProducer kafkaProducer() {
|
||||
Map<String, Object> configs = new HashMap<>();
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
|
||||
|
||||
import com.muyu.common.rabbit.constants.RabbitmqConstants;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @ClassName: DelayedQueueConfig
|
||||
* @Description: 延迟队列配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class DelayedQueueConfig {
|
||||
|
||||
|
||||
@Resource
|
||||
private RabbitAdmin rabbitAdmin;
|
||||
|
||||
/**
|
||||
* 声明队列
|
||||
* @return 返回队列
|
||||
*/
|
||||
@Bean
|
||||
public Queue delayedQueue() {
|
||||
Queue queue = new Queue(RabbitmqConstants.DELAYED_QUEUE_NAME);
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
return queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 声明交换机
|
||||
* @return 返回交换机
|
||||
*/
|
||||
@Bean
|
||||
public Exchange delayedExchange() {
|
||||
HashMap<String, Object> arguments = new HashMap<>(3);
|
||||
|
||||
arguments.put("x-delayed-type", "direct");
|
||||
|
||||
/**
|
||||
* 声明自定义交换机
|
||||
* 第一个参数:交换机的名称
|
||||
* 第二个参数:交换机的类型
|
||||
* 第三个参数:是否需要持久化
|
||||
* 第四个参数:是否自动删除
|
||||
* 第五个参数:其他参数
|
||||
*/
|
||||
CustomExchange customExchange = new CustomExchange(
|
||||
RabbitmqConstants.DELAYED_EXCHANGE_NAME,
|
||||
"x-delayed-message",
|
||||
true,
|
||||
false,
|
||||
arguments);
|
||||
rabbitAdmin.declareExchange(customExchange);
|
||||
return customExchange;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定交换机
|
||||
* @param delayedQueue 队列对象
|
||||
* @param delayedExchange 交换机对象
|
||||
*/
|
||||
@Bean
|
||||
public Binding delayedQueueBindingDelayedExchange(
|
||||
@Qualifier("delayedQueue") Queue delayedQueue,
|
||||
@Qualifier("delayedExchange") Exchange delayedExchange) {
|
||||
|
||||
Binding noargs = BindingBuilder.bind(delayedQueue)
|
||||
.to(delayedExchange)
|
||||
.with(RabbitmqConstants.DELAYED_ROUTING_KEY)
|
||||
.noargs();
|
||||
rabbitAdmin.declareBinding(noargs);
|
||||
return noargs;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @Time: 2024/4/22 11:55
|
||||
* @Description: 主题模式配置
|
||||
*/
|
||||
@Configuration
|
||||
public class TopicConfig {
|
||||
|
||||
/**
|
||||
* 主题模式交换机
|
||||
* @return exchange
|
||||
*/
|
||||
@Bean(name = "topicExchange")
|
||||
public Exchange getTopicExchange(){
|
||||
return ExchangeBuilder
|
||||
.topicExchange("exchange_topic")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 主题队列 01
|
||||
* @return queue
|
||||
*/
|
||||
@Bean(name = "topicQueue01")
|
||||
public Queue getTopicQueue01(){
|
||||
return QueueBuilder
|
||||
.durable("queue_topic_01")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 主题队列 02
|
||||
* @return queue
|
||||
*/
|
||||
@Bean(name = "topicQueue02")
|
||||
public Queue getTopicQueue02(){
|
||||
return QueueBuilder
|
||||
.durable("queue_topic_02")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定队列 01
|
||||
* @return binding
|
||||
*/
|
||||
@Bean
|
||||
public Binding getTopicBinding01(){
|
||||
return BindingBuilder
|
||||
.bind(getTopicQueue01())
|
||||
.to(getTopicExchange())
|
||||
//路由键 队列1接收debug级别的消息
|
||||
.with("front.#")
|
||||
.noargs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定队列 02
|
||||
* @return binding
|
||||
*/
|
||||
@Bean
|
||||
public Binding getTopicBinding02(){
|
||||
return BindingBuilder
|
||||
.bind(getTopicQueue02())
|
||||
.to(getTopicExchange())
|
||||
// 路由键 队列2接收info级别的消息
|
||||
.with("back.order.*")
|
||||
.noargs();
|
||||
}
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
package com.muyu.common.rabbit.producer;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.rabbit.constants.RabbitmqConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @ClassName: RabbitMQProducer
|
||||
* @Description: rabbitmq生产者
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@Log4j2
|
||||
public class RabbitMQProducerUtil {
|
||||
//redis工具类对象
|
||||
|
||||
//rabbit
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 简单模型
|
||||
*
|
||||
* @param param 传递的消息 (如果是对象需要序列化)
|
||||
* @return 结果集
|
||||
* 一对一消费,只有一个消费者能接收到
|
||||
*/
|
||||
public Result<?> basicSendMessage(String queueName, Object param, String msg) {
|
||||
|
||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", RabbitmqConstants.BASIC_QUEUE_NAME, param, msg);
|
||||
// 发送简单模型消息
|
||||
// 第一个参数: 绑定规则 相当于 队列名称
|
||||
// 第二个参数:消息内容
|
||||
rabbitTemplate.convertAndSend(queueName, param, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
|
||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", RabbitmqConstants.BASIC_QUEUE_NAME);
|
||||
|
||||
return Result.success(msg!=null?msg:"消息发送成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* Work queue 工作模型
|
||||
*
|
||||
* @param obj 传递的消息 (如果是对象需要序列化)
|
||||
* @return 结果集
|
||||
* 多个消费者,你一个我一个分配消费消息,有预取机制,默认公平消费,可配置 能者多劳模式(),谁完成的快,谁多做一点
|
||||
*/
|
||||
public Result<?> workSendMessage(String queueName, Object obj, String msg) {
|
||||
|
||||
log.info("【工作模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", queueName, obj, msg);
|
||||
// 发送简单模型消息
|
||||
// 第一个参数: 绑定规则 相当于 队列名称
|
||||
// 第二个参数:消息内容
|
||||
rabbitTemplate.convertAndSend(queueName, obj, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
|
||||
log.info("【工作模型mq】 : method: 【 workSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", queueName);
|
||||
|
||||
return Result.success("消息发送成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish/Subscribe 发布订阅者模型
|
||||
* 多个消费者,多个消费者可以同时接收到消息 有交换机 类型 fanout
|
||||
*
|
||||
* @param exchange 交换机名称
|
||||
* @param obj 发送的消息Object
|
||||
* @param msg 响应的内容
|
||||
* @return 结果集
|
||||
*/
|
||||
public Result<?> publishSubscribeSendMessage(String exchange, Object obj, String msg) {
|
||||
|
||||
log.info("【订阅模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
|
||||
// 发送简单模型消息
|
||||
// 第一个参数: exchange 交换机的名称
|
||||
// 第二个参数: 绑定规则 发布订阅者模型 不写 默认 "" 只要绑定就行 不需要规则
|
||||
// 第三个参数:消息内容
|
||||
rabbitTemplate.convertAndSend(exchange, "", obj, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
|
||||
log.info("【订阅模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
||||
|
||||
return Result.success("消息发送成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* Routing路由模型
|
||||
* 使用的是 Direct 类型的交换机,会将接收到的消息根据 规则 路由到指定的Queue(队列),因此称为路由模式
|
||||
*
|
||||
* @param exchange 交换机名称
|
||||
* @param rule 绑定规则 一个字符串即可
|
||||
* @param obj 发送的消息Object
|
||||
* @param msg 响应的内容
|
||||
* @return 结果集
|
||||
*/
|
||||
public Result<?> routingSendMessage(String exchange, String rule, Object obj, String msg) {
|
||||
|
||||
log.info("【路由模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
|
||||
// 发送简单模型消息
|
||||
// 第一个参数: 绑定规则 相当于 队列名称
|
||||
// 第二个参数:消息内容
|
||||
rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
|
||||
log.info("【路由模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
||||
|
||||
return Result.success("消息发送成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Topic主题模型模型
|
||||
* 使用的是 topic 类型的交换机
|
||||
*
|
||||
* @param exchange 交换机名称
|
||||
* @param rule 绑定规则 可以绑定多个单词以 . 拼接 也可以使用 #(匹配 零个 一个 或 多个 单词) 或 *(匹配 一个 单词) 通配符(例如:name.msg, *.msg, age.# )
|
||||
* @param obj 发送的消息Object
|
||||
* @param msg 响应的内容
|
||||
* @return 结果集
|
||||
*/
|
||||
public Result<?> topicSendMessage(String exchange, String rule, Object obj) {
|
||||
|
||||
log.info("【主题模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {} 】 ---> 【 消息发送中。。。 】", exchange, obj);
|
||||
// 发送简单模型消息
|
||||
// 第一个参数: 绑定规则 相当于 队列名称
|
||||
// 第二个参数:消息内容
|
||||
rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
|
||||
log.info("【主题模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
||||
|
||||
return Result.success(obj,"消息发送成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 延迟队列模型
|
||||
* @param param 传输内容
|
||||
* @param delayTime 延迟时间
|
||||
* @return 结果集
|
||||
*/
|
||||
public Result<?> delayedSendMessage(Long delayTime, Object param) {
|
||||
log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送中。。。 】",param);
|
||||
|
||||
rabbitTemplate.convertAndSend(RabbitmqConstants.DELAYED_EXCHANGE_NAME, RabbitmqConstants.DELAYED_ROUTING_KEY,param, message -> {
|
||||
MessageProperties messageProperties = message.getMessageProperties();
|
||||
messageProperties.setMessageId(UUID.randomUUID().toString());
|
||||
messageProperties.setDelayLong(delayTime);
|
||||
return message;
|
||||
});
|
||||
log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送成功 】",param);
|
||||
|
||||
return Result.success(param,"消息发送成功");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
|
||||
|
||||
|
@ -21,16 +21,16 @@ public class RabbitAdminConfig {
|
|||
private String username;
|
||||
@Value("${spring.rabbitmq.password}")
|
||||
private String password;
|
||||
@Value("${spring.rabbitmq.virtualhost}")
|
||||
private String virtualHost;
|
||||
@Value("${spring.rabbitmq.port}")
|
||||
private Integer port;
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactory() {
|
||||
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
|
||||
cachingConnectionFactory.setHost(host);
|
||||
cachingConnectionFactory.setPort(port);
|
||||
cachingConnectionFactory.setUsername(username);
|
||||
cachingConnectionFactory.setPassword(password);
|
||||
cachingConnectionFactory.setVirtualHost(virtualHost);
|
||||
return cachingConnectionFactory;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.amqp.core.ReturnedMessage;
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.constants;
|
||||
package com.muyu.rabbitmq.constants;
|
||||
|
||||
/**
|
||||
*
|
|
@ -1,11 +1,15 @@
|
|||
package com.muyu.common.rabbit.consumer;
|
||||
package com.muyu.rabbitmq.consumer;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
//import com.muyu.rabbitmq.util.CacheUtil;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -22,6 +26,9 @@ public class RabbitMQConsumerUtil {
|
|||
|
||||
private final RedisService redisService;
|
||||
|
||||
// @Autowired
|
||||
// private CacheUtil cacheUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 普通消费者
|
||||
|
@ -29,7 +36,8 @@ public class RabbitMQConsumerUtil {
|
|||
* @param message
|
||||
* @param channel
|
||||
*/
|
||||
public void rabbitMQBasicConsumer(Object data ,Message message , Channel channel) {
|
||||
// @RabbitListener(queuesToDeclare = @Queue(name = "basic"))
|
||||
public void rabbitMQBasicConsumer(String data ,Message message , Channel channel) {
|
||||
log.info("当前时间:{} :RabbitMQConsumerUtil : {}", new Date(), message);
|
||||
try {
|
||||
// 获取到消息 开始消费
|
||||
|
@ -42,10 +50,12 @@ public class RabbitMQConsumerUtil {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* -----------------------------------以下为异步业务操作----------------------------
|
||||
*/
|
||||
String carList = (String) redisService.redisTemplate.opsForValue().get("carList");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------------
|
|
@ -0,0 +1,174 @@
|
|||
package com.muyu.rabbitmq.producer;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.rabbitmq.constants.RabbitmqConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @ClassName: RabbitMQProducer
|
||||
* @Description: rabbitmq生产者
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@Log4j2
|
||||
public class RabbitMQProducerUtil {
|
||||
//redis工具类对象
|
||||
|
||||
//rabbit
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 简单模型
|
||||
*
|
||||
* @param param 传递的消息 (如果是对象需要序列化)
|
||||
* @return 结果集
|
||||
* 一对一消费,只有一个消费者能接收到
|
||||
*/
|
||||
public void basicSendMessage(String queueName, String param) {
|
||||
|
||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】 - ages: 【 String : {}, Object : {}】 ---> 【 消息发送中。。。 】", RabbitmqConstants.BASIC_QUEUE_NAME, param);
|
||||
// 发送简单模型消息
|
||||
// 第一个参数: 绑定规则 相当于 队列名称
|
||||
// 第二个参数:消息内容
|
||||
rabbitTemplate.convertAndSend(queueName, param, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
|
||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", RabbitmqConstants.BASIC_QUEUE_NAME);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Work queue 工作模型
|
||||
// *
|
||||
// * @param obj 传递的消息 (如果是对象需要序列化)
|
||||
// * @return 结果集
|
||||
// * 多个消费者,你一个我一个分配消费消息,有预取机制,默认公平消费,可配置 能者多劳模式(),谁完成的快,谁多做一点
|
||||
// */
|
||||
// public Result<?> workSendMessage(String queueName, Object obj, String msg) {
|
||||
//
|
||||
// log.info("【工作模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", queueName, obj, msg);
|
||||
// // 发送简单模型消息
|
||||
// // 第一个参数: 绑定规则 相当于 队列名称
|
||||
// // 第二个参数:消息内容
|
||||
// rabbitTemplate.convertAndSend(queueName, obj, message -> {
|
||||
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
// return message;
|
||||
// } );
|
||||
//
|
||||
// log.info("【工作模型mq】 : method: 【 workSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", queueName);
|
||||
//
|
||||
// return Result.success("消息发送成功");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Publish/Subscribe 发布订阅者模型
|
||||
// * 多个消费者,多个消费者可以同时接收到消息 有交换机 类型 fanout
|
||||
// *
|
||||
// * @param exchange 交换机名称
|
||||
// * @param obj 发送的消息Object
|
||||
// * @param msg 响应的内容
|
||||
// * @return 结果集
|
||||
// */
|
||||
// public Result<?> publishSubscribeSendMessage(String exchange, Object obj, String msg) {
|
||||
//
|
||||
// log.info("【订阅模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
|
||||
// // 发送简单模型消息
|
||||
// // 第一个参数: exchange 交换机的名称
|
||||
// // 第二个参数: 绑定规则 发布订阅者模型 不写 默认 "" 只要绑定就行 不需要规则
|
||||
// // 第三个参数:消息内容
|
||||
// rabbitTemplate.convertAndSend(exchange, "", obj, message -> {
|
||||
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
// return message;
|
||||
// } );
|
||||
//
|
||||
// log.info("【订阅模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
||||
//
|
||||
// return Result.success("消息发送成功");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Routing路由模型
|
||||
// * 使用的是 Direct 类型的交换机,会将接收到的消息根据 规则 路由到指定的Queue(队列),因此称为路由模式
|
||||
// *
|
||||
// * @param exchange 交换机名称
|
||||
// * @param rule 绑定规则 一个字符串即可
|
||||
// * @param obj 发送的消息Object
|
||||
// * @param msg 响应的内容
|
||||
// * @return 结果集
|
||||
// */
|
||||
// public Result<?> routingSendMessage(String exchange, String rule, Object obj, String msg) {
|
||||
//
|
||||
// log.info("【路由模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
|
||||
// // 发送简单模型消息
|
||||
// // 第一个参数: 绑定规则 相当于 队列名称
|
||||
// // 第二个参数:消息内容
|
||||
// rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
|
||||
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
// return message;
|
||||
// } );
|
||||
//
|
||||
// log.info("【路由模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
||||
//
|
||||
// return Result.success("消息发送成功");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Topic主题模型模型
|
||||
// * 使用的是 topic 类型的交换机
|
||||
// *
|
||||
// * @param exchange 交换机名称
|
||||
// * @param rule 绑定规则 可以绑定多个单词以 . 拼接 也可以使用 #(匹配 零个 一个 或 多个 单词) 或 *(匹配 一个 单词) 通配符(例如:name.msg, *.msg, age.# )
|
||||
// * @param obj 发送的消息Object
|
||||
// * @param msg 响应的内容
|
||||
// * @return 结果集
|
||||
// */
|
||||
// public Result<?> topicSendMessage(String exchange, String rule, Object obj) {
|
||||
//
|
||||
// log.info("【主题模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {} 】 ---> 【 消息发送中。。。 】", exchange, obj);
|
||||
// // 发送简单模型消息
|
||||
// // 第一个参数: 绑定规则 相当于 队列名称
|
||||
// // 第二个参数:消息内容
|
||||
// rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
|
||||
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
// return message;
|
||||
// } );
|
||||
//
|
||||
// log.info("【主题模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
||||
//
|
||||
// return Result.success(obj,"消息发送成功");
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 延迟队列模型
|
||||
* @param param 传输内容
|
||||
* @param delayTime 延迟时间
|
||||
* @return 结果集
|
||||
*/
|
||||
// public Result<?> delayedSendMessage(Long delayTime, Object param) {
|
||||
// log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送中。。。 】",param);
|
||||
//
|
||||
// rabbitTemplate.convertAndSend(RabbitmqConstants.DELAYED_EXCHANGE_NAME, RabbitmqConstants.DELAYED_ROUTING_KEY,param, message -> {
|
||||
// MessageProperties messageProperties = message.getMessageProperties();
|
||||
// messageProperties.setMessageId(UUID.randomUUID().toString());
|
||||
// messageProperties.setDelayLong(delayTime);
|
||||
// return message;
|
||||
// });
|
||||
// log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送成功 】",param);
|
||||
//
|
||||
// return Result.success(param,"消息发送成功");
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
|
@ -2,6 +2,5 @@ com.muyu.rabbitmq.producer.RabbitMQProducerUtil
|
|||
com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil
|
||||
com.muyu.rabbitmq.config.RabbitmqConfig
|
||||
com.muyu.rabbitmq.config.MyConfirmCallback
|
||||
com.muyu.rabbitmq.config.DelayedQueueConfig
|
||||
com.muyu.rabbitmq.config.RabbitAdminConfig
|
||||
com.muyu.rabbitmq.config.ReturnCallbackConfig
|
||||
|
|
|
@ -33,9 +33,10 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -6,17 +6,17 @@ import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
|||
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
||||
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
|
||||
import com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory;
|
||||
import com.muyu.cloud.common.many.datasource.init.InitDataSource;
|
||||
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
||||
import com.muyu.cloud.common.saas.domain.Datasource;
|
||||
import com.muyu.cloud.common.saas.domain.model.EntInfo;
|
||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.common.system.domain.Datasource;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteSaaSService;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
|
@ -29,8 +29,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 多数据源
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: 多数据源
|
||||
* @Version: 1.0
|
||||
|
@ -39,9 +38,14 @@ import java.util.Map;
|
|||
@Component
|
||||
@AutoConfiguration(before = {MybatisPlusAutoConfiguration.class, MybatisAutoConfiguration.class})
|
||||
public class ManyDataSource implements ApplicationRunner{
|
||||
|
||||
@Autowired
|
||||
private InitDataSource initDataSource;
|
||||
|
||||
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
RemoteSaaSService remoteSaaSService = SpringUtils.getBean(RemoteSaaSService.class);
|
||||
Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseList();
|
||||
Result<List<Datasource>> tableDataInfoResult = initDataSource.initDatasource();
|
||||
if (tableDataInfoResult==null){
|
||||
throw new SaaSException("saas远调数据源错误");
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.muyu.cloud.common.many.datasource.constents;
|
||||
|
||||
/**
|
||||
* 数据源常量
|
||||
* @author liuwu
|
||||
* @author DongZl
|
||||
* @description: 数据源常量
|
||||
* @Date 2023-8-1 上午 11:02
|
||||
*/
|
||||
|
@ -17,8 +16,4 @@ public class DatasourceContent {
|
|||
public final static String IP = "47.101.53.251";
|
||||
|
||||
public final static Integer PORT = 3306;
|
||||
|
||||
public static String getDatasourceUrl(String databaseName) {
|
||||
return String.format(DATASOURCE_URL,USER_NAME,PASSWORD,IP,PORT, databaseName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 数据源实体类
|
||||
* @author liuwu
|
||||
* @author DongZl
|
||||
* @description: 数据源实体类
|
||||
* @Date 2023-8-1 上午 11:15
|
||||
*/
|
||||
|
|
|
@ -8,8 +8,7 @@ import org.springframework.stereotype.Component;
|
|||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Druid工厂
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: Druid工厂
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.util.Assert;
|
|||
/**
|
||||
* 数据源切换处理
|
||||
*
|
||||
* @author liuwu
|
||||
* @author Dongzl
|
||||
*/
|
||||
@Slf4j
|
||||
public class DynamicDataSourceHolder {
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.cloud.common.many.datasource.init;
|
||||
|
||||
|
||||
import com.muyu.cloud.common.saas.domain.Datasource;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class InitDataSource {
|
||||
|
||||
public static final String USER="root";
|
||||
public static final String PASSWORD="Lw030106";
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public Result<List<Datasource>> initDatasource(){
|
||||
ArrayList<Datasource> list = new ArrayList<>();
|
||||
|
||||
try {
|
||||
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
|
||||
Connection connection= DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/datasource?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false",USER,PASSWORD);
|
||||
String sql="select * from `datasource` ";
|
||||
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
|
||||
while (rs.next()){
|
||||
Datasource datasource = new Datasource();
|
||||
datasource.setId(rs.getInt("id"));
|
||||
datasource.setFirmName(rs.getString("firm_name"));
|
||||
datasource.setDatabaseName(rs.getString("database_name"));
|
||||
list.add(datasource);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return Result.success(list);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
package com.muyu.cloud.common.saas.contents;
|
||||
|
||||
/**
|
||||
* SAAS常量
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: SAAS常量
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -6,7 +6,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: 企业信息
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -4,8 +4,7 @@ package com.muyu.cloud.common.saas.exception;
|
|||
import com.muyu.common.core.exception.ServiceException;
|
||||
|
||||
/**
|
||||
* SaaS异常类
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: SaaS异常类
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.muyu.cloud.common.saas.interceptor;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.common.saas.contents.SaaSConstant;
|
||||
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
|
||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
||||
import com.muyu.cloud.common.saas.contents.SaaSConstant;
|
||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.common.core.utils.ServletUtils;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -14,8 +13,7 @@ import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
|||
|
||||
|
||||
/**
|
||||
* SAAS拦截器
|
||||
* @author liuwu
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: SAAS拦截器
|
||||
* @Version: 1.0
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
com.muyu.cloud.common.saas.interceptor.WebMvcSaaSConfig
|
||||
com.muyu.cloud.common.many.datasource.ManyDataSource
|
||||
com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory
|
||||
com.muyu.cloud.common.many.datasource.init.InitDataSource
|
|
@ -8,6 +8,7 @@ import com.muyu.common.system.domain.SysUser;
|
|||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -52,4 +53,12 @@ public interface RemoteUserService {
|
|||
*/
|
||||
@PostMapping("/user/enterprise")
|
||||
Result<Boolean>settlementEnterpriseInfo(@RequestBody Business enterprise, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 用户添加
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/user/addUser")
|
||||
public Result<Integer> addUser(@RequestBody SysUser sysUser,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,12 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
return Result.error("入驻企业失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Integer> addUser(SysUser sysUser, String source) {
|
||||
return Result.error("用户添加失败");
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: four
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -115,6 +115,12 @@
|
|||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>saas-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -28,6 +28,4 @@ public class EventPublisher implements ApplicationEventPublisherAware {
|
|||
publisher.publishEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -66,9 +66,7 @@ public class IoTDBConfig {
|
|||
measurements.add("car_vin");
|
||||
measurements.add("information");
|
||||
|
||||
|
||||
session.insertRecord(TABLENAME,System.currentTimeMillis(),measurements,list);
|
||||
|
||||
//关闭连接
|
||||
session.close();
|
||||
} catch (IoTDBConnectionException e) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.muyu.event.consumer;
|
||||
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.event.basic.EventPublisher;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -36,7 +34,6 @@ public class MessageConsumer implements ApplicationRunner {
|
|||
|
||||
private final String topic="four_car";
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
List<String> list = Collections.singletonList(topic);
|
||||
|
@ -48,10 +45,8 @@ public class MessageConsumer implements ApplicationRunner {
|
|||
String value = record.value();
|
||||
JSONObject jsonObject = JSONObject.parseObject(value);
|
||||
log.info("value:{}",value);
|
||||
// eventPublisher.publishEvent(jsonObject);
|
||||
eventPublisher.publishEvent(jsonObject);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package com.muyu.event.consumer;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cache.ElectronicFenceGroupCacheService;
|
||||
import com.muyu.cache.SysCarCacheService;
|
||||
import com.muyu.common.domain.database.ElectronicFenceGroup;
|
||||
import com.muyu.common.domain.resp.SysCarVo;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* rabbitmq 监听器
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.consumer
|
||||
* @name:MqConsumer
|
||||
* @date:2024/10/2 14:17
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class MqConsumer {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private SysCarCacheService sysCarCacheService;
|
||||
@Autowired
|
||||
private ElectronicFenceGroupCacheService electronicFenceGroupCacheService;
|
||||
|
||||
@RabbitListener(queuesToDeclare = @Queue(name = "basic"))
|
||||
public void rabbitMQBasicConsumer(String data , Message message , Channel channel) {
|
||||
log.info("当前时间:{} :RabbitMQConsumerUtil : {}", new Date(), message);
|
||||
try {
|
||||
// 获取到消息 开始消费
|
||||
log.info("消息消费者接收到消息,消息内容:{}", JSONObject.toJSONString(data));
|
||||
|
||||
Long add = redisService.redisTemplate.opsForSet().add(data, message.getMessageProperties().getMessageId());
|
||||
|
||||
if (add != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* -----------------------------------以下为异步业务操作----------------------------
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------------
|
||||
*/
|
||||
// 消费消息成功之后需要确认
|
||||
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
|
||||
// boolean multiple 是否批量确认 true 批量 确认小于等于当前投递序号的消息 false 单个确认
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
log.info("xxx消费者接收到消息,消息内容:{},消费成功...", message);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("xxx消费者接收到消息,消息内容:{},消费消息异常,异常信息:{}", message, e);
|
||||
// 消息回退 拒绝消费消息
|
||||
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
|
||||
// boolean requeue 是否回到原来的队列
|
||||
try {
|
||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
|
||||
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
||||
} catch (IOException ex) {
|
||||
log.error("xxx消费者接收到消息,消息内容:{},回退消息异常,异常信息:{}", message, ex);
|
||||
}
|
||||
}finally {
|
||||
try {
|
||||
channel.close();
|
||||
} catch (Exception e) {
|
||||
log.error("xxx消费者关闭Channel异常,消息内容:{},异常信息:{}", message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -18,4 +18,6 @@ public class OnlineConsumer {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,11 +4,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 数据处理
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.controller
|
||||
* @name:DataController
|
||||
* @date:2024/9/29 20:16
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("data")
|
||||
public class DataController {
|
||||
|
|
|
@ -19,13 +19,12 @@ import java.util.List;
|
|||
* @name:ItodbController
|
||||
* @date:2024/9/28 19:17
|
||||
*/
|
||||
@RestController()
|
||||
@RestController
|
||||
public class IoTDBController {
|
||||
|
||||
@Autowired
|
||||
private IoTDBService tdbService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询实时车辆信息列表
|
||||
* @return list
|
||||
|
@ -47,7 +46,6 @@ public class IoTDBController {
|
|||
return Result.success(carInformation);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 车辆添加
|
||||
* @param addCarInformation
|
||||
|
@ -59,16 +57,4 @@ public class IoTDBController {
|
|||
return Result.success("添加成功");
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,20 +2,17 @@ package com.muyu.event.controller;
|
|||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.event.service.TestService;
|
||||
import com.muyu.rabbitmq.producer.RabbitMQProducerUtil;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.springframework.amqp.core.AmqpTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 测试
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.controller
|
||||
* @name:TestController
|
||||
|
@ -26,25 +23,33 @@ public class TestController {
|
|||
|
||||
@Resource
|
||||
private KafkaProducer kafkaProducer;
|
||||
|
||||
@Resource
|
||||
private RabbitMQProducerUtil rabbitMQProducerUtil;
|
||||
|
||||
|
||||
private static final String topic="four_car";
|
||||
|
||||
@GetMapping("send")
|
||||
@GetMapping("sendKafka")
|
||||
public String sendKafka(){
|
||||
|
||||
String message="发送一条信息";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("cj","sb");
|
||||
|
||||
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>(topic,jsonObject.toJSONString());
|
||||
jsonObject.put("cj","hh");
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>(topic,jsonObject.toString());
|
||||
kafkaProducer.send(producerRecord);
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
@GetMapping("sendMq")
|
||||
public String sendMq(){
|
||||
String message="发送一条信息-mq";
|
||||
rabbitMQProducerUtil.basicSendMessage("basic",message);
|
||||
return "success-mq";
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,13 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 事件实体类
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.domain
|
||||
* @name:Event
|
||||
* @date:2024/9/28 23:10
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -28,6 +28,10 @@ public class AddDatabaseListener implements EventListener {
|
|||
keys.add(key);
|
||||
values.add((String) value);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -302,4 +302,11 @@ public class SysUserController extends BaseController {
|
|||
public Result deptTree (SysDept dept) {
|
||||
return success(deptService.selectDeptTreeList(dept));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/addUser")
|
||||
public Result<Integer> addUser(@RequestBody SysUser sysUser){
|
||||
Integer i = userService.addUser(sysUser);
|
||||
return Result.success(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,5 +158,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||
List<SysUser> selectCompanyList();
|
||||
|
||||
|
||||
Integer addUser(SysUser sysUser);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -230,5 +230,6 @@ public interface SysUserService extends IService<SysUser> {
|
|||
|
||||
List<SysUser> selectCompanyList();
|
||||
|
||||
Integer addUser(SysUser sysUser);
|
||||
|
||||
}
|
||||
|
|
|
@ -518,4 +518,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return userMapper.selectCompanyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer addUser(SysUser sysUser) {
|
||||
return userMapper.addUser(sysUser);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: four
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<result property="databaseName" column="database_name"/>
|
||||
<association property="dept" javaType="com.muyu.common.system.domain.SysDept" resultMap="deptResult"/>
|
||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
|
||||
</resultMap>
|
||||
|
@ -204,6 +205,7 @@
|
|||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="databaseName !=null and databaseName!=''">database_name,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="userId != null and userId != ''">#{userId},</if>
|
||||
|
@ -218,6 +220,7 @@
|
|||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="databaseName!=null and databaseName!=''">#{databaseName}</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
@ -228,6 +231,11 @@
|
|||
INSERT INTO `saas`.`tb_enterprise` (`enterprise_id`, `enterprise_name`, `enterprise_car_count`, `enterprise_fence_count`, `enterprise_database_name`)
|
||||
VALUES (NULL, #{firmName}, 0, 0, #{databaseName});
|
||||
</insert>
|
||||
<insert id="addUser">
|
||||
INSERT INTO `four`.`sys_user`
|
||||
(`dept_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `del_flag`, `login_ip`, `login_date`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`, `database_name`)
|
||||
VALUES ( 105, #{userName}, '若依', '00', 'ry@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '47.101.53.251', '2024-05-23 15:08:18', 'admin', #{createTime}, '', NULL, '测试员', #{databaseName});
|
||||
</insert>
|
||||
|
||||
<update id="updateUser" parameterType="com.muyu.common.system.domain.SysUser">
|
||||
update sys_user
|
||||
|
|
|
@ -17,11 +17,12 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-kafka</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.muyu</groupId>-->
|
||||
<!-- <artifactId>cloud-common-kafka</artifactId>-->
|
||||
<!-- <version>3.6.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.server</groupId>
|
||||
|
@ -88,6 +89,15 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-xxl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId> <!-- or lettuce -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -13,11 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class CloudTemplateApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(CloudTemplateApplication.class, args);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package com.muyu.template.config;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.muyu.cache.MessageTemplateCacheService;
|
||||
import com.muyu.cache.MessageTemplateTypeCacheService;
|
||||
import com.muyu.cache.SysCarCacheService;
|
||||
import com.muyu.cache.TemplateCacheService;
|
||||
import com.muyu.common.domain.MessageTemplate;
|
||||
import com.muyu.common.domain.MessageTemplateType;
|
||||
import com.muyu.common.domain.SysCar;
|
||||
import com.muyu.common.domain.Template;
|
||||
import com.muyu.common.domain.resp.SysCarVo;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.server.service.MessageTemplateTypeService;
|
||||
import com.muyu.server.service.SysCarService;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
|
@ -13,11 +19,18 @@ 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 org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
/**
|
||||
*
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.mqtt.configure
|
||||
* @Project:cloud-server
|
||||
|
@ -32,21 +45,20 @@ public class MqttConfigure {
|
|||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
private SysCarCacheService service;
|
||||
|
||||
@Autowired
|
||||
private MessageTemplateCacheService messageTemplateCacheService;
|
||||
|
||||
@Autowired
|
||||
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
|
||||
|
||||
@Autowired
|
||||
private KafkaProducer kafkaProducer;
|
||||
|
||||
@Autowired
|
||||
private SysCarService service;
|
||||
|
||||
@Autowired
|
||||
private MessageTemplateTypeService messageTemplateTypeService;
|
||||
|
||||
@PostConstruct
|
||||
public void MQTTMonitoring(){
|
||||
|
||||
String topic = "vehicle";
|
||||
String topic = "car";
|
||||
int qos = 2;
|
||||
String broker = "tcp://47.101.53.251:1883";
|
||||
String clientId = "lxy";
|
||||
|
@ -74,8 +86,8 @@ public class MqttConfigure {
|
|||
JSONObject jsonObject = new JSONObject(messageContent);
|
||||
// 从JSON对象中获取"msg"字段的值
|
||||
String msgValue = jsonObject.getStr("msg");
|
||||
// messageParsing(msgValue);
|
||||
log.info("接收到的值为:"+msgValue);
|
||||
log.info("接收到的报文为:"+msgValue);
|
||||
messageParsing(msgValue);
|
||||
}
|
||||
//交付完成
|
||||
@Override
|
||||
|
@ -100,7 +112,8 @@ public class MqttConfigure {
|
|||
if (templateMessage.length() < 18) {
|
||||
throw new RuntimeException("The vehicle message is incorrect");
|
||||
}
|
||||
//将报文进行切割
|
||||
//将 templateMessage 按空格切割成多个字符串,得到一个字符串数组 hexArray。接着,
|
||||
// 将每个十六进制字符串转换成十进制整数,然后再转换为字符,最后将所有字符拼接成一个完整的字符串 result。
|
||||
String[] hexArray = templateMessage.split(" ");
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String hex : hexArray) {
|
||||
|
@ -108,35 +121,34 @@ public class MqttConfigure {
|
|||
result.append((char) decimal);
|
||||
}
|
||||
//取出VIN码
|
||||
String carVin = result.substring(0, 18 - 1);
|
||||
String carVin = result.substring(1, 18 );
|
||||
log.info("carVin码为:" + carVin);
|
||||
//根据VIN码获取车辆信息
|
||||
SysCar carByVin = service.findCarByVin(carVin);
|
||||
SysCar carByVin = null;
|
||||
List<SysCarVo> carList = service.get("carList");
|
||||
if(carList==null){
|
||||
throw new RuntimeException("Redis未获取到车辆数据!!!");
|
||||
}else{
|
||||
// 使用 HashMap 存储车信息,以 VIN 作为键
|
||||
Map<String, SysCarVo> carMap = carList.stream()
|
||||
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
|
||||
carByVin = carMap.get(carVin);
|
||||
}
|
||||
|
||||
log.info("车辆信息为:" + carByVin);
|
||||
//对应车辆所对应的报文模版
|
||||
Integer templateId = carByVin.getTemplateId();
|
||||
List<MessageTemplateType> templateTypeList;
|
||||
//key
|
||||
String redisKey = "messageTemplateType" + templateId;
|
||||
List<MessageTemplateType> messageTemplateTypes=null;
|
||||
String redisKey = "messageTemplateTypeList";
|
||||
//key存在
|
||||
if (redisTemplate.hasKey(redisKey)) {
|
||||
|
||||
List list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
||||
|
||||
templateTypeList = list.stream().map(o -> JSON.parseObject(o.toString(), MessageTemplateType.class))
|
||||
.toList();
|
||||
} else {
|
||||
List<MessageTemplateType> templateTypeList1 = messageTemplateTypeService.findTemplateById(templateId);
|
||||
templateTypeList = templateTypeList1;
|
||||
templateTypeList.forEach(
|
||||
templateType ->
|
||||
redisTemplate.opsForList().rightPush(
|
||||
redisKey, com.alibaba.fastjson.JSON.toJSONString(templateType)
|
||||
)
|
||||
);
|
||||
Boolean b = redisService.hasKey(redisKey);
|
||||
if (b) {
|
||||
messageTemplateTypes = messageTemplateTypeCacheService.get(redisKey);
|
||||
}else{
|
||||
throw new RuntimeException("请先将配置存入Redis!!!");
|
||||
}
|
||||
//将模版里面有的配置进行循环
|
||||
for (MessageTemplateType messageTemplateType : templateTypeList) {
|
||||
for (MessageTemplateType messageTemplateType : messageTemplateTypes) {
|
||||
//开始位置
|
||||
Integer startIndex = messageTemplateType.getStartIndex() - 1;
|
||||
//结束位置
|
||||
|
@ -144,14 +156,13 @@ public class MqttConfigure {
|
|||
//将每个解析后的字段都存入到JSON对象中
|
||||
jsonObject.put(messageTemplateType.getMessageField(), result.substring(startIndex, endIndex));
|
||||
}
|
||||
|
||||
log.info("解析后的报文是:" + jsonObject);
|
||||
sendKafka(jsonObject);
|
||||
log.info("发送kafka成功");
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
//kafka发送消息
|
||||
public void sendKafka(JSONObject jsonObject){
|
||||
ProducerRecord<String, String> stringStringProducerRecord = new ProducerRecord<>("four_car", jsonObject.toString());
|
||||
kafkaProducer.send(stringStringProducerRecord);
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
package com.muyu.template;
|
||||
import cn.hutool.json.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 lombok.extern.log4j.Log4j2;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
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.template
|
||||
* @name:test2
|
||||
* @Date:2024/10/6 10:34
|
||||
*/
|
||||
@Log4j2
|
||||
public class test {
|
||||
private static int DURATION_SECONDS = 5;
|
||||
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
||||
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static int elapsedSeconds = 0;
|
||||
private static String file="elapsed";
|
||||
private static List<MessageTemplateType> 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;
|
||||
public void main(String[] args) {
|
||||
//协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings
|
||||
//根据这个车辆VIN查询出他对应的车辆类型
|
||||
String carVin=null;
|
||||
//报文模版的ID
|
||||
Integer templateId=null;
|
||||
for (JSONObject receivedString : receivedStrings) {
|
||||
carVin = receivedString.getStr("carVin");
|
||||
}
|
||||
SysCar carByVin = null;
|
||||
List<SysCarVo> carVoList = sysCarCacheService.get(sysCarCacheService.keyPre());
|
||||
Map<String, SysCarVo> carMap = carVoList.stream()
|
||||
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
|
||||
//获取到了这个车辆的信息
|
||||
carByVin = carMap.get(carVin);
|
||||
//获取到这辆车绑定的报文模版
|
||||
templateId=carByVin.getTemplateId();
|
||||
//这个是这辆车对应的所有策略
|
||||
List<WarnStrategyResp> carWithWarnStrategyList=null;
|
||||
List<WarnStrategyResp> warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre());
|
||||
for (WarnStrategyResp warnStrategyResp : warnStrategyResps) {
|
||||
if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){
|
||||
carWithWarnStrategyList.add(warnStrategyResp);
|
||||
}
|
||||
}
|
||||
//该车对应的所有预警规则
|
||||
List<WarnRuleResp> warnRuleResp=null;
|
||||
List<WarnRuleResp> 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()+"不正常,请检查!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -131,6 +131,18 @@
|
|||
<version>4.2.0</version><!-- 请根据实际情况使用最新的版本 -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.server</groupId>
|
||||
<artifactId>saas-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Forest HTTP Client -->
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<version>1.5.36</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
|
||||
@SpringBootApplication
|
||||
@EnableMyFeignClients
|
||||
|
||||
public class VehicleGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VehicleGatewayApplication.class,args);
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.*;
|
||||
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.config.SelectInstance;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import com.muyu.vehicle.service.OpenInstance;
|
||||
import com.muyu.vehicle.service.SelectInstance;
|
||||
import com.muyu.vehicle.utils.CreateClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
|
@ -19,73 +19,49 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
/**
|
||||
* 项目启动创建实例
|
||||
*/
|
||||
public class ManageInstance implements ApplicationRunner {
|
||||
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID="m-uf6agr9i6g27gj23om34";
|
||||
public static final String IMAGE_ID = "m-uf6ffgkry85fwu4znr6s";
|
||||
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
public static final String INSTANCE_TYPE="ecs.e-c1m1.large";
|
||||
public static final String INSTANCE_TYPE = "ecs.e-c1m1.large";
|
||||
|
||||
/**
|
||||
* 安全组ID
|
||||
*/
|
||||
public static final String SECURITY_GROUP_ID="sg-uf6glo8c4k17szhxu7sk";
|
||||
public static final String SECURITY_GROUP_ID = "sg-uf6glo8c4k17szhxu7sk";
|
||||
|
||||
/**
|
||||
*交换机ID
|
||||
*/
|
||||
public static final String V_SWITCH_ID="vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
public static final String V_SWITCH_ID = "vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
|
||||
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
public static final String INSTANCE_CHARGE_TY="PostPaid";
|
||||
public static final String INSTANCE_CHARGE_TY = "PostPaid";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
|
||||
public static void generateInstance() throws Exception {
|
||||
public static List<String> generateInstance() throws Exception {
|
||||
// 创建阿里云ECS客户端
|
||||
Client client = ManageInstance.createClient();
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CreateClient.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk=
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk =
|
||||
new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
|
@ -109,7 +85,7 @@ public class ManageInstance implements ApplicationRunner {
|
|||
|
||||
|
||||
//创建运行时选择对象
|
||||
RuntimeOptions runTime=
|
||||
RuntimeOptions runTime =
|
||||
new RuntimeOptions();
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
|
@ -121,6 +97,7 @@ public class ManageInstance implements ApplicationRunner {
|
|||
list.add(instance);
|
||||
}
|
||||
log.info("ESC创建成功,实例ID为:" + list);
|
||||
return list;
|
||||
} catch (TeaException error) {
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
|
@ -131,43 +108,27 @@ public class ManageInstance implements ApplicationRunner {
|
|||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info("实例创建失败:"+error.getMessage());
|
||||
log.info("实例创建失败:" + error.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<InstanceInfo> selectInstance() throws Exception {
|
||||
Client client = ManageInstance.createClient();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai")
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInstanceChargeType("PostPaid")
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
;
|
||||
// 创建运行时选项对象
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
//实例ID Instances.Instance.InstanceId
|
||||
//实例IP Instances.Instance.PublicIpAddress.IpAddress
|
||||
//状态 Instances.Instance.Status
|
||||
DescribeInstancesResponse resp =client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = resp.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
instanceInfos.add(instanceInfo);
|
||||
|
||||
}
|
||||
log.info("实例信息为:"+Common.toJSONString(instanceInfos));
|
||||
return instanceInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
generateInstance();
|
||||
selectInstance();
|
||||
List<String> list = generateInstance();
|
||||
log.info("创建实例成功");
|
||||
log.info("正在加载实例");
|
||||
Thread.sleep(30000);
|
||||
List<InstanceInfo> instanceInfos = SelectInstance.selectInstance(list);
|
||||
log.info("实例信息查询成功");
|
||||
for (InstanceInfo instanceInfo : instanceInfos) {
|
||||
redisService.setCacheObject("FourInstanceIdKey:"+instanceInfo.getInstanceId(),instanceInfo);
|
||||
}
|
||||
System.out.println("实例信息:"+instanceInfos);
|
||||
log.info("实例信息:", JSONObject.toJSONString(instanceInfos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
|
||||
package com.muyu.vehicle.config;
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DeleteInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
|
@ -10,42 +8,33 @@ 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.vehicle.utils.CreateClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 删除实例信息
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class CloseInstance implements DisposableBean {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
public class CloseInstance implements DisposableBean{
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @return Client
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public static void delInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CloseInstance.createClient();
|
||||
Client client = CreateClient.createClient();
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai");
|
||||
|
@ -61,7 +50,7 @@ public class CloseInstance implements DisposableBean {
|
|||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
if (!instance.getInstanceId().equals("i-uf68jwsbbqq4b4xc893s")){
|
||||
if (!instance.getInstanceId().equals("i-uf68jwsbbqq4b4xc893s")) {
|
||||
list.add(instance.getInstanceId());
|
||||
}
|
||||
}
|
||||
|
@ -108,3 +97,4 @@ public class CloseInstance implements DisposableBean {
|
|||
delInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package com.muyu.vehicle.config;
|
||||
|
||||
import com.muyu.vehicle.domain.MqttServerModel;
|
||||
import feign.Client;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
|
||||
/**
|
||||
* 链接fluxMq
|
||||
*/
|
||||
@Log4j2
|
||||
public class ConnectFluxMq {
|
||||
|
||||
|
||||
|
||||
public void FluxMqConnect(String IP,String vin){
|
||||
String topic = "car";
|
||||
String broker = "tcp://"+IP+":1883";
|
||||
String clientId = vin+"vehicleGateway";
|
||||
MqttClient client;
|
||||
try {
|
||||
//创建
|
||||
client = new MqttClient(broker,clientId);
|
||||
//设置连接参数
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
options.setCleanSession(true);
|
||||
//连接到Broker
|
||||
client.connect(options);
|
||||
log.info("Connecting to broker: " + broker);
|
||||
//连接
|
||||
client.subscribe(topic,0);
|
||||
client.setCallback(new MqttCallback() {
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.muyu.vehicle.config;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("=====>开始创建交换机");
|
||||
|
||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||
|
||||
// 创建Fanout类型的交换机
|
||||
FanoutExchange exchange = new FanoutExchange("ONLINE_EXCHANGE", true, false);
|
||||
|
||||
rabbitAdmin.declareExchange(exchange);
|
||||
|
||||
// 创建队列
|
||||
Queue queue = new Queue("GO_ONLINE", true, false, false);
|
||||
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
|
||||
// Fanout交换机绑定
|
||||
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange));
|
||||
|
||||
log.info("=====>交换机创建成功");
|
||||
log.info("=====>队列创建成功并绑定到交换机");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.muyu.vehicle.config;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import com.muyu.vehicle.utils.CreateClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 查询实例信息
|
||||
*/
|
||||
|
||||
/**
|
||||
* 查询实例信息
|
||||
*/
|
||||
|
||||
@Log4j2
|
||||
public class SelectInstance {
|
||||
public static List<InstanceInfo> selectInstance(List<String> instanceIds) throws Exception {
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CreateClient.createClient();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||
.setInstanceIds(JSON.toJSONString(instanceIds))
|
||||
.setRegionId("cn-shanghai");
|
||||
// 创建运行时选项对象
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
//实例ID Instances.Instance.InstanceId
|
||||
//实例IP Instances.Instance.PublicIpAddress.IpAddress
|
||||
//状态 Instances.Instance.Status
|
||||
DescribeInstancesResponse resp = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = resp.getBody();
|
||||
|
||||
ArrayList<InstanceInfo> list = new ArrayList<>();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
log.info("实例ID:{}",instanceInfo.getInstanceId());
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
log.info("实例状态:{}",instanceInfo.getStatus());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
log.info("实例IP:{}",instanceInfo.getIpAddress());
|
||||
list.add(instanceInfo);
|
||||
}
|
||||
System.out.println("实例信息:"+list);
|
||||
log.info("实例信息:",list);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.vehicle.controller;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.vehicle.domain.MqttServerModel;
|
||||
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
|
||||
import com.muyu.vehicle.service.VehicleConnectService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/carInstance")
|
||||
public class CarInstanceController {
|
||||
|
||||
@Autowired
|
||||
private VehicleConnectService vehicleConnectService;
|
||||
|
||||
|
||||
@PostMapping("/receiveMsg")
|
||||
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
||||
log.info("=======>"+vehicleConnectionReq);
|
||||
Result<MqttServerModel> connect = vehicleConnectService.getConnect(vehicleConnectionReq);
|
||||
return Result.success(connect);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.muyu.vehicle.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* fluxMq配置
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FluxMqProperties {
|
||||
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 网关实例信息
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.vehicle.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Mqtt服务器模型
|
||||
* @author YunFei.Du
|
||||
* @date 22:08 2024/5/29
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MqttServerModel {
|
||||
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.vehicle.domain.req;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆连接信息
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName(value = "vehicle_connection")
|
||||
public class VehicleConnectionReq {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
|
||||
/**
|
||||
* 车辆VIN
|
||||
*/
|
||||
private String vehicleVin;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
|
||||
private String timestamp;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
||||
private String username;
|
||||
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce;
|
||||
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,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;
|
||||
|
||||
@Mapper
|
||||
public interface VehicleConnectMapper extends BaseMapper<VehicleConnectionReq> {
|
||||
|
||||
VehicleConnectionReq selectByVehicleVin(String vin);
|
||||
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponseBody;
|
||||
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.vehicle.ManageInstance;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Log4j2
|
||||
public class OpenInstance {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID="m-uf6agr9i6g27gj23om34";
|
||||
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
public static final String INSTANCE_TYPE="ecs.e-c1m1.large";
|
||||
|
||||
/**
|
||||
* 安全组ID
|
||||
*/
|
||||
public static final String SECURITY_GROUP_ID="sg-uf6glo8c4k17szhxu7sk";
|
||||
|
||||
/**
|
||||
*交换机ID
|
||||
*/
|
||||
public static final String V_SWITCH_ID="vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
|
||||
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
public static final String INSTANCE_CHARGE_TY="PostPaid";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
|
||||
public static void generateInstance() throws Exception {
|
||||
// 创建阿里云ECS客户端
|
||||
Client client = OpenInstance.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk=
|
||||
new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
|
||||
// 创建创建实例请求对象并设置参数
|
||||
|
||||
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
|
||||
.setRegionId("cn-shanghai") // 设置地域ID
|
||||
.setImageId(IMAGE_ID) // 设置镜像ID
|
||||
.setInstanceType(INSTANCE_TYPE) // 设置实例类型
|
||||
.setSecurityGroupId(SECURITY_GROUP_ID) // 设置安全组ID
|
||||
.setVSwitchId(V_SWITCH_ID) // 设置虚拟交换机ID
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
.setInstanceChargeType(INSTANCE_CHARGE_TY) // 设置实例付费类型为后付费按量付费
|
||||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("2112A-four") // 设置实例密码
|
||||
.setAmount(2) // 设置创建实例的数量
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInternetMaxBandwidthOut(1);
|
||||
|
||||
|
||||
//创建运行时选择对象
|
||||
RuntimeOptions runTime=
|
||||
new RuntimeOptions();
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runTime);
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
for (String instance : body.getInstanceIdSets().getInstanceIdSet()) {
|
||||
list.add(instance);
|
||||
log.info("ESC创建成功,实例ID为:" + list);
|
||||
}
|
||||
} catch (TeaException error) {
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info("实例创建失败:"+error.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Log4j2
|
||||
public class SelectInstance {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,您的 AccessKey ID
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,您的 AccessKey Secret
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// 访问的域名
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
java.util.List<String> args = java.util.Arrays.asList(args_);
|
||||
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式
|
||||
Client client = SelectInstance.createClient(ALIBABA_CLOUD_ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai")
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInstanceChargeType("PostPaid")
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
;
|
||||
//实例ID Instances.Instance.InstanceId
|
||||
//实例IP Instances.Instance.PublicIpAddress.IpAddress
|
||||
//状态 Instances.Instance.Status
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
DescribeInstancesResponse resp = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = resp.getBody();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
instanceInfos.add(instanceInfo);
|
||||
}
|
||||
log.info(Common.toJSONString(instanceInfos));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.vehicle.domain.MqttServerModel;
|
||||
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
|
||||
|
||||
public interface VehicleConnectService extends IService<VehicleConnectionReq> {
|
||||
|
||||
Result<MqttServerModel> getConnect(VehicleConnectionReq vehicleConnectionReq);
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.vehicle.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Log4j2
|
||||
public class VehicleConnectServiceImpl extends ServiceImpl<VehicleConnectMapper, VehicleConnectionReq> implements VehicleConnectService {
|
||||
@Autowired
|
||||
private VehicleConnectMapper vehicleConnectMapper;
|
||||
|
||||
@Override
|
||||
public Result<MqttServerModel> getConnect(VehicleConnectionReq vehicleConnectionReq) {
|
||||
log.info("车辆连接信息:{}", vehicleConnectionReq);
|
||||
//生成密码
|
||||
vehicleConnectionReq.setPassword(vehicleConnectionReq.getVehicleVin() + vehicleConnectionReq.getTimestamp()
|
||||
+ vehicleConnectionReq.getNonce());
|
||||
|
||||
VehicleConnectionReq connection = vehicleConnectMapper.selectByVehicleVin(vehicleConnectionReq.getVehicleVin());
|
||||
if (connection==null){
|
||||
vehicleConnectMapper.insert(vehicleConnectionReq);
|
||||
log.info("车辆预上线成功");
|
||||
}else {
|
||||
log.info("车辆已预上线成功,禁止重复");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
package com.muyu.vehicle.utils;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
|
||||
/**
|
||||
* 创建ECS客户端对象
|
||||
*/
|
||||
public class CreateClient {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID = "LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET = "NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
}
|
|
@ -7,10 +7,12 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: sx
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-vehicleGateway
|
||||
|
|
|
@ -51,6 +51,16 @@
|
|||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
<!-- <artifactId>mybatis-plus-boot-starter</artifactId>-->
|
||||
<!-- <version>3.5.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -30,7 +30,7 @@ public class MessageTemplateType implements Serializable {
|
|||
* 主键
|
||||
*/
|
||||
@TableId(value = "message_template_type_id",type = IdType.AUTO)
|
||||
private String messageTemplateTypeId;
|
||||
private Long messageTemplateTypeId;
|
||||
/**
|
||||
* 报文类别
|
||||
*/
|
||||
|
|
|
@ -2,10 +2,7 @@ package com.muyu.common.domain.resp;
|
|||
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.domain.SysCar;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 车辆管理返回值
|
||||
|
@ -18,6 +15,7 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class SysCarVo extends SysCar {
|
||||
|
||||
@Excel(name = "车辆类型名称")
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-xxl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>service-rpc</artifactId>
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package com.muyu.server;
|
||||
|
||||
|
||||
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
|
||||
/**
|
||||
* saas模块启动类
|
||||
* @author YuPing
|
||||
|
@ -11,7 +16,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
* @Version 1.0
|
||||
* @Data 2024-09-28 17:34:31
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {
|
||||
DataSourceAutoConfiguration.class,
|
||||
DruidDataSourceAutoConfigure.class,
|
||||
DynamicDataSourceAutoConfiguration.class
|
||||
})
|
||||
@EnableCustomConfig
|
||||
@EnableMyFeignClients
|
||||
public class SaasApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -21,8 +21,6 @@ import java.util.List;
|
|||
* @Date 2024/9/29 12:06
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/carType")
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.muyu.common.core.constant.SecurityConstants;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.Enterprise;
|
||||
import com.muyu.common.system.domain.Business;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.common.util.PageUtils;
|
||||
import com.muyu.server.controller.form.DeleteEnterpriseByIds;
|
||||
|
@ -27,6 +28,7 @@ import java.sql.Connection;
|
|||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -95,9 +97,14 @@ public class EnterpriseController {
|
|||
business.setDatabaseName(form.getEnterpriseDatabaseName());
|
||||
remoteUserService.settlementEnterpriseInfo(business, SecurityConstants.INNER);
|
||||
|
||||
//创建新的数据库
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setDatabaseName(form.getEnterpriseDatabaseName());
|
||||
sysUser.setUserName(form.getEnterpriseName());
|
||||
sysUser.setCreateTime(new Date());
|
||||
remoteUserService.addUser(sysUser, SecurityConstants.INNER);
|
||||
String createDatabaseUrl="jdbc:mysql://"+ DatasourceContent.IP+":"+DatasourceContent.PORT+"?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
||||
String createDatabaseSql = "CREATE DATABASE IF NOT EXISTS " + form.getEnterpriseDatabaseName() + ";";
|
||||
|
||||
try (Connection adminConn = DriverManager.getConnection(createDatabaseUrl, DatasourceContent.USER_NAME, DatasourceContent.PASSWORD);
|
||||
Statement stmt = adminConn.createStatement()) {
|
||||
|
||||
|
@ -123,6 +130,8 @@ public class EnterpriseController {
|
|||
ClassPathResource rc = new ClassPathResource("static/saas.sql");
|
||||
EncodedResource er = new EncodedResource(rc, "utf-8");
|
||||
ScriptUtils.executeSqlScript(connection, er);
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cache.SysCarCacheService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.SysCar;
|
||||
|
@ -12,6 +13,8 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
@ -31,6 +34,8 @@ public class SysCarController {
|
|||
@Autowired
|
||||
private SysCarService sysCarService;
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
private SysCarCacheService sysCarCacheService;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
import com.muyu.cache.TemplateCacheService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.Template;
|
||||
import com.muyu.server.service.TemplateService;
|
||||
|
@ -35,9 +34,6 @@ public class TemplateController {
|
|||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private TemplateCacheService templateCacheService;
|
||||
|
||||
/**
|
||||
* 报文模版列表
|
||||
* @return
|
||||
|
@ -45,19 +41,24 @@ public class TemplateController {
|
|||
@PostMapping("/templateList")
|
||||
@Operation(summary = "报文模版列表",description = "报文模版列表")
|
||||
public Result<List<Template>> templateList() {
|
||||
|
||||
List<Template> list = templateService.list();
|
||||
|
||||
templateCacheService.put("List",list);
|
||||
|
||||
return Result.success(list);
|
||||
return Result.success(templateService.list());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 解析报文
|
||||
* @param templateMessage
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/messageParsing")
|
||||
@Operation(summary = "报文解析",description = "报文解析")
|
||||
public Result messageParsing(@RequestParam("templateMessage") String templateMessage) throws SQLException, IoTDBConnectionException, ClassNotFoundException, StatementExecutionException, ExecutionException, InterruptedException {
|
||||
templateService.messageParsing(templateMessage);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 报文模版添加
|
||||
* 报文模版添加0002222220
|
||||
* @param template
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.muyu.server.service.CarTypeService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,104 +7,10 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yzl
|
||||
namespace: four
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
datasource:
|
||||
dynamic:
|
||||
druid:
|
||||
initial-size: 5
|
||||
min-idle: 5
|
||||
maxActive: 20
|
||||
maxWait: 60000
|
||||
timeBetweenEvictionRunsMillis: 60000
|
||||
minEvictableIdleTimeMillis: 300000
|
||||
validationQuery: SELECT 1 FROM DUAL
|
||||
testWhileIdle: true
|
||||
testOnReturn: false
|
||||
testOnBorrow: false
|
||||
poolPreparedStatements: true
|
||||
maxPoolPreparedStatementPerConnection-size: 20
|
||||
filters: stat,slf4j
|
||||
datasource:
|
||||
# 主库数据源
|
||||
master:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://47.101.53.251:3306/saas?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: Lw030106
|
||||
|
||||
kafka:
|
||||
producer:
|
||||
# Kafka服务器
|
||||
bootstrap-servers: 150.158.33.234:9092
|
||||
# 开启事务,必须在开启了事务的方法中发送,否则报错
|
||||
transaction-id-prefix: kafkaTx-
|
||||
# 发生错误后,消息重发的次数,开启事务必须设置大于0。
|
||||
retries: 3
|
||||
# acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
|
||||
# acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
|
||||
# acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
|
||||
acks: all
|
||||
# 开启事务时,必须设置为all
|
||||
# 当有多个消息需要被发送到同一个分区时,生产者会把它们放在同一个批次里。该参数指定了一个批次可以使用的内存大小,按照字节数计算。
|
||||
batch-size: 16384
|
||||
# 生产者内存缓冲区的大小。
|
||||
buffer-memory: 1024000
|
||||
# 键的序列化方式
|
||||
key-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# 值的序列化方式(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
value-serializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
consumer:
|
||||
# Kafka服务器
|
||||
group-id: my-kafka
|
||||
# 自动提交的时间间隔 在spring boot 2.X 版本中这里采用的是值的类型为Duration 需要符合特定的格式,如1S,1M,2H,5D
|
||||
#auto-commit-interval: 2s
|
||||
# 该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
|
||||
# earliest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费分区的记录
|
||||
# latest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据(在消费者启动之后生成的记录)
|
||||
# none:当各分区都存在已提交的offset时,从提交的offset开始消费;只要有一个分区不存在已提交的offset,则抛出异常
|
||||
auto-offset-reset: latest
|
||||
# 是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量
|
||||
enable-auto-commit: true
|
||||
# 键的反序列化方式
|
||||
#key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
|
||||
key-deserializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# 值的反序列化方式(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
value-deserializer: org.apache.kafka.common.serialization.StringSerializer
|
||||
# 这个参数定义了poll方法最多可以拉取多少条消息,默认值为500。如果在拉取消息的时候新消息不足500条,那有多少返回多少;如果超过500条,每次只返回500。
|
||||
# 这个默认值在有些场景下太大,有些场景很难保证能够在5min内处理完500条消息,
|
||||
# 如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
|
||||
# 然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
|
||||
# 要避免出现上述问题,提前评估好处理一条消息最长需要多少时间,然后覆盖默认的max.poll.records参数
|
||||
# 注:需要开启BatchListener批量监听才会生效,如果不开启BatchListener则不会出现reBalance情况
|
||||
max-poll-records: 500
|
||||
bootstrap-servers: 150.158.33.234:9092
|
||||
auto-commit-interval: 5000
|
||||
fetch-max-wait: 500
|
||||
fetch-min-size: 1
|
||||
heartbeat-interval: 3000
|
||||
properties:
|
||||
# 两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||
max:
|
||||
poll:
|
||||
interval:
|
||||
ms: 600000
|
||||
# 当broker多久没有收到consumer的心跳请求后就触发reBalance,默认值是10s
|
||||
session:
|
||||
timeout:
|
||||
ms: 10000
|
||||
listener:
|
||||
# 在侦听器容器中运行的线程数,一般设置为 机器数*分区数
|
||||
concurrency: 4
|
||||
# 自动提交关闭,需要设置手动消息确认
|
||||
ack-mode: manual_immediate
|
||||
# 消费监听接口监听的主题不存在时,默认会报错,所以设置为false忽略错误
|
||||
missing-topics-fatal: false
|
||||
# 两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||
poll-timeout: 600000
|
||||
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
|
|
|
@ -31,15 +31,14 @@
|
|||
insert into tb_enterprise
|
||||
set enterprise_name = #{enterpriseName},
|
||||
enterprise_car_count = #{enterpriseCarCount},
|
||||
enterprise_fence_count = #{enterpriseFenceCount},
|
||||
enterprise_database_name=#{enterpriseDatabaseName}
|
||||
enterprise_fence_count = #{enterpriseFenceCount}
|
||||
</insert>
|
||||
|
||||
|
||||
|
||||
<!--根据编号查询企业信息-->
|
||||
<select id="searchById" resultType="java.util.HashMap">
|
||||
select enterprise_id,enterprise_name,enterprise_car_count,enterprise_fence_count,enterprise_database_name
|
||||
select enterprise_id,enterprise_name,enterprise_car_count,enterprise_fence_count
|
||||
from tb_enterprise
|
||||
where enterprise_id = #{enterpriseId}
|
||||
</select>
|
||||
|
@ -48,8 +47,7 @@
|
|||
update tb_enterprise
|
||||
set enterprise_name = #{enterpriseName},
|
||||
enterprise_car_count = #{enterpriseCarCount},
|
||||
enterprise_fence_count = #{enterpriseFenceCount},
|
||||
enterprise_database_name=#{enterpriseDatabaseName}
|
||||
enterprise_fence_count = #{enterpriseFenceCount}
|
||||
where enterprise_id = #{enterpriseId} and enterprise_id != 0
|
||||
</update>
|
||||
|
||||
|
|
|
@ -77,5 +77,7 @@
|
|||
<select id="findCarByVin" resultType="com.muyu.common.domain.SysCar">
|
||||
select * from sys_car where car_vin=#{carVin}
|
||||
</select>
|
||||
|
||||
<select id="selectByCarVin" resultType="com.muyu.common.domain.SysCar">
|
||||
select * from sys_car where car_cin=#{carVin}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.TemplateNeedMapper">
|
||||
|
||||
<select id="selectByTemplateId" resultType="com.muyu.common.domain.MessageTemplateType">
|
||||
SELECT * FROM `message_template_type` WHERE template_id=#{templateId}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.SysCarFaultMapper">
|
||||
|
||||
<resultMap type="com.muyu.common.domain.SysCarFault" id="SysCarFaultResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="faultCode" column="fault_code" />
|
||||
<result property="faultName" column="fault_name" />
|
||||
<result property="typeId" column="type_id" />
|
||||
<result property="faultLabel" column="fault_label" />
|
||||
<result property="faultBit" column="fault_bit" />
|
||||
<result property="faultValue" column="fault_value" />
|
||||
<result property="faultRank" column="fault_rank" />
|
||||
<result property="faultDesc" column="fault_desc" />
|
||||
<result property="faultMinThreshold" column="fault_min_threshold" />
|
||||
<result property="faultMaxThreshold" column="fault_max_threshold" />
|
||||
<result property="status" column="status" />
|
||||
<result property="warnStatus" column="warn_status" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="carTypeId" column="car_type_id"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysCarFaultVo">
|
||||
select id, fault_code, fault_name, type_id, fault_label, fault_bit, fault_value, fault_rank, fault_desc, fault_min_threshold, fault_max_threshold, status, warn_status, remark, create_by, create_time, update_by, update_time,car_type_id from sys_car_fault
|
||||
</sql>
|
||||
|
||||
<select id="selectSysCarFaultList" parameterType="com.muyu.common.domain.SysCarFault" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
<where>
|
||||
<if test="faultCode != null and faultCode != ''"> and fault_code = #{faultCode}</if>
|
||||
<if test="faultBit != null and faultBit != ''"> and fault_bit = #{faultBit}</if>
|
||||
<if test="faultRank != null "> and fault_rank = #{faultRank}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectSysCarFaultById" parameterType="Long" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectSysCarFaultIds" resultMap="SysCarFaultResult">
|
||||
<include refid="selectSysCarFaultVo"/>
|
||||
where id in
|
||||
<foreach collection="array" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<insert id="insertSysCarFault" parameterType="com.muyu.common.domain.SysCarFault" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into sys_car_fault
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">fault_code,</if>
|
||||
<if test="faultName != null">fault_name,</if>
|
||||
<if test="typeId != null">type_id,</if>
|
||||
<if test="faultLabel != null">fault_label,</if>
|
||||
<if test="faultBit != null">fault_bit,</if>
|
||||
<if test="faultValue != null">fault_value,</if>
|
||||
<if test="faultRank != null">fault_rank,</if>
|
||||
<if test="faultDesc != null">fault_desc,</if>
|
||||
<if test="faultMinThreshold != null">fault_min_threshold,</if>
|
||||
<if test="faultMaxThreshold != null">fault_max_threshold,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="warnStatus != null">warn_status,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="carTypeId !=null">car_type_id</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">#{faultCode},</if>
|
||||
<if test="faultName != null">#{faultName},</if>
|
||||
<if test="typeId != null">#{typeId},</if>
|
||||
<if test="faultLabel != null">#{faultLabel},</if>
|
||||
<if test="faultBit != null">#{faultBit},</if>
|
||||
<if test="faultValue != null">#{faultValue},</if>
|
||||
<if test="faultRank != null">#{faultRank},</if>
|
||||
<if test="faultDesc != null">#{faultDesc},</if>
|
||||
<if test="faultMinThreshold != null">#{faultMinThreshold},</if>
|
||||
<if test="faultMaxThreshold != null">#{faultMaxThreshold},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="warnStatus != null">#{warnStatus},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="carTypeId != null">#{catTypeId}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateSysCarFault" parameterType="com.muyu.common.domain.SysCarFault">
|
||||
update sys_car_fault
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="faultCode != null and faultCode != ''">fault_code = #{faultCode},</if>
|
||||
<if test="faultName != null">fault_name = #{faultName},</if>
|
||||
<if test="typeId != null">type_id = #{typeId},</if>
|
||||
<if test="faultLabel != null">fault_label = #{faultLabel},</if>
|
||||
<if test="faultBit != null">fault_bit = #{faultBit},</if>
|
||||
<if test="faultValue != null">fault_value = #{faultValue},</if>
|
||||
<if test="faultRank != null">fault_rank = #{faultRank},</if>
|
||||
<if test="faultDesc != null">fault_desc = #{faultDesc},</if>
|
||||
<if test="faultMinThreshold != null">fault_min_threshold = #{faultMinThreshold},</if>
|
||||
<if test="faultMaxThreshold != null">fault_max_threshold = #{faultMaxThreshold},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="warnStatus != null">warn_status = #{warnStatus},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="carTypeId !=null">car_type_id=#{catTypeId}</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteSysCarFaultById" parameterType="Long">
|
||||
delete from sys_car_fault where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteSysCarFaultByIds" parameterType="String">
|
||||
delete from sys_car_fault where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<update id="enableWarningsById" parameterType="Long">
|
||||
update sys_car_fault set warn_status = 0 where id = #{id}
|
||||
</update>
|
||||
<update id="disableWarningsById" parameterType="Long">
|
||||
update sys_car_fault set warn_status = 1 where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.DataTypeMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.MessageTemplateTypeMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.TemplateMapper">
|
||||
|
||||
<select id="templateList" resultType="com.muyu.common.domain.Template">
|
||||
select * from t_template
|
||||
</select>
|
||||
|
||||
<select id="findTemplateByName" resultType="com.muyu.common.domain.Template">
|
||||
select * from t_template where template_name=#{typeName}
|
||||
</select>
|
||||
<select id="findTemplateById" resultType="com.muyu.common.domain.MessageTemplateType">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
message_template_type
|
||||
WHERE
|
||||
template_id = #{templateId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue