潘志宝
2024-08-23 585be5b57da60870edf6e555aab1f0e61c609745
动态influxdb
已添加4个文件
已修改3个文件
114 ■■■■ 文件已修改
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/DataController.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexQueryDTO.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexStatisticDTO.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/echarts/BarLineDTO.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/echarts/SeriesItem.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/common/config/InfluxDBInstance.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/DataController.java
@@ -2,9 +2,9 @@
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.module.data.common.dto.IndexQueryDTO;
import com.iailab.module.data.common.dto.echarts.BarLineDTO;
import com.iailab.module.data.common.dto.echarts.SeriesItem;
import com.iailab.module.data.api.dto.IndexQueryDTO;
import com.iailab.module.data.api.dto.echarts.BarLineDTO;
import com.iailab.module.data.api.dto.echarts.SeriesItem;
import com.iailab.module.data.common.utils.R;
import com.iailab.module.data.api.dto.ApiPointValueQueryDTO;
import com.iailab.module.data.point.collection.PointCollector;
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexQueryDTO.java
对比新文件
@@ -0,0 +1,20 @@
package com.iailab.module.data.api.dto;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class IndexQueryDTO {
    private Date startDate;
    private Date endDate;
    private String code;
    private Integer granularity;
    private List<String> codes;
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/IndexStatisticDTO.java
对比新文件
@@ -0,0 +1,16 @@
package com.iailab.module.data.api.dto;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class IndexStatisticDTO implements Serializable {
    private static final long serialVersionUID = 1L;
    public Date dateTime;
    public BigDecimal data;
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/echarts/BarLineDTO.java
对比新文件
@@ -0,0 +1,25 @@
package com.iailab.module.data.api.dto.echarts;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
 * @author lirm
 * @Description
 * @createTime 2023.05.11
 */
@Data
public class BarLineDTO implements Serializable {
    private static final long serialVersionUID = 1L;
    private String valueName;//表名称
    private List<String> legend;//线的名称
    private List<String> categories;//X轴数据
    private List<SeriesItem> series;//Y轴数据集合
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/dto/echarts/SeriesItem.java
对比新文件
@@ -0,0 +1,18 @@
package com.iailab.module.data.api.dto.echarts;
import lombok.Data;
import java.util.List;
/**
 * @author lirm
 * @Description
 * @createTime 2023.05.11
 */
@Data
public class SeriesItem {
    private String name;
    private List<Object[]> data;
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/common/config/InfluxDBInstance.java
@@ -1,5 +1,6 @@
package com.iailab.module.data.influxdb.common.config;
import com.iailab.framework.tenant.core.context.TenantContextHolder;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import org.slf4j.Logger;
@@ -18,14 +19,13 @@
    @Value("${influx-db.org}")
    public String org;
    @Value("${influx-db.bucket}")
    public String bucket;
    @Value("${influx-db.token}")
    public String token;
    @Value("${influx-db.url}")
    public String url;
    private final static String BUCKET_NAME = "tenant_";
    private Logger logger = LoggerFactory.getLogger(getClass());
@@ -43,5 +43,8 @@
        return client;
    }
    public String getBucket() {
        return BUCKET_NAME + TenantContextHolder.getRequiredTenantId();
    }
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/influxdb/service/impl/InfluxDBServiceImpl.java
@@ -66,7 +66,7 @@
        point.addTag("point", pointNo);
        point.addField("value", Double.parseDouble(dataValue));
        point.time(time, WritePrecision.MS);
        writeApiBlocking.writePoint(influxDBInstance.bucket, influxDBInstance.org, point);
        writeApiBlocking.writePoint(influxDBInstance.getBucket(), influxDBInstance.org, point);
    }
    @Override
@@ -78,7 +78,7 @@
        point.addTag("point", pointNo);
        point.addField("value", Integer.parseInt(dataValue));
        point.time(time, WritePrecision.MS);
        writeApiBlocking.writePoint(influxDBInstance.bucket, influxDBInstance.org, point);
        writeApiBlocking.writePoint(influxDBInstance.getBucket(), influxDBInstance.org, point);
    }
    @Override
@@ -90,7 +90,7 @@
        point.addTag("point", pointNo);
        point.addField("value", Boolean.parseBoolean(dataValue));
        point.time(time, WritePrecision.MS);
        writeApiBlocking.writePoint(influxDBInstance.bucket, influxDBInstance.org, point);
        writeApiBlocking.writePoint(influxDBInstance.getBucket(), influxDBInstance.org, point);
    }
    @Override
@@ -100,7 +100,7 @@
        }
        if (!CollectionUtils.isEmpty(pointValues)) {
            pointValues.forEach(item -> {
                writeApi.writeMeasurement(influxDBInstance.bucket, influxDBInstance.org, WritePrecision.MS, item);
                writeApi.writeMeasurement(influxDBInstance.getBucket(), influxDBInstance.org, WritePrecision.MS, item);
            });
        }
        writeApi.flush();
@@ -113,7 +113,7 @@
        }
        if (!CollectionUtils.isEmpty(tagValues)) {
            tagValues.forEach(item -> {
                writeApi.writeMeasurement(influxDBInstance.bucket, influxDBInstance.org, WritePrecision.MS, item);
                writeApi.writeMeasurement(influxDBInstance.getBucket(), influxDBInstance.org, WritePrecision.MS, item);
            });
        }
        writeApi.flush();
@@ -142,7 +142,7 @@
            InfluxTagValuePOJO tag = influxParams.get(i);
            String measurement = TagValueUtils.getMeasurement(tag.getType());
            StringBuilder sb = new StringBuilder();
            sb.append("from(bucket:\"" + influxDBInstance.bucket + "\") ");
            sb.append("from(bucket:\"" + influxDBInstance.getBucket() + "\") ");
            sb.append("|> range(start: ").append(start).append(", stop: ").append(stop).append(") ");
            sb.append("|> filter(fn: (r) => r[\"_measurement\"] == \"" + measurement + "\")");
            sb.append("|> filter(fn: (r) => r[\"_field\"] == \"value\")");
@@ -179,7 +179,7 @@
        String measurement = TagValueUtils.getMeasurement(tag.getType());
        StringBuilder sb = new StringBuilder();
        sb.append("from(bucket:\"" + influxDBInstance.bucket + "\") ");
        sb.append("from(bucket:\"" + influxDBInstance.getBucket() + "\") ");
        sb.append("|> range(start: ").append(start).append(", stop: ").append(stop).append(") ");
        sb.append("|> filter(fn: (r) => r[\"_measurement\"] == \"" + measurement + "\")");
        sb.append("|> filter(fn: (r) => r[\"_field\"] == \"value\")");
@@ -232,7 +232,7 @@
            sql.append(" WHERE point = '");
            sql.append(point.getPoint());
            sql.append("'");
            InfluxQLQueryResult data = influxQLQueryApi.query(new InfluxQLQuery(sql.toString(), influxDBInstance.bucket));
            InfluxQLQueryResult data = influxQLQueryApi.query(new InfluxQLQuery(sql.toString(), influxDBInstance.getBucket()));
            Object value = data.getResults().get(0).getSeries().get(0).getValues().get(0).getValueByKey("last");
            result.put(point.getPoint(), value);
        }
@@ -254,7 +254,7 @@
        sql.append(" WHERE point = '");
        sql.append(point.getPoint());
        sql.append("' AND time >= '" + utsStart +"'");
        InfluxQLQueryResult data = influxQLQueryApi.query(new InfluxQLQuery(sql.toString(), influxDBInstance.bucket));
        InfluxQLQueryResult data = influxQLQueryApi.query(new InfluxQLQuery(sql.toString(), influxDBInstance.getBucket()));
        if (data == null) {
            return null;
        }
@@ -291,7 +291,7 @@
            InfluxPointValuePOJO point = influxParams.get(i);
            String measurement = PointValueUtils.getMeasurement(point.getType());
            StringBuilder sb = new StringBuilder();
            sb.append("from(bucket:\"" + influxDBInstance.bucket + "\") ");
            sb.append("from(bucket:\"" + influxDBInstance.getBucket() + "\") ");
            sb.append("|> range(start: ").append(start).append(", stop: ").append(stop).append(") ");
            sb.append("|> filter(fn: (r) => r[\"_measurement\"] == \"" + measurement + "\")");
            sb.append("|> filter(fn: (r) => r[\"_field\"] == \"value\")");