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.ComInfoRmation;
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/7/12 9:55
 */
@Data
@Measurement(name = "pqs_communicate")
public class InfluxDBComInfoRmation {

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

    @Column(name = "dev_id")
    private String devId;

    @Column(name = "description")
    private String description;

    @Column(name = "type")
    private Integer type;

    public static InfluxDBComInfoRmation oralceToInfluxDB(ComInfoRmation comInfoRmation) {
        if (comInfoRmation == null) {
            return null;
        }
        InfluxDBComInfoRmation influxDBDataCommunicate = new InfluxDBComInfoRmation();
        Instant instant = comInfoRmation.getUpdateTime().atZone(ZoneId.systemDefault()).toInstant();

        influxDBDataCommunicate.setTime(instant);
        influxDBDataCommunicate.setDevId(comInfoRmation.getLineIndex());
        influxDBDataCommunicate.setDescription(comInfoRmation.getDescription());
        influxDBDataCommunicate.setType(comInfoRmation.getType());

        return influxDBDataCommunicate;
    }
}
