package com.njcn; import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.njcn.harmonic.pojo.vo.RtDataVO; import com.njcn.harmonic.service.ILineTargetService; import com.njcn.influxdb.param.InfluxDBPublicParam; import com.njcn.influxdb.utils.InfluxDbUtils; import lombok.AllArgsConstructor; import org.influxdb.InfluxDB; import org.influxdb.dto.BatchPoints; import org.influxdb.dto.Point; import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.Resource; import java.util.*; import java.util.concurrent.TimeUnit; /** * 类的介绍: * * @author xuyang * @version 1.0.0 * @createTime 2023/6/5 14:44 */ @AllArgsConstructor public class InfluxDbTest { public static void main(String[] args) { InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.16:8086", "pqsbase_zl", ""); List records = new ArrayList<>(); List phasic = Arrays.asList("A","B","C"); List dataType = Arrays.asList("max","min","avg","cp95"); long time = System.currentTimeMillis(); for (String item1 : phasic) { for (String item2 : dataType) { Map tags = new HashMap<>(); Map fields = new HashMap<>(); tags.put("line_id","7f6753c721dbf1ce37117073eddf2215"); tags.put("phasic_type",item1); tags.put("value_type",item2); fields.put("W",new Random().nextDouble()); fields.put("PhV",new Random().nextDouble()); Point point = influxDbUtils.pointBuilder("pqd_data", time, TimeUnit.MILLISECONDS, tags, fields); BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName ()).tag(InfluxDBPublicParam.LINE_ID, "7f6753c721dbf1ce37117073eddf2215").tag(InfluxDBPublicParam.PHASIC_TYPE,item1).tag(InfluxDBPublicParam.VALUE_TYPE,item2).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build(); batchPoints.point(point); records.add(batchPoints.lineProtocol()); } } influxDbUtils.batchInsert(influxDbUtils.getDbName (),"", InfluxDB.ConsistencyLevel.ALL, records); } }