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.DataFlicker;
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.LocalDateTime;
import java.time.ZoneId;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 */
@Data
@Measurement(name = "data_flicker")
public class InfluxDBDataFlicker {

    @TimeColumn
    @Column(name = "time",tag = true)
    @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 = "fluc")
    private Float fluc;

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

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

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


    public static InfluxDBDataFlicker oralceToInfluxDB(DataFlicker dataFlicker) {
        if (dataFlicker == null) {
            return null;
        }
        InfluxDBDataFlicker influxDBDataFlicker = new InfluxDBDataFlicker();

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

        influxDBDataFlicker.setTime(instant);
        influxDBDataFlicker.setLineId(dataFlicker.getLineid());
        influxDBDataFlicker.setPhaseType(dataFlicker.getPhasicType());
        influxDBDataFlicker.setFluc(dataFlicker.getFluc());
        influxDBDataFlicker.setPlt(dataFlicker.getPlt());
        influxDBDataFlicker.setPst(dataFlicker.getPst());
        influxDBDataFlicker.setQualityFlag(dataFlicker.getQualityflag()+"");


        return influxDBDataFlicker;
    }
}
