package com.njcn.influx.bo.po;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.njcn.influx.utils.InstantDateSerializer;
import com.njcn.oracle.bo.po.DataPlt;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import org.influxdb.annotation.TimeColumn;

import java.time.Instant;
import java.time.ZoneId;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/4/12 16:01
 */
@Data
@Measurement(name = "data_plt")
public class InfluxDBDataPlt {

    @Column(name = "time",tag =true)
    @TimeColumn
    @JsonSerialize(using = InstantDateSerializer.class)
    private Instant time;

    @Column(name = "line_id",tag = true)
    private String lineId;

    @Column(name = "phasic_type",tag = true)
    private String phaseType;

    @Column(name = "quality_flag",tag = true)
    private String qualityFlag;

    @Column(name = "plt")
    private Float plt;

    public static InfluxDBDataPlt oralceToInfluxDB(DataPlt dataPlt) {
        if (dataPlt == null) {
            return null;
        }
        InfluxDBDataPlt influxDBDataPlt = new InfluxDBDataPlt();

        Instant instant = dataPlt.getTimeid().atZone(ZoneId.systemDefault()).toInstant();

        influxDBDataPlt.setTime(instant);
        influxDBDataPlt.setLineId(dataPlt.getLineid());
        influxDBDataPlt.setPhaseType(dataPlt.getPhasicType());
        influxDBDataPlt.setPlt(dataPlt.getPlt());
        influxDBDataPlt.setQualityFlag(dataPlt.getQualityflag()+"");


        return influxDBDataPlt;
    }
    

}
