依赖jar包

引入包 版本
jdk 1.8
spring boot 2.7.2
influxdb-java 2.21
spring-boot-autoconfigure 2.7.2

使用

添加依赖

<dependency>
  <groupId>cn.allbs</groupId>
  <artifactId>allbs-influx</artifactId>
  <version>1.1.8</version>
</dependency>
<dependency>
    <groupId>org.influxdb</groupId>
    <artifactId>influxdb-java</artifactId>
    <version>2.21</version>
</dependency>
implementation 'cn.allbs:allbs-influx:1.1.8'
implementation("cn.allbs:allbs-influx:1.1.8")

添加配置

influx:
  open_url: http://192.168.1.111:8086
  username: ${INFLUX-USER:root}
  password: ${INFLUX-PWD:123456}
  database: allbstest
  # influxdb储存策略
  retention_policy: autogen
  # 储存永久
  retention_policy_time: 0s

启用

添加注解@EnableAllbsInflux

注入template

private final InfluxTemplate influxTemplate;

业务使用

插入数据

time时间为系统默认时间

// tags
Map<String, String> tagMap = new HashMap<>(2);
tagMap.put("entNo", "q0038");
tagMap.put("outletNo", "q0038g0001");
// fields
Map<String, Object> fieldMap = new HashMap<>(2);
fieldMap.put("IPA", "1");
fieldMap.put("pushTime", "2020-03-05 15:00:00");
influxTemplate.insert("表名", tagMap, fieldMap);

表中time设定自定义时间

influxTemplate.insert("表名", tagMap, fieldMap, Instant.now().toEpochMilli(), TimeUnit.MILLISECONDS);

查询数据

QueryResult result = influxTemplate.query("SELECT * FROM \"zt_gas_waste\" order by time desc limit 100\n");
List<QueryResult.Series> series = result.getResults().get(0).getSeries();