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.DataI;
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;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/5/11 15:13
 */
@Data
@Measurement(name = "data_i")
public class InfluxDBDataI {

    @Column(name = "time",tag =true)
    @JsonSerialize(using = InstantDateSerializer.class)
    @TimeColumn
    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 = "value_type",tag = true)
    private String valueType;

    @Column(name = "i_neg")
    private Float iNeg;

    @Column(name = "i_pos")
    private Float iPos;

    @Column(name = "i_thd")
    private Float iThd;

    @Column(name = "i_unbalance")
    private Float iUnbalance;

    @Column(name = "i_zero")
    private Float iZero;

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

    @Column(name = "i_1")
    private Float i1;

    @Column(name = "i_2")
    private Float i2;

    @Column(name = "i_3")
    private Float i3;

    @Column(name = "i_4")
    private Float i4;

    @Column(name = "i_5")
    private Float i5;

    @Column(name = "i_6")
    private Float i6;

    @Column(name = "i_7")
    private Float i7;

    @Column(name = "i_8")
    private Float i8;

    @Column(name = "i_9")
    private Float i9;

    @Column(name = "i_10")
    private Float i10;

    @Column(name = "i_11")
    private Float i11;

    @Column(name = "i_12")
    private Float i12;

    @Column(name = "i_13")
    private Float i13;

    @Column(name = "i_14")
    private Float i14;

    @Column(name = "i_15")
    private Float i15;

    @Column(name = "i_16")
    private Float i16;

    @Column(name = "i_17")
    private Float i17;

    @Column(name = "i_18")
    private Float i18;

    @Column(name = "i_19")
    private Float i19;

    @Column(name = "i_20")
    private Float i20;

    @Column(name = "i_21")
    private Float i21;

    @Column(name = "i_22")
    private Float i22;

    @Column(name = "i_23")
    private Float i23;

    @Column(name = "i_24")
    private Float i24;

    @Column(name = "i_25")
    private Float i25;

    @Column(name = "i_26")
    private Float i26;

    @Column(name = "i_27")
    private Float i27;

    @Column(name = "i_28")
    private Float i28;

    @Column(name = "i_29")
    private Float i29;

    @Column(name = "i_30")
    private Float i30;

    @Column(name = "i_31")
    private Float i31;

    @Column(name = "i_32")
    private Float i32;

    @Column(name = "i_33")
    private Float i33;

    @Column(name = "i_34")
    private Float i34;

    @Column(name = "i_35")
    private Float i35;

    @Column(name = "i_36")
    private Float i36;

    @Column(name = "i_37")
    private Float i37;

    @Column(name = "i_38")
    private Float i38;

    @Column(name = "i_39")
    private Float i39;

    @Column(name = "i_40")
    private Float i40;

    @Column(name = "i_41")
    private Float i41;

    @Column(name = "i_42")
    private Float i42;

    @Column(name = "i_43")
    private Float i43;

    @Column(name = "i_44")
    private Float i44;

    @Column(name = "i_45")
    private Float i45;

    @Column(name = "i_46")
    private Float i46;

    @Column(name = "i_47")
    private Float i47;

    @Column(name = "i_48")
    private Float i48;

    @Column(name = "i_49")
    private Float i49;

    @Column(name = "i_50")
    private Float i50;

    public static List<InfluxDBDataI> oralceToInfluxDB(DataI dataI) {
        if (dataI == null) {
            return null;
        }
        List<InfluxDBDataI> influxDBDataIList = new ArrayList<>();
        List<String> valueTypeList = Stream.of("AVG", "MAX", "MIN", "CP95").collect(Collectors.toList());
        for (String valueType : valueTypeList) {
            InfluxDBDataI influxDBDataI = new InfluxDBDataI();
            Instant instant = dataI.getTimeid().atZone(ZoneId.systemDefault()).toInstant();

            influxDBDataI.setTime(instant);
            influxDBDataI.setLineId(dataI.getLineid());
            influxDBDataI.setPhaseType(dataI.getPhasicType());
            influxDBDataI.setQualityFlag(dataI.getQualityflag()+"");
            influxDBDataI.setValueType(valueType);
            if (valueType.equals("AVG")) {

                influxDBDataI.setINeg(dataI.getINeg());
                influxDBDataI.setIPos(dataI.getIPos());
                influxDBDataI.setIThd(dataI.getIThd());
                influxDBDataI.setIUnbalance(dataI.getIUnbalance());
                influxDBDataI.setIZero(dataI.getIZero());
                influxDBDataI.setRms(dataI.getRms());


                influxDBDataI.setI1(dataI.getI1());
                influxDBDataI.setI2(dataI.getI2());
                influxDBDataI.setI3(dataI.getI3());
                influxDBDataI.setI4(dataI.getI4());
                influxDBDataI.setI5(dataI.getI5());
                influxDBDataI.setI6(dataI.getI6());
                influxDBDataI.setI7(dataI.getI7());
                influxDBDataI.setI8(dataI.getI8());
                influxDBDataI.setI9(dataI.getI9());
                influxDBDataI.setI10(dataI.getI10());
                influxDBDataI.setI11(dataI.getI11());
                influxDBDataI.setI12(dataI.getI12());
                influxDBDataI.setI13(dataI.getI13());
                influxDBDataI.setI14(dataI.getI14());
                influxDBDataI.setI15(dataI.getI15());
                influxDBDataI.setI16(dataI.getI16());
                influxDBDataI.setI17(dataI.getI17());
                influxDBDataI.setI18(dataI.getI18());
                influxDBDataI.setI19(dataI.getI19());
                influxDBDataI.setI20(dataI.getI20());
                influxDBDataI.setI21(dataI.getI21());
                influxDBDataI.setI22(dataI.getI22());
                influxDBDataI.setI23(dataI.getI23());
                influxDBDataI.setI24(dataI.getI24());
                influxDBDataI.setI25(dataI.getI25());
                influxDBDataI.setI26(dataI.getI26());
                influxDBDataI.setI27(dataI.getI27());
                influxDBDataI.setI28(dataI.getI28());
                influxDBDataI.setI29(dataI.getI29());
                influxDBDataI.setI30(dataI.getI30());
                influxDBDataI.setI31(dataI.getI31());
                influxDBDataI.setI32(dataI.getI32());
                influxDBDataI.setI33(dataI.getI33());
                influxDBDataI.setI34(dataI.getI34());
                influxDBDataI.setI35(dataI.getI35());
                influxDBDataI.setI36(dataI.getI36());
                influxDBDataI.setI37(dataI.getI37());
                influxDBDataI.setI38(dataI.getI38());
                influxDBDataI.setI39(dataI.getI39());
                influxDBDataI.setI40(dataI.getI40());
                influxDBDataI.setI41(dataI.getI41());
                influxDBDataI.setI42(dataI.getI42());
                influxDBDataI.setI43(dataI.getI43());
                influxDBDataI.setI44(dataI.getI44());
                influxDBDataI.setI45(dataI.getI45());
                influxDBDataI.setI46(dataI.getI46());
                influxDBDataI.setI47(dataI.getI47());
                influxDBDataI.setI48(dataI.getI48());
                influxDBDataI.setI49(dataI.getI49());
                influxDBDataI.setI50(dataI.getI50());
            }
            else if (valueType.equals("MAX")){

                influxDBDataI.setINeg(dataI.getINegMax());
                influxDBDataI.setIPos(dataI.getIPosMax());
                influxDBDataI.setIThd(dataI.getIThdMax());
                influxDBDataI.setIUnbalance(dataI.getIUnbalanceMax());
                influxDBDataI.setIZero(dataI.getIZeroMax());
                influxDBDataI.setRms(dataI.getRmsMax());

                influxDBDataI.setI1(dataI.getI1Max());
                influxDBDataI.setI2(dataI.getI2Max());
                influxDBDataI.setI3(dataI.getI3Max());
                influxDBDataI.setI4(dataI.getI4Max());
                influxDBDataI.setI5(dataI.getI5Max());
                influxDBDataI.setI6(dataI.getI6Max());
                influxDBDataI.setI7(dataI.getI7Max());
                influxDBDataI.setI8(dataI.getI8Max());
                influxDBDataI.setI9(dataI.getI9Max());
                influxDBDataI.setI10(dataI.getI10Max());
                influxDBDataI.setI11(dataI.getI11Max());
                influxDBDataI.setI12(dataI.getI12Max());
                influxDBDataI.setI13(dataI.getI13Max());
                influxDBDataI.setI14(dataI.getI14Max());
                influxDBDataI.setI15(dataI.getI15Max());
                influxDBDataI.setI16(dataI.getI16Max());
                influxDBDataI.setI17(dataI.getI17Max());
                influxDBDataI.setI18(dataI.getI18Max());
                influxDBDataI.setI19(dataI.getI19Max());
                influxDBDataI.setI20(dataI.getI20Max());
                influxDBDataI.setI21(dataI.getI21Max());
                influxDBDataI.setI22(dataI.getI22Max());
                influxDBDataI.setI23(dataI.getI23Max());
                influxDBDataI.setI24(dataI.getI24Max());
                influxDBDataI.setI25(dataI.getI25Max());
                influxDBDataI.setI26(dataI.getI26Max());
                influxDBDataI.setI27(dataI.getI27Max());
                influxDBDataI.setI28(dataI.getI28Max());
                influxDBDataI.setI29(dataI.getI29Max());
                influxDBDataI.setI30(dataI.getI30Max());
                influxDBDataI.setI31(dataI.getI31Max());
                influxDBDataI.setI32(dataI.getI32Max());
                influxDBDataI.setI33(dataI.getI33Max());
                influxDBDataI.setI34(dataI.getI34Max());
                influxDBDataI.setI35(dataI.getI35Max());
                influxDBDataI.setI36(dataI.getI36Max());
                influxDBDataI.setI37(dataI.getI37Max());
                influxDBDataI.setI38(dataI.getI38Max());
                influxDBDataI.setI39(dataI.getI39Max());
                influxDBDataI.setI40(dataI.getI40Max());
                influxDBDataI.setI41(dataI.getI41Max());
                influxDBDataI.setI42(dataI.getI42Max());
                influxDBDataI.setI43(dataI.getI43Max());
                influxDBDataI.setI44(dataI.getI44Max());
                influxDBDataI.setI45(dataI.getI45Max());
                influxDBDataI.setI46(dataI.getI46Max());
                influxDBDataI.setI47(dataI.getI47Max());
                influxDBDataI.setI48(dataI.getI48Max());
                influxDBDataI.setI49(dataI.getI49Max());
                influxDBDataI.setI50(dataI.getI50Max());
            }
            else if (valueType.equals("MIN")){

                influxDBDataI.setINeg(dataI.getINegMin());
                influxDBDataI.setIPos(dataI.getIPosMin());
                influxDBDataI.setIThd(dataI.getIThdMin());
                influxDBDataI.setIUnbalance(dataI.getIUnbalanceMin());
                influxDBDataI.setIZero(dataI.getIZeroMin());
                influxDBDataI.setRms(dataI.getRmsMin());

                influxDBDataI.setI1(dataI.getI1Min());
                influxDBDataI.setI2(dataI.getI2Min());
                influxDBDataI.setI3(dataI.getI3Min());
                influxDBDataI.setI4(dataI.getI4Min());
                influxDBDataI.setI5(dataI.getI5Min());
                influxDBDataI.setI6(dataI.getI6Min());
                influxDBDataI.setI7(dataI.getI7Min());
                influxDBDataI.setI8(dataI.getI8Min());
                influxDBDataI.setI9(dataI.getI9Min());
                influxDBDataI.setI10(dataI.getI10Min());
                influxDBDataI.setI11(dataI.getI11Min());
                influxDBDataI.setI12(dataI.getI12Min());
                influxDBDataI.setI13(dataI.getI13Min());
                influxDBDataI.setI14(dataI.getI14Min());
                influxDBDataI.setI15(dataI.getI15Min());
                influxDBDataI.setI16(dataI.getI16Min());
                influxDBDataI.setI17(dataI.getI17Min());
                influxDBDataI.setI18(dataI.getI18Min());
                influxDBDataI.setI19(dataI.getI19Min());
                influxDBDataI.setI20(dataI.getI20Min());
                influxDBDataI.setI21(dataI.getI21Min());
                influxDBDataI.setI22(dataI.getI22Min());
                influxDBDataI.setI23(dataI.getI23Min());
                influxDBDataI.setI24(dataI.getI24Min());
                influxDBDataI.setI25(dataI.getI25Min());
                influxDBDataI.setI26(dataI.getI26Min());
                influxDBDataI.setI27(dataI.getI27Min());
                influxDBDataI.setI28(dataI.getI28Min());
                influxDBDataI.setI29(dataI.getI29Min());
                influxDBDataI.setI30(dataI.getI30Min());
                influxDBDataI.setI31(dataI.getI31Min());
                influxDBDataI.setI32(dataI.getI32Min());
                influxDBDataI.setI33(dataI.getI33Min());
                influxDBDataI.setI34(dataI.getI34Min());
                influxDBDataI.setI35(dataI.getI35Min());
                influxDBDataI.setI36(dataI.getI36Min());
                influxDBDataI.setI37(dataI.getI37Min());
                influxDBDataI.setI38(dataI.getI38Min());
                influxDBDataI.setI39(dataI.getI39Min());
                influxDBDataI.setI40(dataI.getI40Min());
                influxDBDataI.setI41(dataI.getI41Min());
                influxDBDataI.setI42(dataI.getI42Min());
                influxDBDataI.setI43(dataI.getI43Min());
                influxDBDataI.setI44(dataI.getI44Min());
                influxDBDataI.setI45(dataI.getI45Min());
                influxDBDataI.setI46(dataI.getI46Min());
                influxDBDataI.setI47(dataI.getI47Min());
                influxDBDataI.setI48(dataI.getI48Min());
                influxDBDataI.setI49(dataI.getI49Min());
                influxDBDataI.setI50(dataI.getI50Min());
            }
            else if (valueType.equals("CP95")){
                influxDBDataI.setINeg(dataI.getINegCp95());
                influxDBDataI.setIPos(dataI.getIPosCp95());
                influxDBDataI.setIThd(dataI.getIThdCp95());
                influxDBDataI.setIUnbalance(dataI.getIUnbalanceCp95());
                influxDBDataI.setIZero(dataI.getIZeroCp95());
                influxDBDataI.setRms(dataI.getRmsCp95());

                influxDBDataI.setI1(dataI.getI1Cp95());
                influxDBDataI.setI2(dataI.getI2Cp95());
                influxDBDataI.setI3(dataI.getI3Cp95());
                influxDBDataI.setI4(dataI.getI4Cp95());
                influxDBDataI.setI5(dataI.getI5Cp95());
                influxDBDataI.setI6(dataI.getI6Cp95());
                influxDBDataI.setI7(dataI.getI7Cp95());
                influxDBDataI.setI8(dataI.getI8Cp95());
                influxDBDataI.setI9(dataI.getI9Cp95());
                influxDBDataI.setI10(dataI.getI10Cp95());
                influxDBDataI.setI11(dataI.getI11Cp95());
                influxDBDataI.setI12(dataI.getI12Cp95());
                influxDBDataI.setI13(dataI.getI13Cp95());
                influxDBDataI.setI14(dataI.getI14Cp95());
                influxDBDataI.setI15(dataI.getI15Cp95());
                influxDBDataI.setI16(dataI.getI16Cp95());
                influxDBDataI.setI17(dataI.getI17Cp95());
                influxDBDataI.setI18(dataI.getI18Cp95());
                influxDBDataI.setI19(dataI.getI19Cp95());
                influxDBDataI.setI20(dataI.getI20Cp95());
                influxDBDataI.setI21(dataI.getI21Cp95());
                influxDBDataI.setI22(dataI.getI22Cp95());
                influxDBDataI.setI23(dataI.getI23Cp95());
                influxDBDataI.setI24(dataI.getI24Cp95());
                influxDBDataI.setI25(dataI.getI25Cp95());
                influxDBDataI.setI26(dataI.getI26Cp95());
                influxDBDataI.setI27(dataI.getI27Cp95());
                influxDBDataI.setI28(dataI.getI28Cp95());
                influxDBDataI.setI29(dataI.getI29Cp95());
                influxDBDataI.setI30(dataI.getI30Cp95());
                influxDBDataI.setI31(dataI.getI31Cp95());
                influxDBDataI.setI32(dataI.getI32Cp95());
                influxDBDataI.setI33(dataI.getI33Cp95());
                influxDBDataI.setI34(dataI.getI34Cp95());
                influxDBDataI.setI35(dataI.getI35Cp95());
                influxDBDataI.setI36(dataI.getI36Cp95());
                influxDBDataI.setI37(dataI.getI37Cp95());
                influxDBDataI.setI38(dataI.getI38Cp95());
                influxDBDataI.setI39(dataI.getI39Cp95());
                influxDBDataI.setI40(dataI.getI40Cp95());
                influxDBDataI.setI41(dataI.getI41Cp95());
                influxDBDataI.setI42(dataI.getI42Cp95());
                influxDBDataI.setI43(dataI.getI43Cp95());
                influxDBDataI.setI44(dataI.getI44Cp95());
                influxDBDataI.setI45(dataI.getI45Cp95());
                influxDBDataI.setI46(dataI.getI46Cp95());
                influxDBDataI.setI47(dataI.getI47Cp95());
                influxDBDataI.setI48(dataI.getI48Cp95());
                influxDBDataI.setI49(dataI.getI49Cp95());
                influxDBDataI.setI50(dataI.getI50Cp95());
            }

            influxDBDataIList.add(influxDBDataI);

        }



        return influxDBDataIList;
    }

}
