Compare commits
19 Commits
f4faf4d828
...
ddf4ede829
Author | SHA1 | Date |
---|---|---|
|
ddf4ede829 | |
|
7d7950e925 | |
|
e3f65e7f1e | |
|
0228051467 | |
|
dfacea67f6 | |
|
c35dea9159 | |
|
030f16e6a8 | |
|
fd529f0cec | |
|
2ec6d89c62 | |
|
cb20606e47 | |
|
3aab1823a1 | |
|
6079949a7a | |
|
cd0d2e4475 | |
|
7d3f422dc3 | |
|
e716ad9bfc | |
|
71083dc580 | |
|
05bc325434 | |
|
52453e089b | |
|
9747b41b34 |
|
@ -1,26 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-server</artifactId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.muyu</groupId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cloud-common-swagger</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-common-swagger swagger2文档聚合
|
||||
</description>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -22,9 +22,9 @@ import java.util.function.Predicate;
|
|||
|
||||
/**
|
||||
* @author 袁子龙
|
||||
* @package:com.muyu.common.swagger.config
|
||||
* @name:SwaggerAutoConfiguration
|
||||
* @date:2024/9/29 10:07
|
||||
* @package com.muyu.common.swagger.config
|
||||
* @name SwaggerAutoConfiguration
|
||||
* @date 2024/9/29 10:07
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-event</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<description>
|
||||
cloud-event 数据处理
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-session</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>node-commons</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package com.muyu.event;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableMyFeignClients
|
||||
public class EventApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EventApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.event.basics;
|
||||
|
||||
/**
|
||||
* @author 刘武
|
||||
* @package:
|
||||
* @name:EventHandler
|
||||
* @date:2024/9/29
|
||||
*/
|
||||
public class EventHandler {
|
||||
|
||||
private static final ThreadLocal<EventQueueConfig> EVENT_THREAD = new ThreadLocal<>();
|
||||
|
||||
public static void set(final EventQueueConfig handler) {
|
||||
EVENT_THREAD.set(handler);
|
||||
}
|
||||
|
||||
public static EventQueueConfig get() {
|
||||
return EVENT_THREAD.get();
|
||||
}
|
||||
|
||||
public static void remove(){
|
||||
EVENT_THREAD.remove();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.event.basics;
|
||||
|
||||
|
||||
public abstract class EventProcessBasics {
|
||||
|
||||
/**
|
||||
* 下一个事件对象
|
||||
*/
|
||||
protected EventProcessBasics nextEvent;
|
||||
|
||||
/**
|
||||
* 下一个事件
|
||||
* @param nextHandler 下一个事件处理
|
||||
*/
|
||||
public void setNextHandler(EventProcessBasics nextHandler) {
|
||||
this.nextEvent = nextHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 事件处理抽象类
|
||||
* @param eventKey 事件唯一key
|
||||
*/
|
||||
public abstract void handleEvent(String eventKey);
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.event.basics;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
/**
|
||||
* @author 刘武
|
||||
* @package:
|
||||
* @name:EventQueueConfig
|
||||
* @date:2024/9/29
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EventQueueConfig {
|
||||
|
||||
private LinkedBlockingDeque<EventProcessBasics> taskNodeQueue = new LinkedBlockingDeque<>();
|
||||
|
||||
public void addEvent(EventProcessBasics obj){
|
||||
this.taskNodeQueue.add(obj);
|
||||
}
|
||||
|
||||
public boolean hashEventNext(){
|
||||
return !taskNodeQueue.isEmpty();
|
||||
}
|
||||
|
||||
private EventProcessBasics nextTaskNode(){
|
||||
return taskNodeQueue.poll();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.event.basics;
|
||||
|
||||
|
||||
import com.muyu.event.domian.EventActuate;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 刘武
|
||||
* @package:
|
||||
* @name:StartEvent
|
||||
* @date:2024/9/29
|
||||
*/
|
||||
|
||||
public class StartEvent extends ApplicationEvent {
|
||||
|
||||
private EventActuate eventActuate;
|
||||
|
||||
public StartEvent(EventActuate source) {
|
||||
super(source);
|
||||
this.eventActuate = source;
|
||||
}
|
||||
|
||||
public EventActuate getEventActuate() {
|
||||
return eventActuate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package com.muyu.event.config;
|
||||
|
||||
import com.muyu.event.domian.CarInformation;
|
||||
import org.apache.iotdb.isession.SessionDataSet;
|
||||
import org.apache.iotdb.isession.util.Version;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.Session;
|
||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||
import org.apache.iotdb.tsfile.read.common.Field;
|
||||
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* iotdb数据库 配置
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.config
|
||||
* @name:IOTDBConfig
|
||||
* @date:2024/9/28 19:35
|
||||
*/
|
||||
@Configuration
|
||||
public class IoTDBConfig {
|
||||
|
||||
public static final String HOST="47.116.173.119";
|
||||
public static final Integer PORT=6667;
|
||||
public static final String USERNAME="root";
|
||||
public static final String PASSWORD="root";
|
||||
public static final String TABLENAME="root.four.car_information";
|
||||
|
||||
|
||||
/**
|
||||
* 初始化连接
|
||||
* @return
|
||||
*/
|
||||
public Session initIoTDB(){
|
||||
// 初始化与连接
|
||||
Session session = new Session.Builder()
|
||||
.host(HOST)
|
||||
.port(PORT)
|
||||
.username(USERNAME)
|
||||
.password(PASSWORD)
|
||||
.version(Version.V_1_0)
|
||||
.build();
|
||||
return session;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 实时数据库添加
|
||||
* @param list
|
||||
*/
|
||||
public void insertIoTDB(List<String> list){
|
||||
Session session = initIoTDB();
|
||||
// 开启session Rpc不压缩
|
||||
try {
|
||||
session.open(false);
|
||||
|
||||
//添加字段名称
|
||||
ArrayList<String> measurements = new ArrayList<>();
|
||||
//添加字段类型
|
||||
ArrayList<TSDataType> types = new ArrayList<>();
|
||||
|
||||
measurements.add("car_vin");
|
||||
measurements.add("information");
|
||||
|
||||
|
||||
session.insertRecord(TABLENAME,System.currentTimeMillis(),measurements,list);
|
||||
|
||||
//关闭连接
|
||||
session.close();
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public CarInformation queryIoTDB(String carVin) {
|
||||
Session session = initIoTDB();
|
||||
try {
|
||||
session.open(false);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Long timeMillis = System.currentTimeMillis();
|
||||
|
||||
CarInformation carInformation = new CarInformation();
|
||||
|
||||
try(SessionDataSet dataSet= session.executeQueryStatement("select * from root.four.car_information where car_vin='"+carVin+"'")){
|
||||
System.out.println(dataSet.getColumnNames());
|
||||
dataSet.setFetchSize(1024);
|
||||
while (dataSet.hasNext()){
|
||||
// List<Field> fields = dataSet.next().getFields();
|
||||
// carInformation.setCarVin(String.valueOf(fields.get(0)));
|
||||
// carInformation.setInformation(String.valueOf(fields.get(1)));
|
||||
|
||||
String[] fields = dataSet.next().toString().split("\t");
|
||||
carInformation.setTime(Long.valueOf(fields[0]));
|
||||
carInformation.setCarVin(fields[1]);
|
||||
carInformation.setInformation(fields[2]);
|
||||
}
|
||||
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
//关闭连接
|
||||
try {
|
||||
session.close();
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return carInformation;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package com.muyu.event.config;
|
||||
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||
import org.springframework.kafka.config.KafkaListenerContainerFactory;
|
||||
import org.springframework.kafka.core.ConsumerFactory;
|
||||
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
|
||||
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
|
||||
import org.springframework.kafka.listener.ContainerProperties;
|
||||
import org.springframework.kafka.support.serializer.JsonDeserializer;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 徐一杰
|
||||
* @date 2022/10/31 18:05
|
||||
* kafka配置,也可以写在yml,这个文件会覆盖yml
|
||||
*/
|
||||
@SpringBootConfiguration
|
||||
public class KafkaConsumerConfig {
|
||||
|
||||
/**
|
||||
* 配置 Kafka的 主机地址
|
||||
*/
|
||||
@Value("${spring.kafka.consumer.bootstrap-servers}")
|
||||
private String bootstrapServers;
|
||||
/**
|
||||
* 配置分分组
|
||||
*/
|
||||
@Value("${spring.kafka.consumer.group-id}")
|
||||
private String groupId;
|
||||
/**
|
||||
* 是否自动提交 偏移量
|
||||
*/
|
||||
@Value("${spring.kafka.consumer.enable-auto-commit}")
|
||||
private boolean enableAutoCommit;
|
||||
/**
|
||||
* 消费者与Kafka的心跳续约的会话超时时间
|
||||
*/
|
||||
@Value("${spring.kafka.properties.session.timeout.ms}")
|
||||
private String sessionTimeout;
|
||||
/**
|
||||
* 两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||
*/
|
||||
@Value("${spring.kafka.properties.max.poll.interval.ms}")
|
||||
private String maxPollIntervalTime;
|
||||
|
||||
@Value("${spring.kafka.consumer.max-poll-records}")
|
||||
private String maxPollRecords;
|
||||
|
||||
@Value("${spring.kafka.consumer.auto-offset-reset}")
|
||||
private String autoOffsetReset;
|
||||
|
||||
@Value("${spring.kafka.listener.concurrency}")
|
||||
private Integer concurrency;
|
||||
|
||||
@Value("${spring.kafka.listener.missing-topics-fatal}")
|
||||
private boolean missingTopicsFatal;
|
||||
|
||||
@Value("${spring.kafka.listener.poll-timeout}")
|
||||
private long pollTimeout;
|
||||
|
||||
@Bean
|
||||
public Map<String, Object> consumerConfigs() {
|
||||
Map<String, Object> propsMap = new HashMap<>(16);
|
||||
propsMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||
propsMap.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
|
||||
//是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量
|
||||
propsMap.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, enableAutoCommit);
|
||||
//自动提交的时间间隔,自动提交开启时生效
|
||||
propsMap.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "2000");
|
||||
//该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
|
||||
//earliest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费分区的记录
|
||||
//latest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据(在消费者启动之后生成的记录)
|
||||
//none:当各分区都存在已提交的offset时,从提交的offset开始消费;只要有一个分区不存在已提交的offset,则抛出异常
|
||||
propsMap.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
|
||||
//两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||
propsMap.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalTime);
|
||||
//这个参数定义了poll方法最多可以拉取多少条消息,默认值为500。如果在拉取消息的时候新消息不足500条,那有多少返回多少;如果超过500条,每次只返回500。
|
||||
//这个默认值在有些场景下太大,有些场景很难保证能够在5min内处理完500条消息,
|
||||
//如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
|
||||
//然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
|
||||
//要避免出现上述问题,提前评估好处理一条消息最长需要多少时间,然后覆盖默认的max.poll.records参数
|
||||
//注:需要开启BatchListener批量监听才会生效,如果不开启BatchListener则不会出现reBalance情况
|
||||
propsMap.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords);
|
||||
//当broker多久没有收到consumer的心跳请求后就触发reBalance,默认值是10s
|
||||
propsMap.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, sessionTimeout);
|
||||
//序列化(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||
propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
|
||||
propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
|
||||
return propsMap;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConsumerFactory<Object, Object> consumerFactory() {
|
||||
// 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要
|
||||
try (JsonDeserializer<Object> deserializer = new JsonDeserializer<>()) {
|
||||
deserializer.trustedPackages("*");
|
||||
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new JsonDeserializer<>(), deserializer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* kafka监听容器工厂 负责 从 Kafka的主题中 取出消息进行消费 可以设置消费者的配置
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<Object, Object>> kafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory());
|
||||
//在侦听器容器中运行的线程数,一般设置为 机器数*分区数
|
||||
factory.setConcurrency(concurrency);
|
||||
// 消费监听接口监听的主题不存在时,默认会报错,所以设置为false忽略错误
|
||||
factory.setMissingTopicsFatal(missingTopicsFatal);
|
||||
// 自动提交关闭,需要设置手动消息确认
|
||||
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
|
||||
factory.getContainerProperties().setPollTimeout(pollTimeout);
|
||||
// 设置为批量监听,需要用List接收
|
||||
// factory.setBatchListener(true);
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package com.muyu.event.config;
|
||||
|
||||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.core.ProducerFactory;
|
||||
import org.springframework.kafka.transaction.KafkaTransactionManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 主题生产者的配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaProviderConfig {
|
||||
|
||||
/**
|
||||
* kafka 的主机地址
|
||||
*/
|
||||
@Value("${spring.kafka.producer.bootstrap-servers}")
|
||||
private String bootstrapServers;
|
||||
/**
|
||||
* 配置 Kafka的事务
|
||||
*/
|
||||
@Value("${spring.kafka.producer.transaction-id-prefix}")
|
||||
private String transactionIdPrefix;
|
||||
/**
|
||||
* 发送确认机制
|
||||
*/
|
||||
@Value("${spring.kafka.producer.acks}")
|
||||
private String acks;
|
||||
/**
|
||||
* 发送重试
|
||||
*/
|
||||
@Value("${spring.kafka.producer.retries}")
|
||||
private String retries;
|
||||
/**
|
||||
* 发送消息的批次大小
|
||||
*/
|
||||
@Value("${spring.kafka.producer.batch-size}")
|
||||
private String batchSize;
|
||||
/**
|
||||
* 消息的缓冲区内存大小
|
||||
*/
|
||||
@Value("${spring.kafka.producer.buffer-memory}")
|
||||
private String bufferMemory;
|
||||
|
||||
/**
|
||||
* 设置 健的序列化方式
|
||||
*/
|
||||
@Value("${spring.kafka.producer.key-serializer}")
|
||||
private String keySerializer;
|
||||
|
||||
/**
|
||||
* 设置 值的序列化方式
|
||||
*/
|
||||
@Value("${spring.kafka.producer.value-serializer}")
|
||||
private String valueSerializer;
|
||||
|
||||
/**
|
||||
* 构建 map 配置消息生产者对象的配置
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Map<String, Object> producerConfigs() {
|
||||
Map<String, Object> props = new HashMap<>(16);
|
||||
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||
//acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
|
||||
//acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
|
||||
//acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
|
||||
//开启事务必须设为all
|
||||
props.put(ProducerConfig.ACKS_CONFIG, acks);
|
||||
//发生错误后,消息重发的次数,开启事务必须大于0
|
||||
props.put(ProducerConfig.RETRIES_CONFIG, retries);
|
||||
//当多个消息发送到相同分区时,生产者会将消息打包到一起,以减少请求交互. 而不是一条条发送
|
||||
//批次的大小可以通过batch.size 参数设置.默认是16KB
|
||||
//较小的批次大小有可能降低吞吐量(批次大小为0则完全禁用批处理)。
|
||||
//比如说,kafka里的消息5秒钟Batch才凑满了16KB,才能发送出去。那这些消息的延迟就是5秒钟
|
||||
//实测batchSize这个参数没有用
|
||||
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
|
||||
//有的时刻消息比较少,过了很久,比如5min也没有凑够16KB,这样延时就很大,所以需要一个参数. 再设置一个时间,到了这个时间,
|
||||
//即使数据没达到16KB,也将这个批次发送出去
|
||||
props.put(ProducerConfig.LINGER_MS_CONFIG, "5000");
|
||||
//生产者内存缓冲区的大小
|
||||
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
|
||||
//反序列化,和生产者的序列化方式对应
|
||||
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, keySerializer);
|
||||
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, valueSerializer);
|
||||
return props;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 主题生产者工厂
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ProducerFactory<Object, Object> producerFactory() {
|
||||
DefaultKafkaProducerFactory<Object, Object> factory = new DefaultKafkaProducerFactory<>(producerConfigs());
|
||||
//开启事务,会导致 LINGER_MS_CONFIG 配置失效
|
||||
factory.setTransactionIdPrefix(transactionIdPrefix);
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置 Kafka的事务管理器
|
||||
* @param producerFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public KafkaTransactionManager<Object, Object> kafkaTransactionManager(ProducerFactory<Object, Object> producerFactory) {
|
||||
return new KafkaTransactionManager<>(producerFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 KafkaTemplate
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public KafkaTemplate<Object, Object> kafkaTemplate() {
|
||||
return new KafkaTemplate<>(producerFactory());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.muyu.event.config;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.support.ProducerListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
public class KafkaSendResultHandler implements ProducerListener<Object,Object> {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate<Object,Object> kafkaTemplate;
|
||||
|
||||
/**
|
||||
* bean 初始化方法
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
this.kafkaTemplate.setProducerListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息发送到Kafka成功的回调
|
||||
* @param producerRecord
|
||||
* @param recordMetadata
|
||||
*/
|
||||
@Override
|
||||
public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata){
|
||||
System.out.println("信息发送成功:"+ producerRecord.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 息发送到 Kafka 失败的回调
|
||||
* @param producerRecord the failed record
|
||||
* @param recordMetadata The metadata for the record that was sent (i.e. the partition
|
||||
* and offset). If an error occurred, metadata will contain only valid topic and maybe
|
||||
* the partition. If the partition is not provided in the ProducerRecord and an error
|
||||
* occurs before partition is assigned, then the partition will be set to
|
||||
* RecordMetadata.UNKNOWN_PARTITION.
|
||||
* @param exception the exception thrown
|
||||
*/
|
||||
@Override
|
||||
public void onError(ProducerRecord producerRecord, @Nullable RecordMetadata recordMetadata,
|
||||
Exception exception){
|
||||
System.out.println("消息发送失败: "+ producerRecord.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.event.config;
|
||||
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
|
||||
import org.springframework.kafka.listener.ListenerExecutionFailedException;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyKafkaListenerErrorHandler implements KafkaListenerErrorHandler {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Object handleError(@NonNull Message<?> message,
|
||||
ListenerExecutionFailedException exception) {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Object handleError(@NonNull Message<?> message,
|
||||
@NonNull ListenerExecutionFailedException exception,
|
||||
Consumer<?, ?> consumer) {
|
||||
System.out.println("消息详情:"+ message);
|
||||
System.out.println("异常信息:"+ exception);
|
||||
System.out.println("消费者详情:" +consumer.groupMetadata());
|
||||
System.out.println("监听主题:"+ consumer.listTopics());
|
||||
return KafkaListenerErrorHandler.super.handleError(message, exception, consumer);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.event.constant;
|
||||
|
||||
|
||||
/**
|
||||
* 事件常量
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.constant
|
||||
* @name:EventConstant
|
||||
* @date:2024/9/28 19:25
|
||||
*/
|
||||
|
||||
public interface EventConstant {
|
||||
|
||||
String STORAGE_EVENT = "storageEvent";
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.event.consumer;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.kafka.support.Acknowledgment;
|
||||
|
||||
/**
|
||||
* kafka监听
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.consumer
|
||||
* @name:KafkaConsumer
|
||||
* @date:2024/9/28 23:34
|
||||
*/
|
||||
|
||||
public class KafkaConsumer {
|
||||
|
||||
|
||||
@KafkaListener(topics = "data")
|
||||
public void dataKafkaConsumer(ConsumerRecord<Object,Object> consumerRecord, Acknowledgment acknowledgment){
|
||||
Object key = consumerRecord.key();
|
||||
Object value = consumerRecord.value();
|
||||
|
||||
//事件调用
|
||||
|
||||
|
||||
//消息确认消费
|
||||
acknowledgment.acknowledge();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.muyu.event.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.event.domian.AddCarInformation;
|
||||
import com.muyu.event.domian.CarInformation;
|
||||
import com.muyu.event.service.IoTDBService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* iotdb数据CRUD
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.controller
|
||||
* @name:ItodbController
|
||||
* @date:2024/9/28 19:17
|
||||
*/
|
||||
@RestController()
|
||||
public class IoTDBController {
|
||||
|
||||
@Autowired
|
||||
private IoTDBService tdbService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询实时车辆信息列表
|
||||
* @return list
|
||||
*/
|
||||
@GetMapping("findIoTDBList")
|
||||
private Result<List<CarInformation>> findIoTDBList(){
|
||||
List<CarInformation> list=tdbService.findIoTDBList();
|
||||
return Result.success(list);
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据车辆vin 查询车辆实时信息
|
||||
* @param carVin
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("findIoTDBByVin")
|
||||
public Result<CarInformation> findIoTDBByVin(@RequestParam("carVin") String carVin){
|
||||
CarInformation carInformation=tdbService.findIoTDBByVin(carVin);
|
||||
return Result.success(carInformation);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 车辆添加
|
||||
* @param addCarInformation
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("insertIoTDB")
|
||||
public Result insertIoTDB(@RequestBody AddCarInformation addCarInformation){
|
||||
tdbService.insertIoTDB(addCarInformation);
|
||||
return Result.success("添加成功");
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.event.domian;
|
||||
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 数据添加实体类
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.domian
|
||||
* @name:AddCarInformation
|
||||
* @date:2024/9/28 23:10
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class AddCarInformation {
|
||||
/**
|
||||
* 车辆vin码
|
||||
*/
|
||||
@Excel(name = "车辆vin码")
|
||||
private String carVin;
|
||||
|
||||
/**
|
||||
* 车辆vin码
|
||||
*/
|
||||
@Excel(name = "车辆实时信息")
|
||||
private String information;
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.muyu.event.domian;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆实时信息实体类
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.domian
|
||||
* @name:CarInformation
|
||||
* @date:2024/9/28 19:25
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CarInformation {
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
@Excel(name = "时间戳")
|
||||
private Long Time;
|
||||
|
||||
/**
|
||||
* 车辆vin码
|
||||
*/
|
||||
@Excel(name = "车辆vin码")
|
||||
private String carVin;
|
||||
|
||||
/**
|
||||
* 车辆实时信息
|
||||
*/
|
||||
@Excel(name = "车辆实时信息")
|
||||
private String information;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.muyu.event.domian;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("event")
|
||||
public class Event {
|
||||
|
||||
@TableId(value ="event_id" )
|
||||
@Excel(name = "事件id")
|
||||
private Integer eventId;
|
||||
|
||||
@Excel(name = "事件名称")
|
||||
private String eventName;
|
||||
|
||||
@Excel(name = "车辆vin")
|
||||
private String carVin;
|
||||
|
||||
private String createBy;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.event.domian;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 事件驱动对象
|
||||
* @Author 刘武
|
||||
* @Data 2024/9/29
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EventActuate {
|
||||
/**
|
||||
* json数据
|
||||
*/
|
||||
private String jsonData;
|
||||
/**
|
||||
* 事件驱动key集合
|
||||
*/
|
||||
private List<String> eventKeys;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.event.eventDispose;
|
||||
|
||||
|
||||
import com.muyu.event.basics.StartEvent;
|
||||
import com.muyu.event.domian.EventActuate;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author 刘武
|
||||
* @package:
|
||||
* @name:AutoStartupEventListener
|
||||
* @date:2024/9/29
|
||||
*/
|
||||
@Component
|
||||
public class AutoStartupEventListener implements ApplicationListener<StartEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(StartEvent event) {
|
||||
|
||||
EventActuate eventActuate = event.getEventActuate();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.event.eventDispose;
|
||||
|
||||
|
||||
import com.muyu.event.basics.EventProcessBasics;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
/**
|
||||
* @author 刘武
|
||||
* @package:
|
||||
* @name:StorageEvent
|
||||
* @date:2024/9/29
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Log4j2
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class StorageEvent extends EventProcessBasics {
|
||||
/**
|
||||
* 事件名称
|
||||
*/
|
||||
private String eventName;
|
||||
|
||||
@Override
|
||||
public void handleEvent(String eventKey) {
|
||||
if (eventKey.equals(eventName)){
|
||||
log.info("开始执行 [{}] 事件", eventKey);
|
||||
|
||||
}else if (nextEvent != null){
|
||||
nextEvent.handleEvent(eventKey);
|
||||
}else {
|
||||
log.info("处理结束,最后处理的事件为 [{}]", eventKey);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.event.service;
|
||||
|
||||
import com.muyu.event.domian.AddCarInformation;
|
||||
import com.muyu.event.domian.CarInformation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.service
|
||||
* @name:IotdbService
|
||||
* @date:2024/9/28 19:19
|
||||
*/
|
||||
public interface IoTDBService {
|
||||
|
||||
|
||||
List<CarInformation> findIoTDBList();
|
||||
|
||||
CarInformation findIoTDBByVin(String carVin);
|
||||
|
||||
void insertIoTDB(AddCarInformation addCarInformation);
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.muyu.event.service.impl;
|
||||
|
||||
import com.muyu.event.config.IoTDBConfig;
|
||||
import com.muyu.event.domian.AddCarInformation;
|
||||
import com.muyu.event.domian.CarInformation;
|
||||
import com.muyu.event.service.IoTDBService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.service
|
||||
* @name:IotdbService
|
||||
* @date:2024/9/28 19:19
|
||||
*/
|
||||
@Service
|
||||
public class IoTDBServiceImpl implements IoTDBService {
|
||||
|
||||
@Autowired
|
||||
private IoTDBConfig ioTDBConfig;
|
||||
|
||||
|
||||
@Override
|
||||
public List<CarInformation> findIoTDBList() {
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarInformation findIoTDBByVin(String carVin) {
|
||||
CarInformation carInformation = ioTDBConfig.queryIoTDB(carVin);
|
||||
return carInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertIoTDB(AddCarInformation addCarInformation) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
if (addCarInformation!=null){
|
||||
list.add(addCarInformation.getCarVin());
|
||||
list.add(addCarInformation.getInformation());
|
||||
}
|
||||
|
||||
ioTDBConfig.insertIoTDB(list);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.event.util;
|
||||
|
||||
import org.apache.iotdb.isession.SessionDataSet;
|
||||
import org.apache.iotdb.isession.util.Version;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.Session;
|
||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Iotdb {
|
||||
public static void main(String[] args) throws IoTDBConnectionException, StatementExecutionException {
|
||||
|
||||
System.out.println("测试数据库开始~~~~~");
|
||||
|
||||
// 初始化与连接
|
||||
Session session = new Session.Builder()
|
||||
.host("47.116.173.119")
|
||||
.port(6667)
|
||||
.username("root")
|
||||
.password("root")
|
||||
.version(Version.V_1_0)
|
||||
.build();
|
||||
|
||||
// 开启session Rpc不压缩
|
||||
session.open(false);
|
||||
|
||||
// 写入数据
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
list.add(100);
|
||||
insertRecord(session,list);
|
||||
|
||||
//查询数据
|
||||
queryRecord(session);
|
||||
|
||||
//关闭连接
|
||||
session.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void insertRecord(Session session, List<Object> values) throws IoTDBConnectionException, StatementExecutionException {
|
||||
ArrayList<String> measurements = new ArrayList<>();
|
||||
ArrayList<TSDataType> types = new ArrayList<>();
|
||||
|
||||
measurements.add("status");
|
||||
types.add(TSDataType.INT32);
|
||||
session.insertRecord("root.four.test",System.currentTimeMillis(),measurements,types,values);
|
||||
System.out.println("————————————————写入数据成功————————————————");
|
||||
}
|
||||
|
||||
private static void queryRecord(Session session) throws IoTDBConnectionException, StatementExecutionException {
|
||||
System.out.println("————————————————查询数据开始————————————————");
|
||||
try(SessionDataSet dataSet= session.executeQueryStatement("select * from root.four.test")){
|
||||
System.out.println(dataSet.getColumnNames());
|
||||
dataSet.setFetchSize(1024);
|
||||
while (dataSet.hasNext()){
|
||||
System.out.println(dataSet.next());
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("————————————————查询数据结束————————————————");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.event.util;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
|
||||
public class Receive {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String topic = "vehicle";
|
||||
String broker = "tcp://47.101.53.251:1883";
|
||||
String clientId="lw";
|
||||
|
||||
try {
|
||||
MqttClient mqttClient= new MqttClient(broker,clientId);
|
||||
MqttConnectOptions connectOptions=new MqttConnectOptions();
|
||||
connectOptions.setCleanSession(true);
|
||||
System.out.println("Connecting to broker:" + broker);
|
||||
mqttClient.connect(connectOptions);
|
||||
System.out.println("已连接");
|
||||
mqttClient.setCallback(new MqttCallback(){
|
||||
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
System.out.println("Connect lost!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
System.out.println("Message arrived. topic:"+topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mqttClient.subscribe(topic);
|
||||
System.out.println("Subscribed to topic " + topic);
|
||||
} catch (MqttException e) {
|
||||
System.out.println("reason "+e.getReasonCode());
|
||||
System.out.println("msg " +e.getMessage());
|
||||
System.out.println("loc " +e.getLocalizedMessage());
|
||||
System.out.println("cause "+e.getCause());
|
||||
System.out.println("excep "+e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,59 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 10009
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
amqp:
|
||||
deserialization:
|
||||
trust:
|
||||
all: true
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-data
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
config:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统环境Config共享配置
|
||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# xxl-job 配置文件
|
||||
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# rabbit 配置文件
|
||||
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.muyu.fence.mapper: DEBUG
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-data"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,88 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-data"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
</root>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,88 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-data"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
</root>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -11,6 +11,10 @@
|
|||
|
||||
<artifactId>cloud-modules-vehiclegateway</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-modules-vehiclegateway 车辆网关
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
|
@ -121,6 +125,11 @@
|
|||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-ecs</artifactId>
|
||||
<version>4.2.0</version><!-- 请根据实际情况使用最新的版本 -->
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
|
||||
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.vehicle.domain.InstanceInfo;
|
||||
import com.muyu.vehicle.service.OpenInstance;
|
||||
import com.muyu.vehicle.service.SelectInstance;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.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";
|
||||
|
||||
|
||||
/**
|
||||
* 镜像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 = ManageInstance.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());
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.vehicle.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class InstanceInfo {
|
||||
|
||||
//实例ID
|
||||
private String InstanceId;
|
||||
|
||||
private String IpAddress;
|
||||
|
||||
private String status;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.vehicle;
|
||||
package com.muyu.vehicle.service;
|
||||
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
|
@ -1,20 +1,20 @@
|
|||
package com.muyu.vehicle;
|
||||
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 org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Log4j2
|
||||
public class OpenInstance implements ApplicationRunner {
|
||||
|
||||
public class OpenInstance {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
|
@ -95,7 +95,7 @@ public class OpenInstance implements ApplicationRunner {
|
|||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("2112A-four") // 设置实例密码
|
||||
.setAmount(1) // 设置创建实例的数量
|
||||
.setAmount(2) // 设置创建实例的数量
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInternetMaxBandwidthOut(1);
|
||||
|
||||
|
@ -105,9 +105,14 @@ public class OpenInstance implements ApplicationRunner {
|
|||
new RuntimeOptions();
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.runInstancesWithOptions(runInstancesRequest, runTime);
|
||||
log.info("实例创建成功");
|
||||
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());
|
||||
|
@ -121,8 +126,4 @@ public class OpenInstance implements ApplicationRunner {
|
|||
log.info("实例创建失败:"+error.getMessage());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
generateInstance();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
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));
|
||||
}
|
||||
}
|
|
@ -54,3 +54,5 @@ logging:
|
|||
level:
|
||||
com.muyu.system.mapper: DEBUG
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
</parent>
|
||||
<artifactId>cloud-modules-wechat</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-modules-wechat 微信公众号模块
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
|
|
|
@ -23,11 +23,13 @@
|
|||
<!-- <module>enterprise-operations</module>-->
|
||||
<module>saas</module>
|
||||
<module>cloud-modules-vehiclegateway</module>
|
||||
<module>cloud-event</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
||||
<description>
|
||||
cloud-modules业务模块
|
||||
</description>
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
<module>saas-server</module>
|
||||
</modules>
|
||||
|
||||
<description>
|
||||
saas 企业业务平台
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!--mqtt依赖-->
|
||||
<dependency>
|
||||
|
@ -29,6 +33,11 @@
|
|||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -32,12 +32,6 @@
|
|||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>2.2.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu.server</groupId>
|
||||
<artifactId>saas-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -6,6 +6,14 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆类型对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:MessageTemplateType
|
||||
* @Date:2024/9/18 21:01
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.experimental.SuperBuilder;
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
* 数据类型对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
|
|
|
@ -9,6 +9,7 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.sql.Date;
|
||||
|
||||
/**
|
||||
* 新能源车模版
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.domain
|
||||
* @Project:cloud-server
|
||||
|
|
|
@ -11,6 +11,7 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 模版对应的配置
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
|
@ -25,6 +26,7 @@ import java.io.Serializable;
|
|||
@TableName(value = "message_template_type",autoResultMap = true)
|
||||
public class MessageTemplateType implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
|
|
|
@ -9,12 +9,21 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:MessageTemplateType
|
||||
* @Date:2024/9/18 21:01
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "sys_car",autoResultMap = true)
|
||||
public class SysCar extends BaseEntity {
|
||||
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String carVin;
|
||||
|
|
|
@ -9,7 +9,7 @@ import lombok.*;
|
|||
|
||||
/**
|
||||
* 企业信息 sys_car_enterprise
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package com.muyu.breakdown.domain
|
||||
* @name: SysCarEnterprise
|
||||
* @date: 2024/9/26 19:54
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||
|
||||
/**
|
||||
* 车辆故障管理对象 sys_car_fault
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.domain
|
||||
* @name: SysCarFault
|
||||
* @date: 2024/9/20 10:56
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* 故障记录对象 sys_car_fault_log
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.domain
|
||||
* @name: SysCarFaultLog
|
||||
* @date: 2024/9/22 20:17
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* 站内信息对象 sys_car_fault_message
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.domain
|
||||
* @name: SysCarFaultMessage
|
||||
* @date: 2024/9/22 11:57
|
||||
|
|
|
@ -10,6 +10,14 @@ import lombok.NoArgsConstructor;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 车辆记录对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:MessageTemplateType
|
||||
* @Date:2024/9/18 21:01
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -12,6 +12,7 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 报文模版对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.template.domain
|
||||
* @Project:cloud-server-c
|
||||
|
|
|
@ -0,0 +1,239 @@
|
|||
package com.muyu.common.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* kafka通用配置
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.common.util
|
||||
* @name:KafkaCommonProperties
|
||||
* @Date:2024/9/29 12:26
|
||||
*/
|
||||
public class KafkaCommonProperties{
|
||||
|
||||
/**
|
||||
* Kafka主机
|
||||
*/
|
||||
private String kafkaHost = "47.101.53.251:9092";
|
||||
|
||||
/**
|
||||
* 生产者:要求leader请求结束前收到的确认次数,来控制发送数据的持久化
|
||||
* 消息确认:
|
||||
* 0:生产者不等待服务器确认,此时retry参数不生效
|
||||
* 1:leader写入记录到log,不会等待follower的确认即向生产者发送通知
|
||||
* all:leader等待所有副本通知,然后向生产者发送通知,保证所有数据落盘到所有副本,功能同设置为-1
|
||||
*/
|
||||
private String ack = "all";
|
||||
|
||||
/**
|
||||
* 生产者重试次数
|
||||
*/
|
||||
private Integer retryTimes = 1;
|
||||
|
||||
/**
|
||||
* 生产者:向同一分区发送打包发送的数据量,单位:bytes,默认16384bytes=16K
|
||||
*/
|
||||
private Integer batchSize = 16384;
|
||||
|
||||
/**
|
||||
* 生产者:批量发送消息的间隔时间(延迟时间),单位:毫秒
|
||||
*/
|
||||
private Integer lingerMs = 1;
|
||||
|
||||
/**
|
||||
* 生产者:可以使用的最大缓存空间,单位:bytes,默认33554432bytes=32M.
|
||||
*/
|
||||
private Integer bufferMemory = 33554432;
|
||||
|
||||
/**
|
||||
* 生产者:键编码器
|
||||
*/
|
||||
private String keyEncoder = "org.apache.kafka.common.serialization.StringSerializer";
|
||||
|
||||
/**
|
||||
* 生产者:值编码器
|
||||
*/
|
||||
private String valueEncoder = "org.apache.kafka.common.serialization.StringSerializer";
|
||||
|
||||
/**
|
||||
* 消费者:消费topic的组ID
|
||||
*/
|
||||
private String groupId = "my-group-id";
|
||||
|
||||
/**
|
||||
* 消费者:后台定期提交offset
|
||||
*/
|
||||
private String autoCommit = "true";
|
||||
|
||||
/**
|
||||
* 消费者提交offset的时间间隔:单位:毫秒,当enable.auto.commit为true时生效
|
||||
*/
|
||||
private String autoCommitIntervalMs = "1000";
|
||||
|
||||
/**
|
||||
* 消费者:键解码器
|
||||
*/
|
||||
private String keyDecoder = "org.apache.kafka.common.serialization.StringDeserializer";
|
||||
|
||||
/**
|
||||
* 消费者:值解码器
|
||||
*/
|
||||
private String valueDecoder = "org.apache.kafka.common.serialization.StringDeserializer";
|
||||
|
||||
/**
|
||||
* 消费者:重启后配置offset
|
||||
* earliest:消费者恢复到当前topic最早的offset
|
||||
* latest:消费者从最新的offset开始消费
|
||||
* none:如果消费者组没找到之前的offset抛出异常
|
||||
* 其他任何值都会抛出异常
|
||||
*/
|
||||
private String autoOffsetReset = "latest";
|
||||
|
||||
/**
|
||||
* TOPIC
|
||||
*/
|
||||
private Collection<String> topic = Collections.singleton("my-topic");
|
||||
|
||||
public KafkaCommonProperties() {
|
||||
|
||||
}
|
||||
|
||||
public KafkaCommonProperties(String kafkaHost, String ack, Integer retryTimes, Integer batchSize, Integer lingerMs, Integer bufferMemory, String keyEncoder, String valueEncoder, String groupId, String autoCommit, String autoCommitIntervalMs, String keyDecoder, String valueDecoder, String autoOffsetReset, Collection<String> topic) {
|
||||
this.kafkaHost = kafkaHost;
|
||||
this.ack = ack;
|
||||
this.retryTimes = retryTimes;
|
||||
this.batchSize = batchSize;
|
||||
this.lingerMs = lingerMs;
|
||||
this.bufferMemory = bufferMemory;
|
||||
this.keyEncoder = keyEncoder;
|
||||
this.valueEncoder = valueEncoder;
|
||||
this.groupId = groupId;
|
||||
this.autoCommit = autoCommit;
|
||||
this.autoCommitIntervalMs = autoCommitIntervalMs;
|
||||
this.keyDecoder = keyDecoder;
|
||||
this.valueDecoder = valueDecoder;
|
||||
this.autoOffsetReset = autoOffsetReset;
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
public String getKafkaHost() {
|
||||
return kafkaHost;
|
||||
}
|
||||
|
||||
public void setKafkaHost(String kafkaHost) {
|
||||
this.kafkaHost = kafkaHost;
|
||||
}
|
||||
|
||||
public String getAck() {
|
||||
return ack;
|
||||
}
|
||||
|
||||
public void setAck(String ack) {
|
||||
this.ack = ack;
|
||||
}
|
||||
|
||||
public Integer getRetryTimes() {
|
||||
return retryTimes;
|
||||
}
|
||||
|
||||
public void setRetryTimes(Integer retryTimes) {
|
||||
this.retryTimes = retryTimes;
|
||||
}
|
||||
|
||||
public Integer getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(Integer batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public Integer getLingerMs() {
|
||||
return lingerMs;
|
||||
}
|
||||
|
||||
public void setLingerMs(Integer lingerMs) {
|
||||
this.lingerMs = lingerMs;
|
||||
}
|
||||
|
||||
public Integer getBufferMemory() {
|
||||
return bufferMemory;
|
||||
}
|
||||
|
||||
public void setBufferMemory(Integer bufferMemory) {
|
||||
this.bufferMemory = bufferMemory;
|
||||
}
|
||||
|
||||
public String getKeyEncoder() {
|
||||
return keyEncoder;
|
||||
}
|
||||
|
||||
public void setKeyEncoder(String keyEncoder) {
|
||||
this.keyEncoder = keyEncoder;
|
||||
}
|
||||
|
||||
public String getValueEncoder() {
|
||||
return valueEncoder;
|
||||
}
|
||||
|
||||
public void setValueEncoder(String valueEncoder) {
|
||||
this.valueEncoder = valueEncoder;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getAutoCommit() {
|
||||
return autoCommit;
|
||||
}
|
||||
|
||||
public void setAutoCommit(String autoCommit) {
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
public String getAutoCommitIntervalMs() {
|
||||
return autoCommitIntervalMs;
|
||||
}
|
||||
|
||||
public void setAutoCommitIntervalMs(String autoCommitIntervalMs) {
|
||||
this.autoCommitIntervalMs = autoCommitIntervalMs;
|
||||
}
|
||||
|
||||
public String getKeyDecoder() {
|
||||
return keyDecoder;
|
||||
}
|
||||
|
||||
public void setKeyDecoder(String keyDecoder) {
|
||||
this.keyDecoder = keyDecoder;
|
||||
}
|
||||
|
||||
public String getValueDecoder() {
|
||||
return valueDecoder;
|
||||
}
|
||||
|
||||
public void setValueDecoder(String valueDecoder) {
|
||||
this.valueDecoder = valueDecoder;
|
||||
}
|
||||
|
||||
public String getAutoOffsetReset() {
|
||||
return autoOffsetReset;
|
||||
}
|
||||
|
||||
public void setAutoOffsetReset(String autoOffsetReset) {
|
||||
this.autoOffsetReset = autoOffsetReset;
|
||||
}
|
||||
|
||||
public Collection<String> getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
public void setTopic(Collection<String> topic) {
|
||||
this.topic = topic;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package com.muyu.common.util;
|
||||
|
||||
import org.apache.kafka.clients.producer.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
/**
|
||||
* kafka生产
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.common.util
|
||||
* @name:KafkaProducerTest
|
||||
* @Date:2024/9/29 12:27
|
||||
*/
|
||||
public class KafkaProducerTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(KafkaProducerTest.class);
|
||||
|
||||
public static KafkaProducer<String, String> getDefaultKafkaProducer(KafkaCommonProperties kafkaCommonProperties) {
|
||||
Properties properties = new Properties();
|
||||
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaCommonProperties.getKafkaHost());
|
||||
properties.put(ProducerConfig.ACKS_CONFIG, kafkaCommonProperties.getAck());
|
||||
properties.put(ProducerConfig.RETRIES_CONFIG, kafkaCommonProperties.getRetryTimes());
|
||||
properties.put(ProducerConfig.BATCH_SIZE_CONFIG, kafkaCommonProperties.getBatchSize());
|
||||
properties.put(ProducerConfig.LINGER_MS_CONFIG, kafkaCommonProperties.getLingerMs());
|
||||
properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG, kafkaCommonProperties.getBufferMemory());
|
||||
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, kafkaCommonProperties.getKeyEncoder());
|
||||
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, kafkaCommonProperties.getValueEncoder());
|
||||
return new KafkaProducer<>(properties);
|
||||
}
|
||||
|
||||
static class MyProducerCallback implements Callback {
|
||||
|
||||
@Override
|
||||
public void onCompletion(RecordMetadata metadata, Exception exception) {
|
||||
if (Objects.nonNull(exception)) {
|
||||
logger.error(">>>>>>>>>>Producer生产消息异常:", exception);
|
||||
}
|
||||
if (Objects.nonNull(metadata)) {
|
||||
logger.info(">>>>>>>>>>Producer生产消息:metadata:{},partition:{}, offset:{}", metadata, metadata.partition(), metadata.offset());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
KafkaCommonProperties kafkaCommonProperties = new KafkaCommonProperties();
|
||||
KafkaProducer<String, String> producer = getDefaultKafkaProducer(kafkaCommonProperties);
|
||||
String message = "hello world ";
|
||||
try {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// 异步写入数据
|
||||
String topic = kafkaCommonProperties.getTopic().toArray()[0].toString();
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>(topic, message + i);
|
||||
producer.send(producerRecord, new MyProducerCallback());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(">>>>>>>>生产数据异常:", ex);
|
||||
throw new RuntimeException(ex);
|
||||
} finally {
|
||||
producer.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -95,6 +95,7 @@
|
|||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.muyu.server.config;
|
||||
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.apache.kafka.common.serialization.Deserializer;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.mqtt.configure
|
||||
* @Project:cloud-server
|
||||
* @name:KafkaConsumerConfig
|
||||
* @Date:2024/9/28 23:42
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaConsumerConfig {
|
||||
@Bean
|
||||
public KafkaConsumer kafkaConsumer() {
|
||||
Map<String, Object> configs = new HashMap<>();
|
||||
//kafka服务端的IP和端口,格式:(ip:port)
|
||||
configs.put("bootstrap.servers", "47.101.53.251:9092");
|
||||
//开启consumer的偏移量(offset)自动提交到Kafka
|
||||
configs.put("enable.auto.commit", true);
|
||||
//consumer的偏移量(offset) 自动提交的时间间隔,单位毫秒
|
||||
configs.put("auto.commit.interval", 5000);
|
||||
//在Kafka中没有初始化偏移量或者当前偏移量不存在情况
|
||||
//earliest, 在偏移量无效的情况下, 自动重置为最早的偏移量
|
||||
//latest, 在偏移量无效的情况下, 自动重置为最新的偏移量
|
||||
//none, 在偏移量无效的情况下, 抛出异常.
|
||||
configs.put("auto.offset.reset", "latest");
|
||||
//请求阻塞的最大时间(毫秒)
|
||||
configs.put("fetch.max.wait", 500);
|
||||
//请求应答的最小字节数
|
||||
configs.put("fetch.min.size", 1);
|
||||
//心跳间隔时间(毫秒)
|
||||
configs.put("heartbeat-interval", 3000);
|
||||
//一次调用poll返回的最大记录条数
|
||||
configs.put("max.poll.records", 500);
|
||||
//指定消费组
|
||||
configs.put("group.id", "kafka_grop");
|
||||
//指定key使用的反序列化类
|
||||
Deserializer keyDeserializer = new StringDeserializer();
|
||||
//指定value使用的反序列化类
|
||||
Deserializer valueDeserializer = new StringDeserializer();
|
||||
//创建Kafka消费者
|
||||
KafkaConsumer kafkaConsumer = new KafkaConsumer(configs, keyDeserializer, valueDeserializer);
|
||||
return kafkaConsumer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.muyu.server.config;
|
||||
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.common.serialization.Serializer;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.mqtt.configure
|
||||
* @Project:cloud-server
|
||||
* @name:KafkaProviderConfig
|
||||
* @Date:2024/9/28 23:50
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaProviderConfig {
|
||||
|
||||
@Bean
|
||||
public KafkaProducer kafkaProducer() {
|
||||
Map<String, Object> configs = new HashMap<>();
|
||||
//#kafka服务端的IP和端口,格式:(ip:port)
|
||||
configs.put("bootstrap.servers", "47.116.173.119:9092");
|
||||
//客户端发送服务端失败的重试次数
|
||||
configs.put("retries", 2);
|
||||
//多个记录被发送到同一个分区时,生产者将尝试将记录一起批处理成更少的请求.
|
||||
//此设置有助于提高客户端和服务器的性能,配置控制默认批量大小(以字节为单位)
|
||||
configs.put("batch.size", 16384);
|
||||
//生产者可用于缓冲等待发送到服务器的记录的总内存字节数(以字节为单位)
|
||||
configs.put("buffer-memory", 33554432);
|
||||
//生产者producer要求leader节点在考虑完成请求之前收到的确认数,用于控制发送记录在服务端的持久化
|
||||
//acks=0,设置为0,则生产者producer将不会等待来自服务器的任何确认.该记录将立即添加到套接字(socket)缓冲区并视为已发送.在这种情况下,无法保证服务器已收到记录,并且重试配置(retries)将不会生效(因为客户端通常不会知道任何故障),每条记录返回的偏移量始终设置为-1.
|
||||
//acks=1,设置为1,leader节点会把记录写入本地日志,不需要等待所有follower节点完全确认就会立即应答producer.在这种情况下,在follower节点复制前,leader节点确认记录后立即失败的话,记录将会丢失.
|
||||
//acks=all,acks=-1,leader节点将等待所有同步复制副本完成再确认记录,这保证了只要至少有一个同步复制副本存活,记录就不会丢失.
|
||||
configs.put("acks", "-1");
|
||||
//指定key使用的序列化类
|
||||
Serializer keySerializer = new StringSerializer();
|
||||
//指定value使用的序列化类
|
||||
Serializer valueSerializer = new StringSerializer();
|
||||
//创建Kafka生产者
|
||||
KafkaProducer kafkaProducer = new KafkaProducer(configs, keySerializer, valueSerializer);
|
||||
return kafkaProducer;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.config;
|
||||
package com.muyu.server.config;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.muyu.server.service.TemplateService;
|
||||
|
@ -10,7 +10,8 @@ import org.springframework.stereotype.Component;
|
|||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
*
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.mqtt.configure
|
||||
* @Project:cloud-server
|
||||
* @name:MqttConfigure
|
||||
|
@ -29,7 +30,7 @@ public class MqttConfigure {
|
|||
String topic = "vehicle";
|
||||
int qos = 2;
|
||||
String broker = "tcp://47.101.53.251:1883";
|
||||
String clientId = "hhhhhh";
|
||||
String clientId = "测试mqtt";
|
||||
try {
|
||||
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
|
@ -10,7 +10,14 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* 车辆类型管理
|
||||
* @author liuxingue
|
||||
* @package com.muyu.server.controller
|
||||
* @name CarTypeController
|
||||
* @Date 2024/9/29 12:06
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
|
|
|
@ -16,7 +16,8 @@ import java.util.List;
|
|||
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* 数据类型管理
|
||||
* @author liuxinyue
|
||||
* @Package:com.sheep.controller
|
||||
* @Project:cloud-server-c
|
||||
* @name:DataTypeController
|
||||
|
|
|
@ -18,14 +18,15 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 电子围栏
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.controller
|
||||
* @Project:cloud-server
|
||||
* @name:FenceEtlController
|
||||
* @Date:2024/9/17 16:28
|
||||
*/
|
||||
@Log4j2
|
||||
@Tag(name = "电子围栏")
|
||||
@Tag(name = "电子围栏",description = "电子围栏")
|
||||
@RestController
|
||||
@RequestMapping("/fence")
|
||||
@RequiredArgsConstructor
|
||||
|
@ -36,21 +37,21 @@ public class ElectronicFenceController {
|
|||
|
||||
|
||||
@PostMapping("/fenceArray")
|
||||
@Operation(description = "查询所有可用的围栏")
|
||||
@Operation(summary = "查询所有可用的电子围栏",description = "查询所有可用的围栏")
|
||||
public Result<List<ElectronicFenceResp>> fenceArray() {
|
||||
System.out.println("=====>" + "hgfvhgjy");
|
||||
return Result.success(electronicFenceService.fenceArray());
|
||||
}
|
||||
|
||||
@PostMapping("/fenceselectList")
|
||||
@Operation(description = "列表")
|
||||
@Operation(summary = "列表",description = "列表")
|
||||
public Result<List<ElectronicFenceResp>> fenceselectList(@RequestBody ElectroicFenceListReq electroicFenceListReq) {
|
||||
System.out.println("=====>" + "hgfvhgjy");
|
||||
return Result.success(electronicFenceService.fenceselectList(electroicFenceListReq));
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(description = "添加")
|
||||
@Operation(summary = "添加电子围栏",description = "添加电子围栏")
|
||||
public Result AddFence(@RequestBody ElectroicFenceAddReq electroicFenceAddReq) {
|
||||
|
||||
electronicFenceService.unquireFence(electroicFenceAddReq.getName());
|
||||
|
@ -60,7 +61,7 @@ public class ElectronicFenceController {
|
|||
}
|
||||
|
||||
@PostMapping("/upd/{id}")
|
||||
@Operation(description = "修改")
|
||||
@Operation(summary = "修改电子围栏",description = "修改电子围栏")
|
||||
public Result UpdFence(@PathVariable("id") Long id, @RequestBody ElectroicFenceUpdReq electroicFenceUpdReq) {
|
||||
|
||||
electronicFenceService.updateById(ElectronicFence.buildByElectronicUpd(electroicFenceUpdReq, () -> id));
|
||||
|
@ -69,7 +70,7 @@ public class ElectronicFenceController {
|
|||
}
|
||||
|
||||
@PostMapping("/findElectronicByid/{id}")
|
||||
@Operation(description = "通过id回显围栏信息")
|
||||
@Operation(summary = "通过Id回显电子围栏信息",description = "通过Id回显电子围栏")
|
||||
public Result<ElectronicFence> findElectronicByid(@PathVariable("id") Long id) {
|
||||
|
||||
ElectronicFence electronicFence= electronicFenceService.findElectronicByid(id);
|
||||
|
@ -101,7 +102,7 @@ public class ElectronicFenceController {
|
|||
}
|
||||
|
||||
@PostMapping("/open/{id}")
|
||||
@Operation(description = "开启围栏")
|
||||
@Operation(summary = "开启电子围栏",description = "开启电子围栏")
|
||||
public Result openFence(@PathVariable("id") Long id) {
|
||||
|
||||
electronicFenceService.openFence(id);
|
||||
|
@ -110,7 +111,7 @@ public class ElectronicFenceController {
|
|||
}
|
||||
|
||||
@PostMapping("/close/{id}")
|
||||
@Operation(description = "关闭围栏")
|
||||
@Operation(summary = "关闭电子围栏",description = "关闭电子围栏")
|
||||
public Result closeFence(@PathVariable("id") Long id) {
|
||||
|
||||
electronicFenceService.closeFence(id);
|
||||
|
@ -119,7 +120,7 @@ public class ElectronicFenceController {
|
|||
}
|
||||
|
||||
@PostMapping("/setFenceWay")
|
||||
@Operation(description = "设置电子围栏的位置")
|
||||
@Operation(summary = "设置电子围栏的位置",description = "设置电子围栏的位置")
|
||||
public Result setFenceWay(@RequestBody FenceWayReq fenceWayReq) {
|
||||
|
||||
Long id = fenceWayReq.getId();
|
||||
|
|
|
@ -20,7 +20,8 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 围栏组
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.controller
|
||||
* @Project:cloud-server
|
||||
* @name:FenceGroupController
|
||||
|
@ -30,7 +31,7 @@ import java.util.List;
|
|||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/group")
|
||||
@Tag(name = "围栏组")
|
||||
@Tag(name = "围栏组",description = "围栏组管理")
|
||||
public class ElectronicFenceGroupController {
|
||||
|
||||
@Autowired
|
||||
|
@ -41,6 +42,7 @@ public class ElectronicFenceGroupController {
|
|||
|
||||
|
||||
@PostMapping("/selectGroupList")
|
||||
@Operation(summary = "围栏组列表",description = "围栏组列表")
|
||||
public Result<List<GroupFenceListresp>> selectGroupList(@RequestBody ElectronicFenceGroupListReq req) {
|
||||
//查询所有的围栏组
|
||||
List<ElectronicFenceGroup> fenceListList = electronicFenceGroupService.selectGroupList(req);
|
||||
|
@ -52,6 +54,7 @@ public class ElectronicFenceGroupController {
|
|||
|
||||
@Transactional
|
||||
@PostMapping("/addGroup")
|
||||
@Operation(summary = "添加围栏组",description = "添加围栏组")
|
||||
public Result addGroup(@RequestBody ElectronicFenceGroupAddReq addReq) {
|
||||
|
||||
ElectronicFenceGroup electronicFenceGroup = ElectronicFenceGroup.buildByAdd(addReq);
|
||||
|
@ -66,7 +69,7 @@ public class ElectronicFenceGroupController {
|
|||
}
|
||||
|
||||
@PostMapping("/findGroupByid/{id}")
|
||||
@Operation(description = "通过id回显围栏组信息")
|
||||
@Operation(summary = "通过id回显围栏组信息",description = "通过id回显围栏组信息")
|
||||
public Result<ElectronicFenceGroupResp> findGroupByid(@PathVariable("id") Long id) {
|
||||
|
||||
ElectronicFenceGroupResp fenceGroupResp = electronicFenceGroupService.findGroupByid(id);
|
||||
|
@ -77,7 +80,7 @@ public class ElectronicFenceGroupController {
|
|||
|
||||
@Transactional
|
||||
@PostMapping("/updGroup/{id}")
|
||||
@Operation(description = "修改")
|
||||
@Operation(summary = "修改围栏组",description = "修改")
|
||||
public Result UpdFence(@PathVariable("id") Long id, @RequestBody ElectronicFenceGroupUpdReq req) {
|
||||
|
||||
electronicFenceGroupService.updateById(ElectronicFenceGroup.buildByUpd(req, () -> id));
|
||||
|
|
|
@ -9,7 +9,10 @@ import com.muyu.server.controller.form.InsertEnterprise;
|
|||
import com.muyu.server.controller.form.SearchEnterpriseName;
|
||||
import com.muyu.server.controller.form.UpdateEnterprise;
|
||||
import com.muyu.server.service.EnterpriseService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -17,12 +20,16 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* 企业运营控制层
|
||||
* @author yuping
|
||||
* @Description 企业运营控制层
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-26 20:24:05
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/enterprise")
|
||||
@Log4j2
|
||||
@Tag(name = "企业运营管理",description = "企业运营管理")
|
||||
public class EnterpriseController {
|
||||
|
||||
@Autowired
|
||||
|
@ -35,6 +42,7 @@ public class EnterpriseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/selectEnterprise")
|
||||
@Operation(summary = "查询分页企业信息",description = "查询分页企业信息")
|
||||
public Result selectEnterprise(@RequestBody @Valid SearchEnterpriseName form) {
|
||||
Integer page = form.getPage();
|
||||
Integer length = form.getLength();
|
||||
|
@ -55,6 +63,7 @@ public class EnterpriseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/insert")
|
||||
@Operation(summary = "新增企业信息",description = "新增企业信息")
|
||||
public Result insert(@RequestBody @Valid InsertEnterprise form){
|
||||
Enterprise enterprise = new Enterprise();
|
||||
|
||||
|
@ -73,6 +82,7 @@ public class EnterpriseController {
|
|||
* @return
|
||||
*/
|
||||
@GetMapping("/searchById")
|
||||
@Operation(summary = "根据编号查询企业信息",description = "根据编号查询企业信息")
|
||||
public Result searchById(@RequestParam("enterpriseId") Integer enterpriseId){
|
||||
HashMap map = enterpriseService.searchById(enterpriseId);
|
||||
return Result.success(map);
|
||||
|
@ -85,6 +95,7 @@ public class EnterpriseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/updateEnterEnterprise")
|
||||
@Operation(summary = "修改企业信息",description = "修改企业信息")
|
||||
public Result updateEnterprise(@RequestBody @Valid UpdateEnterprise form){
|
||||
Enterprise enterprise = new Enterprise();
|
||||
|
||||
|
@ -104,6 +115,7 @@ public class EnterpriseController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/deleteByIds")
|
||||
@Operation(summary = "删除企业信息",description = "删除企业信息")
|
||||
public Result deleteByIds(@RequestBody @Valid DeleteEnterpriseByIds form){
|
||||
int rows = enterpriseService.deleteByIds(form.getIds());
|
||||
return Result.success(rows);
|
||||
|
|
|
@ -13,7 +13,8 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* 报文模版管理
|
||||
* @author liuxinyue
|
||||
* @Package:com.sheep.message.controller
|
||||
* @Project:cloud-server-c
|
||||
* @name:MessageTemplateTypeController
|
||||
|
|
|
@ -14,6 +14,13 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 车辆管理
|
||||
* @author sx
|
||||
* @Package:com.template.controller
|
||||
* @name:SysCarController
|
||||
* @Date:2024/9/20 12:12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sysCar")
|
||||
@AllArgsConstructor
|
||||
|
@ -84,9 +91,10 @@ public class SysCarController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/findCarByVin")
|
||||
@Operation(summary = "根据VIN码查询车信息",description = "根据VIN码查询车信息")
|
||||
// @Operation(summary = "根据VIN码查询车信息",description = "根据VIN码查询车信息")
|
||||
public Result<SysCar> findCarByVin(@RequestParam("carVin") String carVin){
|
||||
return Result.success(sysCarService.findCarByVin(carVin));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,11 @@ import com.muyu.common.domain.SysCarFault;
|
|||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.server.service.SysCarFaultService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -18,24 +21,27 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 故障码 接口控制层
|
||||
* @author YuanZiLong
|
||||
* 车辆故障码 接口控制层
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.controller
|
||||
* @name: SysCarFaultController
|
||||
* @date: 2024/9/20 11:00
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/breakdown")
|
||||
@Tag(name = "车辆故障码",description = "车辆故障码管理")
|
||||
@Log4j2
|
||||
public class SysCarFaultController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private SysCarFaultService sysCarFaultService;
|
||||
|
||||
/**
|
||||
* 查询车辆故障管理列表
|
||||
* 查询车辆故障码管理列表
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:list")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询车辆故障码管理列表",description ="查询车辆故障码管理列表")
|
||||
public Result<TableDataInfo<SysCarFault>> list(SysCarFault sysCarFault)
|
||||
{
|
||||
startPage();
|
||||
|
@ -46,10 +52,11 @@ public class SysCarFaultController extends BaseController
|
|||
|
||||
|
||||
/**
|
||||
* 导出车辆故障管理列表
|
||||
* 导出车辆故障码管理列表
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:export")
|
||||
@PostMapping("/export")
|
||||
@Operation(summary = "导出车辆故障码管理列表",description = "导出车辆故障码管理列表")
|
||||
public void export(HttpServletResponse response, SysCarFault sysCarFault)
|
||||
{
|
||||
List<SysCarFault> list = sysCarFaultService.selectSysCarFaultList(sysCarFault);
|
||||
|
@ -58,20 +65,22 @@ public class SysCarFaultController extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取车辆故障管理详细信息
|
||||
* 获取车辆故障码管理详细信息
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@Operation(summary = "获取车辆故障码管理详细信息")
|
||||
public Result<List<SysCarFault>> getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(sysCarFaultService.selectSysCarFaultById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增车辆故障管理
|
||||
* 新增车辆故障码管理
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:add")
|
||||
@PostMapping
|
||||
@Operation(summary = "新增车辆故障码管理")
|
||||
public Result<Integer> add(
|
||||
@Validated @RequestBody SysCarFault sysCarFault)
|
||||
{
|
||||
|
@ -80,18 +89,17 @@ public class SysCarFaultController extends BaseController
|
|||
if (selectFaultByFaultCode!=null){
|
||||
return error("新增车辆故障 ,故障码已存在");
|
||||
}
|
||||
|
||||
|
||||
sysCarFault.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(sysCarFaultService.save(sysCarFault));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改车辆故障管理
|
||||
* 修改车辆故障码管理
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:edit")
|
||||
@PutMapping
|
||||
@Operation(summary = "修改车辆故障码管理")
|
||||
public Result<Integer> edit(
|
||||
@Validated @RequestBody SysCarFault sysCarFault)
|
||||
{
|
||||
|
@ -101,10 +109,11 @@ public class SysCarFaultController extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 删除车辆故障管理
|
||||
* 删除车辆故障码管理
|
||||
*/
|
||||
@RequiresPermissions("breakdown:breakdown:remove")
|
||||
@DeleteMapping("/{ids}")
|
||||
@Operation(summary = "删除车辆故障码管理")
|
||||
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
|
||||
{
|
||||
sysCarFaultService.removeBatchByIds(Arrays.asList(ids));
|
||||
|
@ -112,21 +121,23 @@ public class SysCarFaultController extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 启用告警
|
||||
* 启用故障码警告
|
||||
* @param id
|
||||
*/
|
||||
@PutMapping("/enableWarningsById/{id}")
|
||||
@Operation(summary = "启用故障码警告")
|
||||
public void enableWarningsById(@PathVariable("id")Long id){
|
||||
UpdateWrapper<SysCarFault> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("id",id);
|
||||
wrapper.set("warn_status",0);
|
||||
sysCarFaultService.update(wrapper);
|
||||
sysCarFaultService.update(wrapper);
|
||||
}
|
||||
/**
|
||||
* 禁用告警
|
||||
* 禁用故障码告警
|
||||
* @param id
|
||||
*/
|
||||
@PutMapping("/disableWarningsById/{id}")
|
||||
@Operation(summary = "禁用故障码告警")
|
||||
public void disableWarningsById(@PathVariable("id")Long id){
|
||||
UpdateWrapper<SysCarFault> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("id",id);
|
||||
|
|
|
@ -7,7 +7,10 @@ import com.muyu.common.core.web.controller.BaseController;
|
|||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.domain.SysCarFaultLog;
|
||||
import com.muyu.server.service.SysCarFaultLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -16,25 +19,39 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 车辆故障记录 接口控制层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.controller
|
||||
* @name: SysCarFaultLogController
|
||||
* @date: 2024/9/22 21:08
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/log")
|
||||
@Tag(name = "车辆故障记录",description = "车辆故障记录管理")
|
||||
@Log4j2
|
||||
public class SysCarFaultLogController extends BaseController {
|
||||
@Autowired
|
||||
private SysCarFaultLogService service;
|
||||
|
||||
/**
|
||||
* 查询故障记录列表
|
||||
* @param sysCarFaultLog
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "查询故障记录列表",description = "查询故障记录列表")
|
||||
public Result<TableDataInfo<SysCarFaultLog>> list(@RequestBody SysCarFaultLog sysCarFaultLog){
|
||||
startPage();
|
||||
List<SysCarFaultLog> list = service.selectSysCarFaultLogList(sysCarFaultLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询故障记录状态为忽略的数据列表
|
||||
* @param sysCarFaultLog
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/listStatusIgnore")
|
||||
@Operation(summary = "查询故障记录状态为忽略的数据列表",description = "查询故障记录状态为忽略的数据列表")
|
||||
public Result<TableDataInfo<SysCarFaultLog>>listStatusIgnore(@RequestBody SysCarFaultLog sysCarFaultLog){
|
||||
startPage();
|
||||
List<SysCarFaultLog> list = service.listStatusIgnore(sysCarFaultLog);
|
||||
|
@ -42,29 +59,51 @@ public class SysCarFaultLogController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询故障记录状态为已解决的数据列表
|
||||
* @param sysCarFaultLog
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/listStatusSolve")
|
||||
@Operation(summary = "查询故障记录状态为已解决的数据列表",description = "查询故障记录状态为已解决的数据列表")
|
||||
public Result<TableDataInfo<SysCarFaultLog>>listStatusSolve(@RequestBody SysCarFaultLog sysCarFaultLog){
|
||||
startPage();
|
||||
List<SysCarFaultLog> list = service.listStatusSolve(sysCarFaultLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询故障记录状态为处理中的数据列表
|
||||
* @param sysCarFaultLog
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/listStatusProcess")
|
||||
@Operation(summary = "查询故障记录状态为处理中的数据列表",description = "查询故障记录状态为处理中的数据列表")
|
||||
public Result<TableDataInfo<SysCarFaultLog>>listStatusProcess(@RequestBody SysCarFaultLog sysCarFaultLog){
|
||||
startPage();
|
||||
List<SysCarFaultLog> list = service.listStatusProcess(sysCarFaultLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增故障记录
|
||||
* @param sysCarFaultLog
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增故障记录",description = "新增故障记录")
|
||||
public Result<Integer> add(@RequestBody SysCarFaultLog sysCarFaultLog){
|
||||
|
||||
return toAjax(service.save(sysCarFaultLog));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出故障记录
|
||||
* @param response
|
||||
* @param sysCarFaultLog
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
@Operation(summary = "导出故障记录",description = "导出故障记录")
|
||||
public void export(HttpServletResponse response, SysCarFaultLog sysCarFaultLog){
|
||||
List<SysCarFaultLog> list = service.selectSysCarFaultLogList(sysCarFaultLog);
|
||||
ExcelUtil<SysCarFaultLog> util = new ExcelUtil<SysCarFaultLog>(SysCarFaultLog.class);
|
||||
|
@ -72,11 +111,12 @@ public class SysCarFaultLogController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 修改为忽略
|
||||
* 把处理中的数据修改为忽略
|
||||
* @param idsStr
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/updateStatusById/{ids}")
|
||||
@Operation(summary = "把处理中的数据修改为忽略",description = "把处理中的数据修改为忽略")
|
||||
public Result updateStatusById(@PathVariable("ids")String idsStr){
|
||||
Long[] ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Long::valueOf)
|
||||
|
|
|
@ -6,6 +6,9 @@ import com.muyu.common.core.web.controller.BaseController;
|
|||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.domain.SysCarFaultMessage;
|
||||
import com.muyu.server.service.SysCarFaultMessageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -14,22 +17,25 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 站内信 接口控制层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.controller
|
||||
* @name: SysCarFaultMessageController
|
||||
* @date: 2024/9/22 14:39
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/message")
|
||||
@Log4j2
|
||||
@Tag(name = "站内信",description = "站内信管理")
|
||||
public class SysCarFaultMessageController extends BaseController {
|
||||
@Autowired
|
||||
private SysCarFaultMessageService service;
|
||||
|
||||
/**
|
||||
* 查询所有故障信息
|
||||
* 查询所有站内信信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询所有站内信信息",description = "查询所有站内信信息")
|
||||
public Result<TableDataInfo<SysCarFaultMessage>> list(){
|
||||
startPage();
|
||||
List<SysCarFaultMessage> list = service.list();
|
||||
|
@ -37,11 +43,12 @@ public class SysCarFaultMessageController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 查询状态为1的故障信息
|
||||
* 查询状态为已读的信息
|
||||
* @return
|
||||
*/
|
||||
|
||||
@GetMapping("/listStatusOne")
|
||||
@Operation(summary ="查询状态为以解决的故障信息",description = "查询状态为已解决的故障信息")
|
||||
public Result<TableDataInfo<SysCarFaultMessage>>listStatusOne(){
|
||||
startPage();
|
||||
List<SysCarFaultMessage> list = service.listStatusOnt();
|
||||
|
@ -49,10 +56,11 @@ public class SysCarFaultMessageController extends BaseController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 查询状态为2的故障信息
|
||||
* 查询状态为未读的信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/listStatusTwo")
|
||||
@Operation(summary = "查询状态为未读的信息",description = "查询状态为未读的信息")
|
||||
public Result<TableDataInfo<SysCarFaultMessage>>listStatusTwo(){
|
||||
startPage();
|
||||
List<SysCarFaultMessage> list = service.listStatusTwo();
|
||||
|
@ -64,6 +72,7 @@ public class SysCarFaultMessageController extends BaseController {
|
|||
* @return
|
||||
*/
|
||||
@PutMapping("/updateStatusById/{id}")
|
||||
@Operation(summary = "修改未读站内信息为已读",description = "修改未读站内信息为已读")
|
||||
public Result updateStatusById(@PathVariable("id")Long id){
|
||||
UpdateWrapper<SysCarFaultMessage> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("id",id);
|
||||
|
|
|
@ -12,7 +12,13 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* 车辆日志管理 接口控制层
|
||||
* @author liuxinyue
|
||||
* @package: com.muyu.breakdown.controller
|
||||
* @name: SysCarLogController
|
||||
* @date: 2024/9/22 14:39
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sysCarLog")
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.muyu.server.service.TemplateService;
|
|||
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.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -19,7 +20,8 @@ import java.util.List;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* 报文模版管理
|
||||
* @author liuxinyue
|
||||
* @Package:com.template.controller
|
||||
* @Project:cloud-server-c
|
||||
* @name:TemplateController
|
||||
|
@ -29,6 +31,7 @@ import java.util.concurrent.ExecutionException;
|
|||
@RequestMapping("/template")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "报文模版管理",description = "报文模版管理")
|
||||
@Log4j2
|
||||
public class TemplateController {
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -3,20 +3,34 @@ package com.muyu.server.controller;
|
|||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.server.service.TemplateNeedService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 查询报文模版
|
||||
* @author sx
|
||||
* @Package:com.template.controller
|
||||
* @name:templateNeed
|
||||
* @Date:2024/9/20 12:12
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/templateNeed")
|
||||
@Tag(name = "查询报文模版",description = "查询报文模版")
|
||||
@Log4j2
|
||||
public class TemplateNeedController {
|
||||
@Autowired
|
||||
private TemplateNeedService templateNeedService;
|
||||
|
||||
|
||||
@GetMapping("/selectByTemplateId/{templateId}")
|
||||
@Operation(summary = "根据模板ID查询报文模版",description = "根据模板ID查询报文模版")
|
||||
public Result selectByTemplateId(@PathVariable("templateId") Long templateId){
|
||||
return Result.success(templateNeedService.selectByTemplateId(templateId));
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.muyu.server.controller;
|
|||
|
||||
import com.muyu.common.domain.WarnLogs;
|
||||
import com.muyu.server.service.WarnLogsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -20,6 +23,8 @@ import com.muyu.common.core.domain.Result;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/logs")
|
||||
@Tag(name = "预警日志",description = "预警日志管理")
|
||||
@Log4j2
|
||||
public class WarnLogsController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
|
@ -29,6 +34,7 @@ public class WarnLogsController extends BaseController
|
|||
* 查询预警日志列表
|
||||
*/
|
||||
@GetMapping("/selectWarnLogsList")
|
||||
@Operation(summary = "预警日志列表",description = "预警日志列表")
|
||||
public Result selectWarnLogsList(){
|
||||
return Result.success(warnLogsService.selectWarnLogsList());
|
||||
}
|
||||
|
@ -38,6 +44,7 @@ public class WarnLogsController extends BaseController
|
|||
* 获取预警日志详细信息
|
||||
*/
|
||||
@GetMapping(value = "selectWarnLogsById/{id}")
|
||||
@Operation(summary = "根据ID查询预警日志信息",description = "根据ID查询预警日志信息")
|
||||
public Result selectWarnLogsById(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(warnLogsService.selectWarnLogsById(id));
|
||||
|
@ -47,6 +54,7 @@ public class WarnLogsController extends BaseController
|
|||
* 新增预警日志
|
||||
*/
|
||||
@PostMapping("/addWarnLogs")
|
||||
@Operation(summary = "新增预警日志",description = "新增预警日志")
|
||||
public Result<Integer> addWarnLogs(@RequestBody WarnLogs warnLogs)
|
||||
{
|
||||
int i = warnLogsService.addWarnLogs(warnLogs);
|
||||
|
|
|
@ -6,6 +6,9 @@ import javax.annotation.Resource;
|
|||
|
||||
import com.muyu.common.domain.WarnRule;
|
||||
import com.muyu.server.service.WarnRuleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
|
@ -24,6 +27,8 @@ import com.muyu.common.core.domain.Result;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/rule")
|
||||
@Tag(name = "预警规则管理",description = "预警规则管理")
|
||||
@Log4j2
|
||||
public class WarnRuleController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
|
@ -33,6 +38,7 @@ public class WarnRuleController extends BaseController
|
|||
* 查询预警规则列表
|
||||
*/
|
||||
@GetMapping("/selectWarnRuleRespList")
|
||||
@Operation(summary = "预警规则列表",description = "预警规则列表")
|
||||
public Result selectWarnRuleRespList()
|
||||
{
|
||||
return Result.success(warnRuleService.selectWarnRuleRespList());
|
||||
|
@ -43,6 +49,7 @@ public class WarnRuleController extends BaseController
|
|||
*/
|
||||
|
||||
@GetMapping(value = "selectById/{id}")
|
||||
@Operation(summary = "根据ID查询预警规则信息",description = "根据ID查询预警规则信息")
|
||||
public Result<List<WarnRule>> selectById(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(warnRuleService.selectWarnRuleById(id));
|
||||
|
@ -53,6 +60,7 @@ public class WarnRuleController extends BaseController
|
|||
*/
|
||||
|
||||
@PostMapping("/addWarnRule")
|
||||
@Operation(summary = "新增预警规则",description = "新增预警规则")
|
||||
public Result<Integer> addWarnRule(@RequestBody WarnRule warnRule)
|
||||
{
|
||||
int i = warnRuleService.addWarnRule(warnRule);
|
||||
|
@ -64,6 +72,7 @@ public class WarnRuleController extends BaseController
|
|||
*/
|
||||
|
||||
@PostMapping("/updWarnRule")
|
||||
@Operation(summary = "修改预警规则",description = "修改预警规则")
|
||||
public Result updWarnRule(@RequestBody WarnRule warnRule)
|
||||
{
|
||||
int i = warnRuleService.updWarnRule(warnRule);
|
||||
|
@ -74,6 +83,7 @@ public class WarnRuleController extends BaseController
|
|||
* 删除预警规则
|
||||
*/
|
||||
@DeleteMapping("/{ids}")
|
||||
@Operation(summary = "删除预警规则",description = "删除预警规则")
|
||||
public Result remove(@PathVariable("ids") Long[] ids)
|
||||
{
|
||||
warnRuleService.removeBatchByIds(Arrays.asList(ids));
|
||||
|
@ -84,6 +94,7 @@ public class WarnRuleController extends BaseController
|
|||
|
||||
//根据策略ID查规则
|
||||
@GetMapping("/selectListByStrategyId/{strategyId}")
|
||||
@Operation(summary = "根据策略ID查询预警规则列表",description = "根据策略ID查询预警规则列表")
|
||||
public Result selectListByStrategyId(@PathVariable("strategyId") Long strategyId){
|
||||
return Result.success(warnRuleService.selectListByStrategyId(strategyId));
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ import jakarta.validation.constraints.NotEmpty;
|
|||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* 删除企业信息
|
||||
* @author yuping
|
||||
* @Description 删除企业信息
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-26 22:05:47
|
||||
|
|
|
@ -5,10 +5,11 @@ import jakarta.validation.constraints.NotNull;
|
|||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 新增企业信息表单
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-26 21:16:06
|
||||
* 新增企业信息表单
|
||||
* @author yuping
|
||||
* @package com.muyu.server.controller.form
|
||||
* @name InsertEnterprise
|
||||
* @Date 2024/9/29 12:06
|
||||
*/
|
||||
@Data
|
||||
public class InsertEnterprise {
|
||||
|
|
|
@ -6,10 +6,11 @@ import lombok.Data;
|
|||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 企业名称查询表单
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-26 20:48:33
|
||||
* 企业名称查询表单
|
||||
* @author yuping
|
||||
* @package com.muyu.server.controller.form
|
||||
* @name SearchEnterpriseName
|
||||
* @Date 2024/9/29 12:06
|
||||
*/
|
||||
@Data
|
||||
public class SearchEnterpriseName {
|
||||
|
|
|
@ -7,10 +7,11 @@ import jakarta.validation.constraints.Pattern;
|
|||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 修改企业信息
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-26 21:22:05
|
||||
* 修改企业信息
|
||||
* @author yuping
|
||||
* @package com.muyu.server.controller.form
|
||||
* @name UpdateEnterprise
|
||||
* @Date 2024/9/29 12:06
|
||||
*/
|
||||
@Data
|
||||
public class UpdateEnterprise {
|
||||
|
|
|
@ -9,6 +9,13 @@ import org.apache.ibatis.annotations.Select;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 车辆类型Mapper接口
|
||||
* @author sx
|
||||
* @package com.muyu.server.mapper
|
||||
* @name CarTypeMapper
|
||||
* @Date 2024/9/29 12:06
|
||||
*/
|
||||
@Mapper
|
||||
public interface CarTypeMapper extends BaseMapper<CarType> {
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 故障记录日志 管理层
|
||||
* @author YuanZiLong
|
||||
* 故障记录日志 Mapper接口
|
||||
* @author 袁子龙
|
||||
* @package com.muyu.breakdown.mapper
|
||||
* @name: SysCarFaultLogMapper
|
||||
* @date: 2024/9/22 21:06
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 车辆故障码 管理层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @Package: com.muyu.breakdown.mapper
|
||||
* @Name: SysCarFaultMapper
|
||||
* @Date: 2024/9/20 10:57
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 站内信 管理层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @packer: com.muyu.breakdown.mapper
|
||||
* @name: SysCarFaultMessageMapper
|
||||
* @date: 2024/9/22 11:59
|
||||
|
|
|
@ -19,4 +19,8 @@ public interface SysCarMapper extends BaseMapper<SysCar> {
|
|||
List<SysCarFaultLogVo> findFenceByCarVin(@Param("carVin") String carVin);
|
||||
|
||||
|
||||
SysCar findCarByVin(@Param("carVin") String carVin);
|
||||
|
||||
SysCar selectByCarVin(@Param("carVin") String carVin);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@ import org.apache.ibatis.annotations.Param;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 预警日志Mapper接口
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-09-20
|
||||
* 车辆预警日志 Mapper 接口
|
||||
* @author sx
|
||||
* @package com.muyu.server.mapper
|
||||
* @name WarnLogsMapper
|
||||
* @date 2024-09-29 12:21:09
|
||||
*/
|
||||
@Mapper
|
||||
public interface WarnLogsMapper extends BaseMapper<WarnLogs> {
|
||||
|
|
|
@ -11,8 +11,9 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 预警规则Mapper接口
|
||||
*
|
||||
* @author muyu
|
||||
* @author sx
|
||||
* @package com.muyu.server.mapper
|
||||
* @name WarnRuleMapper
|
||||
* @date 2024-09-20
|
||||
*/
|
||||
@Mapper
|
||||
|
|
|
@ -12,8 +12,9 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 预警策略Mapper接口
|
||||
*
|
||||
* @author muyu
|
||||
* @package com.muyu.server.mapper
|
||||
* @name WarnStrategyMapper
|
||||
* @date 2024-09-20
|
||||
*/
|
||||
@Mapper
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 车辆故障记录 服务层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.service
|
||||
* @name: SysCarFaultLogService
|
||||
* @date: 2024/9/22 21:07
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 站内信 服务层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.service
|
||||
* @name: SysCarFaultMessageService
|
||||
* @date: 2024/9/22 14:35
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 车辆故障码 服务层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.service
|
||||
* @name : SysCarFaultService
|
||||
* @date: 2024/9/20 10:57
|
||||
|
|
|
@ -22,4 +22,5 @@ public interface SysCarService {
|
|||
|
||||
SysCar findCarByVin(String carVin);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 车辆故障记录 业务层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.service.impl
|
||||
* @name: sysCarFaultLogServiceImpl
|
||||
* @date: 2024/9/22 21:07
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 站内信 业务层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.service.impl
|
||||
* @name: SysCarFaultMessageServiceImpl
|
||||
* @date: 2024/9/22 14:36
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 车辆故障码 业务层
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.service.impl
|
||||
* @name: SysCarFaultServiceImpl
|
||||
* @date: 2024/9/20 10:58
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.server.service.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.domain.SysCar;
|
||||
|
@ -13,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
@DS("lizzDB")
|
||||
@Service
|
||||
public class SysCarServiceImpl extends ServiceImpl<SysCarMapper, SysCar> implements SysCarService {
|
||||
@Autowired
|
||||
|
@ -51,7 +53,8 @@ public class SysCarServiceImpl extends ServiceImpl<SysCarMapper, SysCar> impleme
|
|||
public SysCar findCarByVin(String carVin) {
|
||||
QueryWrapper<SysCar> sysCarQueryWrapper = new QueryWrapper<>();
|
||||
sysCarQueryWrapper.eq("car_vin", carVin);
|
||||
SysCar sysCar = sysCarMapper.selectOne(sysCarQueryWrapper);
|
||||
return sysCar;
|
||||
List<SysCar> sysCars = sysCarMapper.selectList(sysCarQueryWrapper);
|
||||
return sysCars.isEmpty() ? null : sysCars.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ public class TemplateServiceImpl extends ServiceImpl<TemplateMapper, Template> i
|
|||
log.info("carVin码为:" + carVin);
|
||||
//根据VIN码获取车辆信息
|
||||
SysCar carByVin = sysCarService.findCarByVin(carVin);
|
||||
log.info("车辆信息为:" + carByVin);
|
||||
//对应车辆所对应的报文模版
|
||||
Integer templateId = carByVin.getTemplateId();
|
||||
|
||||
|
@ -102,6 +103,7 @@ public class TemplateServiceImpl extends ServiceImpl<TemplateMapper, Template> i
|
|||
jsonObject.put(messageTemplateType.getMessageField(), result.substring(startIndex, endIndex));
|
||||
}
|
||||
|
||||
System.out.println("哈哈哈红红火火恍恍惚惚");
|
||||
log.info("解析后的报文是:" + jsonObject);
|
||||
|
||||
|
||||
|
|
|
@ -74,4 +74,10 @@
|
|||
WHERE
|
||||
sys_car_fault_log.vin = #{carVin};
|
||||
</select>
|
||||
<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>
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -278,6 +278,11 @@
|
|||
<artifactId>cloud-common-saas</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-swagger</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue