From 605e90dbb3c1d0ca17913e3982eeaf115f0aac44 Mon Sep 17 00:00:00 2001 From: Luoye_W Date: Wed, 4 Aug 2021 17:53:55 +0800 Subject: [PATCH] backup --- .../qyi/e5/bean/influx2/InfluxdbConfig.java | 1 + .../controller/OutlookLogController.java | 48 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java b/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java index 57ceaae..2502999 100644 --- a/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java +++ b/src/main/java/io/qyi/e5/bean/influx2/InfluxdbConfig.java @@ -21,4 +21,5 @@ public class InfluxdbConfig { return influxDBClient; } + } diff --git a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java index 87afa2d..e7a15b6 100644 --- a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java +++ b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java @@ -3,10 +3,13 @@ package io.qyi.e5.outlook_log.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.influxdb.client.InfluxDBClient; +import com.influxdb.client.QueryApi; import com.influxdb.client.WriteApi; import com.influxdb.client.WriteOptions; import com.influxdb.client.domain.WritePrecision; import com.influxdb.client.write.Point; +import com.influxdb.query.FluxRecord; +import com.influxdb.query.FluxTable; import io.qyi.e5.bean.result.Result; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.service.IOutlookService; @@ -102,7 +105,6 @@ public class OutlookLogController { } - try (WriteApi writeApi = influxDBClient.getWriteApi()) { // writeApi.writePoint(bucket, org, point); writeApi.writePoints(bucket,org, arrayList); @@ -110,4 +112,48 @@ public class OutlookLogController { return "ok"; } + @GetMapping("/find") + public void find(){ + String flux = "from(bucket:\"e5\") |> range(start: 0)" + + "|> filter(fn: (r) => r[\"_measurement\"] == \"e5s\")" + + // "|> filter(fn: (r) => r[\"_field\"] == \"aaaaaa1\")" + + "|> limit(n: 100)"; + + QueryApi queryApi = influxDBClient.getQueryApi(); + List tables = queryApi.query(flux,org); + for (FluxTable fluxTable : tables) { + List records = fluxTable.getRecords(); + + for (FluxRecord fluxRecord : records) { + System.out.println(fluxRecord.getField()); + System.out.println(fluxRecord.getTime() + " ->" + fluxRecord.getValueByKey("_value")); + } + } + + /*queryApi.query(flux,org,(cancellable, fluxRecord) -> { + + // + // The callback to consume a FluxRecord. + // + // cancelable - object has the cancel method to stop asynchronous query + // + System.out.println(fluxRecord.getTime() + ": " + fluxRecord.getValueByKey("_value")); + + }, throwable -> { + + // + // The callback to consume any error notification. + // + System.out.println("Error occurred: " + throwable.getMessage()); + + }, () -> { + // + // The callback to consume a notification about successfully end of stream. + // + System.out.println("Query completed"); + + });*/ + + } + }