补充新更新

This commit is contained in:
2022-06-22 09:14:52 +08:00
parent 59da3376c1
commit 6870c2ccc3
323 changed files with 18518 additions and 441 deletions

View File

@@ -1,7 +1,6 @@
package com.njcn.influxdb.utils;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.InfluxDB;
@@ -170,7 +169,6 @@ public class InfluxDbUtils {
builder.tag(tags);
builder.fields(fields);
if (0 != time) {
time = time + 28800000;
builder.time(time, timeUnit);
}
influxDB.write(dbName, retentionPolicy, builder.build());

View File

@@ -1,8 +1,11 @@
import cn.hutool.core.date.DateUtil;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.influxdb.utils.InfluxDbUtils;
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.util.*;
import java.util.concurrent.TimeUnit;
@@ -21,9 +24,17 @@ public class test {
//查询
public static QueryResult select(InfluxDbUtils influxDBUtil) {
long startTime = System.currentTimeMillis();
QueryResult result = influxDBUtil.query("select * from data_V where phasic_type='A'");
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse("2022-05-06"))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse("2022-05-06"))).append("' and (");
//sql语句
stringBuilder.append("line_id ='").append("1e3b8531483b2a8cbee6747f1f641cf9").append("')");
//获取暂降事件
QueryResult result = influxDBUtil.query("select * from pqs_eventdetail where " + stringBuilder.toString());
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<EventDetail> eventDetailList = influxDBResultMapper.toPOJO(result, EventDetail.class);
long endTime = System.currentTimeMillis();
System.out.println(endTime - startTime);
System.out.println(eventDetailList);
return result;
}
@@ -47,101 +58,152 @@ public class test {
}
}
public static void main(String[] args) {
public static void main(String[] args) {
InfluxDbUtils influxDBUtil = new InfluxDbUtils("root", "123456789", "http://192.168.1.16:8086", "pqsbase", "");
insert(influxDBUtil);
//select(influxDBUtil);
}
public static void deleteDB(InfluxDbUtils influxDBUtil) {
influxDBUtil.deleteDB("LIMIT_RATE");
}
//单条数据插入
public static void insert(InfluxDbUtils influxDBUtil) {
// long time = Long.parseLong("1655135328135");
// Map<String, String> tags = new HashMap<>();
// // tags.put("line_id", "127fad1dcb0077ac2979141b8473a5e4");
// tags.put("line_id", "1883a1fe6d9c3c5a03a4371bda024452");
// Map<String, Object> fields = new HashMap<>();
// fields.put("create_time", "2022-06-13 23:57:31");
// fields.put("update_time", "");
// fields.put("push_failed",0);
// fields.put("result",1);
// influxDBUtil.insert("pqs_event_push_logs", tags, fields, time, TimeUnit.MILLISECONDS);
long time = Long.parseLong("1646180719000");
Map<String, String> tags = new HashMap<>();
tags.put("lineid", "1e3b8531483b2a8cbee6747f1f641cf9");
Map<String, Object> fields = new HashMap<>();
fields.put("phasic_type","T");
fields.put("value_type","MAX");
fields.put("Freq_Dev", 48.6 );
fields.put("Voltage_Dev", 8.3 );
fields.put("UBalance", 7.6 );
fields.put("Flicker", 4.6 );
fields.put("UAberrance", 6.5 );
fields.put("I_Neg", 5.6 );
fields.put("UHarm_2", 6.8 );
fields.put("UHarm_3", 5.5 );
fields.put("UHarm_4", 5.4 );
fields.put("UHarm_5", 7.8 );
fields.put("UHarm_6", 6.2 );
fields.put("UHarm_7", 2.5 );
fields.put("UHarm_8", 8.3 );
fields.put("UHarm_9", 6.2 );
fields.put("UHarm_10", 12.8 );
fields.put("UHarm_11", 2.8 );
fields.put("UHarm_12", 8.4 );
fields.put("UHarm_13", 5.6 );
fields.put("UHarm_14", 5.2 );
fields.put("UHarm_15", 9.5 );
fields.put("UHarm_16", 8.3 );
fields.put("UHarm_17", 7.8 );
fields.put("UHarm_18", 6.2 );
fields.put("UHarm_19", 2.5);
fields.put("UHarm_20", 4.5 );
fields.put("UHarm_21", 4.5 );
fields.put("UHarm_22", 6.5 );
fields.put("UHarm_23", 5.9 );
fields.put("UHarm_24", 9.2 );
fields.put("UHarm_25", 5.8 );
fields.put("IHarm_2", 12.8 );
fields.put("IHarm_3", 5.4 );
fields.put("IHarm_4", 6.2 );
fields.put("IHarm_5", 3.2 );
fields.put("IHarm_6", 5.2 );
fields.put("IHarm_7", 5.2 );
fields.put("IHarm_8", 5.5 );
fields.put("IHarm_9", 4.8 );
fields.put("IHarm_10", 8.2 );
fields.put("IHarm_11", 2.5 );
fields.put("IHarm_12", 8.6 );
fields.put("IHarm_13", 5.8 );
fields.put("IHarm_14", 3.5 );
fields.put("IHarm_15", 2.4 );
fields.put("IHarm_16", 5.2 );
fields.put("IHarm_17", 2.5 );
fields.put("IHarm_18", 9.2 );
fields.put("IHarm_19", 8.5);
fields.put("IHarm_20", 8.5 );
fields.put("IHarm_21", 6.2 );
fields.put("IHarm_22", 5.2 );
fields.put("IHarm_23", 8.5 );
fields.put("IHarm_24", 5.2 );
fields.put("IHarm_25", 8.4 );
fields.put("InUHARM_1", 8.2 );
fields.put("InUHARM_2", 5.2 );
fields.put("InUHARM_3", 6.2 );
fields.put("InUHARM_4", 4.2 );
fields.put("InUHARM_5", 2.3 );
fields.put("InUHARM_6", 6.2 );
fields.put("InUHARM_7", 5.2 );
fields.put("InUHARM_8", 10.2 );
fields.put("InUHARM_9", 2.3 );
fields.put("InUHARM_10", 4.2 );
fields.put("InUHARM_11", 3.5 );
fields.put("InUHARM_12", 3.6 );
fields.put("InUHARM_13", 2.3 );
fields.put("InUHARM_14", 7.2 );
fields.put("InUHARM_15", 5.6 );
fields.put("InUHARM_16", 5.6 );
influxDBUtil.insert("PQS_AbnormalData", tags, fields, System.currentTimeMillis(), TimeUnit.MILLISECONDS);
<<<<<<< .mine tags.put("LineID", "fd4ffb0dd33eafaaf403b07a3fc1afe5");
======= tags.put("line_id", "89604adcaf7df6284fdaa352ccaba56b");
>>>>>>> .theirs Map<String, Object> fields = new HashMap<>();
fields.put("VU_Dev1",5.706);
fields.put("VU_Dev2",5.706);
fields.put("VU_Dev3",5.706);
fields.put("VU_Dev4",5.706);
fields.put("VU_Dev5",5.706);
fields.put("Freq_Dev1",0.534);
fields.put("Freq_Dev2",0.534);
fields.put("Freq_Dev3",2.534);
fields.put("Freq_Dev4",0.534);
fields.put("Freq_Dev5",0.534);
fields.put("Data_PST1",0.604);
fields.put("Data_PST2",0.0);
fields.put("Data_PST3",0.691);
fields.put("Data_PST4",0.910);
fields.put("Data_PST5",0.691);
fields.put("V_Unbalance1",2.713);
fields.put("V_Unbalance2",2.713);
fields.put("V_Unbalance3",2.713);
fields.put("V_Unbalance4",2.713);
fields.put("V_Unbalance5",2.713);
fields.put("V_THD1",20.001);
fields.put("V_THD2",20.003);
fields.put("V_THD3",20.00);
fields.put("V_THD4",20.008);
fields.put("V_THD5",20.00);
fields.put("Event1",1.619);
fields.put("Event2",1.619);
fields.put("Event3",1.619);
fields.put("Event4",1.619);
fields.put("Event5",1.619);
influxDBUtil.insert("PQS_COMASSES", tags, fields, time, TimeUnit.MILLISECONDS);
// long time = Long.parseLong("1647473742000");
// tags.put("MYINDEX", "df1ff413949f6d1fc07ffdb5440b4907");
// Map<String, Object> fields = new HashMap<>();
// fields.put("Phasic_Type","T");
// fields.put("AllTime",1155);
// fields.put("Flicker_AllTime",550);
// fields.put("Flicker_OverTime",0);
// fields.put("Freq_Dev_OverTime",0);
// fields.put("Voltage_Dev_OverTime",0);
// fields.put("UBalance_OverTime",0);
// fields.put("UAberrance_OverTime",0);
// fields.put("I_Neg_OverTime",0);
// fields.put("UHarm_2_OverTime",0);
// fields.put("UHarm_3_OverTime",0);
// fields.put("UHarm_4_OverTime",0);
// fields.put("UHarm_5_OverTime",0);
// fields.put("UHarm_6_OverTime",0);
// fields.put("UHarm_7_OverTime",0);
// fields.put("UHarm_8_OverTime",0);
// fields.put("UHarm_9_OverTime",0);
// fields.put("UHarm_10_OverTime",0);
// fields.put("UHarm_11_OverTime",0);
// fields.put("UHarm_12_OverTime",0);
// fields.put("UHarm_13_OverTime",0);
// fields.put("UHarm_14_OverTime",0);
// fields.put("UHarm_15_OverTime",0);
// fields.put("UHarm_16_OverTime",0);
// fields.put("UHarm_17_OverTime",0);
// fields.put("UHarm_18_OverTime",0);
// fields.put("UHarm_19_OverTime",0);
// fields.put("UHarm_20_OverTime",0);
// fields.put("UHarm_21_OverTime",0);
// fields.put("UHarm_22_OverTime",0);
// fields.put("UHarm_23_OverTime",0);
// fields.put("UHarm_24_OverTime",0);
// fields.put("UHarm_25_OverTime",0);
// fields.put("IHarm_2_OverTime",0);
// fields.put("IHarm_3_OverTime",0);
// fields.put("IHarm_4_OverTime",0);
// fields.put("IHarm_5_OverTime",0);
// fields.put("IHarm_6_OverTime",0);
// fields.put("IHarm_7_OverTime",0);
// fields.put("IHarm_8_OverTime",0);
// fields.put("IHarm_9_OverTime",0);
// fields.put("IHarm_10_OverTime",0);
// fields.put("IHarm_11_OverTime",0);
// fields.put("IHarm_12_OverTime",0);
// fields.put("IHarm_13_OverTime",0);
// fields.put("IHarm_14_OverTime",0);
// fields.put("IHarm_15_OverTime",0);
// fields.put("IHarm_16_OverTime",0);
// fields.put("IHarm_17_OverTime",0);
// fields.put("IHarm_18_OverTime",0);
// fields.put("IHarm_19_OverTime",0);
// fields.put("IHarm_20_OverTime",0);
// fields.put("IHarm_21_OverTime",0);
// fields.put("IHarm_22_OverTime",0);
// fields.put("IHarm_23_OverTime",0);
// fields.put("IHarm_24_OverTime",0);
// fields.put("IHarm_25_OverTime",0);
// fields.put("InUHARM_1_OverTime",0);
// fields.put("InUHARM_2_OverTime",0);
// fields.put("InUHARM_3_OverTime",0);
// fields.put("InUHARM_4_OverTime",0);
// fields.put("InUHARM_5_OverTime",0);
// fields.put("InUHARM_6_OverTime",0);
// fields.put("InUHARM_7_OverTime",0);
// fields.put("InUHARM_8_OverTime",0);
// fields.put("InUHARM_9_OverTime",0);
// fields.put("InUHARM_10_OverTime",0);
// fields.put("InUHARM_11_OverTime",0);
// fields.put("InUHARM_12_OverTime",0);
// fields.put("InUHARM_13_OverTime",0);
// fields.put("InUHARM_14_OverTime",0);
// fields.put("InUHARM_15_OverTime",0);
// fields.put("InUHARM_16_OverTime",0);
// influxDBUtil.insert("LIMIT_RATE", tags, fields, time, TimeUnit.MILLISECONDS);
}
//循环写入数据库
public static void batchInsertOne(InfluxDbUtils influxDBUtil) {
Map<String, String> tags1 = new HashMap<>();
tags1.put("LineID", "8");
tags1.put("Phasic_Type", "A");
tags1.put("line_id", "127fad1dcb0077ac2979141b8473a5e4");
Map<String, Object> fields1 = new HashMap<>();
fields1.put("RMS", 2);
fields1.put("RMS_AB", 2);
fields1.put("RMS_BC", 2);
fields1.put("RMS_CA", 2);
fields1.put("describe", "暂降事件1");
fields1.put("wave_type", 1);
fields1.put("persist_time", 1620);
fields1.put("event_value", 0.956);
Map<String, String> tags2 = new HashMap<>();
tags2.put("LineID", "9");
tags2.put("Phasic_Type", "A");