pull/3/head
parent
49fe2961f0
commit
b299c8d3a1
|
@ -0,0 +1,97 @@
|
|||
<?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-modules-carData</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>2.9.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-session</artifactId>
|
||||
<version>0.13.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.carData;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData
|
||||
* @Project:cloud-server-8
|
||||
* @name:CarDataApplication
|
||||
* @Date:2024/9/26 15:33
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableMyFeignClients
|
||||
public class CarDataApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CarDataApplication.class,args);
|
||||
System.out.println("caused: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;;caused: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.carData.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.annotation
|
||||
* @Project:cloud-server-8
|
||||
* @name:IoTTableName
|
||||
* @Date:2024/9/27 19:29
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
|
||||
public @interface IoTTableName {
|
||||
|
||||
String value() default "";
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.carData.config.cacheconfig;
|
||||
import com.github.benmanes.caffeine.cache.Expiry;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.cacheconfig
|
||||
* @Project:cloud-server-8
|
||||
* @name:CacheExpiry
|
||||
* @Date:2024/9/26 23:46
|
||||
*/
|
||||
public class CacheExpiry implements Expiry<String,ExpiryTime>{
|
||||
@Override
|
||||
public long expireAfterCreate(String key, ExpiryTime value, long currentTime) {
|
||||
return TimeUnit.SECONDS.toNanos(value.getExpiryTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long expireAfterUpdate(String key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
|
||||
return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long expireAfterRead(String key, ExpiryTime value, long currentTime, @NonNegative long currentDuration) {
|
||||
return TimeUnit.SECONDS.toNanos(value.getRefreshTime());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.carData.config.cacheconfig;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.cacheconfig
|
||||
* @Project:cloud-server-8
|
||||
* @name:CaffeineConfig
|
||||
* @Date:2024/9/26 23:51
|
||||
*/
|
||||
@Configuration
|
||||
public class CaffeineConfig {
|
||||
|
||||
@Bean
|
||||
public Cache<String, ? extends ExpiryTime> caffeineCache(){
|
||||
CacheExpiry cacheExpiry = new CacheExpiry();
|
||||
return Caffeine.newBuilder()
|
||||
.expireAfter(cacheExpiry)
|
||||
.initialCapacity(128)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.carData.config.cacheconfig;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.cacheconfig
|
||||
* @Project:cloud-server-8
|
||||
* @name:ExpiryTime
|
||||
* @Date:2024/9/26 23:44
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ExpiryTime {
|
||||
|
||||
/**
|
||||
* 过期时间单位(秒)默认30分钟
|
||||
*/
|
||||
@Builder.Default
|
||||
private long expiryTime = 30 * 60;
|
||||
|
||||
/**
|
||||
* 刷新时间单位(秒) 默认15分钟
|
||||
*/
|
||||
@Builder.Default
|
||||
private long refreshTime = 15 * 60;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.carData.config.kafkaconfig;
|
||||
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.config.kafkaconfig
|
||||
* @Project:cloud-server-8
|
||||
* @name:KafkaConfig
|
||||
* @Date:2024/9/28 12:19
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaConfig {
|
||||
|
||||
@Bean
|
||||
public KafkaProducer kafkaProducer(){
|
||||
HashMap<String, Object> configs = new HashMap<>();
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,282 @@
|
|||
package com.muyu.carData.config.lotdbconfig;
|
||||
|
||||
import com.muyu.carData.domain.IoTDBRecord;
|
||||
import com.muyu.carData.interfaces.IoTDBRecordable;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.Session;
|
||||
import org.apache.iotdb.session.SessionDataSet;
|
||||
import org.apache.iotdb.session.util.Version;
|
||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.lotdbconfig
|
||||
* @Project:cloud-server-8
|
||||
* @name:IotDBSessionConfig
|
||||
* @Date:2024/9/27 12:25
|
||||
* IotDB线程池
|
||||
*/
|
||||
@Component
|
||||
@Configuration
|
||||
public class IotDBSessionConfig {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(IotDBSessionConfig.class);
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Value("${spring.iotdb.username}")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@Value("${spring.iotdb.password}")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
@Value("${spring.iotdb.ip}")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
@Value("${spring.iotdb.port}")
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* 最大连接数
|
||||
*/
|
||||
@Value("${spring.iotdb.maxSize}")
|
||||
private Integer maxSize;
|
||||
|
||||
private static Session session;
|
||||
|
||||
/**
|
||||
* 获取session iotdb数据库初始化
|
||||
* @return
|
||||
*/
|
||||
public Session getSession(){
|
||||
|
||||
if (null == session){
|
||||
try {
|
||||
logger.info("正在连接iotdb......");
|
||||
session = new Session.Builder()
|
||||
.host(ip)
|
||||
.port(port)
|
||||
.username(username)
|
||||
.password(password)
|
||||
.version(Version.V_0_13)
|
||||
.build();
|
||||
|
||||
IotDBSessionConfig.session.open(false);
|
||||
session.setFetchSize(maxSize);
|
||||
//设置时区
|
||||
session.setTimeZone("+08:00");
|
||||
} catch (IoTDBConnectionException | StatementExecutionException e) {
|
||||
logger.error(String.valueOf(e.getCause()));
|
||||
}
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点路径
|
||||
* @param records
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<String> getDeviceIds(List<? extends IoTDBRecordable> records) throws Exception {
|
||||
List<String> deviceIds = new ArrayList<>();
|
||||
for (IoTDBRecordable record : records) {
|
||||
IoTDBRecord ioTDBRecord = record.toRecord();
|
||||
String deviceId = ioTDBRecord.getDeviceId();
|
||||
deviceIds.add(deviceId);
|
||||
}
|
||||
return deviceIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
* @param records
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<Long> getTimes(List<? extends IoTDBRecordable> records) throws Exception {
|
||||
List<Long> times = new ArrayList<>();
|
||||
for (IoTDBRecordable record : records) {
|
||||
long time = record.toRecord().getTime();
|
||||
times.add(time);
|
||||
}
|
||||
return times;
|
||||
}
|
||||
|
||||
/**
|
||||
* 物理量 即属性
|
||||
* @param records
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<List<String>> getMeasurementsList(List<? extends IoTDBRecordable> records) throws Exception {
|
||||
List<List<String>> measurementList = new ArrayList<>();
|
||||
for (IoTDBRecordable record : records) {
|
||||
List<String> iotDBRecord = record.toRecord().getMeasurementList();
|
||||
measurementList.add(iotDBRecord);
|
||||
}
|
||||
return measurementList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 属性 必须和属性值一一对应
|
||||
* @param records
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<List<Object>> getValueList(List<? extends IoTDBRecordable> records) throws Exception {
|
||||
List<List<Object>> valueList = new ArrayList<>();
|
||||
for (IoTDBRecordable record : records) {
|
||||
List<Object> iotDBRecord = record.toRecord().getValueList();
|
||||
valueList.add(iotDBRecord);
|
||||
}
|
||||
return valueList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据类型 八大基本数据类型
|
||||
* @param records
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<List<TSDataType>> getTypeList(List<? extends IoTDBRecordable> records) throws Exception {
|
||||
List<List<TSDataType>> typeList = new ArrayList<>();
|
||||
for (IoTDBRecordable record : records) {
|
||||
IoTDBRecord tdbRecord = record.toRecord();
|
||||
List<TSDataType> strList = new ArrayList<>();
|
||||
for (String str : tdbRecord.getTypeList()) {
|
||||
strList.add(TSDataType.valueOf(str));
|
||||
}
|
||||
typeList.add(strList);
|
||||
}
|
||||
return typeList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 实体类数据类型转换
|
||||
* @param type 属性类型
|
||||
* @return
|
||||
*/
|
||||
private TSDataType convertTypeByEntity(String type){
|
||||
switch (type){
|
||||
case "java.lang.Double":
|
||||
return TSDataType.DOUBLE;
|
||||
case "java.lang.Integer":
|
||||
return TSDataType.INT32;
|
||||
case "java.lang.Long":
|
||||
return TSDataType.INT64;
|
||||
case "java.lang.Boolean":
|
||||
return TSDataType.BOOLEAN;
|
||||
case "java.lang.Float":
|
||||
return TSDataType.FLOAT;
|
||||
default:
|
||||
return TSDataType.TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量插入
|
||||
* @param records 类集合
|
||||
*/
|
||||
public void insertRecords(List<? extends IoTDBRecordable> records){
|
||||
try {
|
||||
session.insertRecords(getDeviceIds(records),
|
||||
getTimes(records),getMeasurementsList(records),getTypeList(records),getValueList(records));
|
||||
} catch (Exception e) {
|
||||
logger.error("IotDB批量插入异常:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void insertRecord(IoTDBRecordable ioTDBRecordable){
|
||||
try {
|
||||
IoTDBRecord tdbRecord = ioTDBRecordable.toRecord();
|
||||
List<TSDataType> typeList = new ArrayList<>();
|
||||
for (String str : tdbRecord.getTypeList()) {
|
||||
typeList.add(TSDataType.valueOf(str));
|
||||
}
|
||||
session.insertRecord(tdbRecord.getDeviceId(), tdbRecord.getTime(), tdbRecord.getMeasurementList(), typeList, tdbRecord.getValueList());
|
||||
} catch (Exception e) {
|
||||
logger.error("IotDB插入异常:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据sql查询
|
||||
* @param sql sql语句
|
||||
* @return
|
||||
*/
|
||||
public SessionDataSet query(String sql) throws IoTDBConnectionException, StatementExecutionException {
|
||||
return session.executeQueryStatement(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分组
|
||||
* @param groupName
|
||||
* @throws IoTDBConnectionException
|
||||
* @throws StatementExecutionException
|
||||
*/
|
||||
public void deleteStorageGroup(String groupName) throws IoTDBConnectionException, StatementExecutionException {
|
||||
session.deleteStorageGroup(groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的时间序列数据
|
||||
*/
|
||||
public void deleteTimeSeries(String timeSeries) throws IoTDBConnectionException, StatementExecutionException {
|
||||
session.deleteTimeseries(timeSeries);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除时间序列数据
|
||||
* @param timeSeriesList
|
||||
*/
|
||||
public void batchDeleteTimeSeries(List<String> timeSeriesList) throws IoTDBConnectionException, StatementExecutionException {
|
||||
session.deleteTimeseries(timeSeriesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分组批量删除
|
||||
*/
|
||||
public void deleteStorageGroupList(List<String> storageGroupList) throws IoTDBConnectionException, StatementExecutionException {
|
||||
session.deleteStorageGroups(storageGroupList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定时间戳的数据
|
||||
* @param path
|
||||
* @param endTime
|
||||
*/
|
||||
public void deleteDataByPathAndEndTime(String path,Long endTime){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.muyu.carData.constract;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.constract
|
||||
* @Project:cloud-server-8
|
||||
* @name:IoTDBTableParam
|
||||
* @Date:2024/9/27 20:02
|
||||
*/
|
||||
public class IoTDBTableParam {
|
||||
|
||||
public static final String SYSLOG_IOT_TABLE = "student";
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.consumer
|
||||
* @Project:cloud-server-8
|
||||
* @name:MyKafkaConsumer
|
||||
* @Date:2024/9/26 15:42
|
||||
*/
|
||||
@Component
|
||||
public class MyKafkaConsumer {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.carData.controller;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.muyu.carData.config.cacheconfig.CaffeineConfig;
|
||||
import com.muyu.carData.pojo.Student;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:TestController
|
||||
* @Date:2024/9/26 23:56
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/testCache")
|
||||
@Log4j2
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
private CaffeineConfig caffeineConfig;
|
||||
|
||||
@RequestMapping("/caffeine")
|
||||
public String caffeine() throws InterruptedException {
|
||||
Cache<String, Student> stringCache = (Cache<String, Student>) caffeineConfig.caffeineCache();
|
||||
Student build = Student.builder().id(1)
|
||||
.name("小马")
|
||||
.sex("男")
|
||||
.expiryTime(20 * 60)
|
||||
.refreshTime(15 * 30)
|
||||
.build();
|
||||
stringCache.put("1", build);
|
||||
Thread.sleep(1000);
|
||||
//返回缓存的个数
|
||||
log.info(stringCache.estimatedSize());
|
||||
//返回缓存的数据
|
||||
log.info(stringCache.getIfPresent("1"));
|
||||
return "111";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.muyu.carData.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:IoTDBRecord
|
||||
* @Date:2024/9/27 19:25
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class IoTDBRecord {
|
||||
|
||||
/**
|
||||
* 节点路径
|
||||
*/
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private long time = System.currentTimeMillis();
|
||||
|
||||
/**
|
||||
* 属性
|
||||
*/
|
||||
private List<String> measurementList;
|
||||
|
||||
/**
|
||||
* 属性值
|
||||
*/
|
||||
private List<Object> valueList;
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private List<String> typeList;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.carData.interfaces;
|
||||
|
||||
import com.muyu.carData.annotation.IoTTableName;
|
||||
import com.muyu.carData.domain.IoTDBRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.interfaces
|
||||
* @Project:cloud-server-8
|
||||
* @name:IoTDBRecordable
|
||||
* @Date:2024/9/27 19:22
|
||||
* iot基类
|
||||
*/
|
||||
public interface IoTDBRecordable {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(IoTDBRecordable.class);
|
||||
|
||||
/**
|
||||
* 数据载入方法
|
||||
* @return Record
|
||||
*/
|
||||
default IoTDBRecord toRecord() throws Exception {
|
||||
IoTDBRecord ioTDBRecord = new IoTDBRecord();
|
||||
Object getIoTDBTime = this.getClass().getMethod("getIoTDBTime").invoke(this);
|
||||
if (null != getIoTDBTime){
|
||||
ioTDBRecord.setTime((Long) getIoTDBTime);
|
||||
}
|
||||
Class aClass = this.getClass();
|
||||
IoTTableName name = this.getClass().getAnnotation(IoTTableName.class);
|
||||
ioTDBRecord.setDeviceId(name.value());
|
||||
Field[] declaredFields = aClass.getDeclaredFields();
|
||||
ArrayList<String> measurements = new ArrayList<>();
|
||||
ArrayList<Object> records = new ArrayList<>();
|
||||
ArrayList<String> types = new ArrayList<>();
|
||||
for (Field declaredField : declaredFields) {
|
||||
measurements.add(declaredField.getName());
|
||||
String methodNamePro = declaredField.getName().substring(0, 1).toUpperCase() + declaredField.getName().substring(1);
|
||||
Method methodName = this.getClass().getMethod("get" + methodNamePro);
|
||||
records.add(methodName.invoke(this));
|
||||
types.add(methodName.getReturnType().getName());
|
||||
}
|
||||
ioTDBRecord.setMeasurementList(measurements);
|
||||
ioTDBRecord.setValueList(records);
|
||||
ioTDBRecord.setTypeList(types);
|
||||
return ioTDBRecord;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.muyu.carData.pojo;
|
||||
|
||||
import com.muyu.carData.annotation.IoTTableName;
|
||||
import com.muyu.carData.config.cacheconfig.ExpiryTime;
|
||||
import com.muyu.carData.constract.IoTDBTableParam;
|
||||
import com.muyu.carData.interfaces.IoTDBRecordable;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.pojo
|
||||
* @Project:cloud-server-8
|
||||
* @name:Student
|
||||
* @Date:2024/9/27 0:40
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@IoTTableName(value = IoTDBTableParam.SYSLOG_IOT_TABLE)
|
||||
public class Student extends ExpiryTime implements IoTDBRecordable {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 插入时间
|
||||
*/
|
||||
private long time = System.currentTimeMillis();
|
||||
}
|
|
@ -80,6 +80,7 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<module>cloud-modules-system</module>
|
||||
<module>cloud-modules-gen</module>
|
||||
<module>cloud-modules-file</module>
|
||||
<module>cloud-modules-carData</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-modules</artifactId>
|
||||
|
|
Loading…
Reference in New Issue