将终端台账拆分为pq&pms两类
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
//package com.njcn.influxdb.config;
|
||||
//
|
||||
///**
|
||||
// * @author hongawen
|
||||
// * @version 1.0.0
|
||||
// * @date 2022年09月20日 22:24
|
||||
// */
|
||||
//
|
||||
//import okhttp3.OkHttpClient;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//@Configuration
|
||||
//public class InfluxDbOkHttpClientBuilderProvider implements org.springframework.boot.autoconfigure.influx.InfluxDbOkHttpClientBuilderProvider {
|
||||
//
|
||||
// @Override
|
||||
// public OkHttpClient.Builder get() {
|
||||
// // 设置超时时间为100秒
|
||||
// return new OkHttpClient.Builder()
|
||||
// .connectTimeout(100, TimeUnit.SECONDS)
|
||||
// .readTimeout(100, TimeUnit.SECONDS)
|
||||
// .writeTimeout(100, TimeUnit.SECONDS);
|
||||
// }
|
||||
//}
|
||||
@@ -12,7 +12,7 @@ public interface InfluxDBPublicParam {
|
||||
/**
|
||||
* influxDB数据库名称
|
||||
*/
|
||||
String DATABASE = "pqsbase";
|
||||
String DATABASE = "PQSBASE";
|
||||
|
||||
/**
|
||||
* 暂态事件汇总表
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.njcn.influxdb.utils;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.InfluxDB.ConsistencyLevel;
|
||||
import org.influxdb.InfluxDBFactory;
|
||||
@@ -31,6 +32,10 @@ import java.util.concurrent.TimeUnit;
|
||||
@Slf4j
|
||||
@Data
|
||||
public class InfluxDbUtils {
|
||||
static OkHttpClient.Builder client = new OkHttpClient.Builder()
|
||||
.connectTimeout(1000,TimeUnit.SECONDS)
|
||||
.readTimeout(1000, TimeUnit.SECONDS)
|
||||
.writeTimeout(1000, TimeUnit.SECONDS);
|
||||
private static final int FRACTION_MIN_WIDTH = 0;
|
||||
private static final int FRACTION_MAX_WIDTH = 9;
|
||||
private static final boolean ADD_DECIMAL_POINT = true;
|
||||
@@ -70,7 +75,7 @@ public class InfluxDbUtils {
|
||||
*/
|
||||
public InfluxDB influxDbBuild() {
|
||||
if (influxDB == null) {
|
||||
influxDB = InfluxDBFactory.connect(openurl, username, password);
|
||||
influxDB = InfluxDBFactory.connect(openurl, username, password,client);
|
||||
}
|
||||
try {
|
||||
// if (!influxDB.databaseExists(database)) {
|
||||
@@ -87,6 +92,8 @@ public class InfluxDbUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建数据库
|
||||
*
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.event.pojo.po.EventDetail;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import feign.Util;
|
||||
import org.influxdb.InfluxDB.ConsistencyLevel;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
import org.influxdb.dto.Point;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -59,19 +63,27 @@ public class DataTest {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
InfluxDbUtils influxDBUtil = new InfluxDbUtils("admin", "123456", "http://192.168.1.18:8086", "pqsbase", "");
|
||||
insert(influxDBUtil);
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
long time = Long.parseLong("1657959227000");
|
||||
tags.put("line_id","656da093bdb523b6ac619067a4045624");
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
fields.put("statis_value",1024000000.00);
|
||||
influxDBUtil.insert("cld_month_flow", tags, fields, time, TimeUnit.MILLISECONDS);
|
||||
InfluxDbUtils influxDBUtil = new InfluxDbUtils("admin", "njcnpqs", "http://192.168.1.18:8086", "PQSBASE", "");
|
||||
String sql = "select * from pqs_eventdetail limit 10";
|
||||
//获取暂降事件
|
||||
QueryResult result = influxDBUtil.query(sql);
|
||||
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
|
||||
List<EventDetail> eventDetailList = influxDBResultMapper.toPOJO(result, EventDetail.class);
|
||||
String bodyStr = PubUtils.obj2json(eventDetailList.get(0));
|
||||
//对结果进行转换
|
||||
EventDetail o = PubUtils.json2obj(bodyStr, EventDetail.class);
|
||||
Instant timeId = o.getTimeId();
|
||||
System.out.println(timeId);
|
||||
|
||||
|
||||
System.out.println(1);
|
||||
//select(influxDBUtil);
|
||||
}
|
||||
|
||||
public static void deleteDB(InfluxDbUtils influxDBUtil) {
|
||||
influxDBUtil.deleteDB("LIMIT_RATE");
|
||||
}
|
||||
|
||||
//单条数据插入
|
||||
public static void insert(InfluxDbUtils influxDBUtil) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
@@ -80,8 +92,8 @@ public class DataTest {
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
// fields.put("due",1440);
|
||||
// fields.put("real",1200);
|
||||
fields.put("onlinemin",1123);
|
||||
fields.put("offlinemin",377);
|
||||
fields.put("onlinemin", 1123);
|
||||
fields.put("offlinemin", 377);
|
||||
influxDBUtil.insert("pqs_onlinerate", tags, fields, time, TimeUnit.MILLISECONDS);
|
||||
// long time = Long.parseLong("1655135328135");
|
||||
// Map<String, String> tags = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user