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.DataV;
import lombok.Data;
import org.influxdb.annotation.Column;
import org.influxdb.annotation.Measurement;
import org.influxdb.annotation.TimeColumn;
import org.springframework.beans.BeanUtils;

import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/4/7 10:00
 */
@Data
@Measurement(name = "data_v")
public class InfluxDBDataV {

    @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 phasicType;

    @Column(name = "value_type",tag = true)
    private String valueType;


    @Column(name = "v_neg")
    private Float vNeg;

    @Column(name = "v_pos")
    private Float vPos;

    @Column(name = "v_thd")
    private Float vThd;

    @Column(name = "v_unbalance")
    private Float vUnbalance;

    @Column(name = "v_zero")
    private Float vZero;


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

    @Column(name = "freq_dev")
    private Float freqDev;

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

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

    @Column(name = "rms_lvr")
    private Float rmsLvr;

    @Column(name = "vl_dev")
    private Float vlDev;

    @Column(name = "vu_dev")
    private Float vuDev;


    @Column(name = "v_1")
    private Float v1;

    @Column(name = "v_2")
    private Float v2;

    @Column(name = "v_3")
    private Float v3;

    @Column(name = "v_4")
    private Float v4;

    @Column(name = "v_5")
    private Float v5;

    @Column(name = "v_6")
    private Float v6;

    @Column(name = "v_7")
    private Float v7;

    @Column(name = "v_8")
    private Float v8;

    @Column(name = "v_9")
    private Float v9;

    @Column(name = "v_10")
    private Float v10;

    @Column(name = "v_11")
    private Float v11;

    @Column(name = "v_12")
    private Float v12;

    @Column(name = "v_13")
    private Float v13;

    @Column(name = "v_14")
    private Float v14;

    @Column(name = "v_15")
    private Float v15;

    @Column(name = "v_16")
    private Float v16;

    @Column(name = "v_17")
    private Float v17;

    @Column(name = "v_18")
    private Float v18;

    @Column(name = "v_19")
    private Float v19;

    @Column(name = "v_20")
    private Float v20;

    @Column(name = "v_21")
    private Float v21;

    @Column(name = "v_22")
    private Float v22;

    @Column(name = "v_23")
    private Float v23;

    @Column(name = "v_24")
    private Float v24;

    @Column(name = "v_25")
    private Float v25;

    @Column(name = "v_26")
    private Float v26;

    @Column(name = "v_27")
    private Float v27;

    @Column(name = "v_28")
    private Float v28;

    @Column(name = "v_29")
    private Float v29;

    @Column(name = "v_30")
    private Float v30;

    @Column(name = "v_31")
    private Float v31;

    @Column(name = "v_32")
    private Float v32;

    @Column(name = "v_33")
    private Float v33;

    @Column(name = "v_34")
    private Float v34;

    @Column(name = "v_35")
    private Float v35;

    @Column(name = "v_36")
    private Float v36;

    @Column(name = "v_37")
    private Float v37;

    @Column(name = "v_38")
    private Float v38;

    @Column(name = "v_39")
    private Float v39;

    @Column(name = "v_40")
    private Float v40;

    @Column(name = "v_41")
    private Float v41;

    @Column(name = "v_42")
    private Float v42;

    @Column(name = "v_43")
    private Float v43;

    @Column(name = "v_44")
    private Float v44;

    @Column(name = "v_45")
    private Float v45;

    @Column(name = "v_46")
    private Float v46;

    @Column(name = "v_47")
    private Float v47;

    @Column(name = "v_48")
    private Float v48;

    @Column(name = "v_49")
    private Float v49;

    @Column(name = "v_50")
    private Float v50;

    public static List<InfluxDBDataV> oralceToInfluxDB(DataV dataV) {
        if (dataV == null) {
            return null;
        }

        List<InfluxDBDataV> influxDBDataVList = new ArrayList<>();
        List<String> valueTypeList = Stream.of("AVG", "MAX", "MIN", "CP95").collect(Collectors.toList());
        for (String valueType : valueTypeList) {
                InfluxDBDataV influxDBDataV = new InfluxDBDataV();
                Instant instant = dataV.getTimeid().atZone(ZoneId.systemDefault()).toInstant();

                influxDBDataV.setTime(instant);
                influxDBDataV.setLineId(dataV.getLineid());
                influxDBDataV.setPhasicType(dataV.getPhasicType());
                influxDBDataV.setQualityFlag(dataV.getQualityflag()+"");
                influxDBDataV.setValueType(valueType);
                //T相时特殊处理RmsLvr将Rmsab，Rmsbc，Rmsca转纯的abc3相里
                if(Objects.equals(dataV.getPhasicType(),"T")){

                    InfluxDBDataV influxDBDataVA = new InfluxDBDataV();
                    BeanUtils.copyProperties(influxDBDataV,influxDBDataVA);
                    InfluxDBDataV influxDBDataVB = new InfluxDBDataV();
                    BeanUtils.copyProperties(influxDBDataV,influxDBDataVB);
                    InfluxDBDataV influxDBDataVC = new InfluxDBDataV();
                    BeanUtils.copyProperties(influxDBDataV,influxDBDataVC);
                    influxDBDataVA.setPhasicType("A");
                    influxDBDataVB.setPhasicType("B");
                    influxDBDataVC.setPhasicType("C");


                    if (valueType.equals("AVG")) {
                        influxDBDataVA.setRmsLvr(dataV.getRmsab());

                        influxDBDataVB.setRmsLvr(dataV.getRmsbc());

                        influxDBDataVC.setRmsLvr(dataV.getRmsca());
                    }
                    else if (valueType.equals("MAX")){
                        influxDBDataVA.setRmsLvr(dataV.getRmsabMax());

                        influxDBDataVB.setRmsLvr(dataV.getRmsbcMax());

                        influxDBDataVC.setRmsLvr(dataV.getRmscaMax());

                    }
                    else if (valueType.equals("MIN")){
                        influxDBDataVA.setRmsLvr(dataV.getRmsabMin());
                        influxDBDataVB.setRmsLvr(dataV.getRmsbcMin());
                        influxDBDataVC.setRmsLvr(dataV.getRmscaMin());

                    }
                    else if (valueType.equals("CP95")){
                        influxDBDataVA.setRmsLvr(dataV.getRmsabCp95());

                        influxDBDataVB.setRmsLvr(dataV.getRmsbcCp95());

                        influxDBDataVC.setRmsLvr(dataV.getRmscaCp95());
                    }
                    influxDBDataVList.add(influxDBDataVA);
                    influxDBDataVList.add(influxDBDataVB);
                    influxDBDataVList.add(influxDBDataVC);


                }
                if (valueType.equals("AVG")) {

                    influxDBDataV.setVNeg(dataV.getVNeg());
                    influxDBDataV.setVPos(dataV.getVPos());
                    influxDBDataV.setVThd(dataV.getVThd());
                    influxDBDataV.setVUnbalance(dataV.getVUnbalance());
                    influxDBDataV.setVZero(dataV.getVZero());
                    influxDBDataV.setFreq(dataV.getFreq());
                    influxDBDataV.setFreqDev(dataV.getFreqDev());
                    influxDBDataV.setRms(dataV.getRms());
//                    influxDBDataV.setRmsLvr(dataV.getRmsab());
                    influxDBDataV.setVlDev(dataV.getVlDev());
                    influxDBDataV.setVuDev(dataV.getVuDev());




                    influxDBDataV.setV1(dataV.getV1());
                    influxDBDataV.setV2(dataV.getV2());
                    influxDBDataV.setV3(dataV.getV3());
                    influxDBDataV.setV4(dataV.getV4());
                    influxDBDataV.setV5(dataV.getV5());
                    influxDBDataV.setV6(dataV.getV6());
                    influxDBDataV.setV7(dataV.getV7());
                    influxDBDataV.setV8(dataV.getV8());
                    influxDBDataV.setV9(dataV.getV9());
                    influxDBDataV.setV10(dataV.getV10());
                    influxDBDataV.setV11(dataV.getV11());
                    influxDBDataV.setV12(dataV.getV12());
                    influxDBDataV.setV13(dataV.getV13());
                    influxDBDataV.setV14(dataV.getV14());
                    influxDBDataV.setV15(dataV.getV15());
                    influxDBDataV.setV16(dataV.getV16());
                    influxDBDataV.setV17(dataV.getV17());
                    influxDBDataV.setV18(dataV.getV18());
                    influxDBDataV.setV19(dataV.getV19());
                    influxDBDataV.setV20(dataV.getV20());
                    influxDBDataV.setV21(dataV.getV21());
                    influxDBDataV.setV22(dataV.getV22());
                    influxDBDataV.setV23(dataV.getV23());
                    influxDBDataV.setV24(dataV.getV24());
                    influxDBDataV.setV25(dataV.getV25());
                    influxDBDataV.setV26(dataV.getV26());
                    influxDBDataV.setV27(dataV.getV27());
                    influxDBDataV.setV28(dataV.getV28());
                    influxDBDataV.setV29(dataV.getV29());
                    influxDBDataV.setV30(dataV.getV30());
                    influxDBDataV.setV31(dataV.getV31());
                    influxDBDataV.setV32(dataV.getV32());
                    influxDBDataV.setV33(dataV.getV33());
                    influxDBDataV.setV34(dataV.getV34());
                    influxDBDataV.setV35(dataV.getV35());
                    influxDBDataV.setV36(dataV.getV36());
                    influxDBDataV.setV37(dataV.getV37());
                    influxDBDataV.setV38(dataV.getV38());
                    influxDBDataV.setV39(dataV.getV39());
                    influxDBDataV.setV40(dataV.getV40());
                    influxDBDataV.setV41(dataV.getV41());
                    influxDBDataV.setV42(dataV.getV42());
                    influxDBDataV.setV43(dataV.getV43());
                    influxDBDataV.setV44(dataV.getV44());
                    influxDBDataV.setV45(dataV.getV45());
                    influxDBDataV.setV46(dataV.getV46());
                    influxDBDataV.setV47(dataV.getV47());
                    influxDBDataV.setV48(dataV.getV48());
                    influxDBDataV.setV49(dataV.getV49());
                    influxDBDataV.setV50(dataV.getV50());
                }
                else if (valueType.equals("MAX")){

                    influxDBDataV.setVNeg(dataV.getVNegMax());
                    influxDBDataV.setVPos(dataV.getVPosMax());
                    influxDBDataV.setVThd(dataV.getVThdMax());
                    influxDBDataV.setVUnbalance(dataV.getVUnbalanceMax());
                    influxDBDataV.setVZero(dataV.getVZeroMax());
                    influxDBDataV.setFreq(dataV.getFreqMax());
                    influxDBDataV.setFreqDev(dataV.getFreqDevMax());
                    influxDBDataV.setRms(dataV.getRmsMax());
                    influxDBDataV.setVlDev(dataV.getVlDevMax());
                    influxDBDataV.setVuDev(dataV.getVuDevMax());

                    influxDBDataV.setV1(dataV.getV1Max());
                    influxDBDataV.setV2(dataV.getV2Max());
                    influxDBDataV.setV3(dataV.getV3Max());
                    influxDBDataV.setV4(dataV.getV4Max());
                    influxDBDataV.setV5(dataV.getV5Max());
                    influxDBDataV.setV6(dataV.getV6Max());
                    influxDBDataV.setV7(dataV.getV7Max());
                    influxDBDataV.setV8(dataV.getV8Max());
                    influxDBDataV.setV9(dataV.getV9Max());
                    influxDBDataV.setV10(dataV.getV10Max());
                    influxDBDataV.setV11(dataV.getV11Max());
                    influxDBDataV.setV12(dataV.getV12Max());
                    influxDBDataV.setV13(dataV.getV13Max());
                    influxDBDataV.setV14(dataV.getV14Max());
                    influxDBDataV.setV15(dataV.getV15Max());
                    influxDBDataV.setV16(dataV.getV16Max());
                    influxDBDataV.setV17(dataV.getV17Max());
                    influxDBDataV.setV18(dataV.getV18Max());
                    influxDBDataV.setV19(dataV.getV19Max());
                    influxDBDataV.setV20(dataV.getV20Max());
                    influxDBDataV.setV21(dataV.getV21Max());
                    influxDBDataV.setV22(dataV.getV22Max());
                    influxDBDataV.setV23(dataV.getV23Max());
                    influxDBDataV.setV24(dataV.getV24Max());
                    influxDBDataV.setV25(dataV.getV25Max());
                    influxDBDataV.setV26(dataV.getV26Max());
                    influxDBDataV.setV27(dataV.getV27Max());
                    influxDBDataV.setV28(dataV.getV28Max());
                    influxDBDataV.setV29(dataV.getV29Max());
                    influxDBDataV.setV30(dataV.getV30Max());
                    influxDBDataV.setV31(dataV.getV31Max());
                    influxDBDataV.setV32(dataV.getV32Max());
                    influxDBDataV.setV33(dataV.getV33Max());
                    influxDBDataV.setV34(dataV.getV34Max());
                    influxDBDataV.setV35(dataV.getV35Max());
                    influxDBDataV.setV36(dataV.getV36Max());
                    influxDBDataV.setV37(dataV.getV37Max());
                    influxDBDataV.setV38(dataV.getV38Max());
                    influxDBDataV.setV39(dataV.getV39Max());
                    influxDBDataV.setV40(dataV.getV40Max());
                    influxDBDataV.setV41(dataV.getV41Max());
                    influxDBDataV.setV42(dataV.getV42Max());
                    influxDBDataV.setV43(dataV.getV43Max());
                    influxDBDataV.setV44(dataV.getV44Max());
                    influxDBDataV.setV45(dataV.getV45Max());
                    influxDBDataV.setV46(dataV.getV46Max());
                    influxDBDataV.setV47(dataV.getV47Max());
                    influxDBDataV.setV48(dataV.getV48Max());
                    influxDBDataV.setV49(dataV.getV49Max());
                    influxDBDataV.setV50(dataV.getV50Max());
                }
                else if (valueType.equals("MIN")){

                    influxDBDataV.setVNeg(dataV.getVNegMin());
                    influxDBDataV.setVPos(dataV.getVPosMin());
                    influxDBDataV.setVThd(dataV.getVThdMin());
                    influxDBDataV.setVUnbalance(dataV.getVUnbalanceMin());
                    influxDBDataV.setVZero(dataV.getVZeroMin());
                    influxDBDataV.setFreq(dataV.getFreqMin());
                    influxDBDataV.setFreqDev(dataV.getFreqDevMin());
                    influxDBDataV.setRms(dataV.getRmsMin());
                    influxDBDataV.setVlDev(dataV.getVlDevMin());
                    influxDBDataV.setVuDev(dataV.getVuDevMin());

                    influxDBDataV.setV1(dataV.getV1Min());
                    influxDBDataV.setV2(dataV.getV2Min());
                    influxDBDataV.setV3(dataV.getV3Min());
                    influxDBDataV.setV4(dataV.getV4Min());
                    influxDBDataV.setV5(dataV.getV5Min());
                    influxDBDataV.setV6(dataV.getV6Min());
                    influxDBDataV.setV7(dataV.getV7Min());
                    influxDBDataV.setV8(dataV.getV8Min());
                    influxDBDataV.setV9(dataV.getV9Min());
                    influxDBDataV.setV10(dataV.getV10Min());
                    influxDBDataV.setV11(dataV.getV11Min());
                    influxDBDataV.setV12(dataV.getV12Min());
                    influxDBDataV.setV13(dataV.getV13Min());
                    influxDBDataV.setV14(dataV.getV14Min());
                    influxDBDataV.setV15(dataV.getV15Min());
                    influxDBDataV.setV16(dataV.getV16Min());
                    influxDBDataV.setV17(dataV.getV17Min());
                    influxDBDataV.setV18(dataV.getV18Min());
                    influxDBDataV.setV19(dataV.getV19Min());
                    influxDBDataV.setV20(dataV.getV20Min());
                    influxDBDataV.setV21(dataV.getV21Min());
                    influxDBDataV.setV22(dataV.getV22Min());
                    influxDBDataV.setV23(dataV.getV23Min());
                    influxDBDataV.setV24(dataV.getV24Min());
                    influxDBDataV.setV25(dataV.getV25Min());
                    influxDBDataV.setV26(dataV.getV26Min());
                    influxDBDataV.setV27(dataV.getV27Min());
                    influxDBDataV.setV28(dataV.getV28Min());
                    influxDBDataV.setV29(dataV.getV29Min());
                    influxDBDataV.setV30(dataV.getV30Min());
                    influxDBDataV.setV31(dataV.getV31Min());
                    influxDBDataV.setV32(dataV.getV32Min());
                    influxDBDataV.setV33(dataV.getV33Min());
                    influxDBDataV.setV34(dataV.getV34Min());
                    influxDBDataV.setV35(dataV.getV35Min());
                    influxDBDataV.setV36(dataV.getV36Min());
                    influxDBDataV.setV37(dataV.getV37Min());
                    influxDBDataV.setV38(dataV.getV38Min());
                    influxDBDataV.setV39(dataV.getV39Min());
                    influxDBDataV.setV40(dataV.getV40Min());
                    influxDBDataV.setV41(dataV.getV41Min());
                    influxDBDataV.setV42(dataV.getV42Min());
                    influxDBDataV.setV43(dataV.getV43Min());
                    influxDBDataV.setV44(dataV.getV44Min());
                    influxDBDataV.setV45(dataV.getV45Min());
                    influxDBDataV.setV46(dataV.getV46Min());
                    influxDBDataV.setV47(dataV.getV47Min());
                    influxDBDataV.setV48(dataV.getV48Min());
                    influxDBDataV.setV49(dataV.getV49Min());
                    influxDBDataV.setV50(dataV.getV50Min());
                }
                else if (valueType.equals("CP95")){

                    influxDBDataV.setVNeg(dataV.getVNegCp95());
                    influxDBDataV.setVPos(dataV.getVPosCp95());
                    influxDBDataV.setVThd(dataV.getVThdCp95());
                    influxDBDataV.setVUnbalance(dataV.getVUnbalanceCp95());
                    influxDBDataV.setVZero(dataV.getVZeroCp95());
                    influxDBDataV.setFreq(dataV.getFreqCp95());
                    influxDBDataV.setFreqDev(dataV.getFreqDevCp95());
                    influxDBDataV.setRms(dataV.getRmsCp95());
                    influxDBDataV.setVlDev(dataV.getVlDevCp95());
                    influxDBDataV.setVuDev(dataV.getVuDevCp95());

                    influxDBDataV.setV1(dataV.getV1Cp95());
                    influxDBDataV.setV2(dataV.getV2Cp95());
                    influxDBDataV.setV3(dataV.getV3Cp95());
                    influxDBDataV.setV4(dataV.getV4Cp95());
                    influxDBDataV.setV5(dataV.getV5Cp95());
                    influxDBDataV.setV6(dataV.getV6Cp95());
                    influxDBDataV.setV7(dataV.getV7Cp95());
                    influxDBDataV.setV8(dataV.getV8Cp95());
                    influxDBDataV.setV9(dataV.getV9Cp95());
                    influxDBDataV.setV10(dataV.getV10Cp95());
                    influxDBDataV.setV11(dataV.getV11Cp95());
                    influxDBDataV.setV12(dataV.getV12Cp95());
                    influxDBDataV.setV13(dataV.getV13Cp95());
                    influxDBDataV.setV14(dataV.getV14Cp95());
                    influxDBDataV.setV15(dataV.getV15Cp95());
                    influxDBDataV.setV16(dataV.getV16Cp95());
                    influxDBDataV.setV17(dataV.getV17Cp95());
                    influxDBDataV.setV18(dataV.getV18Cp95());
                    influxDBDataV.setV19(dataV.getV19Cp95());
                    influxDBDataV.setV20(dataV.getV20Cp95());
                    influxDBDataV.setV21(dataV.getV21Cp95());
                    influxDBDataV.setV22(dataV.getV22Cp95());
                    influxDBDataV.setV23(dataV.getV23Cp95());
                    influxDBDataV.setV24(dataV.getV24Cp95());
                    influxDBDataV.setV25(dataV.getV25Cp95());
                    influxDBDataV.setV26(dataV.getV26Cp95());
                    influxDBDataV.setV27(dataV.getV27Cp95());
                    influxDBDataV.setV28(dataV.getV28Cp95());
                    influxDBDataV.setV29(dataV.getV29Cp95());
                    influxDBDataV.setV30(dataV.getV30Cp95());
                    influxDBDataV.setV31(dataV.getV31Cp95());
                    influxDBDataV.setV32(dataV.getV32Cp95());
                    influxDBDataV.setV33(dataV.getV33Cp95());
                    influxDBDataV.setV34(dataV.getV34Cp95());
                    influxDBDataV.setV35(dataV.getV35Cp95());
                    influxDBDataV.setV36(dataV.getV36Cp95());
                    influxDBDataV.setV37(dataV.getV37Cp95());
                    influxDBDataV.setV38(dataV.getV38Cp95());
                    influxDBDataV.setV39(dataV.getV39Cp95());
                    influxDBDataV.setV40(dataV.getV40Cp95());
                    influxDBDataV.setV41(dataV.getV41Cp95());
                    influxDBDataV.setV42(dataV.getV42Cp95());
                    influxDBDataV.setV43(dataV.getV43Cp95());
                    influxDBDataV.setV44(dataV.getV44Cp95());
                    influxDBDataV.setV45(dataV.getV45Cp95());
                    influxDBDataV.setV46(dataV.getV46Cp95());
                    influxDBDataV.setV47(dataV.getV47Cp95());
                    influxDBDataV.setV48(dataV.getV48Cp95());
                    influxDBDataV.setV49(dataV.getV49Cp95());
                    influxDBDataV.setV50(dataV.getV50Cp95());
                }




                influxDBDataVList.add(influxDBDataV);

            }





        return influxDBDataVList;
    }



}
