Kaynağa Gözat

dcs数据保存到influxDB

hfxc226 2 yıl önce
ebeveyn
işleme
ac73e810d0

+ 13 - 1
platform-common/pom.xml

@@ -149,7 +149,7 @@
         <dependency>
             <groupId>com.itextpdf</groupId>
             <artifactId>itextpdf</artifactId>
-            <version>5.5.11</version>
+            <version>5.3.0</version>
         </dependency>
 
         <dependency>
@@ -175,12 +175,24 @@
             <groupId>org.xhtmlrenderer</groupId>
             <artifactId>flying-saucer-pdf-itext5</artifactId>
             <version>9.1.5</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.itextpdf</groupId>
+                    <artifactId>itextpdf</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>
             <artifactId>velocity</artifactId>
             <groupId>org.apache.velocity</groupId>
             <version>1.7</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>spring-beans</artifactId>
+                    <groupId>org.springframework</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
     </dependencies>

+ 33 - 1
platform-common/src/main/java/com/platform/common/util/DateUtils.java

@@ -4,6 +4,7 @@ import com.platform.common.exception.BusinessException;
 import lombok.experimental.UtilityClass;
 import lombok.extern.slf4j.Slf4j;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
@@ -32,8 +33,37 @@ public class DateUtils {
 
     public final static String PATTERNYMD = "yyyyMMdd";
 
+    public final static String CST = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+
     private final static ZoneId ZONE_ID = ZoneId.systemDefault();
 
+    /**
+     * UTC时间转本地北京时间
+     *
+     * @param UTCStr"2022-07-26T10:57:40Z"
+     * @throws ParseException
+     */
+    public static LocalDateTime UTCToCST(String UTCStr) throws ParseException {
+        SimpleDateFormat df2 = new SimpleDateFormat(CST);
+        df2.setTimeZone(TimeZone.getTimeZone("UTC"));
+        Date date = df2.parse(UTCStr);
+        //Date转换为LocalDateTime
+        Instant instant = date.toInstant();
+        ZoneId zone = ZoneId.systemDefault();
+        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
+        return localDateTime;
+    }
+
+    /**
+     * 本地北京时间转UTC时间
+     *
+     * @param date"2022-07-26T10:57:40Z"
+     * @throws ParseException
+     */
+    public static String localDateTimeToUTC(LocalDateTime date) throws ParseException {
+        return dateToString(date, CST);
+    }
+
     /**
      * 当前时间所在一周的周一时间:000000
      *
@@ -248,12 +278,14 @@ public class DateUtils {
         return (year % 4 == 0 && year % 100 != 0);
 
     }
+
     /**
      * 时间转字符串
+     *
      * @return
      */
     public static String dateToString(Date date) {
-        SimpleDateFormat format= new SimpleDateFormat(PATTERN_YMD_HMS);
+        SimpleDateFormat format = new SimpleDateFormat(PATTERN_YMD_HMS);
         return format.format(date);
     }
 

+ 52 - 6
platform-dao/pom.xml

@@ -25,6 +25,7 @@
         <mapper.starter.version>2.1.5</mapper.starter.version>
         <pagehelper.starter.version>1.2.5</pagehelper.starter.version>
 
+
     </properties>
 
     <dependencies>
@@ -40,6 +41,45 @@
             <version>1.0-SNAPSHOT</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.influxdb</groupId>
+            <artifactId>influxdb-client-java</artifactId>
+            <version>3.1.0</version>
+            <exclusions>
+                <!--排除okhttp3的依赖-->
+                <exclusion>
+                    <groupId>com.squareup.okhttp3</groupId>
+                    <artifactId>*</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.squareup.okio</groupId>
+                    <artifactId>okio</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.jetbrains.kotlin</groupId>
+                    <artifactId>kotlin-stdlib-common</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <!-- 重新指定okhttp3版本-->
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>okhttp</artifactId>
+            <version>4.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>logging-interceptor</artifactId>
+            <version>4.0.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib</artifactId>
+            <version>1.3.50</version>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-aop</artifactId>
@@ -76,11 +116,11 @@
         </dependency>
 
         <!--postgresql-->
-       <!-- <dependency>
-            <groupId>org.postgresql</groupId>
-            <artifactId>postgresql</artifactId>
-            <version>42.2.5</version>
-        </dependency>-->
+        <!-- <dependency>
+             <groupId>org.postgresql</groupId>
+             <artifactId>postgresql</artifactId>
+             <version>42.2.5</version>
+         </dependency>-->
 
         <dependency>
             <groupId>org.mybatis</groupId>
@@ -243,11 +283,17 @@
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
             <version>23.0</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>commons-lang</artifactId>
+                    <groupId>commons-lang</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>
             <artifactId>gson</artifactId>
-            <version>2.8.2</version>
+            <version>2.8.5</version>
         </dependency>
     </dependencies>
 

+ 29 - 0
platform-dao/src/main/java/com/platform/dao/config/InfluxDbConfig.java

@@ -0,0 +1,29 @@
+package com.platform.dao.config;
+
+import com.influxdb.LogLevel;
+import com.influxdb.client.InfluxDBClient;
+import com.influxdb.client.InfluxDBClientFactory;
+import com.platform.dao.util.influxDB.InfluxDBFluxExpression;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * influx配置类
+ */
+@Slf4j
+@Configuration
+public class InfluxDbConfig {
+
+    @Bean
+    public InfluxDBClient influxDBClient() {
+
+        System.out.println("=============="+ InfluxDBFluxExpression.token+"==============");
+        System.out.println("=============="+InfluxDBFluxExpression.url+"==============");
+        InfluxDBClient influxDBClient = InfluxDBClientFactory.create(InfluxDBFluxExpression.url, InfluxDBFluxExpression.token.toCharArray());
+        influxDBClient.setLogLevel(LogLevel.BASIC);
+        return influxDBClient;
+
+    }
+}

+ 22 - 0
platform-dao/src/main/java/com/platform/dao/influxdb/InfluxDBService.java

@@ -0,0 +1,22 @@
+package com.platform.dao.influxdb;
+
+import com.influxdb.query.FluxTable;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+public interface InfluxDBService {
+
+    /**
+     * *
+     *
+     * @param tagName     标签名称
+     * @param fields      字段
+     */
+    void writeOne(String tagName, Map<String, Object> fields);
+
+    void delete(LocalDateTime start, LocalDateTime stop);
+
+    void select(String tagName, LocalDateTime start, LocalDateTime stop);
+}

+ 135 - 0
platform-dao/src/main/java/com/platform/dao/influxdb/impl/InfluxDBServiceImpl.java

@@ -0,0 +1,135 @@
+package com.platform.dao.influxdb.impl;
+
+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.DeletePredicateRequest;
+import com.influxdb.client.domain.WritePrecision;
+import com.influxdb.client.write.Point;
+import com.influxdb.query.FluxRecord;
+import com.influxdb.query.FluxTable;
+import com.platform.common.exception.BusinessException;
+import com.platform.common.util.DateUtils;
+import com.platform.dao.influxdb.InfluxDBService;
+import com.platform.dao.util.influxDB.InfluxDBFluxExpression;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.ParseException;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Service("influxDBService")
+@Slf4j
+@AllArgsConstructor
+public class InfluxDBServiceImpl implements InfluxDBService {
+
+    @Autowired
+    private InfluxDBClient influxDBClient;
+
+    /**
+     * *
+     * @param tagName     标签名称:positionNum的值
+     * @param fields      字段
+     */
+    @Override
+    public void writeOne(String tagName, Map<String, Object> fields) {
+
+        System.out.println("=============开始插入数据=============");
+        WriteOptions writeOptions = WriteOptions.builder()
+                .batchSize(5000)
+                .flushInterval(1000)
+                .bufferLimit(10000)
+                .jitterInterval(1000)
+                .retryInterval(5000)
+                .build();
+        try (WriteApi writeApi = influxDBClient.getWriteApi(writeOptions)) {
+            Point point = Point
+                    .measurement(InfluxDBFluxExpression.measurement)
+                    .addTag(InfluxDBFluxExpression.tag, tagName)
+                    .addFields(fields)
+                    .time(Instant.now(), WritePrecision.NS);
+            writeApi.writePoint(InfluxDBFluxExpression.bucket, InfluxDBFluxExpression.org, point);
+        }catch(Exception e){
+            e.printStackTrace();
+            throw new BusinessException("db写入报错");
+
+        }
+    }
+
+    /**
+     * 批量数据写入
+     */
+    public void writeBatch(List<Point> list){
+        /*Point point = Point
+                .measurement(InfluxDBFluxExpression.measurement)
+                .addTag(InfluxDBFluxExpression.tag, InfluxDBFluxExpression.tag)
+                .addField(InfluxDBFluxExpression.field, 23.43234543)
+                .time(Instant.now(), WritePrecision.NS);
+        list.add(point);*/
+        influxDBClient.getWriteApi().writePoints(list);
+    }
+
+    /**
+     * 删除数据:删除bucket所有的数据
+     */
+    @Override
+    public void delete(LocalDateTime start, LocalDateTime stop) {
+        DeletePredicateRequest deletePredicateRequest = new DeletePredicateRequest();
+        // deletePredicateRequest.start(start.atOffset(ZoneOffset.ofHours(0)).minusDays(5));
+        deletePredicateRequest.start(start.atOffset(ZoneOffset.ofHours(0)));
+        deletePredicateRequest.stop(stop.atOffset(ZoneOffset.ofHours(0)));
+        influxDBClient.getDeleteApi().delete(deletePredicateRequest, InfluxDBFluxExpression.bucket, InfluxDBFluxExpression.org);
+    }
+
+    /**
+     * 查询数据: 查询某个点位,某个时间段的数据*
+     * @param tagName positionNum值
+     * @param start 开始时间
+     * @param stop 结束时间
+     */
+    @Override
+    public void select(String tagName, LocalDateTime start, LocalDateTime stop){
+        StringBuffer stringBuilder = new StringBuffer();
+        try {
+            InfluxDBFluxExpression.appendCommonFlux(stringBuilder, InfluxDBFluxExpression.bucket, InfluxDBFluxExpression.measurement, DateUtils.localDateTimeToUTC(start), DateUtils.localDateTimeToUTC(stop));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        InfluxDBFluxExpression.appendTagFlux(stringBuilder, tagName);
+        InfluxDBFluxExpression.appendTimeShiftFlux(stringBuilder);
+        log.info("查询sql :{}", stringBuilder);
+        // 通过时间分组  查询时间段的数据
+        List<FluxTable> tables = influxDBClient.getQueryApi().query(stringBuilder.toString());
+        List<Map<String, Object>> list = new ArrayList<>();
+        for (FluxTable table : tables) {
+            List<FluxRecord> records = table.getRecords();
+            for (FluxRecord record : records) {
+                log.info("{}---{}---{}---{}", record.getMeasurement(),record.getField(),record.getValue(),record.getTime());
+            }
+        }
+    }
+
+  /*  @Override
+    public List<FluxTable> selectData() {
+
+        System.out.println("==============开始查询数据================");
+        String sql = "from(bucket: \"%s\") |> range(start: 0)";
+        sql +="  |> filter(fn: (r) => r._measurement == \"%s\" and";
+        sql +="  r._field == \"%s\")";
+        sql +="  |> yield()";
+        String flux = String.format(sql, InfluxDBFluxExpression.bucket,InfluxDBFluxExpression.measurement,InfluxDBFluxExpression.field);
+        QueryApi queryApi = influxDBClient.getQueryApi();
+        List<FluxTable> tables = queryApi.query(flux,InfluxDBFluxExpression.org);
+        System.out.println(tables.toString());
+        return tables;
+    }*/
+
+}

+ 437 - 0
platform-dao/src/main/java/com/platform/dao/util/influxDB/InfluxDBFluxExpression.java

@@ -0,0 +1,437 @@
+package com.platform.dao.util.influxDB;
+
+import com.platform.common.util.StringUtils;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * @Description:
+ * @author: skies
+ * @date
+ */
+public class InfluxDBFluxExpression {
+
+    public static final String token = "qEMI2lHel0NPscN32WgmZtuymxmYZZZv67hHeRGA2_VJ_gd5sHH_QTyZ34T_ThhcbwFaqx4Qs9Q5BQBNpfMLkg==";
+    public static final String url = "http://localhost:8086";
+    public static final String org = "qykh";
+    public static final String bucket = "qykh_dcs";
+    public static final String measurement = "tb_dcs";
+    public static final String tag = "positionNum";
+    public static final String field = "result";
+
+    /**
+     * 通用表达式
+     *
+     * @param buffer
+     * @param bucketName 名称
+     * @param tableName  表名
+     * @param start      开始时间
+     * @param stop       结束时间
+     */
+    public static void appendCommonFlux(StringBuffer buffer, String bucketName, String tableName,
+                                        String start, String stop) {
+        appendBucketFlux(buffer, bucketName);
+        appendTimeRangeFlux(buffer, start, stop);
+        appendTableFlux(buffer, tableName);
+//		if(timestampFlag) {
+//			appendTimestampFlux(buffer);
+//		}
+//		if(dropDefaultFlag) {
+//			appendDropFlux(buffer);
+//		}
+
+    }
+
+
+    /**
+     * 数据源(桶)表达式
+     *
+     * @param buffer
+     * @param bucketName 名称
+     */
+    public static void appendBucketFlux(StringBuffer buffer, String bucketName) {
+        buffer.append("from(bucket: \"" + bucketName + "\") ");
+    }
+
+    /**
+     * 表名表达式
+     *
+     * @param buffer
+     * @param tableName 名称
+     */
+    public static void appendTableFlux(StringBuffer buffer, String tableName) {
+        buffer.append("|> filter(fn: (r) => r._measurement == \"" + tableName + "\") ");
+    }
+
+    /**
+     * 表名表达式
+     *
+     * @param buffer
+     * @param tagName    positionNum具体名称
+     */
+    public static void appendTagFlux(StringBuffer buffer, String tagName) {
+        buffer.append("|> filter(fn: (r) => r." + InfluxDBFluxExpression.tag + " == \"" + tagName + "\") ");
+    }
+
+    /**
+     * field表达式
+     *
+     * @param buffer
+     * @param field    名称
+     */
+    public static void appendTagField(StringBuffer buffer, String field) {
+        buffer.append("|> filter(fn: (r) => r._field == \"" + field + "\") ");
+    }
+
+
+    /**
+     * 时间范围表达式  UTC时间
+     *
+     * @param buffer
+     * @param start  开始时间
+     * @param stop   结束时间
+     */
+    public static void appendTimeRangeFlux(StringBuffer buffer, String start, String stop) {
+        if (StringUtils.isBlank(start)) {
+            start = "1970-01-01T00:00:00.000Z";
+        }
+        if (StringUtils.isBlank(stop)) {
+            buffer.append("|> range(start:" + start + ") ");
+        } else {
+            buffer.append("|> range(start:" + start + ", stop:" + stop + ") ");
+        }
+    }
+
+    /**
+     * 删除字段表达式
+     *
+     * @param buffer
+     * @param args   需要删除的字段【 参数为空的话删除host字段】
+     */
+    public static void appendDropFlux(StringBuffer buffer, String... args) {
+        if (args.length == 0) {
+            buffer.append("|> drop(columns: [\"host\"]) ");
+            return;
+        }
+        buffer.append("|> drop(columns: [");
+        for (int i = 0; i < args.length; i++) {
+            if (i != 0) {
+                buffer.append(",");
+            }
+            buffer.append("\"" + args[i] + "\"");
+        }
+        buffer.append("]) ");
+    }
+
+    /**
+     * 复制属性列表达式
+     *
+     * @param buffer
+     * @param oldField 原来的字段名称
+     * @param newField 新的字段名称
+     */
+    public static void appendDuplicateFlux(StringBuffer buffer, String oldField, String newField) {
+        buffer.append("|> duplicate(column: \"" + oldField + "\", as: \"" + newField + "\") ");
+    }
+
+    /**
+     * 重命名属性列表达式
+     *
+     * @param buffer
+     * @param oldField 原来的字段名称
+     * @param newField 新的字段名称
+     */
+    public static void appendRenameFlux(StringBuffer buffer, String oldField, String newField) {
+        buffer.append(" |> rename(columns: {" + oldField + ": \"" + newField + "\"}) ");
+    }
+
+
+    /**
+     * 最新一条数据表达式
+     *
+     * @param buffer
+     */
+    public static void appendLastFlux(StringBuffer buffer) {
+        buffer.append("|> last() ");
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param buffer
+     * @param n
+     * @param offset
+     */
+    public static void appendLimitFlux(StringBuffer buffer, int n, int offset) {
+        buffer.append("|> limit(n:" + n + ", offset: " + offset + ") ");
+    }
+
+    /**
+     * 分组表达式
+     *
+     * @param buffer
+     */
+    public static void appendGroupFlux(StringBuffer buffer, String... columns) {
+        if (columns.length == 0) {
+            buffer.append("|> group() ");
+        } else {
+            buffer.append("|> group(columns:[ ");
+            for (int i = 0; i < columns.length; i++) {
+                if (i != 0) {
+                    buffer.append(",");
+                }
+                buffer.append("\"" + columns[i] + "\"");
+            }
+            buffer.append("]) ");
+        }
+
+    }
+
+    /**
+     * 去重表达式
+     *
+     * @param buffer
+     */
+    public static void appendDistinctFlux(StringBuffer buffer, String... columns) {
+        if (columns.length == 0) {
+            buffer.append("|> distinct() ");
+        } else {
+            buffer.append("|> distinct(column:\"" + columns[0] + "\") ");
+        }
+
+    }
+
+    /**
+     * 总数表达式
+     *
+     * @param buffer
+     */
+    public static void appendCountFlux(StringBuffer buffer) {
+        buffer.append("|> count() ");
+    }
+
+    /**
+     * 前几条数据
+     *
+     * @param buffer
+     * @param n
+     */
+    public static void appendTopFlux(StringBuffer buffer, int n) {
+        buffer.append("|> top(n:" + n + ") ");
+    }
+
+    public static void appendBottomFlux(StringBuffer buffer, int n) {
+        buffer.append("|> bottom(n:" + n + ") ");
+    }
+
+    /**
+     * 排序
+     *
+     * @param buffer
+     * @param descFlag true 降序 ;false 升序
+     * @param columns
+     */
+    public static void appendSortFlux(StringBuffer buffer, boolean descFlag, String... columns) {
+        if (columns.length == 0) {
+            buffer.append("|> sort(columns: [\"_value\"], desc: " + descFlag + ")");
+        } else {
+            buffer.append("|> sort(columns:[ ");
+            for (int i = 0; i < columns.length; i++) {
+                if (i != 0) {
+                    buffer.append(",");
+                }
+                buffer.append("\"" + columns[i] + "\"");
+            }
+            buffer.append("], desc: " + descFlag + ") ");
+        }
+    }
+
+
+    /**
+     * 时移八小时
+     *
+     * @param buffer
+     */
+    public static void appendTimeShiftFlux(StringBuffer buffer) {
+        buffer.append("|> timeShift(duration: 8h) ");
+    }
+
+    /**
+     * 过滤单个字符表达式
+     *
+     * @param buffer
+     * @param list
+     * @param operator  【== != 】
+     * @param join      【and or】
+     * @param fieldName
+     */
+    public static void appendFilterFlux(StringBuffer buffer, List<String> list, String operator, String join, String fieldName) {
+        if (list == null || list.size() == 0) {
+            return;
+        }
+        for (int i = 0, size = list.size(); i < size; i++) {
+            if (i == 0) {
+                buffer.append("|> filter(fn: (r) =>");
+            } else {
+                buffer.append(join);
+            }
+            buffer.append(" r." + fieldName + " " + operator + " \"" + list.get(i) + "\" ");
+        }
+        buffer.append(")  ");
+    }
+
+    /**
+     * 过滤表达式
+     *
+     * @param buffer
+     * @param map
+     * @param operator 【== != 】
+     * @param join     【and or】
+     */
+    public static void appendFilterFlux(StringBuffer buffer, Map<String, Object> map, String operator, String join) {
+        Set<Entry<String, Object>> entrySet = map.entrySet();
+        Iterator<Entry<String, Object>> iterator = entrySet.iterator();
+        boolean flag = true;
+        while (iterator.hasNext()) {
+            Entry<String, Object> next = iterator.next();
+            String key = next.getKey();
+            Object value = next.getValue();
+            if (flag) {
+                buffer.append("|> filter(fn: (r) =>");
+                flag = false;
+            } else {
+                buffer.append(join);
+            }
+            buffer.append(" r." + key + " " + operator + " \"" + value + "\" ");
+        }
+        if (!flag) {
+            buffer.append(")  ");
+        }
+
+    }
+
+    /**
+     * 过滤多个字段表达式
+     *
+     * @param buffer
+     * @param list
+     * @param innerJoin 【and or】
+     * @param operator  【== != 】
+     * @param outerJoin 【and or】
+     */
+    public static void appendMulFilterFlux(StringBuffer buffer, List<Map<String, Object>> list, String innerJoin, String operator, String outerJoin) {
+        if (list == null || list.size() == 0) {
+            return;
+        }
+        buffer.append("|> filter(fn: (r) => ");
+        boolean outerFlag = true;
+        for (int i = 0; i < list.size(); i++) {
+            Map<String, Object> map = list.get(i);
+            Set<Entry<String, Object>> entrySet = map.entrySet();
+            Iterator<Entry<String, Object>> iterator = entrySet.iterator();
+            boolean innerFlag = true;
+            while (iterator.hasNext()) {
+                Entry<String, Object> next = iterator.next();
+                String key = next.getKey();
+                Object value = next.getValue();
+                if (innerFlag) {
+                    if (outerFlag) {
+                        outerFlag = false;
+                    } else {
+                        buffer.append(outerJoin);
+                    }
+                    buffer.append(" ( ");
+                    innerFlag = false;
+                } else {
+                    buffer.append(innerJoin);
+                }
+                buffer.append("  r." + key + " " + operator + " \"" + value + "\"  ");
+            }
+            if (!innerFlag) {
+                buffer.append(" )  ");
+            }
+        }
+        buffer.append(" )  ");
+
+    }
+
+    /**
+     * 时间窗口统计
+     *
+     * @param buffer
+     * @param step    步长值【10m,1h,1d...】
+     * @param aggType 统计类型【sum,count,min,max...)
+     */
+    public static void appendAggregateWindowFlux(StringBuffer buffer, String step, String aggType) {
+        buffer.append("|> aggregateWindow(every: " + step + ", fn: " + aggType + ") ");
+    }
+
+    public static void appendWindowFlux(StringBuffer buffer, String step) {
+        buffer.append("|> window(every: " + step + ") ");
+    }
+
+    /**
+     * 不带时间窗口统计
+     *
+     * @param buffer
+     * @param aggType 统计类型【sum,count,min,max...)
+     */
+    public static void appendAggregateFlux(StringBuffer buffer, String aggType) {
+        buffer.append("|> " + aggType + "() ");
+    }
+
+
+    /**
+     * 多个查询结果需要指定每个输出结果名称
+     *
+     * @param buffer
+     * @param name
+     */
+    public static void appendYieldFlux(StringBuffer buffer, String name) {
+        buffer.append("|> yield(name: \"" + name + "\") ");
+    }
+
+    /**
+     * 将时间指定为某单位
+     *
+     * @param buffer
+     * @param step
+     */
+    public static void appendTruncateTimeColumn(StringBuffer buffer, String step) {
+        buffer.append("|> truncateTimeColumn(unit: " + step + ") ");
+    }
+
+    /**
+     * 导入包名
+     *
+     * @param buffer
+     * @param name   包名
+     */
+    public static void appendImportFlux(StringBuffer buffer, String name) {
+        buffer.append("import \"" + name + "\" ");
+    }
+
+    /**
+     * 过滤空值
+     *
+     * @param buffer
+     */
+    public static void appendExistsFlux(StringBuffer buffer) {
+        buffer.append("|> filter(fn: (r) => exists r._value ) ");
+    }
+
+
+    /**
+     * 过滤0
+     *
+     * @param buffer
+     */
+    public static void appendZeroFlux(StringBuffer buffer) {
+        buffer.append("|> filter(fn: (r) => r._value > 0) ");
+    }
+
+}

+ 5 - 0
platform-dao/src/main/resources/application-influxDB.yml

@@ -0,0 +1,5 @@
+influx:
+  url: http://localhost:8086
+  token: qEMI2lHel0NPscN32WgmZtuymxmYZZZv67hHeRGA2_VJ_gd5sHH_QTyZ34T_ThhcbwFaqx4Qs9Q5BQBNpfMLkg==   #可以从页面上获取
+  org: qykh
+  bucket: qykh_dcs

+ 0 - 2
platform-rest/src/main/java/com/platform/rest/controller/index/IndexController.java

@@ -26,8 +26,6 @@ import java.util.List;
 @RequestMapping("/index")
 public class IndexController {
 
-    private final SbOilService sbOilService;
-
     private final CheckJobService checkJobService;
 
     private final RepairApplicationFormService repairApplicationFormService;

+ 58 - 0
platform-rest/src/main/java/com/platform/rest/controller/influxdb/InfluxDBController.java

@@ -0,0 +1,58 @@
+package com.platform.rest.controller.influxdb;
+
+import com.platform.common.util.R;
+import com.platform.dao.influxdb.InfluxDBService;
+import com.platform.rest.log.annotation.SysLog;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.math.RandomUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Description InfluxDB数据库测试 控制器
+ * @Author future
+ * @Date 2020-06-02 15:30:46
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Slf4j
+@RestController
+@AllArgsConstructor
+@RequestMapping("/influxDB")
+public class InfluxDBController {
+
+    private final InfluxDBService influxDBService;
+
+    /**
+     * 新增记录
+     *
+     * @return R
+     */
+    @SysLog("新增记录")
+    @PostMapping
+    public R save() {
+        String measurement = "tb_dcs";
+        String tag = "positionNum";
+        String tagName = "TE1001_AV";
+        Map<String, Object> fields = new HashMap<>();
+        float value = RandomUtils.nextFloat();
+        log.info(value + "");
+        fields.put("result", value);
+        influxDBService.writeOne(tagName, fields);
+        return new R<>("插入成功");
+    }
+
+    /**
+     * 获取列表
+     *
+     * @return R
+     */
+    @GetMapping("")
+    public R query() {
+        // return new R<>(influxDBService.selectData());
+        return null;
+    }
+
+}