Compare commits

...

1 Commits

Author SHA1 Message Date
andy
5837c43ade 时序数据库, 暂定 2025-04-28 15:57:36 +08:00
15 changed files with 352 additions and 6 deletions

View File

@ -2,6 +2,7 @@
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
@ -9,6 +10,7 @@
<module name="common-mybatis" />
<module name="authorization-server" />
<module name="resource-server" />
<module name="common-permission" />
<module name="gateway-server" />
<module name="admin-server" />
<module name="common-web" />
@ -16,6 +18,7 @@
<module name="cloud-manage-server" />
<module name="common-redis" />
<module name="common-core" />
<module name="common-influxdb" />
</profile>
</annotationProcessing>
</component>
@ -25,7 +28,9 @@
<module name="authorization-server" options="-parameters" />
<module name="cloud-manage-server" options="-parameters" />
<module name="common-core" options="-parameters" />
<module name="common-influxdb" options="-parameters" />
<module name="common-mybatis" options="-parameters" />
<module name="common-permission" options="-parameters" />
<module name="common-redis" options="-parameters" />
<module name="common-web" options="-parameters" />
<module name="gateway-server" options="-parameters" />

View File

@ -4,7 +4,9 @@
<file url="file://$PROJECT_DIR$/admin-server/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/authorization-server/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/base-commons/common-core/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/base-commons/common-influxdb/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/base-commons/common-mybatis/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/base-commons/common-permission/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/base-commons/common-redis/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/base-commons/common-web/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/base-commons/src/main/java" charset="UTF-8" />

View File

@ -8,8 +8,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import jakarta.validation.constraints.Min;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -32,6 +30,7 @@ public class BaseEntity implements Serializable {
@Hidden
private Integer pkId;
@Schema(description = "创建人", hidden = true)
@TableField(fill = FieldFill.INSERT)
private String creater;

View File

@ -0,0 +1,41 @@
<?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.evotech.hd</groupId>
<artifactId>base-commons</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>common-influxdb</artifactId>
<dependencies>
<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>6.6.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.influxdb</groupId>-->
<!-- <artifactId>influxdb-java</artifactId>-->
<!-- <version>2.21</version> &lt;!&ndash; 请检查最新版本 &ndash;&gt;-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,90 @@
package com.evotech.hd.influxdb.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
*
*
* @ClassName:InfluxdbPropertys
* @date: 2025年04月26日 13:30
* @author: andy.shi
* @contact: 17330188597
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
*/
@Data
@Component
@ConfigurationProperties(prefix = "influxdb", ignoreUnknownFields = true)
public class InfluxdbProperty {
static String url;
static String name;
static String password;
static String token;
static String org;
static String bucket;
static Boolean gzip;
public static String getUrl() {
return url;
}
public void setUrl(String url) {
InfluxdbProperty.url = url;
}
public static String getName() {
return name;
}
public void setName(String name) {
InfluxdbProperty.name = name;
}
public static String getPassword() {
return password;
}
public void setPassword(String password) {
InfluxdbProperty.password = password;
}
public static String getToken() {
return token;
}
public void setToken(String token) {
InfluxdbProperty.token = token;
}
public static String getBucket() {
return bucket;
}
public void setBucket(String bucket) {
InfluxdbProperty.bucket = bucket;
}
public static Boolean getGzip() {
return gzip;
}
public void setGzip(Boolean gzip) {
InfluxdbProperty.gzip = gzip;
}
public static String getOrg() {
return org;
}
public void setOrg(String org) {
InfluxdbProperty.org = org;
}
}

View File

@ -0,0 +1,42 @@
package com.evotech.hd.influxdb.config;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.InfluxQLQueryApi;
import com.influxdb.client.WriteApi;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* influxdb的bean
*
* @ClassName:MyInfluxDBConfiguration
* @date: 2025年04月26日 14:26
* @author: andy.shi
* @contact: 17330188597
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
*/
@Configuration
@EnableConfigurationProperties
public class MyInfluxDBConfiguration {
@Bean
public InfluxDBClient influxDBClient(){
InfluxDBClient client = InfluxDBClientFactory.create(InfluxdbProperty.getUrl(), InfluxdbProperty.getToken().toCharArray());
if(InfluxdbProperty.getGzip()){
client.enableGzip();
}
return client;
}
@Bean
public WriteApi writeApiBlocking(final InfluxDBClient influxDBClient){
return influxDBClient.getWriteApi();
}
@Bean
public InfluxQLQueryApi influxQLQueryApi(final InfluxDBClient influxDBClient){
return influxDBClient.getInfluxQLQueryApi();
}
}

View File

@ -0,0 +1,38 @@
//package com.evotech.hd.influxdb.service;
//
//import com.evotech.hd.influxdb.config.InfluxdbProperty;
//import com.influxdb.client.InfluxDBClient;
//import com.influxdb.client.InfluxDBClientFactory;
//import com.influxdb.client.WriteApiBlocking;
//import org.springframework.beans.factory.DisposableBean;
//import org.springframework.stereotype.Service;
///**
// * influxdb 数据库链接类
// *
// * @ClassName:InfluxDbService
// * @date: 2025年04月26日 13:21
// * @author: andy.shi
// * @contact: 17330188597
// * @remark: 开发人员联系方式 1042025947@qq.com/微信同步
// */
//@Service
//public class InfluxDbService implements DisposableBean {
// /***
// * 单例 饿汉式线程安全)
// * 简单天生线程安全实例在类加载时就完成了初始化
// */
// private static InfluxDBClient client = InfluxDBClientFactory.create(InfluxdbProperty.getUrl(), InfluxdbProperty.getName(),InfluxdbProperty.getPassword().toCharArray());
//
//
// public static void write(){
// WriteApiBlocking writeApi = client.getWriteApiBlocking();
// writeApi.writePoint("","",com.influxdb.client.write.Point.measurement(""));
// }
//
// @Override
// public void destroy() throws Exception {
// if(client != null){
// client.close();
// }
// }
//}

View File

@ -0,0 +1,48 @@
package com.evotech.hd.influxdb.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
*
*
* @ClassName:BeanUtil
* @date: 2025年04月26日 14:41
* @author: andy.shi
* @contact: 17330188597
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
*/
@Component
public class BeanUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
setGlobalApplicationContext(applicationContext);
}
private synchronized static void setGlobalApplicationContext(ApplicationContext applicationContext) {
if(BeanUtil.applicationContext == null){
BeanUtil.applicationContext = applicationContext;
}
}
private static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static Object getBean(String name) {
return getApplicationContext().getBean(name);
}
public static <T> T getBean(Class<T> clazz) {
T b = null;
try {
b=getApplicationContext().getBean(clazz);
} catch (BeansException e) {
}
return b;
}
}

View File

@ -0,0 +1,63 @@
package com.evotech.hd.influxdb.util;
import com.evotech.hd.influxdb.config.InfluxdbProperty;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApi;
import com.influxdb.client.domain.WritePrecision;
import org.springframework.util.CollectionUtils;
import java.util.Iterator;
import java.util.Map;
/**
* 数据数据库的工具类
* @ClassName:InfluxDBUtils
* @date: 2025年04月26日 14:36
* @author: andy.shi
* @contact: 17330188597
* @remark: 开发人员联系方式 1042025947@qq.com/微信同步
*/
public class InfluxDBUtils {
public static int insert(String tableName, Map<String, String> tags, Map<String, Object> values){
WriteApi writeApi = BeanUtil.getBean(WriteApi.class);
InfluxDBClient client = InfluxDBClientFactory.create(InfluxdbProperty.getUrl(), InfluxdbProperty.getToken().toCharArray());
com.influxdb.client.write.Point point = com.influxdb.client.write.Point.measurement(tableName)
.time(System.currentTimeMillis(), WritePrecision.NS);
if(!CollectionUtils.isEmpty(tags)){
Iterator<String> iterator = tags.keySet().iterator();
while (iterator.hasNext()){
String key = iterator.next();
point = point.addTag(key, tags.get(key));
}
}
if(!CollectionUtils.isEmpty(values)){
// point = point.addFields(values);
Iterator<String> iterator = values.keySet().iterator();
while (iterator.hasNext()){
String key = iterator.next();
Object value = values.get(key);
if (value instanceof Boolean) {
point = point.addField(key, (Boolean)value);
} else if (value instanceof Long) {
point = point.addField(key, (Long)value);
} else if (value instanceof Double) {
point = point.addField(key, (Double)value);
} else if (value instanceof String) {
point = point.addField(key, (String)value);
}
}
}
client.getWriteApiBlocking().writePoint(InfluxdbProperty.getBucket(),InfluxdbProperty.getOrg(),point);
writeApi.flush();
return 1;
}
}

View File

@ -31,6 +31,11 @@
<artifactId>common-permission</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.evotech.hd</groupId>
<artifactId>common-influxdb</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- openfein -->
<dependency>
<groupId>org.springframework.cloud</groupId>
@ -90,7 +95,8 @@
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
</dependencies>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>

View File

@ -16,6 +16,7 @@ import com.evotech.hd.common.core.entity.cloud.BatteryStation;
import com.evotech.hd.common.core.entity.cloud.OrderSwapBattery;
import com.evotech.hd.common.core.entity.cloud.OrderSwapBatteryPre;
import com.evotech.hd.common.core.utils.Collections;
import com.evotech.hd.influxdb.util.InfluxDBUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
@ -42,6 +43,15 @@ public class TestController {
@Resource
private SwapOrderBasicFeeComponent orderBasicFeeComponent;
@GetMapping("/influxdb")
public Result influxdb() {
InfluxDBUtils.insert("test", Collections.asMap("t","test"), Collections.asMap("name","张三","age",12,"sax",""));
return new Result().success("1");
}
@GetMapping("/station")
public Result list() {
System.out.println("======>>开始......");

View File

@ -12,14 +12,13 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;
@Component
//@Component
@Order(value = 20)
@Slf4j
public class MqttConnectInit implements ApplicationRunner {

View File

@ -23,6 +23,7 @@ spring:
- nacos:yt-common.properties?refreshEnabled=true
- nacos:cloud-server.yaml?refreshEnabled=true
- nacos:yt-redis.yaml?refreshEnabled=true
- nacos:yt-influxdb.yml?refreshEnabled=true
cloud:
nacos:
serverAddr: 192.168.5.213:8848

View File

@ -6,6 +6,7 @@ public class AesDecryTest {
public static void main(String[] args) {
// HttpUtils
System.out.println(new BCryptPasswordEncoder().encode("123456"));
// String key = "94kl35k25d3t2rk2";
// String iv = "k394kf44lf1pyq8k";

View File

@ -164,5 +164,6 @@
<module>resource-server</module>
<module>wechat-server</module>
<module>admin-server</module>
</modules>
<module>base-commons/common-influxdb</module>
</modules>
</project>