caixiang 2 anos atrás
pai
commit
e5def9fb33
28 arquivos alterados com 1404 adições e 2 exclusões
  1. +17
    -0
      pom.xml
  2. +1
    -0
      ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java
  3. +20
    -0
      ym-gateway/pom.xml
  4. +16
    -0
      ym-gateway/src/main/java/com/cnbm/config/SwaggerConfig.java
  5. +15
    -1
      ym-gateway/src/main/resources/application-dev.yml
  6. +2
    -1
      ym-gateway/src/main/resources/application.yml
  7. +76
    -0
      ym-influx/pom.xml
  8. +54
    -0
      ym-influx/src/main/java/Main2.java
  9. +214
    -0
      ym-influx/src/main/java/com/cnbm/influx/Main.java
  10. +69
    -0
      ym-influx/src/main/java/com/cnbm/influx/common/Utils.java
  11. +133
    -0
      ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java
  12. +23
    -0
      ym-influx/src/main/java/com/cnbm/influx/constant/Constant.java
  13. +78
    -0
      ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java
  14. +30
    -0
      ym-influx/src/main/java/com/cnbm/influx/entity/Header.java
  15. +55
    -0
      ym-influx/src/main/java/com/cnbm/influx/health/InfluxDB2HealthIndicator.java
  16. +58
    -0
      ym-influx/src/main/java/com/cnbm/influx/health/InfluxDB2HealthIndicatorAutoConfiguration.java
  17. +71
    -0
      ym-influx/src/main/java/com/cnbm/influx/influx/AbstractInfluxDB2AutoConfiguration.java
  18. +60
    -0
      ym-influx/src/main/java/com/cnbm/influx/influx/InfluxDB2AutoConfiguration.java
  19. +37
    -0
      ym-influx/src/main/java/com/cnbm/influx/influx/InfluxDB2OkHttpClientBuilderProvider.java
  20. +178
    -0
      ym-influx/src/main/java/com/cnbm/influx/influx/InfluxDB2Properties.java
  21. +24
    -0
      ym-influx/src/main/java/com/cnbm/influx/param/BaseParam.java
  22. +24
    -0
      ym-influx/src/main/java/com/cnbm/influx/param/PageInfo.java
  23. +31
    -0
      ym-influx/src/main/java/com/cnbm/influx/param/QueryDataParam.java
  24. +30
    -0
      ym-influx/src/main/java/com/cnbm/influx/param/Range.java
  25. +19
    -0
      ym-influx/src/main/java/com/cnbm/influx/param/Tag.java
  26. +24
    -0
      ym-influx/src/main/java/com/cnbm/influx/template/Event.java
  27. +28
    -0
      ym-influx/src/main/java/com/cnbm/influx/template/Temperature.java
  28. +17
    -0
      ym-influx/src/main/resources/application-influx.yml

+ 17
- 0
pom.xml Ver arquivo

@@ -14,6 +14,7 @@
<module>ym-gateway</module>
<module>ym-baisc</module>
<module>ym-schedule-task</module>
<module>ym-influx</module>
</modules>
<packaging>pom</packaging>

@@ -89,6 +90,22 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<!-- influx start-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- influx end-->

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>


+ 1
- 0
ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java Ver arquivo

@@ -72,6 +72,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/swagger-ui/**",
"/webjars/**",
"/websocket/**",
"/influx/**",
"/captcha").anonymous()
// .antMatchers("/testCors").hasAuthority("system:dept:list222")
// 除上面外的所有请求全部需要鉴权认证


+ 20
- 0
ym-gateway/pom.xml Ver arquivo

@@ -32,6 +32,26 @@
<artifactId>ym-baisc</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cnbm</groupId>
<artifactId>ym-influx</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-actuator-autoconfigure</artifactId>-->
<!-- <version>2.7.0</version>-->
<!-- <optional>true</optional>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<!-- <artifactId>jackson-databind</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->



<dependency>
<groupId>com.cnbm</groupId>
<artifactId>ym-schedule-task</artifactId>


+ 16
- 0
ym-gateway/src/main/java/com/cnbm/config/SwaggerConfig.java Ver arquivo

@@ -86,6 +86,22 @@ public class SwaggerConfig {
.securitySchemes(Arrays.asList(new ApiKey("token", "token", "header")));
}

@Bean
public Docket influxApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("ym-influx")
.apiInfo(apiInfos("influx", "influx模块"))
.useDefaultResponseMessages(true)
.forCodeGeneration(false)
.select()
.apis(RequestHandlerSelectors.basePackage("com.cnbm.influx"))
.paths(PathSelectors.any())
.build()
.securityContexts(Arrays.asList(securityContext()))
// ApiKey的name需与SecurityReference的reference保持一致
.securitySchemes(Arrays.asList(new ApiKey("token", "token", "header")));
}

/**
* 创建该API的基本信息(这些基本信息会展现在文档页面中)
* 访问地址:http://ip:port/swagger-ui.html


+ 15
- 1
ym-gateway/src/main/resources/application-dev.yml Ver arquivo

@@ -37,4 +37,18 @@ spring:
# driver-class-name: org.postgresql.Driver
# url: jdbc:postgresql://123456:5432/renren_security
# username: postgres
# password: 123456
# password: 123456

influx:
url: http://192.168.0.170:8086 # URL to connect to InfluxDB.
username: caixiang # Username to use in the basic auth.
password: 251128856 # Password to use in the basic auth.
token: lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw== # Token to use for the authorization.
org: qgs # Default destination organization for writes and queries.
bucket: qgs-bucket # Default destination bucket for writes.
logLevel: BODY # The log level for logging the HTTP request and HTTP response. (Default: NONE)
readTimeout: 5s # Read timeout for OkHttpClient. (Default: 10s)
writeTimeout: 5s # Write timeout for OkHttpClient. (Default: 10s)
connectTimeout: 5s # Connection timeout for OkHttpClient. (Default: 10s)

# management.health.influx.enabled=true # Whether to enable InfluxDB 2.x health check.

+ 2
- 1
ym-gateway/src/main/resources/application.yml Ver arquivo

@@ -73,4 +73,5 @@ mybatis-plus:

logging:
level:
com.cnbm.admin.dao: DEBUG
com.cnbm.admin.dao: DEBUG


+ 76
- 0
ym-influx/pom.xml Ver arquivo

@@ -0,0 +1,76 @@
<?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">
<parent>
<artifactId>ym-pass</artifactId>
<groupId>com.cnbm</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ym-influx</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>

<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>6.3.0</version>
</dependency>


<!--- begin -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>org.hibernate.validator</groupId>-->
<!-- <artifactId>hibernate-validator</artifactId>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>com.squareup.okhttp3</groupId>-->
<!-- <artifactId>okhttp</artifactId>-->
<!-- <version>4.9.3</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.mockito</groupId>-->
<!-- <artifactId>mockito-core</artifactId>-->
<!-- <version>4.4.0</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->



<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-actuator-autoconfigure</artifactId>-->
<!-- <version>2.7.0</version>-->
<!-- <optional>true</optional>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<!-- <artifactId>jackson-databind</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->


<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-configuration-processor</artifactId>-->
<!-- <version>2.7.0</version>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->
<!--- end -->
</dependencies>
</project>

+ 54
- 0
ym-influx/src/main/java/Main2.java Ver arquivo

@@ -0,0 +1,54 @@
import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.template.Event;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApi;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/7/1 16:39
*/
public class Main2 {
public static void main(String[] args) {
//方式1
Point point = Point.measurement("ASProcessCompleteEvent")
.addTag("transationId", "112311")
.addTag("argName", "argName11")
.addField("argValue", 3D)
.time(Instant.now().toEpochMilli(), WritePrecision.MS);
InfluxClient.Client.getWriteApi().writePoint(point);


// //方式2
// char[] token = "lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==".toCharArray();
// String org = "qgs";
// String bucket = "mytest";
// InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://192.168.0.170:8086", token, org, bucket);
// WriteApi writeApi = influxDBClient.makeWriteApi();
// Point point = Point.measurement("ASProcessCompleteEvent")
// .addTag("transationId", "112311")
// .addTag("argName", "argName11")
// .addField("argValue", 7D)
// .time(Instant.now().toEpochMilli(), WritePrecision.MS);
//
//
// Point point2 = Point.measurement("ASProcessCompleteEvent")
// .addTag("transationId", "222312")
// .addTag("argName", "argName11")
// .addField("argValue", 8D)
// .time(Instant.now().toEpochMilli(), WritePrecision.MS);
// List<Point> list = new ArrayList<>();
// list.add(point);
// list.add(point2);
// writeApi.writePoints(list);
// //一定要close ,不如write 不了数据
// influxDBClient.close();
}
}

+ 214
- 0
ym-influx/src/main/java/com/cnbm/influx/Main.java Ver arquivo

@@ -0,0 +1,214 @@
package com.cnbm.influx;

import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.common.Utils;
import com.cnbm.influx.param.PageInfo;
import com.cnbm.influx.param.Range;
import com.cnbm.influx.param.Tag;

import com.cnbm.influx.template.Event;
import com.influxdb.client.*;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import com.influxdb.query.FluxRecord;
import com.influxdb.query.FluxTable;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/25 11:19
*/
public class Main {
public static void main(String[] args) throws InterruptedException {
char[] token = "lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==".toCharArray();
String org = "qgs";
String bucket = "mytest";
InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://192.168.0.170:8086", token, org, bucket);


WriteApi writeApi = influxDBClient.makeWriteApi();

// InfluxService influxService = new InfluxService();
// Event event = new Event();
// event.time = Instant.now();
// event.transationId = "asas";
// event.argName = "arg5";
// event.argValue = new Double(11);
// influxService.insert(event);

// Event event = new Event();
// event.setTime(Instant.now());
// event.setTransationId("asasd11");
// event.setArgName("argName11");
// event.setArgValue(3d);
// InfluxClient.Client.insert(event,"ASProcessCompleteEvent");


Point point = Point.measurement("ASProcessCompleteEvent")
.addTag("transationId", "112311")
.addTag("argName", "argName11")
.addField("argValue", 3D)
.time(Instant.now().toEpochMilli(), WritePrecision.MS);


Point point2 = Point.measurement("ASProcessCompleteEvent")
.addTag("transationId", "222312")
.addTag("argName", "argName11")
.addField("argValue", 4D)
.time(Instant.now().toEpochMilli(), WritePrecision.MS);
List<Point> list = new ArrayList<>();
list.add(point);
list.add(point2);

writeApi.writePoints(list);

//todo api.writeMeasurements(WritePrecision.NS, Arrays.asList(new H2OFeetMeasurement("coyote_creek", 15.0D, null, Instant.ofEpochSecond(0, 15)), new H2OFeetMeasurement("coyote_creek", 16.0D, null, Instant.ofEpochSecond(0, 16))));
// List<Event> events = new ArrayList<>();
// for(int i=0;i<99;i++){
//
// Event event = new Event();
// event.time = Instant.now();
// event.transationId = "asas"+i;
// event.argName = "arg7";
// event.argValue = new Double(i);
// events.add(event);
// }
// List<Event> qList = new ArrayList<>();
// Event event = new Event();
// event.time = Instant.now();
// event.transationId = "asas";
// event.argName = "arg7";
// event.argValue = new Double(1);
// Thread.sleep(100);
// Event event2 = new Event();
// event2.time = Instant.now();
// event2.transationId = "asas";
// event2.argName = "arg7";
// event2.argValue = new Double(2);
// qList.add(event);
// qList.add(event2);
// writeApi.writeMeasurement( WritePrecision.NS, qList);

// for(int i=0;i<10;i++){
// Temperature temperature = new Temperature();
// temperature.location = "south";
// temperature.value = new Double(i);
// temperature.type = "equipment3";
// temperature.time = Instant.now();
//
// writeApi.writeMeasurement( WritePrecision.NS, temperature);
// }


// String flux = "from(bucket:\"mytest\") |> range(start: -60m)";
// flux += "|> filter(fn: (r) =>\n" +
// " r._measurement == \"ASProcessCompleteEvent\" and \n" +
//// " r._field == \"type\" and \n" + //对应 Field key
// " r.argName == \"arg3\"\n" + //对应 Tags key (Tag 信息无法在FluxRecord 里面获取。)
// " )";
// QueryApi queryApi = influxDBClient.getQueryApi();
//
// List<FluxTable> tables = queryApi.query(flux);
// for (FluxTable fluxTable : tables) {
// List<FluxRecord> records = fluxTable.getRecords();
// for (FluxRecord fluxRecord : records) {
// System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement());
//// System.out.println("time: "+fluxRecord.getTime() +" key:"++" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement());
//
// }
// }


// from(bucket: "mytest")
// |> range(start: 2022-06-29T11:30:00Z, stop: 2022-06-29T12:30:00Z)
// |> filter(fn: (r) => r["_measurement"] == "ASProcessCompleteEvent")
// |> filter(fn: (r) => r["argName"] == "arg4")
// |> drop(columns: ["transationId"])
// |> sort(columns: ["_time"], desc: true)
// 取前10条数据
// |> limit(n: 10, offset: 0)

// 取 10-20 条数据
// |> limit(n: 10, offset: 10)

// 取 20-30 条数据
// |> limit(n: 10, offset: 20)



// QueryDataParam queryDataParam = new QueryDataParam();
// queryDataParam.setBucket("mytest");
// queryDataParam.setRange(new Range(getDate().toInstant(),new Date().toInstant()));
// queryDataParam.setMeasurement("ASProcessCompleteEvent");
// queryDataParam.setTag(new Tag("argName","arg4"));
// queryDataParam.setDropedTagName("transationId");
// queryDataParam.setPageInfo(new PageInfo(1,100));
//
// List<FluxTable> tables = query(queryDataParam,influxDBClient);
// List<FluxRecord> records1 = tables.get(0).getRecords();
// List<List<FluxRecord>> lists = Utils.fixedGroup(records1, 10);

// for (FluxTable fluxTable : tables) {
// List<FluxRecord> records = fluxTable.getRecords();
// for (FluxRecord fluxRecord : records) {
// System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement());
//
// }
// }

influxDBClient.close();
}


public static Date getDate(){
Date date = new Date();//获取当前日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");//格式化一下
Calendar calendar1 = Calendar.getInstance();//获取对日期操作的类对象
//两种写法都可以获取到前三天的日期
// calendar1.set(Calendar.DAY_OF_YEAR,calendar1.get(Calendar.DAY_OF_YEAR) -3);
//在当前时间的基础上获取前三天的日期
calendar1.add(Calendar.DATE, -3);
//add方法 参数也可传入 月份,获取的是前几月或后几月的日期
//calendar1.add(Calendar.MONTH, -3);
Date day = calendar1.getTime();
return day;
}

private static List<FluxTable> query(QueryDataParam param,InfluxDBClient influxDBClient){
String measurement = param.getMeasurement();
String dropedTagName = param.getDropedTagName();
Range range = param.getRange();
String bucket = param.getBucket();
String tagName = param.getTag().getTagName();
String tagValue = param.getTag().getTagValue();
PageInfo pageInfo = param.getPageInfo();

String flux = "from(bucket:\""+bucket+"\")";
flux += "|> range(start: "+range.getBegin().toString()+",stop:"+range.getEnd().toString()+") \n";
flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\") \n";
flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\") \n";
flux += "|> drop(columns: [\""+dropedTagName+"\"]) \n";
flux += "|> sort(columns: [\"_time\"], desc: true) \n";
if(pageInfo!=null){
flux += "|> limit(n: "+pageInfo.getSize()+", offset: "+(pageInfo.getCurrent()-1)* pageInfo.getSize()+")";
}

QueryApi queryApi = influxDBClient.getQueryApi();

List<FluxTable> tables = queryApi.query(flux);
for (FluxTable fluxTable : tables) {
List<FluxRecord> records = fluxTable.getRecords();
for (FluxRecord fluxRecord : records) {
System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement());

}
}

return tables;
}
}

+ 69
- 0
ym-influx/src/main/java/com/cnbm/influx/common/Utils.java Ver arquivo

@@ -0,0 +1,69 @@
package com.cnbm.influx.common;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/29 16:23
*/
public class Utils {
public static void main(String[] args) {
ArrayList<Integer> arrs = new ArrayList<>();

for(int i=0;i<100;i++){
arrs.add(i);
}
List<List<Integer>> lists = fixedGroup(arrs, 10);
System.out.println();

}


public static Date getBeforeDate(Integer number){
Date date = new Date();//获取当前日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");//格式化一下
Calendar calendar1 = Calendar.getInstance();//获取对日期操作的类对象
//两种写法都可以获取到前三天的日期
// calendar1.set(Calendar.DAY_OF_YEAR,calendar1.get(Calendar.DAY_OF_YEAR) -3);
//在当前时间的基础上获取前三天的日期
calendar1.add(Calendar.DATE, 0-number);
//add方法 参数也可传入 月份,获取的是前几月或后几月的日期
//calendar1.add(Calendar.MONTH, -3);
Date day = calendar1.getTime();
return day;
}

/**
* 将一组数据固定分组,每组n个元素
*
* @param source 要分组的数据源
* @param limit 每组n个元素
* @param <T>
* @return
*/
public static <T> List<List<T>> fixedGroup(List<T> source, int limit) {
if (null == source || source.size() == 0 || limit <= 0)
return null;
List<List<T>> result = new ArrayList<List<T>>();
int remainder = source.size() % limit;
int size = (source.size() / limit);
for (int i = 0; i < size; i++) {
List<T> subset = null;
subset = source.subList(i * limit, (i + 1) * limit);
result.add(subset);
}
if (remainder > 0) {
List<T> subset = null;
subset = source.subList(size * limit, size * limit + remainder);
result.add(subset);
}
return result;
}


}

+ 133
- 0
ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java Ver arquivo

@@ -0,0 +1,133 @@
package com.cnbm.influx.config;

import com.cnbm.influx.constant.Constant;
import com.cnbm.influx.param.PageInfo;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.param.Range;
import com.cnbm.influx.template.Event;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.QueryApi;
import com.influxdb.client.WriteApi;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import com.influxdb.query.FluxTable;

import java.util.ArrayList;
import java.util.List;

public enum InfluxClient {

/**
* influxdb 读写客户端,,如果write比较繁忙,后续可以考虑,维护 client一个线程池。
* */
Client("http://192.168.0.170:8086","lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==","qgs","qgs-bucket"),

;
private String url;
private String token;
private String org;
private String bucket;

private InfluxDBClient influxDBClient;
private WriteApi writeApi;

private QueryApi queryApi;

InfluxClient(String url,String token,String org,String bucket){
this.url = url;
this.token = token;
this.org = org;
this.bucket = bucket;
this.influxDBClient = InfluxDBClientFactory.create(this.url, this.token.toCharArray(),this.org,this.bucket);
this.writeApi = influxDBClient.makeWriteApi();
this.queryApi = influxDBClient.getQueryApi();
}


public QueryApi getQueryApi() {
return queryApi;
}

public WriteApi getWriteApi() {
return writeApi;
}

/**
* 测试连接是否正常
*
* @return
* true 服务正常健康
* false 异常
*/
private boolean ping() {
boolean isConnected = false;
Boolean pong;
try {
pong = influxDBClient.ping();
if (pong != null) {
isConnected = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return isConnected;
}

public void insert(Event event, String measurement){
Point point = Point.measurement(measurement)
.addTag("transationId", event.getTransationId())
.addTag("argName", event.getArgName())
.addField("argValue", event.getArgValue())
.time(event.getTime().toEpochMilli(), WritePrecision.MS);
writeApi.writePoint(point);

}

//异步 批量写入数据
//如果要批量插入的话,一次也只能写入
public void batchInsert(List<Event> events, String measurement){
List<Point> list = new ArrayList<>();
for(Event event:events){
Point point = Point.measurement(measurement)
.addTag("transationId", event.getTransationId())
.addTag("argName", event.getArgName())
.addField("argValue", event.getArgValue())
.time(event.getTime().toEpochMilli(), WritePrecision.MS);
list.add(point);
}
writeApi.writePoints(list);
}


public List<FluxTable> query(QueryDataParam param){
String measurement = param.getMeasurement();
String dropedTagName = param.getDropedTagName();
Range range = param.getRange();
String bucket = param.getBucket();
String tagName = param.getTag().getTagName();
String tagValue = param.getTag().getTagValue();
PageInfo pageInfo = param.getPageInfo();

String flux = "from(bucket:\""+bucket+"\")";
flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")";
flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\")";
flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\")";
flux += "|> drop(columns: [\""+dropedTagName+"\"])";
flux += "|> sort(columns: [\"_time\"], desc: true)";
if(pageInfo!=null){
flux += "|> limit(n: "+pageInfo.getSize()+", offset: "+(pageInfo.getCurrent()-1)* pageInfo.getSize()+")";
}


// List<FluxTable> tables = queryApi.query(flux);
// for (FluxTable fluxTable : tables) {
// List<FluxRecord> records = fluxTable.getRecords();
// for (FluxRecord fluxRecord : records) {
// System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement());
//
// }
// }
return queryApi.query(flux);
}
}

+ 23
- 0
ym-influx/src/main/java/com/cnbm/influx/constant/Constant.java Ver arquivo

@@ -0,0 +1,23 @@
package com.cnbm.influx.constant;

import com.influxdb.LogLevel;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/7/1 9:18
*/
public class Constant {
public static final String url = "http://192.168.0.170:8086";
public static final String token = "lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==";
public static final String org = "qgs";
public static final String bucket = "qgs-bucket";
public static final String username = "caixiang";
public static final String password = "25112856";
public static final LogLevel logLevel = LogLevel.BODY;
public static final LogLevel readTimeout = LogLevel.BODY;
public static final LogLevel writeTimeout = LogLevel.BODY;
public static final LogLevel connectTimeout = LogLevel.BODY;


}

+ 78
- 0
ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java Ver arquivo

@@ -0,0 +1,78 @@
package com.cnbm.influx.controller;

import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.template.Event;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;

@RestController
@RequestMapping("/influx")
public class S7DemoController {
private static final Logger logger = LoggerFactory.getLogger(S7DemoController.class);

@Autowired
InfluxDBClient influxDBClient;


// try (WriteApi writeApi = influxDBClient.makeWriteApi()) {
// Temperature temperature = new Temperature();
// temperature.setLocation("east");
// temperature.setValue(106.2D);
// temperature.setTime(Instant.now());
// writeApi.writeMeasurement(WritePrecision.NS,temperature);
// }
//
// try (WriteApi writeApi = influxDBClient.makeWriteApi()) {
// Point point = Point.measurement("temperature")
// .addTag("location","south")
// .addTag("owner","wxm")
// .addField("wxm",230.8);
// writeApi.writePoint(point);
// }


@PostMapping("/insertBatch")
public void insertBatch() throws InterruptedException {
// List<Event> list = new ArrayList<>();
//
// for(int i=0;i<99;i++){
// //Thread.sleep(1000);
// Event event = new Event();
// event.time = Instant.now();
// event.transationId = "asas"+i;
// event.argName = "arg5";
// event.argValue = new Double(i);
// list.add(event);
// }
// influxService.batchInsert(list);
}


public Point insert(Event event, String measurement){
Point point = Point.measurement(measurement)
.addTag("transationId", event.getTransationId())
.addTag("argName", event.getArgName())
.addField("argValue", event.getArgValue())
.time(event.getTime().toEpochMilli(), WritePrecision.MS);
return point;

}
@PostMapping("/insert")
public void insert() throws InterruptedException {
Event event = new Event();
event.setTime(Instant.now());
event.setTransationId("asasd11");
event.setArgName("argName11");
event.setArgValue(7d);
Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent");
influxDBClient.makeWriteApi().writePoint(asProcessCompleteEvent);
}
}

+ 30
- 0
ym-influx/src/main/java/com/cnbm/influx/entity/Header.java Ver arquivo

@@ -0,0 +1,30 @@
package com.cnbm.influx.entity;

import lombok.Data;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/27 10:46
*/
@Data
public class Header {

private String transationId;

private String messageName;

private String messageType;

private String fromWhere;

private String toWhere;

private String equipmentId;

private String sendTimestamp;

private String argName;

private Double argValue;
}

+ 55
- 0
ym-influx/src/main/java/com/cnbm/influx/health/InfluxDB2HealthIndicator.java Ver arquivo

@@ -0,0 +1,55 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cnbm.influx.health;

import com.influxdb.client.InfluxDBClient;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.util.Assert;

/**
* {@link //HealthIndicator} for InfluxDB 2.
*
* @author Jakub Bednar (bednar@github)
*/
public class InfluxDB2HealthIndicator extends AbstractHealthIndicator {

private final InfluxDBClient influxDBClient;

public InfluxDB2HealthIndicator(final InfluxDBClient influxDBClient) {
super("InfluxDBClient 2 health check failed");
Assert.notNull(influxDBClient, "InfluxDBClient must not be null");

this.influxDBClient = influxDBClient;
}

@Override
protected void doHealthCheck(final Health.Builder builder) {
boolean success = this.influxDBClient.ping();

if (success) {
builder.up();
} else {
builder.down();
}
}
}

+ 58
- 0
ym-influx/src/main/java/com/cnbm/influx/health/InfluxDB2HealthIndicatorAutoConfiguration.java Ver arquivo

@@ -0,0 +1,58 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cnbm.influx.health;

import com.cnbm.influx.influx.InfluxDB2AutoConfiguration;
import com.influxdb.client.InfluxDBClient;
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.health.HealthContributor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link InfluxDB2HealthIndicator}.
*
* @author Jakub Bednar
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(InfluxDBClient.class)
@ConditionalOnBean(InfluxDBClient.class)
@ConditionalOnEnabledHealthIndicator("influx")
@AutoConfigureAfter(InfluxDB2AutoConfiguration.class)
public class InfluxDB2HealthIndicatorAutoConfiguration
extends CompositeHealthContributorConfiguration<InfluxDB2HealthIndicator, InfluxDBClient> {

@Bean
@ConditionalOnMissingBean(name = { "influxDB2HealthIndicator", "influxDB2HealthContributor" })
public HealthContributor influxDbHealthContributor(final Map<String, InfluxDBClient> influxDBClients) {
return createContributor(influxDBClients);
}

}

+ 71
- 0
ym-influx/src/main/java/com/cnbm/influx/influx/AbstractInfluxDB2AutoConfiguration.java Ver arquivo

@@ -0,0 +1,71 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cnbm.influx.influx;

import com.influxdb.client.InfluxDBClientOptions;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import org.springframework.util.StringUtils;

import javax.annotation.Nonnull;
import java.util.Collections;

/**
* @author Jakub Bednar (04/08/2021 11:41)
*/
abstract class AbstractInfluxDB2AutoConfiguration {
protected final InfluxDB2Properties properties;
protected final InfluxDB2OkHttpClientBuilderProvider builderProvider;

protected AbstractInfluxDB2AutoConfiguration(final InfluxDB2Properties properties,
final InfluxDB2OkHttpClientBuilderProvider builderProvider) {
this.properties = properties;
this.builderProvider = builderProvider;
}

@Nonnull
protected InfluxDBClientOptions.Builder makeBuilder() {
OkHttpClient.Builder okHttpBuilder;
if (builderProvider == null) {
okHttpBuilder = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
.readTimeout(properties.getReadTimeout())
.writeTimeout(properties.getWriteTimeout())
.connectTimeout(properties.getConnectTimeout());
} else {
okHttpBuilder = builderProvider.get();
}

InfluxDBClientOptions.Builder influxBuilder = InfluxDBClientOptions.builder()
.url(properties.getUrl())
.bucket(properties.getBucket())
.org(properties.getOrg())
.okHttpClient(okHttpBuilder);

if (StringUtils.hasLength(properties.getToken())) {
influxBuilder.authenticateToken(properties.getToken().toCharArray());
} else if (StringUtils.hasLength(properties.getUsername()) && StringUtils.hasLength(properties.getPassword())) {
influxBuilder.authenticate(properties.getUsername(), properties.getPassword().toCharArray());
}
return influxBuilder;
}
}

+ 60
- 0
ym-influx/src/main/java/com/cnbm/influx/influx/InfluxDB2AutoConfiguration.java Ver arquivo

@@ -0,0 +1,60 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cnbm.influx.influx;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.InfluxDBClientOptions;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* {@link EnableAutoConfiguration Auto-configuration} for InfluxDB 2.
*
* @author Jakub Bednar (bednar@github) (06/05/2019 13:09)
*/
@Configuration
@ConditionalOnClass(InfluxDBClient.class)
@EnableConfigurationProperties(InfluxDB2Properties.class)
public class InfluxDB2AutoConfiguration extends AbstractInfluxDB2AutoConfiguration {

public InfluxDB2AutoConfiguration(final InfluxDB2Properties properties,
final ObjectProvider<InfluxDB2OkHttpClientBuilderProvider> builderProvider) {
super(properties, builderProvider.getIfAvailable());
}

@Bean
@ConditionalOnProperty("influx.url")
@ConditionalOnMissingBean(InfluxDBClient.class)
public InfluxDBClient influxDBClient() {

InfluxDBClientOptions.Builder influxBuilder = makeBuilder();

return InfluxDBClientFactory.create(influxBuilder.build()).setLogLevel(properties.getLogLevel());
}
}

+ 37
- 0
ym-influx/src/main/java/com/cnbm/influx/influx/InfluxDB2OkHttpClientBuilderProvider.java Ver arquivo

@@ -0,0 +1,37 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cnbm.influx.influx;

import okhttp3.OkHttpClient;

import java.util.function.Supplier;

/**
* Provide the {@link OkHttpClient.Builder OkHttpClient.Builder} to use to
* customize the auto-configured {@link com.influxdb.client.InfluxDBClient} instance.
*
* @author Jakub Bednar (bednar@github) (06/05/2019 13:11)
*/
@FunctionalInterface
public interface InfluxDB2OkHttpClientBuilderProvider extends Supplier<OkHttpClient.Builder> {

}

+ 178
- 0
ym-influx/src/main/java/com/cnbm/influx/influx/InfluxDB2Properties.java Ver arquivo

@@ -0,0 +1,178 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cnbm.influx.influx;

import com.cnbm.influx.constant.Constant;
import com.influxdb.LogLevel;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.time.Duration;

/**
* Configuration properties for InfluxDB 2.
*
* @author Jakub Bednar (bednar@github) (06/05/2019 12:54)
*/
@ConfigurationProperties(prefix = "influx")
public class InfluxDB2Properties {

// public InfluxDB2Properties{
// this.bucket = Constant.bucket;
// this.url = Constant.url;
// this.org = Constant.org;
// this.token = Constant.token;
// this.username = Constant.username;
// this.password = Constant.password;
// }

private static final int DEFAULT_TIMEOUT = 10_000;

/**
* URL to connect to InfluxDB.
*/
private String url = Constant.url;

/**
* Username to use in the basic auth.
*/
private String username = Constant.username;

/**
* Password to use in the basic auth.
*/
private String password = Constant.password;

/**
* Token to use for the authorization.
*/
private String token = Constant.token;

/**
* Default destination organization for writes and queries.
*/
private String org = Constant.org;

/**
* Default destination bucket for writes.
*/
private String bucket = Constant.bucket;

/**
* The log level for logging the HTTP request and HTTP response.
*/
private LogLevel logLevel = LogLevel.NONE;

/**
* Read timeout for {@code OkHttpClient}.
*/
private Duration readTimeout = Duration.ofMillis(DEFAULT_TIMEOUT);

/**
* Write timeout for {@code OkHttpClient}.
*/
private Duration writeTimeout = Duration.ofMillis(DEFAULT_TIMEOUT);

/**
* Connection timeout for {@code OkHttpClient}.
*/
private Duration connectTimeout = Duration.ofMillis(DEFAULT_TIMEOUT);

public String getUrl() {
return url;
}

public void setUrl(final String url) {
this.url = url;
}

public String getUsername() {
return username;
}

public void setUsername(final String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(final String password) {
this.password = password;
}

public String getToken() {
return token;
}

public void setToken(final String token) {
this.token = token;
}

public LogLevel getLogLevel() {
return logLevel;
}

public void setLogLevel(final LogLevel logLevel) {
this.logLevel = logLevel;
}

public String getOrg() {
return org;
}

public void setOrg(final String org) {
this.org = org;
}

public String getBucket() {
return bucket;
}

public void setBucket(final String bucket) {
this.bucket = bucket;
}

public Duration getReadTimeout() {
return readTimeout;
}

public void setReadTimeout(final Duration readTimeout) {
this.readTimeout = readTimeout;
}

public Duration getWriteTimeout() {
return writeTimeout;
}

public void setWriteTimeout(final Duration writeTimeout) {
this.writeTimeout = writeTimeout;
}

public Duration getConnectTimeout() {
return connectTimeout;
}

public void setConnectTimeout(final Duration connectTimeout) {
this.connectTimeout = connectTimeout;
}
}

+ 24
- 0
ym-influx/src/main/java/com/cnbm/influx/param/BaseParam.java Ver arquivo

@@ -0,0 +1,24 @@
package com.cnbm.influx.param;

import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/29 10:18
*/
@Data
public class BaseParam implements Serializable {
//page 信息可选
private PageInfo pageInfo;

@NotEmpty(message = "measurement 不能为空")
private String measurement;

@NotNull(message = "查询时间段不能为空")
private Range range;
}

+ 24
- 0
ym-influx/src/main/java/com/cnbm/influx/param/PageInfo.java Ver arquivo

@@ -0,0 +1,24 @@
package com.cnbm.influx.param;

import lombok.Data;
import org.hibernate.validator.constraints.Range;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/29 10:19
*/
@Data
public class PageInfo {
@Range(min = 1, message = "页码必须大于等于1")
private Integer current;

// @NotNull(message = "每页显示条数不能为空")
@Range(min = 1, max = 1000, message = "每页显示条数范围需在1-1000之间")
private Integer size;

public PageInfo(Integer current,Integer size){
this.current = current;
this.size = size;
}
}

+ 31
- 0
ym-influx/src/main/java/com/cnbm/influx/param/QueryDataParam.java Ver arquivo

@@ -0,0 +1,31 @@
package com.cnbm.influx.param;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* @Desc: "influx 查询条件构造"
* @Author: caixiang
* @DATE: 2022/6/29 10:17
*
* 注意:
* 必填
* ① measurement 不能为空
* ② 时间段 不能为空
* ③ bucket 不能为空
* 非必填
* ① 分页信息可选
* ② tag
*
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class QueryDataParam extends BaseParam{
private Tag tag;
//查询的时候,需要忽略的字段。(transationId是唯一标识会对 最终的查询结果集产生影响)
private String dropedTagName;
private String bucket;

}

+ 30
- 0
ym-influx/src/main/java/com/cnbm/influx/param/Range.java Ver arquivo

@@ -0,0 +1,30 @@
package com.cnbm.influx.param;

import lombok.Data;

import javax.validation.constraints.NotNull;
import java.time.Instant;

/**
* @Desc: "influxdb查询 时间范围"
* @Author: caixiang
* @DATE: 2022/6/29 11:14
*/
@Data
public class Range {
@NotNull(message = "起始时间不能为空")
private Instant begin;

@NotNull(message = "终点时间不能为空")
private Instant end;

public Range(Instant begin,Instant end){
this.begin = begin;
this.end = end;
}

// public static void main(String[] args) {
// Date date = new Date();
// System.out.println(date.toInstant().toString());
// }
}

+ 19
- 0
ym-influx/src/main/java/com/cnbm/influx/param/Tag.java Ver arquivo

@@ -0,0 +1,19 @@
package com.cnbm.influx.param;

import lombok.Data;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/29 14:38
*/
@Data
public class Tag {
private String tagName;
private String tagValue;

public Tag(String tagName,String tagValue){
this.tagName = tagName;
this.tagValue = tagValue;
}
}

+ 24
- 0
ym-influx/src/main/java/com/cnbm/influx/template/Event.java Ver arquivo

@@ -0,0 +1,24 @@
package com.cnbm.influx.template;

import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.time.Instant;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/25 11:13
*/
@Data
public class Event {
private Instant time;

private String transationId;

private String argName;

private Double argValue;
}

+ 28
- 0
ym-influx/src/main/java/com/cnbm/influx/template/Temperature.java Ver arquivo

@@ -0,0 +1,28 @@
package com.cnbm.influx.template;

import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;

import java.time.Instant;

/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/22 15:52
*/
//Temperature.java
@Measurement(name = "temperature")
public class Temperature {

@Column(tag = true)
public String location;

@Column
public Double value;

@Column
public String type;

@Column(timestamp = true)
public Instant time;
}

+ 17
- 0
ym-influx/src/main/resources/application-influx.yml Ver arquivo

@@ -0,0 +1,17 @@
influx:
url: http://192.168.0.170:8086 # URL to connect to InfluxDB.
username: caixiang # Username to use in the basic auth.
password: 251128856 # Password to use in the basic auth.
token: lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw== # Token to use for the authorization.
org: qgs # Default destination organization for writes and queries.
bucket: qgs-bucket # Default destination bucket for writes.
logLevel: BODY # The log level for logging the HTTP request and HTTP response. (Default: NONE)
readTimeout: 5s # Read timeout for OkHttpClient. (Default: 10s)
writeTimeout: 5s # Write timeout for OkHttpClient. (Default: 10s)
connectTimeout: 5s # Connection timeout for OkHttpClient. (Default: 10s)

# management.health.influx.enabled=true # Whether to enable InfluxDB 2.x health check.
management:
health:
influxdb:
enabled: true

Carregando…
Cancelar
Salvar