代码提交

This commit is contained in:
huangzj
2023-09-26 15:22:52 +08:00
parent 2f8149e709
commit bcd329d9ea

View File

@@ -1,47 +1,47 @@
package com.njcn; //package com.njcn;
//
import com.njcn.influxdb.param.InfluxDBPublicParam; //import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils; //import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor; //import lombok.AllArgsConstructor;
import org.influxdb.InfluxDB; //import org.influxdb.InfluxDB;
import org.influxdb.dto.BatchPoints; //import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point; //import org.influxdb.dto.Point;
//
import java.util.*; //import java.util.*;
import java.util.concurrent.TimeUnit; //import java.util.concurrent.TimeUnit;
//
/** ///**
* 类的介绍: // * 类的介绍:
* // *
* @author xuyang // * @author xuyang
* @version 1.0.0 // * @version 1.0.0
* @createTime 2023/6/5 14:44 // * @createTime 2023/6/5 14:44
*/ // */
@AllArgsConstructor //@AllArgsConstructor
public class InfluxDbTest { //public class InfluxDbTest {
//
public static void main(String[] args) { // public static void main(String[] args) {
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.16:8086", "pqsbase_zl", ""); // InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.16:8086", "pqsbase_zl", "");
List<String> records = new ArrayList<>(); // List<String> records = new ArrayList<>();
List<String> phasic = Arrays.asList("A","B","C"); // List<String> phasic = Arrays.asList("A","B","C");
List<String> dataType = Arrays.asList("max","min","avg","cp95"); // List<String> dataType = Arrays.asList("max","min","avg","cp95");
long time = System.currentTimeMillis(); // long time = System.currentTimeMillis();
for (String item1 : phasic) { // for (String item1 : phasic) {
for (String item2 : dataType) { // for (String item2 : dataType) {
Map<String, String> tags = new HashMap<>(); // Map<String, String> tags = new HashMap<>();
Map<String, Object> fields = new HashMap<>(); // Map<String, Object> fields = new HashMap<>();
tags.put("line_id","4aea410500fc0cea5a62790e8d493542"); // tags.put("line_id","4aea410500fc0cea5a62790e8d493542");
tags.put("phasic_type",item1); // tags.put("phasic_type",item1);
tags.put("value_type",item2); // tags.put("value_type",item2);
fields.put("Hz",new Random().nextDouble()); // fields.put("Hz",new Random().nextDouble());
fields.put("PhV",new Random().nextDouble()); // fields.put("PhV",new Random().nextDouble());
Point point = influxDbUtils.pointBuilder("data_v", time, TimeUnit.MILLISECONDS, tags, fields); // Point point = influxDbUtils.pointBuilder("data_v", time, TimeUnit.MILLISECONDS, tags, fields);
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName ()).tag(InfluxDBPublicParam.LINE_ID, "4aea410500fc0cea5a62790e8d493542").tag(InfluxDBPublicParam.PHASIC_TYPE,item1).tag(InfluxDBPublicParam.VALUE_TYPE,item2).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build(); // BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName ()).tag(InfluxDBPublicParam.LINE_ID, "4aea410500fc0cea5a62790e8d493542").tag(InfluxDBPublicParam.PHASIC_TYPE,item1).tag(InfluxDBPublicParam.VALUE_TYPE,item2).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
batchPoints.point(point); // batchPoints.point(point);
records.add(batchPoints.lineProtocol()); // records.add(batchPoints.lineProtocol());
} // }
} // }
influxDbUtils.batchInsert(influxDbUtils.getDbName (),"", InfluxDB.ConsistencyLevel.ALL, records); // influxDbUtils.batchInsert(influxDbUtils.getDbName (),"", InfluxDB.ConsistencyLevel.ALL, records);
} // }
//
} //}