package com.njcn.prepare.harmonic.service.mysql.Impl.line;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.dto.SimpleDTO;
import com.njcn.common.pojo.enums.common.ServerEnum;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.prepare.harmonic.mapper.mysql.line.AbnormalMapper;
import com.njcn.prepare.harmonic.pojo.mysql.po.line.MpSurplusAbnormalD;
import com.njcn.prepare.harmonic.pojo.param.LineParam;
import com.njcn.prepare.harmonic.service.mysql.line.NormalLimitService;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.po.Dept;
import lombok.AllArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @author denghuajun
 * @version 1.0.0
 * @date 2022年10月17日 19:59
 */

@Service
@AllArgsConstructor
public class NormalLimitServiceImpl extends ServiceImpl<AbnormalMapper, MpSurplusAbnormalD> implements NormalLimitService {

    private final GeneralDeviceInfoClient generalDeviceInfoClient;

    private final LineFeignClient lineFeignClient;

    private final InfluxDbUtils influxDbUtils;

    private final DeptFeignClient deptFeignClient;



    @Override
    @Async("asyncExecutor")
    public Boolean AbnormalLineData(LineParam lineParam) {

        List<String> lineIds = new ArrayList<>();
        List<MpSurplusAbnormalD> all = new ArrayList<>();


        if (CollectionUtils.isEmpty(lineParam.getLineIds())) {
            Dept dept = deptFeignClient.getRootDept().getData();
            DeviceInfoParam deviceInfoParam = new DeviceInfoParam();
            deviceInfoParam.setDeptIndex(dept.getId());
            deviceInfoParam.setPowerFlag(2);
            deviceInfoParam.setMonitorFlag(2);
            deviceInfoParam.setServerName(ServerEnum.HARMONIC.getName());
            SimpleDTO simpleDTO = new SimpleDTO();
            simpleDTO.setName("电网拓扑");
            simpleDTO.setSort(0);
            simpleDTO.setCode("Power_Network");
            deviceInfoParam.setStatisticalType(simpleDTO);
            //处理监测点
            List<GeneralDeviceDTO> deviceDataList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
            for (GeneralDeviceDTO generalDeviceDTO : deviceDataList) {
                lineIds.addAll(generalDeviceDTO.getLineIndexes());
            }
        } else {
            //不为空则为补招
            lineIds.addAll(lineParam.getLineIds());

        }
        String lastSql = " and time>='" + lineParam.getDataDate() + InfluxDBPublicParam.START_TIME + "' and time <='" + lineParam.getDataDate() + InfluxDBPublicParam.END_TIME + "'";
        if (!lineIds.isEmpty()) {
            for (String lineIndex : lineIds) {
                //获取当前监测点的限值详情
                Overlimit overlimit = lineFeignClient.getOverLimitData(lineIndex).getData();

                String phasic = "";
                for (int phase = 1; phase < 5; phase++) {
                    switch (phase) {
                        case 1:
                            phasic = "A";
                            break;
                        case 2:
                            phasic = "B";
                            break;
                        case 3:
                            phasic = "C";
                            break;
                        case 4:
                            phasic = "T";
                            break;
                    }


                    MpSurplusAbnormalD mpSurplusAbnormalD = new MpSurplusAbnormalD();
                    mpSurplusAbnormalD.setPhasicType(phasic);
                    mpSurplusAbnormalD.setValueType("CP95");
                    mpSurplusAbnormalD.setId(lineIndex);
                    mpSurplusAbnormalD.setTimeId(LocalDateTime.parse(lineParam.getDataDate() + InfluxDBPublicParam.START_TIME, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));


                    MpSurplusAbnormalD mpSurplusAbnormalDMax = new MpSurplusAbnormalD();
                    mpSurplusAbnormalDMax.setPhasicType(phasic);
                    mpSurplusAbnormalDMax.setValueType("MAX");
                    mpSurplusAbnormalDMax.setId(lineIndex);
                    mpSurplusAbnormalDMax.setTimeId(LocalDateTime.parse(lineParam.getDataDate() + InfluxDBPublicParam.START_TIME, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));


                    MpSurplusAbnormalD mpSurplusAbnormalDMin = new MpSurplusAbnormalD();
                    mpSurplusAbnormalDMin.setPhasicType(phasic);
                    mpSurplusAbnormalDMin.setValueType("MIN");
                    mpSurplusAbnormalDMin.setId(lineIndex);
                    mpSurplusAbnormalDMin.setTimeId(LocalDateTime.parse(lineParam.getDataDate() + InfluxDBPublicParam.START_TIME, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));


                    MpSurplusAbnormalD mpSurplusAbnormalDAvg = new MpSurplusAbnormalD();
                    mpSurplusAbnormalDAvg.setPhasicType(phasic);
                    mpSurplusAbnormalDAvg.setValueType("AVG");
                    mpSurplusAbnormalDAvg.setId(lineIndex);
                    mpSurplusAbnormalDAvg.setTimeId(LocalDateTime.parse(lineParam.getDataDate() + InfluxDBPublicParam.START_TIME, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

                    //判断标识 true:没有异常 false:存在异常
                    Boolean flag = true;

                    /*2-25次谐波电压含有率*/
                    String bang = " where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic+"' ";
                    StringBuilder tem = new StringBuilder();
                    for (int i = 2; i < 26; i++) {
                        if (i == 25) {
                            tem.append("MAX(v_").append(i).append(") as ").append("v_").append(i);
                        } else {
                            tem.append("MAX(v_").append(i).append(") as ").append("v_").append(i).append(",");
                        }
                    }
                    String sql = "select " + tem + " from data_harmrate_v "+ bang + " and value_type = 'CP95'"+InfluxDBPublicParam.TIME_ZONE;
                    List<Map<String, Object>> mapList = influxDbUtils.getMapResult(sql);
                    if (CollUtil.isNotEmpty(mapList)) {
                        List<String> useList = new ArrayList<>();
                        Float i2 = compareToOver(overlimit.getUharm2(), Float.parseFloat(mapList.get(0).get("v_2").toString()), flag);
                        if (Objects.nonNull(i2)) {
                            mpSurplusAbnormalD.setUharm2(i2);
                            useList.add("v_2");

                        }
                        Float i3 = compareToOver(overlimit.getUharm3(), Float.parseFloat(mapList.get(0).get("v_3").toString()), flag);
                        if (Objects.nonNull(i3)) {
                            mpSurplusAbnormalD.setUharm3(i3);
                            useList.add("v_3");
                        }
                        Float i4 = compareToOver(overlimit.getUharm4(), Float.parseFloat(mapList.get(0).get("v_4").toString()), flag);
                        if (Objects.nonNull(i4)) {
                            mpSurplusAbnormalD.setUharm4(i4);
                        }
                        Float i5 = compareToOver(overlimit.getUharm5(), Float.parseFloat(mapList.get(0).get("v_5").toString()), flag);
                        if (Objects.nonNull(i5)) {
                            mpSurplusAbnormalD.setUharm5(i5);
                            useList.add("v_5");
                        }
                        Float i6 = compareToOver(overlimit.getUharm6(), Float.parseFloat(mapList.get(0).get("v_6").toString()), flag);
                        if (Objects.nonNull(i6)) {
                            mpSurplusAbnormalD.setUharm6(i6);
                            useList.add("v_6");
                        }
                        Float i7 = compareToOver(overlimit.getUharm7(), Float.parseFloat(mapList.get(0).get("v_7").toString()), flag);
                        if (Objects.nonNull(i7)) {
                            mpSurplusAbnormalD.setUharm7(i7);
                            useList.add("v_7");
                        }
                        Float i8 = compareToOver(overlimit.getUharm8(), Float.parseFloat(mapList.get(0).get("v_8").toString()), flag);
                        if (Objects.nonNull(i8)) {
                            mpSurplusAbnormalD.setUharm8(i8);
                            useList.add("v_8");
                        }
                        Float i9 = compareToOver(overlimit.getUharm9(), Float.parseFloat(mapList.get(0).get("v_9").toString()), flag);
                        if (Objects.nonNull(i9)) {
                            mpSurplusAbnormalD.setUharm9(i9);
                            useList.add("v_9");
                        }
                        Float i10 = compareToOver(overlimit.getUharm10(), Float.parseFloat(mapList.get(0).get("v_10").toString()), flag);
                        if (Objects.nonNull(i10)) {
                            mpSurplusAbnormalD.setUharm10(i10);
                            useList.add("v_10");
                        }
                        Float i11 = compareToOver(overlimit.getUharm11(), Float.parseFloat(mapList.get(0).get("v_11").toString()), flag);
                        if (Objects.nonNull(i11)) {
                            mpSurplusAbnormalD.setUharm11(i11);
                            useList.add("v_11");
                        }
                        Float i12 = compareToOver(overlimit.getUharm12(), Float.parseFloat(mapList.get(0).get("v_12").toString()), flag);
                        if (Objects.nonNull(i12)) {
                            mpSurplusAbnormalD.setUharm12(i12);
                            useList.add("v_12");
                        }
                        Float i13 = compareToOver(overlimit.getUharm13(), Float.parseFloat(mapList.get(0).get("v_13").toString()), flag);
                        if (Objects.nonNull(i13)) {
                            mpSurplusAbnormalD.setUharm13(i13);
                            useList.add("v_13");
                        }
                        Float i14 = compareToOver(overlimit.getUharm14(), Float.parseFloat(mapList.get(0).get("v_14").toString()), flag);
                        if (Objects.nonNull(i14)) {
                            mpSurplusAbnormalD.setUharm14(i14);
                            useList.add("v_14");
                        }
                        Float i15 = compareToOver(overlimit.getUharm15(), Float.parseFloat(mapList.get(0).get("v_15").toString()), flag);
                        if (Objects.nonNull(i15)) {
                            mpSurplusAbnormalD.setUharm15(i15);
                            useList.add("v_15");
                        }
                        Float i16 = compareToOver(overlimit.getUharm16(), Float.parseFloat(mapList.get(0).get("v_16").toString()), flag);
                        if (Objects.nonNull(i16)) {
                            mpSurplusAbnormalD.setUharm16(i16);
                            useList.add("v_16");
                        }
                        Float i17 = compareToOver(overlimit.getUharm17(), Float.parseFloat(mapList.get(0).get("v_17").toString()), flag);
                        if (Objects.nonNull(i17)) {
                            mpSurplusAbnormalD.setUharm17(i17);
                            useList.add("v_17");
                        }
                        Float i18 = compareToOver(overlimit.getUharm18(), Float.parseFloat(mapList.get(0).get("v_18").toString()), flag);
                        if (Objects.nonNull(i18)) {
                            mpSurplusAbnormalD.setUharm18(i18);
                            useList.add("v_18");
                        }
                        Float i19 = compareToOver(overlimit.getUharm19(), Float.parseFloat(mapList.get(0).get("v_19").toString()), flag);
                        if (Objects.nonNull(i19)) {
                            mpSurplusAbnormalD.setUharm19(i19);
                            useList.add("v_19");
                        }
                        Float i20 = compareToOver(overlimit.getUharm20(), Float.parseFloat(mapList.get(0).get("v_20").toString()), flag);
                        if (Objects.nonNull(i20)) {
                            mpSurplusAbnormalD.setUharm20(i20);
                            useList.add("v_20");
                        }
                        Float i21 = compareToOver(overlimit.getUharm21(), Float.parseFloat(mapList.get(0).get("v_21").toString()), flag);
                        if (Objects.nonNull(i21)) {
                            mpSurplusAbnormalD.setUharm3(i21);
                        }
                        Float i22 = compareToOver(overlimit.getUharm22(), Float.parseFloat(mapList.get(0).get("v_22").toString()), flag);
                        if (Objects.nonNull(i22)) {
                            mpSurplusAbnormalD.setUharm22(i22);
                            useList.add("v_22");
                        }
                        Float i23 = compareToOver(overlimit.getUharm23(), Float.parseFloat(mapList.get(0).get("v_23").toString()), flag);
                        if (Objects.nonNull(i23)) {
                            mpSurplusAbnormalD.setUharm23(i23);
                            useList.add("v_23");
                        }
                        Float i24 = compareToOver(overlimit.getUharm24(), Float.parseFloat(mapList.get(0).get("v_24").toString()), flag);
                        if (Objects.nonNull(i24)) {
                            mpSurplusAbnormalD.setUharm2(i24);
                            useList.add("v_24");
                        }
                        Float i25 = compareToOver(overlimit.getUharm25(), Float.parseFloat(mapList.get(0).get("v_25").toString()), flag);
                        if (Objects.nonNull(i25)) {
                            mpSurplusAbnormalD.setUharm25(i25);
                            useList.add("v_25");
                        }

                        if (CollUtil.isNotEmpty(useList)) {
                            assTest(useList,bang,"data_harmrate_v",1,mpSurplusAbnormalDMax,mpSurplusAbnormalDMin,mpSurplusAbnormalDAvg);
                        }

                    }

                    /*2-25次谐波电流*/
                    StringBuilder tem1 = new StringBuilder();
                    for (int i = 2; i < 26; i++) {
                        if (i == 25) {
                            tem1.append("MAX(i_").append(i).append(") as ").append("i_").append(i);
                        } else {
                            tem1.append("MAX(i_").append(i).append(") as ").append("i_").append(i).append(",");
                        }
                    }
                    String sqlData_I = "select " + tem1 + " from data_i "+bang+ " and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                    List<Map<String, Object>> mapData_I = influxDbUtils.getMapResult(sqlData_I);

                    if (CollUtil.isNotEmpty(mapData_I)) {
                        List<String> useList = new ArrayList<>();
                        Float i2 = compareToOver(overlimit.getIharm2(), Float.parseFloat(mapData_I.get(0).get("i_2").toString()), flag);
                        if (Objects.nonNull(i2)) {
                            mpSurplusAbnormalD.setIharm2(i2);
                            useList.add("i_2");
                        }
                        Float i3 = compareToOver(overlimit.getIharm3(), Float.parseFloat(mapData_I.get(0).get("i_3").toString()), flag);
                        if (Objects.nonNull(i3)) {
                            mpSurplusAbnormalD.setIharm3(i3);
                            useList.add("i_3");
                        }
                        Float i4 = compareToOver(overlimit.getIharm4(), Float.parseFloat(mapData_I.get(0).get("i_4").toString()), flag);
                        if (Objects.nonNull(i4)) {
                            mpSurplusAbnormalD.setIharm4(i4);
                            useList.add("i_4");
                        }
                        Float i5 = compareToOver(overlimit.getIharm5(), Float.parseFloat(mapData_I.get(0).get("i_5").toString()), flag);
                        if (Objects.nonNull(i5)) {
                            mpSurplusAbnormalD.setIharm5(i5);
                            useList.add("i_5");
                        }
                        Float i6 = compareToOver(overlimit.getIharm6(), Float.parseFloat(mapData_I.get(0).get("i_6").toString()), flag);
                        if (Objects.nonNull(i6)) {
                            mpSurplusAbnormalD.setIharm6(i6);
                            useList.add("i_6");
                        }
                        Float i7 = compareToOver(overlimit.getIharm7(), Float.parseFloat(mapData_I.get(0).get("i_7").toString()), flag);
                        if (Objects.nonNull(i7)) {
                            mpSurplusAbnormalD.setIharm7(i7);
                            useList.add("i_7");
                        }
                        Float i8 = compareToOver(overlimit.getIharm8(), Float.parseFloat(mapData_I.get(0).get("i_8").toString()), flag);
                        if (Objects.nonNull(i8)) {
                            mpSurplusAbnormalD.setIharm8(i8);
                            useList.add("i_8");
                        }
                        Float i9 = compareToOver(overlimit.getIharm9(), Float.parseFloat(mapData_I.get(0).get("i_9").toString()), flag);
                        if (Objects.nonNull(i9)) {
                            mpSurplusAbnormalD.setIharm9(i9);
                            useList.add("i_9");
                        }
                        Float i10 = compareToOver(overlimit.getIharm10(), Float.parseFloat(mapData_I.get(0).get("i_10").toString()), flag);
                        if (Objects.nonNull(i10)) {
                            mpSurplusAbnormalD.setIharm10(i10);
                            useList.add("i_10");
                        }
                        Float i11 = compareToOver(overlimit.getIharm11(), Float.parseFloat(mapData_I.get(0).get("i_11").toString()), flag);
                        if (Objects.nonNull(i11)) {
                            mpSurplusAbnormalD.setIharm11(i11);
                            useList.add("i_11");
                        }
                        Float i12 = compareToOver(overlimit.getIharm12(), Float.parseFloat(mapData_I.get(0).get("i_12").toString()), flag);
                        if (Objects.nonNull(i12)) {
                            mpSurplusAbnormalD.setIharm12(i12);
                            useList.add("i_12");
                        }
                        Float i13 = compareToOver(overlimit.getIharm13(), Float.parseFloat(mapData_I.get(0).get("i_13").toString()), flag);
                        if (Objects.nonNull(i13)) {
                            mpSurplusAbnormalD.setIharm13(i13);
                            useList.add("i_13");
                        }
                        Float i14 = compareToOver(overlimit.getIharm14(), Float.parseFloat(mapData_I.get(0).get("i_14").toString()), flag);
                        if (Objects.nonNull(i14)) {
                            mpSurplusAbnormalD.setIharm14(i14);
                            useList.add("i_14");
                        }
                        Float i15 = compareToOver(overlimit.getIharm15(), Float.parseFloat(mapData_I.get(0).get("i_15").toString()), flag);
                        if (Objects.nonNull(i15)) {
                            mpSurplusAbnormalD.setIharm15(i15);
                            useList.add("i_15");
                        }
                        Float i16 = compareToOver(overlimit.getIharm16(), Float.parseFloat(mapData_I.get(0).get("i_16").toString()), flag);
                        if (Objects.nonNull(i16)) {
                            mpSurplusAbnormalD.setIharm16(i16);
                            useList.add("i_16");
                        }
                        Float i17 = compareToOver(overlimit.getIharm17(), Float.parseFloat(mapData_I.get(0).get("i_17").toString()), flag);
                        if (Objects.nonNull(i17)) {
                            mpSurplusAbnormalD.setIharm17(i17);
                            useList.add("i_17");
                        }
                        Float i18 = compareToOver(overlimit.getIharm18(), Float.parseFloat(mapData_I.get(0).get("i_18").toString()), flag);
                        if (Objects.nonNull(i18)) {
                            mpSurplusAbnormalD.setIharm18(i18);
                            useList.add("i_18");
                        }
                        Float i19 = compareToOver(overlimit.getIharm19(), Float.parseFloat(mapData_I.get(0).get("i_19").toString()), flag);
                        if (Objects.nonNull(i19)) {
                            mpSurplusAbnormalD.setIharm19(i19);
                            useList.add("i_19");
                        }
                        Float i20 = compareToOver(overlimit.getIharm20(), Float.parseFloat(mapData_I.get(0).get("i_20").toString()), flag);
                        if (Objects.nonNull(i20)) {
                            mpSurplusAbnormalD.setIharm20(i20);
                            useList.add("i_20");
                        }
                        Float i21 = compareToOver(overlimit.getIharm21(), Float.parseFloat(mapData_I.get(0).get("i_21").toString()), flag);
                        if (Objects.nonNull(i21)) {
                            mpSurplusAbnormalD.setIharm3(i21);
                            useList.add("i_21");
                        }
                        Float i22 = compareToOver(overlimit.getIharm22(), Float.parseFloat(mapData_I.get(0).get("i_22").toString()), flag);
                        if (Objects.nonNull(i22)) {
                            mpSurplusAbnormalD.setIharm22(i22);
                            useList.add("i_22");
                        }
                        Float i23 = compareToOver(overlimit.getIharm23(), Float.parseFloat(mapData_I.get(0).get("i_23").toString()), flag);
                        if (Objects.nonNull(i23)) {
                            mpSurplusAbnormalD.setIharm23(i23);
                            useList.add("i_23");
                        }
                        Float i24 = compareToOver(overlimit.getIharm24(), Float.parseFloat(mapData_I.get(0).get("i_24").toString()), flag);
                        if (Objects.nonNull(i24)) {
                            mpSurplusAbnormalD.setIharm2(i24);
                            useList.add("i_24");
                        }
                        Float i25 = compareToOver(overlimit.getIharm25(), Float.parseFloat(mapData_I.get(0).get("i_25").toString()), flag);
                        if (Objects.nonNull(i25)) {
                            mpSurplusAbnormalD.setIharm25(i25);
                            useList.add("i_25");
                        }

                        if (CollUtil.isNotEmpty(useList)) {
                            assTest(useList,bang,"data_i",2,mpSurplusAbnormalDMax,mpSurplusAbnormalDMin,mpSurplusAbnormalDAvg);
                        }
                    }


                    /*0.5-15.5次间谐波电压含有率*/
                    StringBuilder tem2 = new StringBuilder();
                    for (int i = 1; i < 17; i++) {
                        if (i == 16) {
                            tem2.append("MAX(i_").append(i).append(") as ").append("i_").append(i);
                        } else {
                            tem2.append("MAX(i_").append(i).append(") as ").append("i_").append(i).append(",");
                        }
                    }

                    String sqlData_Ih = "select " + tem2 + " from data_inharm_v "+bang+ " and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                    List<Map<String, Object>> mapData_Ih = influxDbUtils.getMapResult(sqlData_Ih);
                    if (CollUtil.isNotEmpty(mapData_Ih)) {
                        List<String> useList = new ArrayList<>();
                        Float i1 = compareToOver(overlimit.getInuharm2(), Float.parseFloat(mapData_Ih.get(0).get("v_1").toString()), flag);
                        if (Objects.nonNull(i1)) {
                            mpSurplusAbnormalD.setInuharm1(i1);
                            useList.add("v_1");
                        }
                        Float i2 = compareToOver(overlimit.getInuharm2(), Float.parseFloat(mapData_Ih.get(0).get("v_2").toString()), flag);
                        if (Objects.nonNull(i2)) {
                            mpSurplusAbnormalD.setInuharm2(i2);
                            useList.add("v_2");
                        }
                        Float i3 = compareToOver(overlimit.getInuharm3(), Float.parseFloat(mapData_Ih.get(0).get("v_3").toString()), flag);
                        if (Objects.nonNull(i3)) {
                            mpSurplusAbnormalD.setInuharm3(i3);
                            useList.add("v_3");
                        }
                        Float i4 = compareToOver(overlimit.getInuharm4(), Float.parseFloat(mapData_Ih.get(0).get("v_4").toString()), flag);
                        if (Objects.nonNull(i4)) {
                            mpSurplusAbnormalD.setInuharm4(i4);
                            useList.add("v_4");
                        }
                        Float i5 = compareToOver(overlimit.getInuharm5(), Float.parseFloat(mapData_Ih.get(0).get("v_5").toString()), flag);
                        if (Objects.nonNull(i5)) {
                            mpSurplusAbnormalD.setInuharm5(i5);
                            useList.add("v_5");
                        }

                        Float i6 = compareToOver(overlimit.getInuharm6(), Float.parseFloat(mapData_Ih.get(0).get("v_6").toString()), flag);
                        if (Objects.nonNull(i6)) {
                            mpSurplusAbnormalD.setInuharm6(i6);
                            useList.add("v_6");
                        }
                        Float i7 = compareToOver(overlimit.getInuharm7(), Float.parseFloat(mapData_Ih.get(0).get("v_7").toString()), flag);
                        if (Objects.nonNull(i7)) {
                            mpSurplusAbnormalD.setInuharm7(i7);
                            useList.add("v_7");
                        }
                        Float i8 = compareToOver(overlimit.getInuharm8(), Float.parseFloat(mapData_Ih.get(0).get("v_8").toString()), flag);
                        if (Objects.nonNull(i8)) {
                            mpSurplusAbnormalD.setInuharm8(i8);
                            useList.add("v_8");
                        }
                        Float i9 = compareToOver(overlimit.getInuharm9(), Float.parseFloat(mapData_Ih.get(0).get("v_9").toString()), flag);
                        if (Objects.nonNull(i9)) {
                            mpSurplusAbnormalD.setInuharm9(i9);
                            useList.add("v_9");
                        }
                        Float i10 = compareToOver(overlimit.getInuharm10(), Float.parseFloat(mapData_Ih.get(0).get("v_10").toString()), flag);
                        if (Objects.nonNull(i10)) {
                            mpSurplusAbnormalD.setInuharm10(i10);
                            useList.add("v_10");
                        }
                        Float i11 = compareToOver(overlimit.getInuharm11(), Float.parseFloat(mapData_Ih.get(0).get("v_11").toString()), flag);
                        if (Objects.nonNull(i11)) {
                            mpSurplusAbnormalD.setInuharm11(i11);
                            useList.add("v_11");
                        }
                        Float i12 = compareToOver(overlimit.getInuharm12(), Float.parseFloat(mapData_Ih.get(0).get("v_12").toString()), flag);
                        if (Objects.nonNull(i12)) {
                            mpSurplusAbnormalD.setInuharm12(i12);
                            useList.add("v_12");
                        }
                        Float i13 = compareToOver(overlimit.getInuharm13(), Float.parseFloat(mapData_Ih.get(0).get("v_13").toString()), flag);
                        if (Objects.nonNull(i13)) {
                            mpSurplusAbnormalD.setInuharm13(i13);
                            useList.add("v_13");
                        }
                        Float i14 = compareToOver(overlimit.getInuharm14(), Float.parseFloat(mapData_Ih.get(0).get("v_14").toString()), flag);
                        if (Objects.nonNull(i14)) {
                            mpSurplusAbnormalD.setInuharm14(i14);
                            useList.add("v_14");
                        }
                        Float i15 = compareToOver(overlimit.getInuharm15(), Float.parseFloat(mapData_Ih.get(0).get("v_15").toString()), flag);
                        if (Objects.nonNull(i15)) {
                            mpSurplusAbnormalD.setInuharm15(i15);
                            useList.add("v_15");
                        }
                        Float i16 = compareToOver(overlimit.getInuharm16(), Float.parseFloat(mapData_Ih.get(0).get("v_16").toString()), flag);
                        if (Objects.nonNull(i16)) {
                            mpSurplusAbnormalD.setInuharm16(i16);
                            useList.add("v_16");
                        }

                        if (CollUtil.isNotEmpty(useList)) {
                            assTest(useList,bang,"data_inharm_v",3,mpSurplusAbnormalDMax,mpSurplusAbnormalDMin,mpSurplusAbnormalDAvg);
                        }
                    }


                    /*电压总谐波畸变率*/
                    String sqlData_Vthd = "select MAX(v_thd) as v_thd from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                    List<Map<String, Object>> mapData_Vthd = influxDbUtils.getMapResult(sqlData_Vthd);
                    if (CollUtil.isNotEmpty(mapData_Vthd)) {
                        float thd = Float.parseFloat(mapData_Vthd.get(0).get("v_thd").toString());
                        if (thd > overlimit.getUaberrance()) {
                            mpSurplusAbnormalD.setUaberrance(thd);

                            String vthMax = "select MAX(v_thd) as v_thd from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMax = influxDbUtils.getMapResult(vthMax);
                            mpSurplusAbnormalDMax.setUaberrance(Float.parseFloat(map_vthMax.get(0).get("v_thd").toString()));

                            String vthMin = "select MIN(v_thd) as v_thd from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMin.setUaberrance(Float.parseFloat(map_vthMin.get(0).get("v_thd").toString()));

                            String vthAvg = "select MEAN(v_thd) as v_thd from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setUaberrance(Float.parseFloat(map_vthAvg.get(0).get("v_thd").toString()));
                            flag = false;
                        }
                    }

                    /*负序电压不平衡度*/
                    String sqlData_Unbalance_Max = "select MAX(v_unbalance) as v_unbalance from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
                    String sqlData_Unbalance_CP95 = "select MAX(v_unbalance) as v_unbalance from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;

                    List<Map<String, Object>> mapData_Unbalance_Max = influxDbUtils.getMapResult(sqlData_Unbalance_Max);
                    List<Map<String, Object>> mapData_Unbalance_Cp95 = influxDbUtils.getMapResult(sqlData_Unbalance_CP95);
                    if (CollUtil.isNotEmpty(mapData_Unbalance_Max) && CollUtil.isNotEmpty(mapData_Unbalance_Cp95)) {
                        float ubMax = Float.parseFloat(mapData_Unbalance_Max.get(0).get("v_unbalance").toString());
                        float ubCp95 = Float.parseFloat(mapData_Unbalance_Cp95.get(0).get("v_unbalance").toString());
                        if (ubMax > overlimit.getUbalance() && ubCp95 > overlimit.getUbalance()) {
                            mpSurplusAbnormalD.setUbalance(ubCp95);
                            mpSurplusAbnormalDMax.setUbalance(ubMax);

                            String vthMin = "select MIN(v_unbalance) as v_unbalance from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMin.setUaberrance(Float.parseFloat(map_vthMin.get(0).get("v_unbalance").toString()));

                            String vthAvg = "select MEAN(v_unbalance) as v_unbalance from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setUaberrance(Float.parseFloat(map_vthAvg.get(0).get("v_unbalance").toString()));
                            flag = false;
                        }
                    }

                    /*负序电流*/
                    String sqlData_Neg_Max = "select MAX(i_neg) as i_neg from data_i where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
                    String sqlData_Neg_CP95 = "select MAX(i_neg) as i_neg from data_i where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;

                    List<Map<String, Object>> mapData_Neg_Max = influxDbUtils.getMapResult(sqlData_Neg_Max);
                    List<Map<String, Object>> mapData_Neg_Cp95 = influxDbUtils.getMapResult(sqlData_Neg_CP95);

                    if (CollUtil.isNotEmpty(mapData_Neg_Max) && CollUtil.isNotEmpty(mapData_Neg_Cp95)) {
                        float negMax = Float.parseFloat(mapData_Neg_Max.get(0).get("i_neg").toString());
                        float negCp95 = Float.parseFloat(mapData_Neg_Cp95.get(0).get("i_neg").toString());
                        if (negMax > overlimit.getINeg() && negCp95 > overlimit.getINeg()) {
                            mpSurplusAbnormalD.setINeg(negCp95);
                            mpSurplusAbnormalDMax.setINeg(negMax);

                            String vthMin = "select MIN(i_neg) as i_neg from data_i  where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMin.setINeg(Float.parseFloat(map_vthMin.get(0).get("i_neg").toString()));

                            String vthAvg = "select MEAN(i_neg) as i_neg from data_i  where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setINeg(Float.parseFloat(map_vthAvg.get(0).get("i_neg").toString()));
                            flag = false;
                        }
                    }

                    /*频率偏差、电压偏差*/
                    String sqlData_vu_Max = "select MAX(vu_dev) as vu_dev,MAX(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
                    String sqlData_vl_Min = "select MIN(vl_dev) as vl_dev,MIN(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;

                    List<Map<String, Object>> mapData_vu_Max = influxDbUtils.getMapResult(sqlData_vu_Max);
                    List<Map<String, Object>> mapData_vl_Min = influxDbUtils.getMapResult(sqlData_vl_Min);
                    if (CollUtil.isNotEmpty(mapData_vu_Max) && CollUtil.isNotEmpty(mapData_vl_Min)) {
                        float vuMax = Float.parseFloat(mapData_vu_Max.get(0).get("vu_dev").toString());
                        float freqMax = Float.parseFloat(mapData_vu_Max.get(0).get("freq_dev").toString());
                        if (vuMax > overlimit.getVoltageDev()) {
                            mpSurplusAbnormalDMax.setVoltageDev(vuMax);
                            String vthCp95 = "select MAX(vu_dev) as vu_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthCp95 = influxDbUtils.getMapResult(vthCp95);
                            mpSurplusAbnormalD.setVoltageDev(Float.parseFloat(map_vthCp95.get(0).get("vu_dev").toString()));

                            String vthMin = "select MIN(vu_dev) as vu_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMin.setVoltageDev(Float.parseFloat(map_vthMin.get(0).get("vu_dev").toString()));

                            String vthAvg = "select MEAN(vu_dev) as vu_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setVoltageDev(Float.parseFloat(map_vthAvg.get(0).get("vu_dev").toString()));
                            flag = false;
                        }
                        if (Math.abs(freqMax) > overlimit.getFreqDev()) {
                            mpSurplusAbnormalD.setFreq(freqMax);
                            String vthCp95 = "select MAX(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthCp95 = influxDbUtils.getMapResult(vthCp95);
                            mpSurplusAbnormalD.setFreq(Float.parseFloat(map_vthCp95.get(0).get("freq_dev").toString()));

                            String vthMin = "select MIN(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMin.setFreq(Float.parseFloat(map_vthMin.get(0).get("freq_dev").toString()));

                            String vthAvg = "select MEAN(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setFreq(Float.parseFloat(map_vthAvg.get(0).get("freq_dev").toString()));
                            flag = false;
                        }

                        float vlMin = Float.parseFloat(mapData_vl_Min.get(0).get("vl_dev").toString());
                        float freqMin = Float.parseFloat(mapData_vl_Min.get(0).get("freq_dev").toString());
                        if (vlMin < overlimit.getUvoltageDev()) {
                            mpSurplusAbnormalDMin.setUvoltageDev(vuMax);

                            String vthCp95 = "select MAX(vl_dev) as vl_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthCp95 = influxDbUtils.getMapResult(vthCp95);
                            mpSurplusAbnormalD.setUvoltageDev(Float.parseFloat(map_vthCp95.get(0).get("vl_dev").toString()));

                            String vthMin = "select MIN(vl_dev) as vl_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMax.setUvoltageDev(Float.parseFloat(map_vthMin.get(0).get("vl_dev").toString()));

                            String vthAvg = "select MEAN(vl_dev) as vl_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setUvoltageDev(Float.parseFloat(map_vthAvg.get(0).get("vl_dev").toString()));
                            flag = false;
                        }
                        if (Math.abs(freqMin) > overlimit.getFreqDev()) {
                            mpSurplusAbnormalD.setFreq(freqMin);

                            String vthCp95 = "select MAX(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthCp95 = influxDbUtils.getMapResult(vthCp95);
                            mpSurplusAbnormalD.setFreq(Float.parseFloat(map_vthCp95.get(0).get("freq_dev").toString()));

                            String vthMin = "select MIN(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMax.setFreq(Float.parseFloat(map_vthMin.get(0).get("freq_dev").toString()));

                            String vthAvg = "select MEAN(freq_dev) as freq_dev from data_v where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setFreq(Float.parseFloat(map_vthAvg.get(0).get("freq_dev").toString()));
                            flag = false;
                        }
                    }

                    /*长时闪变*/
                    String sqlData_plt_Max = "select MAX(plt) as plt from data_plt where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
                    List<Map<String, Object>> mapData_plt = influxDbUtils.getMapResult(sqlData_plt_Max);
                    if (CollUtil.isNotEmpty(mapData_plt)) {
                        float thd = Float.parseFloat(mapData_plt.get(0).get("plt").toString());
                        if (thd > overlimit.getFlicker()) {
                            mpSurplusAbnormalD.setFlicker(thd);

                            String vthCp95 = "select MAX(plt) as plt from data_plt where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'CP95'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthCp95 = influxDbUtils.getMapResult(vthCp95);
                            mpSurplusAbnormalD.setFlicker(Float.parseFloat(map_vthCp95.get(0).get("plt").toString()));

                            String vthMin = "select MIN(plt) as plt from data_plt where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthMin = influxDbUtils.getMapResult(vthMin);
                            mpSurplusAbnormalDMax.setFlicker(Float.parseFloat(map_vthMin.get(0).get("plt").toString()));

                            String vthAvg = "select MEAN(plt) as plt from data_plt where line_id ='" + lineIndex + "' " + lastSql + " and phasic_type = '" + phasic + "' and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;
                            List<Map<String, Object>> map_vthAvg = influxDbUtils.getMapResult(vthAvg);
                            mpSurplusAbnormalDAvg.setFlicker(Float.parseFloat(map_vthAvg.get(0).get("plt").toString()));
                            flag = false;
                        }
                    }


                    if (!flag) {
                        all.add(mpSurplusAbnormalD);
                        all.add(mpSurplusAbnormalDMax);
                        all.add(mpSurplusAbnormalDMin);
                        all.add(mpSurplusAbnormalDAvg);
                    }

                }


            }


            if (CollUtil.isNotEmpty(all)) {
                //入库操作
                this.saveBatch(all);
            }


        }


        return true;
    }


    private Float compareToOver(Float overLimit, Float value, Boolean flag) {
        if (value > overLimit) {
            flag = false;
            return value;
        }
        return null;
    }


    private void assPojoI(Map<String, Object> map, MpSurplusAbnormalD mpSurplusAbnormalD,Integer type){
        if(type == 1){
            //谐波电压
            map.forEach((key, val) -> {
                switch (key) {
                    case "v_2":
                        mpSurplusAbnormalD.setUharm2(Float.parseFloat(val.toString()));
                        break;
                    case "v_3":
                        mpSurplusAbnormalD.setUharm3(Float.parseFloat(val.toString()));
                        break;
                    case "v_4":
                        mpSurplusAbnormalD.setUharm4(Float.parseFloat(val.toString()));
                        break;
                    case "v_5":
                        mpSurplusAbnormalD.setUharm5(Float.parseFloat(val.toString()));
                        break;
                    case "v_6":
                        mpSurplusAbnormalD.setUharm6(Float.parseFloat(val.toString()));
                        break;
                    case "v_7":
                        mpSurplusAbnormalD.setUharm7(Float.parseFloat(val.toString()));
                        break;
                    case "v_8":
                        mpSurplusAbnormalD.setUharm8(Float.parseFloat(val.toString()));
                        break;
                    case "v_9":
                        mpSurplusAbnormalD.setUharm9(Float.parseFloat(val.toString()));
                        break;
                    case "v_10":
                        mpSurplusAbnormalD.setUharm10(Float.parseFloat(val.toString()));
                        break;
                    case "v_11":
                        mpSurplusAbnormalD.setUharm11(Float.parseFloat(val.toString()));
                        break;
                    case "v_12":
                        mpSurplusAbnormalD.setUharm12(Float.parseFloat(val.toString()));
                        break;
                    case "v_13":
                        mpSurplusAbnormalD.setUharm13(Float.parseFloat(val.toString()));
                        break;
                    case "v_14":
                        mpSurplusAbnormalD.setUharm14(Float.parseFloat(val.toString()));
                        break;
                    case "v_15":
                        mpSurplusAbnormalD.setUharm15(Float.parseFloat(val.toString()));
                        break;
                    case "v_16":
                        mpSurplusAbnormalD.setUharm16(Float.parseFloat(val.toString()));
                        break;
                    case "v_17":
                        mpSurplusAbnormalD.setUharm17(Float.parseFloat(val.toString()));
                        break;
                    case "v_18":
                        mpSurplusAbnormalD.setUharm18(Float.parseFloat(val.toString()));
                        break;
                    case "v_19":
                        mpSurplusAbnormalD.setUharm19(Float.parseFloat(val.toString()));
                        break;
                    case "v_20":
                        mpSurplusAbnormalD.setUharm20(Float.parseFloat(val.toString()));
                        break;
                    case "v_21":
                        mpSurplusAbnormalD.setUharm21(Float.parseFloat(val.toString()));
                        break;
                    case "v_22":
                        mpSurplusAbnormalD.setUharm22(Float.parseFloat(val.toString()));
                        break;
                    case "v_23":
                        mpSurplusAbnormalD.setUharm23(Float.parseFloat(val.toString()));
                        break;
                    case "v_24":
                        mpSurplusAbnormalD.setUharm24(Float.parseFloat(val.toString()));
                        break;
                    case "v_25":
                        mpSurplusAbnormalD.setUharm25(Float.parseFloat(val.toString()));
                        break;
                    case "time":
                        break;
                    default:
                        throw new IllegalStateException("Unexpected value: " + key);
                }

            });
        }else if(type == 2){
            //谐波电流
            map.forEach((key, val) -> {
                switch (key) {
                    case "i_2":
                        mpSurplusAbnormalD.setIharm2(Float.parseFloat(val.toString()));
                        break;
                    case "i_3":
                        mpSurplusAbnormalD.setIharm3(Float.parseFloat(val.toString()));
                        break;
                    case "i_4":
                        mpSurplusAbnormalD.setIharm4(Float.parseFloat(val.toString()));
                        break;
                    case "i_5":
                        mpSurplusAbnormalD.setIharm5(Float.parseFloat(val.toString()));
                        break;
                    case "i_6":
                        mpSurplusAbnormalD.setIharm6(Float.parseFloat(val.toString()));
                        break;
                    case "i_7":
                        mpSurplusAbnormalD.setIharm7(Float.parseFloat(val.toString()));
                        break;
                    case "i_8":
                        mpSurplusAbnormalD.setIharm8(Float.parseFloat(val.toString()));
                        break;
                    case "i_9":
                        mpSurplusAbnormalD.setIharm9(Float.parseFloat(val.toString()));
                        break;
                    case "i_10":
                        mpSurplusAbnormalD.setIharm10(Float.parseFloat(val.toString()));
                        break;
                    case "i_11":
                        mpSurplusAbnormalD.setIharm11(Float.parseFloat(val.toString()));
                        break;
                    case "i_12":
                        mpSurplusAbnormalD.setIharm12(Float.parseFloat(val.toString()));
                        break;
                    case "i_13":
                        mpSurplusAbnormalD.setIharm13(Float.parseFloat(val.toString()));
                        break;
                    case "i_14":
                        mpSurplusAbnormalD.setIharm14(Float.parseFloat(val.toString()));
                        break;
                    case "i_15":
                        mpSurplusAbnormalD.setIharm15(Float.parseFloat(val.toString()));
                        break;
                    case "i_16":
                        mpSurplusAbnormalD.setIharm16(Float.parseFloat(val.toString()));
                        break;
                    case "i_17":
                        mpSurplusAbnormalD.setIharm17(Float.parseFloat(val.toString()));
                        break;
                    case "i_18":
                        mpSurplusAbnormalD.setIharm18(Float.parseFloat(val.toString()));
                        break;
                    case "i_19":
                        mpSurplusAbnormalD.setIharm19(Float.parseFloat(val.toString()));
                        break;
                    case "i_20":
                        mpSurplusAbnormalD.setIharm20(Float.parseFloat(val.toString()));
                        break;
                    case "i_21":
                        mpSurplusAbnormalD.setIharm21(Float.parseFloat(val.toString()));
                        break;
                    case "i_22":
                        mpSurplusAbnormalD.setIharm22(Float.parseFloat(val.toString()));
                        break;
                    case "i_23":
                        mpSurplusAbnormalD.setIharm23(Float.parseFloat(val.toString()));
                        break;
                    case "i_24":
                        mpSurplusAbnormalD.setIharm24(Float.parseFloat(val.toString()));
                        break;
                    case "i_25":
                        mpSurplusAbnormalD.setIharm25(Float.parseFloat(val.toString()));
                        break;
                    case "time":
                        break;
                    default:
                        throw new IllegalStateException("Unexpected value: " + key);
                }
            });
        }else {
            //间谐波电流
            map.forEach((key, val) -> {
                switch (key) {
                    case "v_1":
                        mpSurplusAbnormalD.setInuharm1(Float.parseFloat(val.toString()));
                        break;
                    case "v_2":
                        mpSurplusAbnormalD.setInuharm2(Float.parseFloat(val.toString()));
                        break;
                    case "v_3":
                        mpSurplusAbnormalD.setInuharm3(Float.parseFloat(val.toString()));
                        break;
                    case "v_4":
                        mpSurplusAbnormalD.setInuharm4(Float.parseFloat(val.toString()));
                        break;
                    case "v_5":
                        mpSurplusAbnormalD.setInuharm5(Float.parseFloat(val.toString()));
                        break;
                    case "v_6":
                        mpSurplusAbnormalD.setInuharm6(Float.parseFloat(val.toString()));
                        break;
                    case "v_7":
                        mpSurplusAbnormalD.setInuharm7(Float.parseFloat(val.toString()));
                        break;
                    case "v_8":
                        mpSurplusAbnormalD.setInuharm8(Float.parseFloat(val.toString()));
                        break;
                    case "v_9":
                        mpSurplusAbnormalD.setInuharm9(Float.parseFloat(val.toString()));
                        break;
                    case "v_10":
                        mpSurplusAbnormalD.setInuharm10(Float.parseFloat(val.toString()));
                        break;
                    case "v_11":
                        mpSurplusAbnormalD.setInuharm11(Float.parseFloat(val.toString()));
                        break;
                    case "v_12":
                        mpSurplusAbnormalD.setInuharm12(Float.parseFloat(val.toString()));
                        break;
                    case "v_13":
                        mpSurplusAbnormalD.setInuharm13(Float.parseFloat(val.toString()));
                        break;
                    case "v_14":
                        mpSurplusAbnormalD.setInuharm14(Float.parseFloat(val.toString()));
                        break;
                    case "v_15":
                        mpSurplusAbnormalD.setInuharm15(Float.parseFloat(val.toString()));
                        break;
                    case "v_16":
                        mpSurplusAbnormalD.setInuharm16(Float.parseFloat(val.toString()));
                        break;
                    case "time":
                        break;
                    default:
                        throw new IllegalStateException("Unexpected value: " + key);
                }

            });
        }

    }



    private void assTest(List<String> useList,String bang,String table,Integer type,MpSurplusAbnormalD mpSurplusAbnormalDMax,MpSurplusAbnormalD mpSurplusAbnormalDMin,MpSurplusAbnormalD mpSurplusAbnormalDAvg){
        StringBuilder uMax = new StringBuilder();
        StringBuilder uMin = new StringBuilder();
        for (int i = 0; i < useList.size(); i++) {
            if (i == useList.size() - 1) {
                uMax.append("MAX(").append(useList.get(i)).append(") as ").append(useList.get(i));
                uMin.append("MIN(").append(useList.get(i)).append(") as ").append(useList.get(i));

            } else {
                uMax.append("MAX(").append(useList.get(i)).append(") as ").append(useList.get(i)).append(",");
                uMin.append("MIN(").append(useList.get(i)).append(") as ").append(useList.get(i)).append(",");

            }
        }

        String sqlMAX = "select " + uMax + " from "+table+bang +" and value_type = 'MAX'" + InfluxDBPublicParam.TIME_ZONE;
        String sqlMIN = "select " + uMin + " from "+table+bang +" and value_type = 'MIN'" + InfluxDBPublicParam.TIME_ZONE;
        String sqlAVG = "select " + uMax + " from "+table+bang +" and value_type = 'AVG'" + InfluxDBPublicParam.TIME_ZONE;

        List<Map<String, Object>> map_MAX = influxDbUtils.getMapResult(sqlMAX);
        if (CollUtil.isNotEmpty(map_MAX)) {
            assPojoI(map_MAX.get(0),mpSurplusAbnormalDMax,type);
        }
        List<Map<String, Object>> map_MIN = influxDbUtils.getMapResult(sqlMIN);
        if (CollUtil.isNotEmpty(map_MIN)) {
            assPojoI(map_MIN.get(0),mpSurplusAbnormalDMin,type);
        }

        List<Map<String, Object>> map_AVG = influxDbUtils.getMapResult(sqlAVG);
        if (CollUtil.isNotEmpty(map_AVG)) {
            assPojoI(map_AVG.get(0),mpSurplusAbnormalDAvg,type);
        }
    }


}
