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

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.common.utils.NjcnBeanUtil;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.harmonic.pojo.po.LimitRate;
import com.njcn.harmonic.pojo.po.LimitRatePO;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.influx.constant.InfluxDbSqlConstant;
import com.njcn.influx.imapper.*;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.pojo.po.*;
import com.njcn.influx.query.InfluxQueryWrapper;
import com.njcn.prepare.harmonic.mapper.mysql.line.LimitRatePOMapper;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.day.IRStatLimitRateDService;
import com.njcn.prepare.harmonic.service.mysql.line.LimitRateService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.time.Instant;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2022/10/18  10:00【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */

@Slf4j
@Component
@AllArgsConstructor
public class LimitRateServiceImpl extends MppServiceImpl<LimitRatePOMapper, LimitRatePO> implements LimitRateService {
    private final CommTerminalGeneralClient commTerminalGeneralClient;
    private final IRStatLimitRateDService statLimitRateDService;
    private final DataVMapper dataVMapper;
    private final DataPltMapper dataPltMapper;
    private final DataHarmRateVMapper dataHarmRateVMapper;
    private final DataIMapper dataIMapper;
    private final DataInHarmVMapper dataInHarmVMapper;

    /*********************************************新算法***********************************************************/
    @Override
    public void limitRate(CalculatedParam calculatedParam,Integer step) {
        List<RStatLimitRateDPO> list = new ArrayList<>();

        //数据集合
        List<DataV> list1 = new ArrayList<>();
        List<DataPlt> list2 = new ArrayList<>();
        List<DataHarmRateV> list3 = new ArrayList<>();
        List<DataI> list4 = new ArrayList<>();
        List<DataInHarmV> list5 = new ArrayList<>();
        List<DataV> list6 = new ArrayList<>();
        List<DataV> list7 = new ArrayList<>();
        List<DataI> list8 = new ArrayList<>();
        List<DataV> list9 = new ArrayList<>();
        List<DataV> list10 = new ArrayList<>();
        List<DataPlt> list11 = new ArrayList<>();

        //获取时间
        String startTime = this.getTime(calculatedParam.getDataDate(),step,true);
        String endTime = this.getTime(calculatedParam.getDataDate(),step,false);
        //监测点集合
        List<String> lineIds = calculatedParam.getIdList();
        //获取所有监测点的限值
        List<Overlimit> overLimitList = commTerminalGeneralClient.getOverLimitDataByIds(lineIds).getData();
        Map<String,Overlimit> overLimitMap = overLimitList.stream().collect(Collectors.toMap(Overlimit::getId, Function.identity()));

        //以尺寸100分片,查询数据
        List<List<String>> pendingIds =  ListUtils.partition(lineIds,100);
        for (List<String> pendingId : pendingIds) {
            list1.addAll(getAllTime(pendingId, startTime, endTime));
            list2.addAll(getFlickerAllTime(pendingId, startTime, endTime));
            list3.addAll(getDataHarmRateV(pendingId, startTime, endTime));
            list4.addAll(getDataI(pendingId, startTime, endTime));
            list5.addAll(getDataInHarmV(pendingId, startTime, endTime));
            list6.addAll(getDataVThd(pendingId, startTime, endTime));
            list7.addAll(getDataVUnbalance(pendingId, startTime, endTime));
            list8.addAll(getDataINeg(pendingId, startTime, endTime));
            list9.addAll(getDataVFreq(pendingId, startTime, endTime));
            list10.addAll(getDataVDev(pendingId, startTime, endTime));
            list11.addAll(getDataPlt(pendingId, startTime, endTime));
        }

        if (CollectionUtils.isEmpty(list1)) {
            log.error("data_v allTime数据缺失");
        }
        if (CollectionUtils.isEmpty(list2)) {
            log.error("data_plt flickerAllTime数据缺失");
        }
        if (CollectionUtils.isEmpty(list3)) {
            log.error("data_harmrate_v 谐波数据缺失");
        }
        if (CollectionUtils.isEmpty(list4)) {
            log.error("data_I 谐波数据缺失");
        }
        if (CollectionUtils.isEmpty(list5)) {
            log.error("data_inharm_v 间谐波数据缺失");
        }
        if (CollectionUtils.isEmpty(list6)) {
            log.error("data_v 电压总谐波畸变率数据缺失");
        }
        if (CollectionUtils.isEmpty(list7)) {
            log.error("data_v 三相电压不平衡度数据缺失");
        }
        if (CollectionUtils.isEmpty(list8)) {
            log.error("data_I 负序电流数据缺失");
        }
        if (CollectionUtils.isEmpty(list9)) {
            log.error("data_v 频率偏差数据缺失");
        }
        if (CollectionUtils.isEmpty(list10)) {
            log.error("data_v 电压偏差数据缺失");
        }
        if (CollectionUtils.isEmpty(list11)) {
            log.error("data_plt 闪变数据缺失");
        }

        //数据处理,按监测点分组
        Map<String,List<DataV>> map1 = CollUtil.emptyIfNull(list1).stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataPlt>> map2 = CollUtil.emptyIfNull(list2).stream().collect(Collectors.groupingBy(DataPlt::getLineId));
        Map<String,List<DataHarmRateV>> map3 = CollUtil.emptyIfNull(list3).stream().collect(Collectors.groupingBy(DataHarmRateV::getLineId));
        Map<String,List<DataI>> map4 = CollUtil.emptyIfNull(list4).stream().collect(Collectors.groupingBy(DataI::getLineId));
        Map<String,List<DataInHarmV>> map5 = CollUtil.emptyIfNull(list5).stream().collect(Collectors.groupingBy(DataInHarmV::getLineId));
        Map<String,List<DataV>> map6 = CollUtil.emptyIfNull(list6).stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataV>> map7 = CollUtil.emptyIfNull(list7).stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataI>> map8 = CollUtil.emptyIfNull(list8).stream().collect(Collectors.groupingBy(DataI::getLineId));
        Map<String,List<DataV>> map9 = CollUtil.emptyIfNull(list9).stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataV>> map10 = CollUtil.emptyIfNull(list10).stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataPlt>> map11 = CollUtil.emptyIfNull(list11).stream().collect(Collectors.groupingBy(DataPlt::getLineId));

        for (String item : lineIds) {
            //如果监测点没有限值，就不进行计算
            if (Objects.isNull(overLimitMap.get(item))) {
                break;
            }
            List<LimitRate> result = getData(overLimitMap.get(item), map1.get(item), map2.get(item), map3.get(item), map4.get(item), map5.get(item), map6.get(item), map7.get(item), map8.get(item), map9.get(item), map10.get(item), map11.get(item));
            List<RStatLimitRateDPO> collect = result.stream().map(t -> {
                RStatLimitRateDPO po = new RStatLimitRateDPO();
                NjcnBeanUtil.copyPropertiesIgnoreCase(t, po);
                po.setTime(LocalDateTimeUtil.parseDate(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
                return po;
            }).collect(Collectors.toList());
            list.addAll(collect);
        }
        if (!CollectionUtils.isEmpty(list)){
            //判断是否要做合并处理
            LambdaQueryWrapper<RStatLimitRateDPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(RStatLimitRateDPO::getTime, calculatedParam.getDataDate());
            List<RStatLimitRateDPO> originalData = statLimitRateDService.list(lambdaQueryWrapper);
            //如果是执行的全链路，且执行第一步，先要删掉原来数据
            if (calculatedParam.isFullChain() && step == 1){
                statLimitRateDService.remove(lambdaQueryWrapper);
                originalData = new ArrayList<>();
            }
            if (CollUtil.isNotEmpty(originalData)){
                list = this.mergeData(originalData,list);
            }
            /*插入mysql*/
            statLimitRateDService.saveOrUpdateBatchByMultiId(list,1000);
        }
    }

    /**
     * 时间选择
     */
    public String getTime(String basisTime, Integer step, boolean type) {
        String time = null;
        switch (step) {
            case 1:
                if (type){
                    time = basisTime + " 00:00:00";
                } else {
                    time = basisTime + " 02:59:59";
                }
                break;
            case 2:
                if (type){
                    time = basisTime + " 03:00:00";
                } else {
                    time = basisTime + " 05:59:59";
                }
            case 3:
                if (type){
                    time = basisTime + " 06:00:00";
                } else {
                    time = basisTime + " 08:59:59";
                }
            case 4:
                if (type){
                    time = basisTime + " 09:00:00";
                } else {
                    time = basisTime + " 11:59:59";
                }
                break;
            case 5:
                if (type){
                    time = basisTime + " 12:00:00";
                } else {
                    time = basisTime + " 14:59:59";
                }
            case 6:
                if (type){
                    time = basisTime + " 15:00:00";
                } else {
                    time = basisTime + " 17:59:59";
                }
                break;
            case 7:
                if (type){
                    time = basisTime + " 18:00:00";
                } else {
                    time = basisTime + " 20:59:59";
                }
                break;
            case 8:
                if (type){
                    time = basisTime + " 21:00:00";
                } else {
                    time = basisTime + " 23:59:59";
                }
                break;
            default:
                break;
        }
        return time;
    }

    /**
     * 数据合并处理
     */
    public List<RStatLimitRateDPO> mergeData(List<RStatLimitRateDPO> list1, List<RStatLimitRateDPO> list2) {
        List<RStatLimitRateDPO> list = list1.stream().map(m -> {
            list2.stream().filter(m2-> Objects.equals(m.getLineId(),m2.getLineId()) && Objects.equals(m.getPhasicType(),m2.getPhasicType())).forEach(m2-> {
                m.setAllTime(m.getAllTime() + m2.getAllTime());
                m.setFlickerAllTime(m.getFlickerAllTime() + m2.getFlickerAllTime());
                m.setFreqDevOvertime(m.getFreqDevOvertime() + m2.getFreqDevOvertime());
                m.setVoltageDevOvertime(m.getVoltageDevOvertime() + m2.getVoltageDevOvertime());
                m.setUbalanceOvertime(m.getUbalanceOvertime() + m2.getUbalanceOvertime());
                m.setFlickerOvertime(m.getFlickerOvertime() + m2.getFlickerOvertime());
                m.setUaberranceOvertime(m.getUaberranceOvertime() + m2.getUaberranceOvertime());

                m.setUharm2Overtime(m.getUharm2Overtime() + m2.getUharm2Overtime());
                m.setUharm3Overtime(m.getUharm3Overtime() + m2.getUharm3Overtime());
                m.setUharm4Overtime(m.getUharm4Overtime() + m2.getUharm4Overtime());
                m.setUharm5Overtime(m.getUharm5Overtime() + m2.getUharm5Overtime());
                m.setUharm6Overtime(m.getUharm6Overtime() + m2.getUharm6Overtime());
                m.setUharm7Overtime(m.getUharm7Overtime() + m2.getUharm7Overtime());
                m.setUharm8Overtime(m.getUharm8Overtime() + m2.getUharm8Overtime());
                m.setUharm9Overtime(m.getUharm9Overtime() + m2.getUharm9Overtime());
                m.setUharm10Overtime(m.getUharm10Overtime() + m2.getUharm10Overtime());
                m.setUharm11Overtime(m.getUharm11Overtime() + m2.getUharm11Overtime());
                m.setUharm12Overtime(m.getUharm12Overtime() + m2.getUharm12Overtime());
                m.setUharm13Overtime(m.getUharm13Overtime() + m2.getUharm13Overtime());
                m.setUharm14Overtime(m.getUharm14Overtime() + m2.getUharm14Overtime());
                m.setUharm15Overtime(m.getUharm15Overtime() + m2.getUharm15Overtime());
                m.setUharm16Overtime(m.getUharm16Overtime() + m2.getUharm16Overtime());
                m.setUharm17Overtime(m.getUharm17Overtime() + m2.getUharm17Overtime());
                m.setUharm18Overtime(m.getUharm18Overtime() + m2.getUharm18Overtime());
                m.setUharm19Overtime(m.getUharm19Overtime() + m2.getUharm19Overtime());
                m.setUharm20Overtime(m.getUharm20Overtime() + m2.getUharm20Overtime());
                m.setUharm21Overtime(m.getUharm21Overtime() + m2.getUharm21Overtime());
                m.setUharm22Overtime(m.getUharm22Overtime() + m2.getUharm22Overtime());
                m.setUharm23Overtime(m.getUharm23Overtime() + m2.getUharm23Overtime());
                m.setUharm24Overtime(m.getUharm24Overtime() + m2.getUharm24Overtime());
                m.setUharm25Overtime(m.getUharm25Overtime() + m2.getUharm25Overtime());

                m.setIharm2Overtime(m.getIharm2Overtime() + m2.getIharm2Overtime());
                m.setIharm3Overtime(m.getIharm3Overtime() + m2.getIharm3Overtime());
                m.setIharm4Overtime(m.getIharm4Overtime() + m2.getIharm4Overtime());
                m.setIharm5Overtime(m.getIharm5Overtime() + m2.getIharm5Overtime());
                m.setIharm6Overtime(m.getIharm6Overtime() + m2.getIharm6Overtime());
                m.setIharm7Overtime(m.getIharm7Overtime() + m2.getIharm7Overtime());
                m.setIharm8Overtime(m.getIharm8Overtime() + m2.getIharm8Overtime());
                m.setIharm9Overtime(m.getIharm9Overtime() + m2.getIharm9Overtime());
                m.setIharm10Overtime(m.getIharm10Overtime() + m2.getIharm10Overtime());
                m.setIharm11Overtime(m.getIharm11Overtime() + m2.getIharm11Overtime());
                m.setIharm12Overtime(m.getIharm12Overtime() + m2.getIharm12Overtime());
                m.setIharm13Overtime(m.getIharm13Overtime() + m2.getIharm13Overtime());
                m.setIharm14Overtime(m.getIharm14Overtime() + m2.getIharm14Overtime());
                m.setIharm15Overtime(m.getIharm15Overtime() + m2.getIharm15Overtime());
                m.setIharm16Overtime(m.getIharm16Overtime() + m2.getIharm16Overtime());
                m.setIharm17Overtime(m.getIharm17Overtime() + m2.getIharm17Overtime());
                m.setIharm18Overtime(m.getIharm18Overtime() + m2.getIharm18Overtime());
                m.setIharm19Overtime(m.getIharm19Overtime() + m2.getIharm19Overtime());
                m.setIharm20Overtime(m.getIharm20Overtime() + m2.getIharm20Overtime());
                m.setIharm21Overtime(m.getIharm21Overtime() + m2.getIharm21Overtime());
                m.setIharm22Overtime(m.getIharm22Overtime() + m2.getIharm22Overtime());
                m.setIharm23Overtime(m.getIharm23Overtime() + m2.getIharm23Overtime());
                m.setIharm24Overtime(m.getIharm24Overtime() + m2.getIharm24Overtime());
                m.setIharm25Overtime(m.getIharm25Overtime() + m2.getIharm25Overtime());

                m.setInuharm1Overtime(m.getInuharm1Overtime() + m2.getInuharm1Overtime());
                m.setInuharm2Overtime(m.getInuharm2Overtime() + m2.getInuharm2Overtime());
                m.setInuharm3Overtime(m.getInuharm3Overtime() + m2.getInuharm3Overtime());
                m.setInuharm4Overtime(m.getInuharm4Overtime() + m2.getInuharm4Overtime());
                m.setInuharm5Overtime(m.getInuharm5Overtime() + m2.getInuharm5Overtime());
                m.setInuharm6Overtime(m.getInuharm6Overtime() + m2.getInuharm6Overtime());
                m.setInuharm7Overtime(m.getInuharm7Overtime() + m2.getInuharm7Overtime());
                m.setInuharm8Overtime(m.getInuharm8Overtime() + m2.getInuharm8Overtime());
                m.setInuharm9Overtime(m.getInuharm9Overtime() + m2.getInuharm9Overtime());
                m.setInuharm10Overtime(m.getInuharm10Overtime() + m2.getInuharm10Overtime());
                m.setInuharm11Overtime(m.getInuharm11Overtime() + m2.getInuharm11Overtime());
                m.setInuharm12Overtime(m.getInuharm12Overtime() + m2.getInuharm12Overtime());
                m.setInuharm13Overtime(m.getInuharm13Overtime() + m2.getInuharm13Overtime());
                m.setInuharm14Overtime(m.getInuharm14Overtime() + m2.getInuharm14Overtime());
                m.setInuharm15Overtime(m.getInuharm15Overtime() + m2.getInuharm15Overtime());
                m.setInuharm16Overtime(m.getInuharm16Overtime() + m2.getInuharm16Overtime());

            });
            return m;
        }).collect(Collectors.toList());



        return list;
    }

    /**
     * 功能描述:获取influxDB -> data_v -> 总计算次数(用data_v中phasic_type=A,value_type=avg,quality_flag=0来参与统计)
     *
     * @param lineIndex 监测点
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataV> getAllTime(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
        influxQueryWrapper.regular(DataV::getLineId, lineIndex)
                .eq(DataV::getValueType, InfluxDbSqlConstant.AVG_WEB)
                .eq(DataV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_A)
                .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .count(DataV::getFreq,DataV::getAllTime)
                .groupBy(DataV::getLineId)
                .between(DataV::getTime, startTime, endTime);
        return dataVMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_plt -> 闪变总计算次数(用data_plt中phasic_type=A,quality_flag=0来参与统计)
     *
     * @param lineIndex 监测点
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataPlt> getFlickerAllTime(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataPlt.class);
        influxQueryWrapper.regular(DataPlt::getLineId, lineIndex)
                .eq(DataPlt::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_A)
                .eq(DataPlt::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .count(DataPlt::getPlt,DataPlt::getFlickerAllTime)
                .groupBy(DataPlt::getLineId)
                .between(DataPlt::getTime, startTime, endTime);
        return dataPltMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_harmrate_v -> 2-25次谐波电压含有率 -> A相||B相||C相的日95%概率值
     *
     * @param lineIndex 监测点
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataHarmRateV> getDataHarmRateV(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataHarmRateV.class);
        influxQueryWrapper.select(DataHarmRateV::getLineId)
                .select(DataHarmRateV::getPhaseType)
                .select(DataHarmRateV::getQualityFlag)
                .select(DataHarmRateV::getValueType)
                .select(DataHarmRateV::getV2)
                .select(DataHarmRateV::getV3)
                .select(DataHarmRateV::getV4).select(DataHarmRateV::getV5).select(DataHarmRateV::getV6).select(DataHarmRateV::getV7)
                .select(DataHarmRateV::getV8).select(DataHarmRateV::getV9).select(DataHarmRateV::getV10).select(DataHarmRateV::getV11)
                .select(DataHarmRateV::getV11).select(DataHarmRateV::getV12).select(DataHarmRateV::getV13).select(DataHarmRateV::getV14)
                .select(DataHarmRateV::getV15).select(DataHarmRateV::getV16).select(DataHarmRateV::getV17).select(DataHarmRateV::getV18)
                .select(DataHarmRateV::getV19).select(DataHarmRateV::getV20).select(DataHarmRateV::getV21).select(DataHarmRateV::getV22)
                .select(DataHarmRateV::getV23).select(DataHarmRateV::getV24).select(DataHarmRateV::getV25)
                .regular(DataHarmRateV::getLineId, lineIndex)
                .regular(DataHarmRateV::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C))
                .eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95)
                .eq(DataHarmRateV::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataHarmRateV::getTime, startTime, endTime);
        return dataHarmRateVMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_i -> 2-25次谐波电流 -> 日95%概率值
     *
     * @param lineIndex 监测点Index
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @Date: 2022/10/18
     */
    public List<DataI> getDataI(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class);
        influxQueryWrapper.select(DataI::getLineId)
                .select(DataI::getPhaseType)
                .select(DataI::getQualityFlag)
                .select(DataI::getValueType)
                .select(DataI::getINeg).select(DataI::getI2).select(DataI::getI3)
                .select(DataI::getI4).select(DataI::getI5).select(DataI::getI6).select(DataI::getI7)
                .select(DataI::getI8).select(DataI::getI9).select(DataI::getI10).select(DataI::getI11)
                .select(DataI::getI11).select(DataI::getI12).select(DataI::getI13).select(DataI::getI14)
                .select(DataI::getI15).select(DataI::getI16).select(DataI::getI17).select(DataI::getI18)
                .select(DataI::getI19).select(DataI::getI20).select(DataI::getI21).select(DataI::getI22)
                .select(DataI::getI23).select(DataI::getI24).select(DataI::getI25)
                .regular(DataI::getLineId, lineIndex)
                .regular(DataI::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C))
                .eq(DataI::getValueType, InfluxDBTableConstant.CP95)
                .eq(DataI::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataI::getTime, startTime, endTime);
        return dataIMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_inharm_v -> 0.5-15.5次间谐波电压含有率 -> 日95%概率值
     *
     * @param lineIndex 监测点index
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataInHarmV> getDataInHarmV(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataInHarmV.class);
        influxQueryWrapper.select(DataHarmRateV::getLineId)
                .select(DataInHarmV::getPhaseType)
                .select(DataInHarmV::getQualityFlag)
                .select(DataInHarmV::getValueType).select(DataInHarmV::getV1)
                .select(DataInHarmV::getV2).select(DataInHarmV::getV3)
                .select(DataInHarmV::getV4).select(DataInHarmV::getV5).select(DataInHarmV::getV6).select(DataInHarmV::getV7)
                .select(DataInHarmV::getV8).select(DataInHarmV::getV9).select(DataInHarmV::getV10).select(DataInHarmV::getV11)
                .select(DataInHarmV::getV11).select(DataInHarmV::getV12).select(DataInHarmV::getV13).select(DataInHarmV::getV14)
                .select(DataInHarmV::getV15).select(DataInHarmV::getV16).select(DataInHarmV::getV17).select(DataInHarmV::getV18)
                .select(DataInHarmV::getV19).select(DataInHarmV::getV20).select(DataInHarmV::getV21).select(DataInHarmV::getV22)
                .select(DataInHarmV::getV23).select(DataInHarmV::getV24).select(DataInHarmV::getV25)
                .regular(DataInHarmV::getLineId, lineIndex)
                .regular(DataInHarmV::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C))
                .eq(DataInHarmV::getValueType, InfluxDBTableConstant.CP95)
                .eq(DataInHarmV::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataInHarmV::getTime, startTime, endTime);
        return dataInHarmVMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_v -> 电压总谐波畸变率 -> 日95%概率值
     *
     * @param lineIndex 监测点Index
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataV> getDataVThd(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
        influxQueryWrapper.select(DataV::getLineId)
                .select(DataV::getPhaseType)
                .select(DataV::getQualityFlag)
                .select(DataV::getValueType)
                .select(DataV::getVThd)
                .regular(DataV::getLineId, lineIndex)
                .eq(DataV::getValueType, InfluxDbSqlConstant.CP95)
                .regular(DataV::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C))
                .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataV::getTime, startTime, endTime);
        return dataVMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_v -> 负序电压不平衡度 -> 最大值 && 日95%概率值
     *
     * @param lineIndex 监测点lineIndex
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataV> getDataVUnbalance(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
        influxQueryWrapper.select(DataV::getLineId)
                .select(DataV::getPhaseType)
                .select(DataV::getQualityFlag)
                .select(DataV::getValueType)
                .select(DataV::getVUnbalance)
                .regular(DataV::getLineId, lineIndex)
                .regular(DataV::getValueType, Arrays.asList(InfluxDbSqlConstant.CP95,InfluxDbSqlConstant.MAX))
                .eq(DataV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T)
                .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataV::getTime, startTime, endTime);
        return dataVMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_i -> 负序电流 -> 最大值 && 日95%概率值
     *
     * @param lineIndex 监测点lineIndex
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataI> getDataINeg(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class);
        influxQueryWrapper.select(DataHarmRateV::getLineId)
                .select(DataI::getPhaseType)
                .select(DataI::getQualityFlag)
                .select(DataI::getValueType)
                .select(DataI::getINeg)
                .regular(DataI::getLineId, lineIndex)
                .eq(DataI::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T)
                .regular(DataI::getValueType, Arrays.asList(InfluxDbSqlConstant.CP95,InfluxDbSqlConstant.MAX))
                .eq(DataI::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataI::getTime, startTime, endTime);
        return dataIMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_v -> 频率偏差 -> 最大值 && 最小值
     *
     * @param lineIndex 监测点lineIndex
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataV> getDataVFreq(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
        influxQueryWrapper.select(DataV::getLineId)
                .select(DataV::getPhaseType)
                .select(DataV::getQualityFlag)
                .select(DataV::getValueType)
                .select(DataV::getFreqDev)
                .regular(DataV::getLineId, lineIndex)
                .regular(DataV::getValueType, Arrays.asList(InfluxDbSqlConstant.MIN,InfluxDbSqlConstant.MAX))
                .eq(DataV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T)
                .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataV::getTime, startTime, endTime);
        return dataVMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_v -> 电压偏差 -> 最大值
     *
     * @param lineIndex 监测点lineIndex
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataV> getDataVDev(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataV.class);
        influxQueryWrapper.select(DataV::getLineId)
                .select(DataV::getPhaseType)
                .select(DataV::getQualityFlag)
                .select(DataV::getValueType)
                .select(DataV::getVlDev)
                .select(DataV::getVuDev).regular(DataV::getLineId, lineIndex)
                .eq(DataV::getValueType, InfluxDbSqlConstant.MAX)
                .regular(DataV::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C))
                .eq(DataV::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataV::getTime, startTime, endTime);
        return dataVMapper.getStatisticsByWraper(influxQueryWrapper);
    }

    /**
     * 功能描述:获取influxDB -> data_plt -> 长时间闪变 -> 最大值
     *
     * @param lineIndex 监测点lineIndex
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     * @date 2022/5/23 10:51
     */
    public List<DataPlt> getDataPlt(List<String> lineIndex, String startTime, String endTime) {
        InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataPlt.class);
        influxQueryWrapper.select(DataPlt::getLineId)
                .select(DataPlt::getPhaseType)
                .select(DataPlt::getQualityFlag)
                .select(DataPlt::getValueType)
                .select(DataPlt::getPlt)
                .regular(DataPlt::getLineId, lineIndex)
                .regular(DataPlt::getPhaseType, Arrays.asList(InfluxDBTableConstant.PHASE_TYPE_A,InfluxDBTableConstant.PHASE_TYPE_B,InfluxDBTableConstant.PHASE_TYPE_C))
                .eq(DataPlt::getQualityFlag, InfluxDBTableConstant.NORMAL)
                .between(DataPlt::getTime, startTime, endTime);
        return dataPltMapper.getStatisticsByWraper(influxQueryWrapper);
    }
    /*********************************************新算法结束***********************************************************/


    /**
     * @Description: getData
     * @Param: [overlimit, allTimeList, flickerAllTimeList, dataHarmRateVPOList, dataIPOList, dataInHarmVPOList, dataVPOList, dataVPOUnbalanceList, dataIPONegList, dataVPOFreqList, dataVPODevList, dataPltPOList]
     * @return: java.util.List<com.njcn.harmonic.pojo.po.LimitRate>
     * @Author: clam
     * @Date: 2022/10/18
     */
    private List<LimitRate> getData(Overlimit overlimit, List<DataV> allTimeList,
                                    List<DataPlt> flickerAllTimeList, List<DataHarmRateV> dataHarmRateVPOList,
                                    List<DataI> dataIPOList, List<DataInHarmV> dataInHarmVPOList,
                                    List<DataV> dataVPOList, List<DataV> dataVPOUnbalanceList, List<DataI> dataIPONegList,
                                    List<DataV> dataVPOFreqList, List<DataV> dataVPODevList, List<DataPlt> dataPltPOList) {
        List<LimitRate> result = new ArrayList<> ( );

        Map<String, List<DataHarmRateV>> harmRateVByPhaseType = new HashMap<> ( );
        Map<String, List<DataI>> dataIByPhaseType = new HashMap<> ( );
        Map<String, List<DataInHarmV>> dataInHarmVPhaseType = new HashMap<> ( );
        Map<String, List<DataV>> dataVPhaseType = new HashMap<> ( );
        Map<String, List<DataV>> dataVDevPhaseType = new HashMap<> ( );
        Map<String, List<DataPlt>> dataPltPhaseType = new HashMap<> ( );
        Map<Instant, List<DataHarmRateV>> harmRateVByTime = new HashMap<> ( );
        Map<Instant, List<DataI>> dataIByTime = new HashMap<> ( );
        Map<Instant, List<DataInHarmV>> dataInHarmVByTime = new HashMap<> ( );
        Map<Instant, List<DataV>> dataVByTime = new HashMap<> ( );
        Map<Instant, List<DataV>> dataVUnbalanceByTime = new HashMap<> ( );
        Map<Instant, List<DataI>> dataINegByTime = new HashMap<> ( );
        Map<Instant, List<DataV>> dataVFreqByTime = new HashMap<> ( );
        Map<Instant, List<DataV>> dataVDevByTime = new HashMap<> ( );
        Map<Instant, List<DataPlt>> dataPltByTime = new HashMap<> ( );
        Integer allTime = 0;
        Integer flickerAllTime = 0;
        if (!CollectionUtils.isEmpty (allTimeList)) {
            allTime = allTimeList.get (0).getAllTime ( );
        }
        if (!CollectionUtils.isEmpty (flickerAllTimeList)) {
            flickerAllTime = flickerAllTimeList.get (0).getFlickerAllTime ();
        }
        if (!CollectionUtils.isEmpty (dataHarmRateVPOList)) {
            //harmRateVByPhaseType = dataHarmRateVPOList.stream ( ).collect (Collectors.groupingBy (DataHarmRateV::getPhaseType));
            //harmRateVByTime = dataHarmRateVPOList.stream ( ).collect (Collectors.groupingBy (DataHarmRateV::getTime));
            for (DataHarmRateV item : dataHarmRateVPOList) {
                harmRateVByPhaseType.computeIfAbsent(item.getPhaseType(), k -> new ArrayList<>()).add(item);
                harmRateVByTime.computeIfAbsent(item.getTime(), k -> new ArrayList<>()).add(item);
            }
        }
        if (!CollectionUtils.isEmpty (dataIPOList)) {
            //dataIByPhaseType = dataIPOList.stream ( ).collect (Collectors.groupingBy (DataI::getPhaseType));
            //dataIByTime = dataIPOList.stream ( ).collect (Collectors.groupingBy (DataI::getTime));
            for (DataI item : dataIPOList) {
                dataIByPhaseType.computeIfAbsent(item.getPhaseType(), k -> new ArrayList<>()).add(item);
                dataIByTime.computeIfAbsent(item.getTime(), k -> new ArrayList<>()).add(item);
            }
        }
        if (!CollectionUtils.isEmpty (dataInHarmVPOList)) {
            //dataInHarmVPhaseType = dataInHarmVPOList.stream ( ).collect (Collectors.groupingBy (DataInHarmV::getPhaseType));
            //dataInHarmVByTime = dataInHarmVPOList.stream ( ).collect (Collectors.groupingBy (DataInHarmV::getTime));
            for (DataInHarmV item : dataInHarmVPOList) {
                dataInHarmVPhaseType.computeIfAbsent(item.getPhaseType(), k -> new ArrayList<>()).add(item);
                dataInHarmVByTime.computeIfAbsent(item.getTime(), k -> new ArrayList<>()).add(item);
            }
        }
        if (!CollectionUtils.isEmpty (dataVPOList)) {
            //dataVPhaseType = dataVPOList.stream ( ).collect (Collectors.groupingBy (DataV::getPhaseType));
            //dataVByTime = dataVPOList.stream ( ).collect (Collectors.groupingBy (DataV::getTime));
            for (DataV item : dataVPOList) {
                dataVPhaseType.computeIfAbsent(item.getPhaseType(), k -> new ArrayList<>()).add(item);
                dataVByTime.computeIfAbsent(item.getTime(), k -> new ArrayList<>()).add(item);
            }
        }
        if (!CollectionUtils.isEmpty (dataVPOUnbalanceList)) {
            dataVUnbalanceByTime = dataVPOUnbalanceList.stream ( ).collect (Collectors.groupingBy (DataV::getTime));
        }
        if (!CollectionUtils.isEmpty (dataIPONegList)) {
            dataINegByTime = dataIPONegList.stream ( ).collect (Collectors.groupingBy (DataI::getTime));
        }
        if (!CollectionUtils.isEmpty (dataVPOFreqList)) {
            dataVFreqByTime = dataVPOFreqList.stream ( ).collect (Collectors.groupingBy (DataV::getTime));
        }
        if (!CollectionUtils.isEmpty (dataVPODevList)) {
            //dataVDevPhaseType = dataVPODevList.stream ( ).collect (Collectors.groupingBy (DataV::getPhaseType));
            //dataVDevByTime = dataVPODevList.stream ( ).collect (Collectors.groupingBy (DataV::getTime));
            for (DataV item : dataVPODevList) {
                dataVDevPhaseType.computeIfAbsent(item.getPhaseType(), k -> new ArrayList<>()).add(item);
                dataVDevByTime.computeIfAbsent(item.getTime(), k -> new ArrayList<>()).add(item);
            }
        }
        if (!CollectionUtils.isEmpty (dataPltPOList)) {
            //dataPltPhaseType = dataPltPOList.stream ( ).collect (Collectors.groupingBy (DataPlt::getPhaseType));
            //dataPltByTime = dataPltPOList.stream ( ).collect (Collectors.groupingBy (DataPlt::getTime));
            for (DataPlt item : dataPltPOList) {
                dataPltPhaseType.computeIfAbsent(item.getPhaseType(), k -> new ArrayList<>()).add(item);
                dataPltByTime.computeIfAbsent(item.getTime(), k -> new ArrayList<>()).add(item);
            }
        }
        LimitRate a = limitRateData (overlimit, allTime, flickerAllTime, "A", overlimit.getId (), harmRateVByPhaseType.get ("A"), dataIByPhaseType.get ("A"), dataInHarmVPhaseType.get ("A"), dataVPhaseType.get ("A"), dataVDevPhaseType.get ("A"), dataPltPhaseType.get ("A"));
        LimitRate b = limitRateData (overlimit, allTime, flickerAllTime, "B", overlimit.getId (), harmRateVByPhaseType.get ("B"), dataIByPhaseType.get ("B"), dataInHarmVPhaseType.get ("B"), dataVPhaseType.get ("B"), dataVDevPhaseType.get ("B"), dataPltPhaseType.get ("B"));
        LimitRate c = limitRateData (overlimit, allTime, flickerAllTime, "C", overlimit.getId (), harmRateVByPhaseType.get ("C"), dataIByPhaseType.get ("C"), dataInHarmVPhaseType.get ("C"), dataVPhaseType.get ("C"), dataVDevPhaseType.get ("C"), dataPltPhaseType.get ("C"));
        LimitRate t = limitRateDataT (overlimit, allTime, flickerAllTime, overlimit.getId (), harmRateVByTime, dataIByTime, dataInHarmVByTime, dataVByTime, dataVUnbalanceByTime, dataINegByTime, dataVFreqByTime, dataVDevByTime, dataPltByTime);
        result.add (a);
        result.add (b);
        result.add (c);
        result.add (t);
        return result;
    }

    /**
     * 通用越限计数辅助方法：遍历列表，统计满足条件的元素个数
     */
    private <T> int countExceeded(List<T> list, Function<T, Double> valueGetter,
                                  Float threshold, double min, double max) {
        if (CollectionUtils.isEmpty(list) || threshold == null) {
            return 0;
        }
        int count = 0;
        for (T item : list) {
            Double val = valueGetter.apply(item);
            if (val != null && val > threshold && val >= min && val <= max) {
                count++;
            }
        }
        return count;
    }

    /**
     * 通用越限存在性检查辅助方法：按时间分组，任一分组中存在越限则计数+1
     */
    private <T> int countTimeSlotsExceeded(Map<Instant, List<T>> map,
                                           Function<T, Double> valueGetter,
                                           Float threshold, double min, double max) {
        if (map == null || threshold == null) {
            return 0;
        }
        int count = 0;
        for (List<T> list : map.values()) {
            if (CollectionUtils.isEmpty(list)) continue;
            boolean exceeded = list.stream().anyMatch(item -> {
                Double val = valueGetter.apply(item);
                return val != null && val > threshold && val >= min && val <= max;
            });
            if (exceeded) count++;
        }
        return count;
    }

    public LimitRate limitRateData(Overlimit overlimit, Integer allTime, Integer flickerAllTime,
                                   String phasicType, String lineId,
                                   List<DataHarmRateV> dataHarmRateVPOList,
                                   List<DataI> dataIPOList,
                                   List<DataInHarmV> dataInHarmVPOList,
                                   List<DataV> dataVPOList,
                                   List<DataV> dataVPODevList,
                                   List<DataPlt> dataPltPOList) {
        LimitRate limitRate = new LimitRate();

        // 2-25次谐波电压含有率
        int v2  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV2,  overlimit.getUharm2(),  0.0, 30.0);
        int v3  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV3,  overlimit.getUharm3(),  0.0, 30.0);
        int v4  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV4,  overlimit.getUharm4(),  0.0, 30.0);
        int v5  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV5,  overlimit.getUharm5(),  0.0, 30.0);
        int v6  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV6,  overlimit.getUharm6(),  0.0, 30.0);
        int v7  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV7,  overlimit.getUharm7(),  0.0, 30.0);
        int v8  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV8,  overlimit.getUharm8(),  0.0, 30.0);
        int v9  = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV9,  overlimit.getUharm9(),  0.0, 30.0);
        int v10 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV10, overlimit.getUharm10(), 0.0, 30.0);
        int v11 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV11, overlimit.getUharm11(), 0.0, 30.0);
        int v12 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV12, overlimit.getUharm12(), 0.0, 30.0);
        int v13 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV13, overlimit.getUharm13(), 0.0, 30.0);
        int v14 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV14, overlimit.getUharm14(), 0.0, 30.0);
        int v15 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV15, overlimit.getUharm15(), 0.0, 30.0);
        int v16 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV16, overlimit.getUharm16(), 0.0, 30.0);
        int v17 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV17, overlimit.getUharm17(), 0.0, 30.0);
        int v18 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV18, overlimit.getUharm18(), 0.0, 30.0);
        int v19 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV19, overlimit.getUharm19(), 0.0, 30.0);
        int v20 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV20, overlimit.getUharm20(), 0.0, 30.0);
        int v21 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV21, overlimit.getUharm21(), 0.0, 30.0);
        int v22 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV22, overlimit.getUharm22(), 0.0, 30.0);
        int v23 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV23, overlimit.getUharm23(), 0.0, 30.0);
        int v24 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV24, overlimit.getUharm24(), 0.0, 30.0);
        int v25 = countExceeded(dataHarmRateVPOList, DataHarmRateV::getV25, overlimit.getUharm25(), 0.0, 30.0);

        // 2-25次谐波电流
        int i2  = countExceeded(dataIPOList, DataI::getI2,  overlimit.getIharm2(),  0.0, 30.0);
        int i3  = countExceeded(dataIPOList, DataI::getI3,  overlimit.getIharm3(),  0.0, 30.0);
        int i4  = countExceeded(dataIPOList, DataI::getI4,  overlimit.getIharm4(),  0.0, 30.0);
        int i5  = countExceeded(dataIPOList, DataI::getI5,  overlimit.getIharm5(),  0.0, 30.0);
        int i6  = countExceeded(dataIPOList, DataI::getI6,  overlimit.getIharm6(),  0.0, 30.0);
        int i7  = countExceeded(dataIPOList, DataI::getI7,  overlimit.getIharm7(),  0.0, 30.0);
        int i8  = countExceeded(dataIPOList, DataI::getI8,  overlimit.getIharm8(),  0.0, 30.0);
        int i9  = countExceeded(dataIPOList, DataI::getI9,  overlimit.getIharm9(),  0.0, 30.0);
        int i10 = countExceeded(dataIPOList, DataI::getI10, overlimit.getIharm10(), 0.0, 30.0);
        int i11 = countExceeded(dataIPOList, DataI::getI11, overlimit.getIharm11(), 0.0, 30.0);
        int i12 = countExceeded(dataIPOList, DataI::getI12, overlimit.getIharm12(), 0.0, 30.0);
        int i13 = countExceeded(dataIPOList, DataI::getI13, overlimit.getIharm13(), 0.0, 30.0);
        int i14 = countExceeded(dataIPOList, DataI::getI14, overlimit.getIharm14(), 0.0, 30.0);
        int i15 = countExceeded(dataIPOList, DataI::getI15, overlimit.getIharm15(), 0.0, 30.0);
        int i16 = countExceeded(dataIPOList, DataI::getI16, overlimit.getIharm16(), 0.0, 30.0);
        int i17 = countExceeded(dataIPOList, DataI::getI17, overlimit.getIharm17(), 0.0, 30.0);
        int i18 = countExceeded(dataIPOList, DataI::getI18, overlimit.getIharm18(), 0.0, 30.0);
        int i19 = countExceeded(dataIPOList, DataI::getI19, overlimit.getIharm19(), 0.0, 30.0);
        int i20 = countExceeded(dataIPOList, DataI::getI20, overlimit.getIharm20(), 0.0, 30.0);
        int i21 = countExceeded(dataIPOList, DataI::getI21, overlimit.getIharm21(), 0.0, 30.0);
        int i22 = countExceeded(dataIPOList, DataI::getI22, overlimit.getIharm22(), 0.0, 30.0);
        int i23 = countExceeded(dataIPOList, DataI::getI23, overlimit.getIharm23(), 0.0, 30.0);
        int i24 = countExceeded(dataIPOList, DataI::getI24, overlimit.getIharm24(), 0.0, 30.0);
        int i25 = countExceeded(dataIPOList, DataI::getI25, overlimit.getIharm25(), 0.0, 30.0);

        // 0.5-15.5次间谐波电压含有率
        int uHarm1  = countExceeded(dataInHarmVPOList, DataInHarmV::getV1,  overlimit.getInuharm1(),  0.0, 30.0);
        int uHarm2  = countExceeded(dataInHarmVPOList, DataInHarmV::getV2,  overlimit.getInuharm2(),  0.0, 30.0);
        int uHarm3  = countExceeded(dataInHarmVPOList, DataInHarmV::getV3,  overlimit.getInuharm3(),  0.0, 30.0);
        int uHarm4  = countExceeded(dataInHarmVPOList, DataInHarmV::getV4,  overlimit.getInuharm4(),  0.0, 30.0);
        int uHarm5  = countExceeded(dataInHarmVPOList, DataInHarmV::getV5,  overlimit.getInuharm5(),  0.0, 30.0);
        int uHarm6  = countExceeded(dataInHarmVPOList, DataInHarmV::getV6,  overlimit.getInuharm6(),  0.0, 30.0);
        int uHarm7  = countExceeded(dataInHarmVPOList, DataInHarmV::getV7,  overlimit.getInuharm7(),  0.0, 30.0);
        int uHarm8  = countExceeded(dataInHarmVPOList, DataInHarmV::getV8,  overlimit.getInuharm8(),  0.0, 30.0);
        int uHarm9  = countExceeded(dataInHarmVPOList, DataInHarmV::getV9,  overlimit.getInuharm9(),  0.0, 30.0);
        int uHarm10 = countExceeded(dataInHarmVPOList, DataInHarmV::getV10, overlimit.getInuharm10(), 0.0, 30.0);
        int uHarm11 = countExceeded(dataInHarmVPOList, DataInHarmV::getV11, overlimit.getInuharm11(), 0.0, 30.0);
        int uHarm12 = countExceeded(dataInHarmVPOList, DataInHarmV::getV12, overlimit.getInuharm12(), 0.0, 30.0);
        int uHarm13 = countExceeded(dataInHarmVPOList, DataInHarmV::getV13, overlimit.getInuharm13(), 0.0, 30.0);
        int uHarm14 = countExceeded(dataInHarmVPOList, DataInHarmV::getV14, overlimit.getInuharm14(), 0.0, 30.0);
        int uHarm15 = countExceeded(dataInHarmVPOList, DataInHarmV::getV15, overlimit.getInuharm15(), 0.0, 30.0);
        int uHarm16 = countExceeded(dataInHarmVPOList, DataInHarmV::getV16, overlimit.getInuharm16(), 0.0, 30.0);

        // 电压总谐波畸变率
        int thd = countExceeded(dataVPOList, DataV::getVThd, overlimit.getUaberrance(), 0.0, 30.0);

        // 电压偏差（特殊逻辑：根据正负选择不同字段和阈值）
        int uDev = 0;
        if (!CollectionUtils.isEmpty(dataVPODevList)) {
            Float voltageDevThreshold = overlimit.getVoltageDev();
            Float uvoltageDevThreshold = overlimit.getUvoltageDev();
            for (DataV item : dataVPODevList) {
                Double vlDev = item.getVlDev();
                Double vuDev = item.getVuDev();
                if (vlDev != null && vlDev >= 0) {
                    if (voltageDevThreshold != null && vlDev > voltageDevThreshold && vlDev <= 20.0) {
                        uDev++;
                    }
                } else if (vuDev != null) {
                    double absVuDev = Math.abs(vuDev);
                    if (uvoltageDevThreshold != null && absVuDev > Math.abs(uvoltageDevThreshold) && absVuDev <= 20.0) {
                        uDev++;
                    }
                }
            }
        }

        // 长时间闪变
        int flicker = countExceeded(dataPltPOList, DataPlt::getPlt, overlimit.getFlicker(), 0.0, 20.0);

        // 组装结果
        limitRate.setLineId(lineId);
        limitRate.setPhasicType(phasicType);
        limitRate.setAllTime(allTime);
        limitRate.setFlickerAllTime(flickerAllTime);
        limitRate.setUAberranceOverTime(thd);
        limitRate.setINegOverTime(0);
        limitRate.setFreqDevOverTime(0);
        limitRate.setUHarm2OverTime(v2);   limitRate.setUHarm3OverTime(v3);
        limitRate.setUHarm4OverTime(v4);   limitRate.setUHarm5OverTime(v5);
        limitRate.setUHarm6OverTime(v6);   limitRate.setUHarm7OverTime(v7);
        limitRate.setUHarm8OverTime(v8);   limitRate.setUHarm9OverTime(v9);
        limitRate.setUHarm10OverTime(v10); limitRate.setUHarm11OverTime(v11);
        limitRate.setUHarm12OverTime(v12); limitRate.setUHarm13OverTime(v13);
        limitRate.setUHarm14OverTime(v14); limitRate.setUHarm15OverTime(v15);
        limitRate.setUHarm16OverTime(v16); limitRate.setUHarm17OverTime(v17);
        limitRate.setUHarm18OverTime(v18); limitRate.setUHarm19OverTime(v19);
        limitRate.setUHarm20OverTime(v20); limitRate.setUHarm21OverTime(v21);
        limitRate.setUHarm22OverTime(v22); limitRate.setUHarm23OverTime(v23);
        limitRate.setUHarm24OverTime(v24); limitRate.setUHarm25OverTime(v25);
        limitRate.setIHarm2OverTime(i2);   limitRate.setIHarm3OverTime(i3);
        limitRate.setIHarm4OverTime(i4);   limitRate.setIHarm5OverTime(i5);
        limitRate.setIHarm6OverTime(i6);   limitRate.setIHarm7OverTime(i7);
        limitRate.setIHarm8OverTime(i8);   limitRate.setIHarm9OverTime(i9);
        limitRate.setIHarm10OverTime(i10); limitRate.setIHarm11OverTime(i11);
        limitRate.setIHarm12OverTime(i12); limitRate.setIHarm13OverTime(i13);
        limitRate.setIHarm14OverTime(i14); limitRate.setIHarm15OverTime(i15);
        limitRate.setIHarm16OverTime(i16); limitRate.setIHarm17OverTime(i17);
        limitRate.setIHarm18OverTime(i18); limitRate.setIHarm19OverTime(i19);
        limitRate.setIHarm20OverTime(i20); limitRate.setIHarm21OverTime(i21);
        limitRate.setIHarm22OverTime(i22); limitRate.setIHarm23OverTime(i23);
        limitRate.setIHarm24OverTime(i24); limitRate.setIHarm25OverTime(i25);
        limitRate.setInuHarm1OverTime(uHarm1);  limitRate.setInuHarm2OverTime(uHarm2);
        limitRate.setInuHarm3OverTime(uHarm3);  limitRate.setInuHarm4OverTime(uHarm4);
        limitRate.setInuHarm5OverTime(uHarm5);  limitRate.setInuHarm6OverTime(uHarm6);
        limitRate.setInuHarm7OverTime(uHarm7);  limitRate.setInuHarm8OverTime(uHarm8);
        limitRate.setInuHarm9OverTime(uHarm9);  limitRate.setInuHarm10OverTime(uHarm10);
        limitRate.setInuHarm11OverTime(uHarm11); limitRate.setInuHarm12OverTime(uHarm12);
        limitRate.setInuHarm13OverTime(uHarm13); limitRate.setInuHarm14OverTime(uHarm14);
        limitRate.setInuHarm15OverTime(uHarm15); limitRate.setInuHarm16OverTime(uHarm16);
        limitRate.setUBalanceOverTime(0);
        limitRate.setVoltageDevOverTime(uDev);
        limitRate.setFlickerOverTime(flicker);
        return limitRate;
    }

    public LimitRate limitRateDataT(Overlimit overlimit, Integer allTime, Integer flickerAllTime,
                                    String lineId,
                                    Map<Instant, List<DataHarmRateV>> map1,
                                    Map<Instant, List<DataI>> map2,
                                    Map<Instant, List<DataInHarmV>> map3,
                                    Map<Instant, List<DataV>> map4,
                                    Map<Instant, List<DataV>> map5,
                                    Map<Instant, List<DataI>> map6,
                                    Map<Instant, List<DataV>> map7,
                                    Map<Instant, List<DataV>> map8,
                                    Map<Instant, List<DataPlt>> map9) {
        LimitRate limitRate = new LimitRate();

        // 2-25次谐波电压含有率（按时间点分组，任一时刻存在越限则该次谐波计数+1）
        int v2  = countTimeSlotsExceeded(map1, DataHarmRateV::getV2,  overlimit.getUharm2(),  0.0, 30.0);
        int v3  = countTimeSlotsExceeded(map1, DataHarmRateV::getV3,  overlimit.getUharm3(),  0.0, 30.0);
        int v4  = countTimeSlotsExceeded(map1, DataHarmRateV::getV4,  overlimit.getUharm4(),  0.0, 30.0);
        int v5  = countTimeSlotsExceeded(map1, DataHarmRateV::getV5,  overlimit.getUharm5(),  0.0, 30.0);
        int v6  = countTimeSlotsExceeded(map1, DataHarmRateV::getV6,  overlimit.getUharm6(),  0.0, 30.0);
        int v7  = countTimeSlotsExceeded(map1, DataHarmRateV::getV7,  overlimit.getUharm7(),  0.0, 30.0);
        int v8  = countTimeSlotsExceeded(map1, DataHarmRateV::getV8,  overlimit.getUharm8(),  0.0, 30.0);
        int v9  = countTimeSlotsExceeded(map1, DataHarmRateV::getV9,  overlimit.getUharm9(),  0.0, 30.0);
        int v10 = countTimeSlotsExceeded(map1, DataHarmRateV::getV10, overlimit.getUharm10(), 0.0, 30.0);
        int v11 = countTimeSlotsExceeded(map1, DataHarmRateV::getV11, overlimit.getUharm11(), 0.0, 30.0);
        int v12 = countTimeSlotsExceeded(map1, DataHarmRateV::getV12, overlimit.getUharm12(), 0.0, 30.0);
        int v13 = countTimeSlotsExceeded(map1, DataHarmRateV::getV13, overlimit.getUharm13(), 0.0, 30.0);
        int v14 = countTimeSlotsExceeded(map1, DataHarmRateV::getV14, overlimit.getUharm14(), 0.0, 30.0);
        int v15 = countTimeSlotsExceeded(map1, DataHarmRateV::getV15, overlimit.getUharm15(), 0.0, 30.0);
        int v16 = countTimeSlotsExceeded(map1, DataHarmRateV::getV16, overlimit.getUharm16(), 0.0, 30.0);
        int v17 = countTimeSlotsExceeded(map1, DataHarmRateV::getV17, overlimit.getUharm17(), 0.0, 30.0);
        int v18 = countTimeSlotsExceeded(map1, DataHarmRateV::getV18, overlimit.getUharm18(), 0.0, 30.0);
        int v19 = countTimeSlotsExceeded(map1, DataHarmRateV::getV19, overlimit.getUharm19(), 0.0, 30.0);
        int v20 = countTimeSlotsExceeded(map1, DataHarmRateV::getV20, overlimit.getUharm20(), 0.0, 30.0);
        int v21 = countTimeSlotsExceeded(map1, DataHarmRateV::getV21, overlimit.getUharm21(), 0.0, 30.0);
        int v22 = countTimeSlotsExceeded(map1, DataHarmRateV::getV22, overlimit.getUharm22(), 0.0, 30.0);
        int v23 = countTimeSlotsExceeded(map1, DataHarmRateV::getV23, overlimit.getUharm23(), 0.0, 30.0);
        int v24 = countTimeSlotsExceeded(map1, DataHarmRateV::getV24, overlimit.getUharm24(), 0.0, 30.0);
        int v25 = countTimeSlotsExceeded(map1, DataHarmRateV::getV25, overlimit.getUharm25(), 0.0, 30.0);

        // 2-25次谐波电流
        int i2  = countTimeSlotsExceeded(map2, DataI::getI2,  overlimit.getIharm2(),  0.0, 30.0);
        int i3  = countTimeSlotsExceeded(map2, DataI::getI3,  overlimit.getIharm3(),  0.0, 30.0);
        int i4  = countTimeSlotsExceeded(map2, DataI::getI4,  overlimit.getIharm4(),  0.0, 30.0);
        int i5  = countTimeSlotsExceeded(map2, DataI::getI5,  overlimit.getIharm5(),  0.0, 30.0);
        int i6  = countTimeSlotsExceeded(map2, DataI::getI6,  overlimit.getIharm6(),  0.0, 30.0);
        int i7  = countTimeSlotsExceeded(map2, DataI::getI7,  overlimit.getIharm7(),  0.0, 30.0);
        int i8  = countTimeSlotsExceeded(map2, DataI::getI8,  overlimit.getIharm8(),  0.0, 30.0);
        int i9  = countTimeSlotsExceeded(map2, DataI::getI9,  overlimit.getIharm9(),  0.0, 30.0);
        int i10 = countTimeSlotsExceeded(map2, DataI::getI10, overlimit.getIharm10(), 0.0, 30.0);
        int i11 = countTimeSlotsExceeded(map2, DataI::getI11, overlimit.getIharm11(), 0.0, 30.0);
        int i12 = countTimeSlotsExceeded(map2, DataI::getI12, overlimit.getIharm12(), 0.0, 30.0);
        int i13 = countTimeSlotsExceeded(map2, DataI::getI13, overlimit.getIharm13(), 0.0, 30.0);
        int i14 = countTimeSlotsExceeded(map2, DataI::getI14, overlimit.getIharm14(), 0.0, 30.0);
        int i15 = countTimeSlotsExceeded(map2, DataI::getI15, overlimit.getIharm15(), 0.0, 30.0);
        int i16 = countTimeSlotsExceeded(map2, DataI::getI16, overlimit.getIharm16(), 0.0, 30.0);
        int i17 = countTimeSlotsExceeded(map2, DataI::getI17, overlimit.getIharm17(), 0.0, 30.0);
        int i18 = countTimeSlotsExceeded(map2, DataI::getI18, overlimit.getIharm18(), 0.0, 30.0);
        int i19 = countTimeSlotsExceeded(map2, DataI::getI19, overlimit.getIharm19(), 0.0, 30.0);
        int i20 = countTimeSlotsExceeded(map2, DataI::getI20, overlimit.getIharm20(), 0.0, 30.0);
        int i21 = countTimeSlotsExceeded(map2, DataI::getI21, overlimit.getIharm21(), 0.0, 30.0);
        int i22 = countTimeSlotsExceeded(map2, DataI::getI22, overlimit.getIharm22(), 0.0, 30.0);
        int i23 = countTimeSlotsExceeded(map2, DataI::getI23, overlimit.getIharm23(), 0.0, 30.0);
        int i24 = countTimeSlotsExceeded(map2, DataI::getI24, overlimit.getIharm24(), 0.0, 30.0);
        int i25 = countTimeSlotsExceeded(map2, DataI::getI25, overlimit.getIharm25(), 0.0, 30.0);

        // 0.5-15.5次间谐波电压含有率
        int uHarm1  = countTimeSlotsExceeded(map3, DataInHarmV::getV1,  overlimit.getInuharm1(),  0.0, 30.0);
        int uHarm2  = countTimeSlotsExceeded(map3, DataInHarmV::getV2,  overlimit.getInuharm2(),  0.0, 30.0);
        int uHarm3  = countTimeSlotsExceeded(map3, DataInHarmV::getV3,  overlimit.getInuharm3(),  0.0, 30.0);
        int uHarm4  = countTimeSlotsExceeded(map3, DataInHarmV::getV4,  overlimit.getInuharm4(),  0.0, 30.0);
        int uHarm5  = countTimeSlotsExceeded(map3, DataInHarmV::getV5,  overlimit.getInuharm5(),  0.0, 30.0);
        int uHarm6  = countTimeSlotsExceeded(map3, DataInHarmV::getV6,  overlimit.getInuharm6(),  0.0, 30.0);
        int uHarm7  = countTimeSlotsExceeded(map3, DataInHarmV::getV7,  overlimit.getInuharm7(),  0.0, 30.0);
        int uHarm8  = countTimeSlotsExceeded(map3, DataInHarmV::getV8,  overlimit.getInuharm8(),  0.0, 30.0);
        int uHarm9  = countTimeSlotsExceeded(map3, DataInHarmV::getV9,  overlimit.getInuharm9(),  0.0, 30.0);
        int uHarm10 = countTimeSlotsExceeded(map3, DataInHarmV::getV10, overlimit.getInuharm10(), 0.0, 30.0);
        int uHarm11 = countTimeSlotsExceeded(map3, DataInHarmV::getV11, overlimit.getInuharm11(), 0.0, 30.0);
        int uHarm12 = countTimeSlotsExceeded(map3, DataInHarmV::getV12, overlimit.getInuharm12(), 0.0, 30.0);
        int uHarm13 = countTimeSlotsExceeded(map3, DataInHarmV::getV13, overlimit.getInuharm13(), 0.0, 30.0);
        int uHarm14 = countTimeSlotsExceeded(map3, DataInHarmV::getV14, overlimit.getInuharm14(), 0.0, 30.0);
        int uHarm15 = countTimeSlotsExceeded(map3, DataInHarmV::getV15, overlimit.getInuharm15(), 0.0, 30.0);
        int uHarm16 = countTimeSlotsExceeded(map3, DataInHarmV::getV16, overlimit.getInuharm16(), 0.0, 30.0);

        // 电压总谐波畸变率
        int thd = countTimeSlotsExceeded(map4, DataV::getVThd, overlimit.getUaberrance(), 0.0, 30.0);

        // 三相电压不平衡度
        int uAberrance = countTimeSlotsExceeded(map5, DataV::getVUnbalance, overlimit.getUbalance(), 0.0, 40.0);

        // 负序电流（注意：原代码无上限约束，此处保持原逻辑，仅加判空）
        int iNeg = 0;
        if (map6 != null && overlimit.getINeg() != null) {
            Float iNegThreshold = overlimit.getINeg();
            for (List<DataI> list : map6.values()) {
                if (CollectionUtils.isEmpty(list)) continue;
                boolean exceeded = list.stream().anyMatch(s -> {
                    Double val = s.getINeg();
                    return val != null && val > iNegThreshold;
                });
                if (exceeded) iNeg++;
            }
        }

        // 频率偏差（含绝对值约束）
        int freqDev = 0;
        if (map7 != null && overlimit.getFreqDev() != null) {
            Float freqDevThreshold = overlimit.getFreqDev();
            for (List<DataV> list : map7.values()) {
                if (CollectionUtils.isEmpty(list)) continue;
                boolean exceeded = list.stream().anyMatch(s -> {
                    Double val = s.getFreqDev();
                    return val != null && val > freqDevThreshold && Math.abs(val) <= 7.5;
                });
                if (exceeded) freqDev++;
            }
        }

        // 电压上偏差、电压下偏差（特殊双条件逻辑）
        int uDev = 0;
        if (map8 != null) {
            Float voltageDevThreshold = overlimit.getVoltageDev();
            Float uvoltageDevThreshold = overlimit.getUvoltageDev();
            for (List<DataV> list : map8.values()) {
                if (CollectionUtils.isEmpty(list)) continue;
                boolean exceeded = list.stream().anyMatch(s -> {
                    Double vlDev = s.getVlDev();
                    Double vuDev = s.getVuDev();
                    // 上偏差条件
                    boolean upperExceeded = vlDev != null && voltageDevThreshold != null
                            && vlDev >= 0.0 && vlDev <= 20.0 && vlDev > voltageDevThreshold;
                    // 下偏差条件
                    boolean lowerExceeded = vuDev != null && uvoltageDevThreshold != null
                            && vuDev >= -20.0 && vuDev <= 0.0
                            && Math.abs(vuDev) > Math.abs(uvoltageDevThreshold);
                    return upperExceeded || lowerExceeded;
                });
                if (exceeded) uDev++;
            }
        }

        // 长时间闪变
        int flicker = countTimeSlotsExceeded(map9, DataPlt::getPlt, overlimit.getFlicker(), 0.0, 20.0);

        // 组装结果
        limitRate.setLineId(lineId);
        limitRate.setPhasicType("T");
        limitRate.setAllTime(allTime);
        limitRate.setFlickerAllTime(flickerAllTime);
        limitRate.setUAberranceOverTime(thd);
        limitRate.setINegOverTime(iNeg);
        limitRate.setFreqDevOverTime(freqDev);
        limitRate.setUHarm2OverTime(v2);   limitRate.setUHarm3OverTime(v3);
        limitRate.setUHarm4OverTime(v4);   limitRate.setUHarm5OverTime(v5);
        limitRate.setUHarm6OverTime(v6);   limitRate.setUHarm7OverTime(v7);
        limitRate.setUHarm8OverTime(v8);   limitRate.setUHarm9OverTime(v9);
        limitRate.setUHarm10OverTime(v10); limitRate.setUHarm11OverTime(v11);
        limitRate.setUHarm12OverTime(v12); limitRate.setUHarm13OverTime(v13);
        limitRate.setUHarm14OverTime(v14); limitRate.setUHarm15OverTime(v15);
        limitRate.setUHarm16OverTime(v16); limitRate.setUHarm17OverTime(v17);
        limitRate.setUHarm18OverTime(v18); limitRate.setUHarm19OverTime(v19);
        limitRate.setUHarm20OverTime(v20); limitRate.setUHarm21OverTime(v21);
        limitRate.setUHarm22OverTime(v22); limitRate.setUHarm23OverTime(v23);
        limitRate.setUHarm24OverTime(v24); limitRate.setUHarm25OverTime(v25);
        limitRate.setIHarm2OverTime(i2);   limitRate.setIHarm3OverTime(i3);
        limitRate.setIHarm4OverTime(i4);   limitRate.setIHarm5OverTime(i5);
        limitRate.setIHarm6OverTime(i6);   limitRate.setIHarm7OverTime(i7);
        limitRate.setIHarm8OverTime(i8);   limitRate.setIHarm9OverTime(i9);
        limitRate.setIHarm10OverTime(i10); limitRate.setIHarm11OverTime(i11);
        limitRate.setIHarm12OverTime(i12); limitRate.setIHarm13OverTime(i13);
        limitRate.setIHarm14OverTime(i14); limitRate.setIHarm15OverTime(i15);
        limitRate.setIHarm16OverTime(i16); limitRate.setIHarm17OverTime(i17);
        limitRate.setIHarm18OverTime(i18); limitRate.setIHarm19OverTime(i19);
        limitRate.setIHarm20OverTime(i20); limitRate.setIHarm21OverTime(i21);
        limitRate.setIHarm22OverTime(i22); limitRate.setIHarm23OverTime(i23);
        limitRate.setIHarm24OverTime(i24); limitRate.setIHarm25OverTime(i25);
        limitRate.setInuHarm1OverTime(uHarm1);  limitRate.setInuHarm2OverTime(uHarm2);
        limitRate.setInuHarm3OverTime(uHarm3);  limitRate.setInuHarm4OverTime(uHarm4);
        limitRate.setInuHarm5OverTime(uHarm5);  limitRate.setInuHarm6OverTime(uHarm6);
        limitRate.setInuHarm7OverTime(uHarm7);  limitRate.setInuHarm8OverTime(uHarm8);
        limitRate.setInuHarm9OverTime(uHarm9);  limitRate.setInuHarm10OverTime(uHarm10);
        limitRate.setInuHarm11OverTime(uHarm11); limitRate.setInuHarm12OverTime(uHarm12);
        limitRate.setInuHarm13OverTime(uHarm13); limitRate.setInuHarm14OverTime(uHarm14);
        limitRate.setInuHarm15OverTime(uHarm15); limitRate.setInuHarm16OverTime(uHarm16);
        limitRate.setUBalanceOverTime(uAberrance);
        limitRate.setVoltageDevOverTime(uDev);
        limitRate.setFlickerOverTime(flicker);
        return limitRate;
    }






    /**
     * @Description: limitRateData
     * @Param: [overlimit, allTime, flickerAllTime, phasicType, lineId, dataHarmRateVPOList, dataIPOList, dataInHarmVPOList, dataVPOList, dataVUnbalanceList, dataINegList]
     * @return: com.njcn.harmonic.pojo.po.LimitRate
     * @Author: clam
     * @Date: 2022/10/18
     */
//    public LimitRate limitRateData(Overlimit overlimit, Integer allTime, Integer
//            flickerAllTime, String phasicType, String lineId,
//                                   List<DataHarmRateV> dataHarmRateVPOList,
//                                   List<DataI> dataIPOList, List<DataInHarmV> dataInHarmVPOList,
//                                   List<DataV> dataVPOList, List<DataV> dataVPODevList, List<DataPlt> dataPltPOList) {
//        LimitRate limitRate = new LimitRate ( );
//        int v2 = 0, v3 = 0, v4 = 0, v5 = 0, v6 = 0, v7 = 0, v8 = 0, v9 = 0, v10 = 0, v11 = 0, v12 = 0, v13 = 0, v14 = 0, v15 = 0, v16 = 0, v17 = 0, v18 = 0, v19 = 0, v20 = 0, v21 = 0, v22 = 0, v23 = 0, v24 = 0, v25 = 0;
//        int i2 = 0, i3 = 0, i4 = 0, i5 = 0, i6 = 0, i7 = 0, i8 = 0, i9 = 0, i10 = 0, i11 = 0, i12 = 0, i13 = 0, i14 = 0, i15 = 0, i16 = 0, i17 = 0, i18 = 0, i19 = 0, i20 = 0, i21 = 0, i22 = 0, i23 = 0, i24 = 0, i25 = 0;
//        int uHarm1 = 0, uHarm2 = 0, uHarm3 = 0, uHarm4 = 0, uHarm5 = 0, uHarm6 = 0, uHarm7 = 0, uHarm8 = 0, uHarm9 = 0, uHarm10 = 0, uHarm11 = 0, uHarm12 = 0, uHarm13 = 0, uHarm14 = 0, uHarm15 = 0, uHarm16 = 0;
//        int thd = 0, uDev = 0, flicker = 0;
//        //2-25次谐波电压含有率
//
//        if (!CollectionUtils.isEmpty (dataHarmRateVPOList)) {
//            for (DataHarmRateV item : dataHarmRateVPOList) {
//                if (item.getV2() != null && item.getV2 ( ) > overlimit.getUharm2 ( ) && item.getV2() >=0.0 && item.getV2() <=30.0) {
//                    v2++;
//                }
//                if (item.getV3() != null && item.getV3 ( ) > overlimit.getUharm3 ( ) && item.getV3() >=0.0 && item.getV3() <=30.0) {
//                    v3++;
//                }
//                if (item.getV4() != null && item.getV4 ( ) > overlimit.getUharm4 ( ) && item.getV4() >=0.0 && item.getV4() <=30.0) {
//                    v4++;
//                }
//                if (item.getV5() != null && item.getV5 ( ) > overlimit.getUharm5 ( ) && item.getV5() >=0.0 && item.getV5() <=30.0) {
//                    v5++;
//                }
//                if (item.getV6() != null && item.getV6 ( ) > overlimit.getUharm6 ( ) && item.getV6() >=0.0 && item.getV6() <=30.0) {
//                    v6++;
//                }
//                if (item.getV7() != null && item.getV7 ( ) > overlimit.getUharm7 ( ) && item.getV7() >=0.0 && item.getV7() <=30.0) {
//                    v7++;
//                }
//                if (item.getV8() != null && item.getV8 ( ) > overlimit.getUharm8 ( ) && item.getV8() >=0.0 && item.getV8() <=30.0) {
//                    v8++;
//                }
//                if (item.getV9() != null && item.getV9 ( ) > overlimit.getUharm9 ( ) && item.getV9() >=0.0 && item.getV9() <=30.0) {
//                    v9++;
//                }
//                if (item.getV10() != null && item.getV10 ( ) > overlimit.getUharm10 ( ) && item.getV10() >=0.0 && item.getV10() <=30.0) {
//                    v10++;
//                }
//                if (item.getV11() != null && item.getV11 ( ) > overlimit.getUharm11 ( ) && item.getV11() >=0.0 && item.getV11() <=30.0) {
//                    v11++;
//                }
//                if (item.getV12() != null && item.getV12 ( ) > overlimit.getUharm12 ( ) && item.getV12() >=0.0 && item.getV12() <=30.0) {
//                    v12++;
//                }
//                if (item.getV13() != null && item.getV13 ( ) > overlimit.getUharm13 ( ) && item.getV13() >=0.0 && item.getV13() <=30.0) {
//                    v13++;
//                }
//                if (item.getV14() != null && item.getV14 ( ) > overlimit.getUharm14 ( ) && item.getV14() >=0.0 && item.getV14() <=30.0) {
//                    v14++;
//                }
//                if (item.getV15() != null && item.getV15 ( ) > overlimit.getUharm15 ( ) && item.getV15() >=0.0 && item.getV15() <=30.0) {
//                    v15++;
//                }
//                if (item.getV16() != null && item.getV16 ( ) > overlimit.getUharm16 ( ) && item.getV16() >=0.0 && item.getV16() <=30.0) {
//                    v16++;
//                }
//                if (item.getV17() != null && item.getV17 ( ) > overlimit.getUharm17 ( ) && item.getV17() >=0.0 && item.getV17() <=30.0) {
//                    v17++;
//                }
//                if (item.getV18() != null && item.getV18 ( ) > overlimit.getUharm18 ( ) && item.getV18() >=0.0 && item.getV18() <=30.0) {
//                    v18++;
//                }
//                if (item.getV19() != null && item.getV19 ( ) > overlimit.getUharm19 ( ) && item.getV19() >=0.0 && item.getV19() <=30.0) {
//                    v19++;
//                }
//                if (item.getV20() != null && item.getV20 ( ) > overlimit.getUharm20 ( ) && item.getV20() >=0.0 && item.getV20() <=30.0) {
//                    v20++;
//                }
//                if (item.getV21() != null && item.getV21 ( ) > overlimit.getUharm21 ( ) && item.getV21() >=0.0 && item.getV21() <=30.0) {
//                    v21++;
//                }
//                if (item.getV22() != null && item.getV22 ( ) > overlimit.getUharm22 ( ) && item.getV22() >=0.0 && item.getV22() <=30.0) {
//                    v22++;
//                }
//                if (item.getV23() != null && item.getV23 ( ) > overlimit.getUharm23 ( ) && item.getV23() >=0.0 && item.getV23() <=30.0) {
//                    v23++;
//                }
//                if (item.getV24() != null && item.getV24 ( ) > overlimit.getUharm24 ( ) && item.getV24() >=0.0 && item.getV24() <=30.0) {
//                    v24++;
//                }
//                if (item.getV25() != null && item.getV25 ( ) > overlimit.getUharm25 ( ) && item.getV25() >=0.0 && item.getV25() <=30.0) {
//                    v25++;
//                }
//            }
//        }
//        //2-25次谐波电流
//        if (!CollectionUtils.isEmpty (dataIPOList)) {
//            for (DataI item : dataIPOList) {
//                if (item.getI2() != null && item.getI2 ( ) > overlimit.getIharm2 ( ) && item.getI2() >=0.0 && item.getI2() <=30.0) {
//                    i2++;
//                }
//                if (item.getI3() != null && item.getI3 ( ) > overlimit.getIharm3 ( ) && item.getI3() >=0.0 && item.getI3() <=30.0) {
//                    i3++;
//                }
//                if (item.getI4() != null && item.getI4 ( ) > overlimit.getIharm4 ( ) && item.getI4() >=0.0 && item.getI4() <=30.0) {
//                    i4++;
//                }
//                if (item.getI5() != null && item.getI5 ( ) > overlimit.getIharm5 ( ) && item.getI5() >=0.0 && item.getI5() <=30.0) {
//                    i5++;
//                }
//                if (item.getI6() != null && item.getI6 ( ) > overlimit.getIharm6 ( ) && item.getI6() >=0.0 && item.getI6() <=30.0) {
//                    i6++;
//                }
//                if (item.getI7() != null && item.getI7 ( ) > overlimit.getIharm7 ( ) && item.getI7() >=0.0 && item.getI7() <=30.0) {
//                    i7++;
//                }
//                if (item.getI8() != null && item.getI8 ( ) > overlimit.getIharm8 ( ) && item.getI8() >=0.0 && item.getI8() <=30.0) {
//                    i8++;
//                }
//                if (item.getI9() != null && item.getI9 ( ) > overlimit.getIharm9 ( ) && item.getI9() >=0.0 && item.getI9() <=30.0) {
//                    i9++;
//                }
//                if (item.getI10() != null && item.getI10 ( ) > overlimit.getIharm10 ( ) && item.getI10() >=0.0 && item.getI10() <=30.0) {
//                    i10++;
//                }
//                if (item.getI11() != null && item.getI11 ( ) > overlimit.getIharm11 ( ) && item.getI11() >=0.0 && item.getI11() <=30.0) {
//                    i11++;
//                }
//                if (item.getI12() != null && item.getI12 ( ) > overlimit.getIharm12 ( ) && item.getI12() >=0.0 && item.getI12() <=30.0) {
//                    i12++;
//                }
//                if (item.getI13() != null && item.getI13 ( ) > overlimit.getIharm13 ( ) && item.getI13() >=0.0 && item.getI13() <=30.0) {
//                    i13++;
//                }
//                if (item.getI14() != null && item.getI14 ( ) > overlimit.getIharm14 ( ) && item.getI14() >=0.0 && item.getI14() <=30.0) {
//                    i14++;
//                }
//                if (item.getI15() != null && item.getI15 ( ) > overlimit.getIharm15 ( ) && item.getI15() >=0.0 && item.getI15() <=30.0) {
//                    i15++;
//                }
//                if (item.getI16() != null && item.getI16 ( ) > overlimit.getIharm16 ( ) && item.getI16() >=0.0 && item.getI16() <=30.0) {
//                    i16++;
//                }
//                if (item.getI17() != null && item.getI17 ( ) > overlimit.getIharm17 ( ) && item.getI17() >=0.0 && item.getI17() <=30.0) {
//                    i17++;
//                }
//                if (item.getI18() != null && item.getI18 ( ) > overlimit.getIharm18 ( ) && item.getI18() >=0.0 && item.getI18() <=30.0) {
//                    i18++;
//                }
//                if (item.getI19() != null && item.getI19 ( ) > overlimit.getIharm19 ( ) && item.getI19() >=0.0 && item.getI19() <=30.0) {
//                    i19++;
//                }
//                if (item.getI20() != null && item.getI20 ( ) > overlimit.getIharm20 ( ) && item.getI20() >=0.0 && item.getI20() <=30.0) {
//                    i20++;
//                }
//                if (item.getI21() != null && item.getI21 ( ) > overlimit.getIharm21 ( ) && item.getI21() >=0.0 && item.getI21() <=30.0) {
//                    i21++;
//                }
//                if (item.getI22() != null && item.getI22 ( ) > overlimit.getIharm22 ( ) && item.getI22() >=0.0 && item.getI22() <=30.0) {
//                    i22++;
//                }
//                if (item.getI23() != null && item.getI23 ( ) > overlimit.getIharm23 ( ) && item.getI23() >=0.0 && item.getI23() <=30.0) {
//                    i23++;
//                }
//                if (item.getI24() != null && item.getI24 ( ) > overlimit.getIharm24 ( ) && item.getI24() >=0.0 && item.getI24() <=30.0) {
//                    i24++;
//                }
//                if (item.getI25() != null && item.getI25 ( ) > overlimit.getIharm25 ( ) && item.getI25() >=0.0 && item.getI25() <=30.0) {
//                    i25++;
//                }
//            }
//        }
//        //0.5-15.5次间谐波电压含有率
//        if (!CollectionUtils.isEmpty (dataInHarmVPOList)) {
//            for (DataInHarmV item : dataInHarmVPOList) {
//                if (item.getV1() != null && item.getV1 ( ) > overlimit.getInuharm1 ( ) && item.getV1() >=0.0 && item.getV1() <=30.0) {
//                    uHarm1++;
//                }
//                if (item.getV2() != null && item.getV2 ( ) > overlimit.getInuharm2 ( ) && item.getV2() >=0.0 && item.getV2() <=30.0) {
//                    uHarm2++;
//                }
//                if (item.getV3() != null && item.getV3 ( ) > overlimit.getInuharm3 ( ) && item.getV3() >=0.0 && item.getV3() <=30.0) {
//                    uHarm3++;
//                }
//                if (item.getV4() != null && item.getV4 ( ) > overlimit.getInuharm4 ( ) && item.getV4() >=0.0 && item.getV4() <=30.0) {
//                    uHarm4++;
//                }
//                if (item.getV5() != null && item.getV5 ( ) > overlimit.getInuharm5 ( ) && item.getV5() >=0.0 && item.getV5() <=30.0) {
//                    uHarm5++;
//                }
//                if (item.getV6() != null && item.getV6 ( ) > overlimit.getInuharm6 ( ) && item.getV6() >=0.0 && item.getV6() <=30.0) {
//                    uHarm6++;
//                }
//                if (item.getV7() != null && item.getV7 ( ) > overlimit.getInuharm7 ( ) && item.getV7() >=0.0 && item.getV7() <=30.0) {
//                    uHarm7++;
//                }
//                if (item.getV8() != null && item.getV8 ( ) > overlimit.getInuharm8 ( ) && item.getV8() >=0.0 && item.getV8() <=30.0) {
//                    uHarm8++;
//                }
//                if (item.getV9() != null && item.getV9 ( ) > overlimit.getInuharm9 ( ) && item.getV9() >=0.0 && item.getV9() <=30.0) {
//                    uHarm9++;
//                }
//                if (item.getV10() != null && item.getV10 ( ) > overlimit.getInuharm10 ( ) && item.getV10() >=0.0 && item.getV10() <=30.0) {
//                    uHarm10++;
//                }
//                if (item.getV11() != null && item.getV11 ( ) > overlimit.getInuharm11 ( ) && item.getV11() >=0.0 && item.getV11() <=30.0) {
//                    uHarm11++;
//                }
//                if (item.getV12() != null && item.getV12 ( ) > overlimit.getInuharm12 ( ) && item.getV12() >=0.0 && item.getV12() <=30.0) {
//                    uHarm12++;
//                }
//                if (item.getV13() != null && item.getV13 ( ) > overlimit.getInuharm13 ( ) && item.getV13() >=0.0 && item.getV13() <=30.0) {
//                    uHarm13++;
//                }
//                if (item.getV14() != null && item.getV14 ( ) > overlimit.getInuharm14 ( ) && item.getV14() >=0.0 && item.getV14() <=30.0) {
//                    uHarm14++;
//                }
//                if (item.getV15() != null && item.getV15 ( ) > overlimit.getInuharm15 ( ) && item.getV15() >=0.0 && item.getV15() <=30.0) {
//                    uHarm15++;
//                }
//                if (item.getV16() != null && item.getV16 ( ) > overlimit.getInuharm16 ( ) && item.getV16() >=0.0 && item.getV16() <=30.0) {
//                    uHarm16++;
//                }
//            }
//        }
//        //电压总谐波畸变率
//        if (!CollectionUtils.isEmpty (dataVPOList)) {
//            for (DataV item : dataVPOList) {
//                if (item.getVThd() != null && item.getVThd ( ) > overlimit.getUaberrance ( ) && item.getVThd() >=0.0 && item.getVThd() <=30.0) {
//                    thd++;
//                }
//            }
//        }
//        //电压上偏差、电压下偏差(根据vl_dev的正负判断是用哪个值判断越限)
//        if (!CollectionUtils.isEmpty (dataVPODevList)) {
//            for (DataV item : dataVPODevList) {
//                Double vlDev = item.getVlDev();
//                Double vuDev = item.getVuDev();
//                if (vlDev != null && vlDev >= 0) {
//                    if (vlDev > overlimit.getVoltageDev() && vlDev <= 20.0) {
//                        uDev++;
//                    }
//                } else if (vuDev != null) {
//                    double absVuDev = Math.abs(vuDev);
//                    if (absVuDev > Math.abs(overlimit.getUvoltageDev()) && absVuDev <= 20.0) {
//                        uDev++;
//                    }
//                }
//            }
//        }
//        //长时间闪变
//        if (!CollectionUtils.isEmpty (dataPltPOList)) {
//            for (DataPlt item : dataPltPOList) {
//                if (item.getPlt() != null && item.getPlt ( ) > overlimit.getFlicker ( ) && item.getPlt()>=0 && item.getPlt()<=20) {
//                    flicker++;
//                }
//            }
//        }
//        limitRate.setLineId (lineId);
//        limitRate.setPhasicType (phasicType);
//        limitRate.setAllTime (allTime);
//        limitRate.setFlickerAllTime (flickerAllTime);
//        limitRate.setUAberranceOverTime (thd);
//        limitRate.setINegOverTime (0);
//        limitRate.setFreqDevOverTime (0);
//        limitRate.setUHarm2OverTime (v2);
//        limitRate.setUHarm3OverTime (v3);
//        limitRate.setUHarm4OverTime (v4);
//        limitRate.setUHarm5OverTime (v5);
//        limitRate.setUHarm6OverTime (v6);
//        limitRate.setUHarm7OverTime (v7);
//        limitRate.setUHarm8OverTime (v8);
//        limitRate.setUHarm9OverTime (v9);
//        limitRate.setUHarm10OverTime (v10);
//        limitRate.setUHarm11OverTime (v11);
//        limitRate.setUHarm12OverTime (v12);
//        limitRate.setUHarm13OverTime (v13);
//        limitRate.setUHarm14OverTime (v14);
//        limitRate.setUHarm15OverTime (v15);
//        limitRate.setUHarm16OverTime (v16);
//        limitRate.setUHarm17OverTime (v17);
//        limitRate.setUHarm18OverTime (v18);
//        limitRate.setUHarm19OverTime (v19);
//        limitRate.setUHarm20OverTime (v20);
//        limitRate.setUHarm21OverTime (v21);
//        limitRate.setUHarm22OverTime (v22);
//        limitRate.setUHarm23OverTime (v23);
//        limitRate.setUHarm24OverTime (v24);
//        limitRate.setUHarm25OverTime (v25);
//        limitRate.setIHarm2OverTime (i2);
//        limitRate.setIHarm3OverTime (i3);
//        limitRate.setIHarm4OverTime (i4);
//        limitRate.setIHarm5OverTime (i5);
//        limitRate.setIHarm6OverTime (i6);
//        limitRate.setIHarm7OverTime (i7);
//        limitRate.setIHarm8OverTime (i8);
//        limitRate.setIHarm9OverTime (i9);
//        limitRate.setIHarm10OverTime (i10);
//        limitRate.setIHarm11OverTime (i11);
//        limitRate.setIHarm12OverTime (i12);
//        limitRate.setIHarm13OverTime (i13);
//        limitRate.setIHarm14OverTime (i14);
//        limitRate.setIHarm15OverTime (i15);
//        limitRate.setIHarm16OverTime (i16);
//        limitRate.setIHarm17OverTime (i17);
//        limitRate.setIHarm18OverTime (i18);
//        limitRate.setIHarm19OverTime (i19);
//        limitRate.setIHarm20OverTime (i20);
//        limitRate.setIHarm21OverTime (i21);
//        limitRate.setIHarm22OverTime (i22);
//        limitRate.setIHarm23OverTime (i23);
//        limitRate.setIHarm24OverTime (i24);
//        limitRate.setIHarm25OverTime (i25);
//        limitRate.setInuHarm1OverTime (uHarm1);
//        limitRate.setInuHarm2OverTime (uHarm2);
//        limitRate.setInuHarm3OverTime (uHarm3);
//        limitRate.setInuHarm4OverTime (uHarm4);
//        limitRate.setInuHarm5OverTime (uHarm5);
//        limitRate.setInuHarm6OverTime (uHarm6);
//        limitRate.setInuHarm7OverTime (uHarm7);
//        limitRate.setInuHarm8OverTime (uHarm8);
//        limitRate.setInuHarm9OverTime (uHarm9);
//        limitRate.setInuHarm10OverTime (uHarm10);
//        limitRate.setInuHarm11OverTime (uHarm11);
//        limitRate.setInuHarm12OverTime (uHarm12);
//        limitRate.setInuHarm13OverTime (uHarm13);
//        limitRate.setInuHarm14OverTime (uHarm14);
//        limitRate.setInuHarm15OverTime (uHarm15);
//        limitRate.setInuHarm16OverTime (uHarm16);
//        limitRate.setUBalanceOverTime (0);
//        limitRate.setVoltageDevOverTime (uDev);
//        limitRate.setFlickerOverTime (flicker);
//        return limitRate;
//    }
//
//
//    public LimitRate limitRateDataT(Overlimit overlimit, Integer allTime, Integer flickerAllTime, String lineId, Map<Instant,List<DataHarmRateV>> map1, Map<Instant,List<DataI>> map2, Map<Instant,List<DataInHarmV>> map3, Map<Instant,List<DataV>> map4, Map<Instant,List<DataV>> map5, Map<Instant,List<DataI>> map6, Map<Instant,List<DataV>> map7, Map<Instant,List<DataV>> map8, Map<Instant,List<DataPlt>> map9){
//        LimitRate limitRate = new LimitRate();
//        int v2 = 0,v3 = 0,v4 = 0,v5 = 0,v6 = 0,v7 = 0,v8 = 0,v9 = 0,v10 = 0,v11 = 0,v12 = 0,v13 = 0,v14 = 0,v15 = 0,v16 = 0,v17 = 0,v18 = 0,v19 = 0,v20 = 0,v21 = 0,v22 = 0,v23 = 0,v24 = 0,v25 = 0;
//        int i2 = 0,i3 = 0,i4 = 0,i5 = 0,i6 = 0,i7 = 0,i8 = 0,i9 = 0,i10 = 0,i11 = 0,i12 = 0,i13 = 0,i14 = 0,i15 = 0,i16 = 0,i17 = 0,i18 = 0,i19 = 0,i20 = 0,i21 = 0,i22 = 0,i23 = 0,i24 = 0,i25 = 0;
//        int uHarm1 = 0,uHarm2 = 0,uHarm3 = 0,uHarm4 = 0,uHarm5 = 0,uHarm6 = 0,uHarm7 = 0,uHarm8 = 0,uHarm9 = 0,uHarm10 = 0,uHarm11 = 0,uHarm12 = 0,uHarm13 = 0,uHarm14 = 0,uHarm15 = 0,uHarm16 = 0;
//        int thd = 0,uDev = 0,flicker = 0,freqDev = 0,uAberrance = 0,iNeg = 0;
//        //2-25次谐波电压含有率
//        for (Instant time:map1.keySet()) {
//            List<DataHarmRateV> list = map1.get(time);
//            List<DataHarmRateV> l2 = list.stream().filter(s->s.getV2() !=null && s.getV2()>overlimit.getUharm2()&&s.getV2()>=0.0&&s.getV2()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l2)){
//                v2++;
//            }
//            List<DataHarmRateV> l3 = list.stream().filter(s->s.getV3() !=null && s.getV3()>overlimit.getUharm3()&&s.getV3()>=0.0&&s.getV3()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l3)){
//                v3++;
//            }
//            List<DataHarmRateV> l4 = list.stream().filter(s->s.getV4() !=null && s.getV4()>overlimit.getUharm4()&&s.getV4()>=0.0&&s.getV4()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l4)){
//                v4++;
//            }
//            List<DataHarmRateV> l5 = list.stream().filter(s->s.getV5()>overlimit.getUharm5()&&s.getV5()>=0.0&&s.getV5()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l5)){
//                v5++;
//            }
//            List<DataHarmRateV> l6 = list.stream().filter(s->s.getV6()>overlimit.getUharm6()&&s.getV6()>=0.0&&s.getV6()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l6)){
//                v6++;
//            }
//            List<DataHarmRateV> l7 = list.stream().filter(s->s.getV7()>overlimit.getUharm7()&&s.getV7()>=0.0&&s.getV7()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l7)){
//                v7++;
//            }
//            List<DataHarmRateV> l8 = list.stream().filter(s->s.getV8()>overlimit.getUharm8()&&s.getV8()>=0.0&&s.getV8()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l8)){
//                v8++;
//            }
//            List<DataHarmRateV> l9 = list.stream().filter(s->s.getV9()>overlimit.getUharm9()&&s.getV9()>=0.0&&s.getV9()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l9)){
//                v9++;
//            }
//            List<DataHarmRateV> l10 = list.stream().filter(s->s.getV10()>overlimit.getUharm10()&&s.getV10()>=0.0&&s.getV10()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l10)){
//                v10++;
//            }
//            List<DataHarmRateV> l11 = list.stream().filter(s->s.getV11()>overlimit.getUharm11()&&s.getV11()>=0.0&&s.getV11()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l11)){
//                v11++;
//            }
//            List<DataHarmRateV> l12 = list.stream().filter(s->s.getV12()>overlimit.getUharm12()&&s.getV12()>=0.0&&s.getV12()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l12)){
//                v12++;
//            }
//            List<DataHarmRateV> l13 = list.stream().filter(s->s.getV13()>overlimit.getUharm13()&&s.getV13()>=0.0&&s.getV13()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l13)){
//                v13++;
//            }
//            List<DataHarmRateV> l14 = list.stream().filter(s->s.getV14()>overlimit.getUharm14()&&s.getV14()>=0.0&&s.getV14()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l14)){
//                v14++;
//            }
//            List<DataHarmRateV> l15 = list.stream().filter(s->s.getV15()>overlimit.getUharm15()&&s.getV15()>=0.0&&s.getV15()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l15)){
//                v15++;
//            }
//            List<DataHarmRateV> l16 = list.stream().filter(s->s.getV16()>overlimit.getUharm16()&&s.getV16()>=0.0&&s.getV16()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l16)){
//                v16++;
//            }
//            List<DataHarmRateV> l17 = list.stream().filter(s->s.getV17()>overlimit.getUharm17()&&s.getV17()>=0.0&&s.getV17()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l17)){
//                v17++;
//            }
//            List<DataHarmRateV> l18 = list.stream().filter(s->s.getV18()>overlimit.getUharm18()&&s.getV18()>=0.0&&s.getV18()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l18)){
//                v18++;
//            }
//            List<DataHarmRateV> l19 = list.stream().filter(s->s.getV19()>overlimit.getUharm19()&&s.getV19()>=0.0&&s.getV19()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l19)){
//                v19++;
//            }
//            List<DataHarmRateV> l20 = list.stream().filter(s->s.getV20()>overlimit.getUharm20()&&s.getV20()>=0.0&&s.getV20()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l20)){
//                v20++;
//            }
//            List<DataHarmRateV> l21 = list.stream().filter(s->s.getV21()>overlimit.getUharm21()&&s.getV21()>=0.0&&s.getV21()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l21)){
//                v21++;
//            }
//            List<DataHarmRateV> l22 = list.stream().filter(s->s.getV22()>overlimit.getUharm22()&&s.getV22()>=0.0&&s.getV22()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l22)){
//                v22++;
//            }
//            List<DataHarmRateV> l23 = list.stream().filter(s->s.getV23()>overlimit.getUharm23()&&s.getV23()>=0.0&&s.getV23()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l23)){
//                v23++;
//            }
//            List<DataHarmRateV> l24 = list.stream().filter(s->s.getV24()>overlimit.getUharm24()&&s.getV24()>=0.0&&s.getV24()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l24)){
//                v24++;
//            }
//            List<DataHarmRateV> l25 = list.stream().filter(s->s.getV25()>overlimit.getUharm25()&&s.getV25()>=0.0&&s.getV25()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l25)){
//                v25++;
//            }
//        }
//        //2-25次谐波电流
//        for (Instant time:map2.keySet()) {
//            List<DataI> list = map2.get(time);
//            List<DataI> l2 = list.stream().filter(s->s.getI2()>overlimit.getIharm2()&&s.getI2()>=0.0&&s.getI2()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l2)){
//                i2++;
//            }
//            List<DataI> l3 = list.stream().filter(s->s.getI3()>overlimit.getIharm3()&&s.getI3()>=0.0&&s.getI3()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l3)){
//                i3++;
//            }
//            List<DataI> l4 = list.stream().filter(s->s.getI4()>overlimit.getIharm4()&&s.getI4()>=0.0&&s.getI4()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l4)){
//                i4++;
//            }
//            List<DataI> l5 = list.stream().filter(s->s.getI5()>overlimit.getIharm5()&&s.getI5()>=0.0&&s.getI5()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l5)){
//                i5++;
//            }
//            List<DataI> l6 = list.stream().filter(s->s.getI6()>overlimit.getIharm6()&&s.getI6()>=0.0&&s.getI6()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l6)){
//                i6++;
//            }
//            List<DataI> l7 = list.stream().filter(s->s.getI7()>overlimit.getIharm7()&&s.getI7()>=0.0&&s.getI7()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l7)){
//                i7++;
//            }
//            List<DataI> l8 = list.stream().filter(s->s.getI8()>overlimit.getIharm8()&&s.getI8()>=0.0&&s.getI8()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l8)){
//                i8++;
//            }
//            List<DataI> l9 = list.stream().filter(s->s.getI9()>overlimit.getIharm9()&&s.getI9()>=0.0&&s.getI9()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l9)){
//                i9++;
//            }
//            List<DataI> l10 = list.stream().filter(s->s.getI10()>overlimit.getIharm10()&&s.getI10()>=0.0&&s.getI10()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l10)){
//                i10++;
//            }
//            List<DataI> l11 = list.stream().filter(s->s.getI11()>overlimit.getIharm11()&&s.getI11()>=0.0&&s.getI11()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l11)){
//                i11++;
//            }
//            List<DataI> l12 = list.stream().filter(s->s.getI12()>overlimit.getIharm12()&&s.getI12()>=0.0&&s.getI12()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l12)){
//                i12++;
//            }
//            List<DataI> l13 = list.stream().filter(s->s.getI13()>overlimit.getIharm13()&&s.getI13()>=0.0&&s.getI13()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l13)){
//                i13++;
//            }
//            List<DataI> l14 = list.stream().filter(s->s.getI14()>overlimit.getIharm14()&&s.getI14()>=0.0&&s.getI14()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l14)){
//                i14++;
//            }
//            List<DataI> l15 = list.stream().filter(s->s.getI15()>overlimit.getIharm15()&&s.getI15()>=0.0&&s.getI15()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l15)){
//                i15++;
//            }
//            List<DataI> l16 = list.stream().filter(s->s.getI16()>overlimit.getIharm16()&&s.getI16()>=0.0&&s.getI16()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l16)){
//                i16++;
//            }
//            List<DataI> l17 = list.stream().filter(s->s.getI17()>overlimit.getIharm17()&&s.getI17()>=0.0&&s.getI17()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l17)){
//                i17++;
//            }
//            List<DataI> l18 = list.stream().filter(s->s.getI18()>overlimit.getIharm18()&&s.getI18()>=0.0&&s.getI18()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l18)){
//                i18++;
//            }
//            List<DataI> l19 = list.stream().filter(s->s.getI19()>overlimit.getIharm19()&&s.getI19()>=0.0&&s.getI19()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l19)){
//                i19++;
//            }
//            List<DataI> l20 = list.stream().filter(s->s.getI20()>overlimit.getIharm20()&&s.getI20()>=0.0&&s.getI20()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l20)){
//                i20++;
//            }
//            List<DataI> l21 = list.stream().filter(s->s.getI21()>overlimit.getIharm21()&&s.getI21()>=0.0&&s.getI21()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l21)){
//                i21++;
//            }
//            List<DataI> l22 = list.stream().filter(s->s.getI22()>overlimit.getIharm22()&&s.getI22()>=0.0&&s.getI22()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l22)){
//                i22++;
//            }
//            List<DataI> l23 = list.stream().filter(s->s.getI23()>overlimit.getIharm23()&&s.getI23()>=0.0&&s.getI23()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l23)){
//                i23++;
//            }
//            List<DataI> l24 = list.stream().filter(s->s.getI24()>overlimit.getIharm24()&&s.getI24()>=0.0&&s.getI24()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l24)){
//                i24++;
//            }
//            List<DataI> l25 = list.stream().filter(s->s.getI25()>overlimit.getIharm25()&&s.getI25()>=0.0&&s.getI25()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l25)){
//                i25++;
//            }
//        }
//        //0.5-15.5次间谐波电压含有率
//        for (Instant time:map3.keySet()) {
//            List<DataInHarmV> list3 = map3.get(time);
//            List<DataInHarmV> l2 = list3.stream().filter(s->s.getV1()>overlimit.getInuharm1()&&s.getV1()>=0.0&&s.getV1()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l2)){
//                uHarm1++;
//            }
//            List<DataInHarmV> l3 = list3.stream().filter(s->s.getV2()>overlimit.getInuharm2()&&s.getV2()>=0.0&&s.getV2()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l3)){
//                uHarm2++;
//            }
//            List<DataInHarmV> l4 = list3.stream().filter(s->s.getV3()>overlimit.getInuharm3()&&s.getV3()>=0.0&&s.getV3()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l4)){
//                uHarm3++;
//            }
//            List<DataInHarmV> l5 = list3.stream().filter(s->s.getV4()>overlimit.getInuharm4()&&s.getV4()>=0.0&&s.getV4()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l5)){
//                uHarm4++;
//            }
//            List<DataInHarmV> l6 = list3.stream().filter(s->s.getV5()>overlimit.getInuharm5()&&s.getV5()>=0.0&&s.getV5()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l6)){
//                uHarm5++;
//            }
//            List<DataInHarmV> l7 = list3.stream().filter(s->s.getV6()>overlimit.getInuharm6()&&s.getV6()>=0.0&&s.getV6()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l7)){
//                uHarm6++;
//            }
//            List<DataInHarmV> l8 = list3.stream().filter(s->s.getV7()>overlimit.getInuharm7()&&s.getV7()>=0.0&&s.getV7()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l8)){
//                uHarm7++;
//            }
//            List<DataInHarmV> l9 = list3.stream().filter(s->s.getV8()>overlimit.getInuharm8()&&s.getV8()>=0.0&&s.getV8()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l9)){
//                uHarm8++;
//            }
//            List<DataInHarmV> l10 = list3.stream().filter(s->s.getV9()>overlimit.getInuharm9()&&s.getV9()>=0.0&&s.getV9()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l10)){
//                uHarm9++;
//            }
//            List<DataInHarmV> l11 = list3.stream().filter(s->s.getV10()>overlimit.getInuharm10()&&s.getV10()>=0.0&&s.getV10()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l11)){
//                uHarm10++;
//            }
//            List<DataInHarmV> l12 = list3.stream().filter(s->s.getV11()>overlimit.getInuharm11()&&s.getV11()>=0.0&&s.getV11()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l12)){
//                uHarm11++;
//            }
//            List<DataInHarmV> l13 = list3.stream().filter(s->s.getV12()>overlimit.getInuharm12()&&s.getV12()>=0.0&&s.getV12()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l13)){
//                uHarm12++;
//            }
//            List<DataInHarmV> l14 = list3.stream().filter(s->s.getV13()>overlimit.getInuharm13()&&s.getV13()>=0.0&&s.getV13()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l14)){
//                uHarm13++;
//            }
//            List<DataInHarmV> l15 = list3.stream().filter(s->s.getV14()>overlimit.getInuharm14()&&s.getV14()>=0.0&&s.getV14()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l15)){
//                uHarm14++;
//            }
//            List<DataInHarmV> l16 = list3.stream().filter(s->s.getV15()>overlimit.getInuharm15()&&s.getV15()>=0.0&&s.getV15()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l16)){
//                uHarm15++;
//            }
//            List<DataInHarmV> l17 = list3.stream().filter(s->s.getV16()>overlimit.getInuharm16()&&s.getV16()>=0.0&&s.getV16()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l17)){
//                uHarm16++;
//            }
//        }
//        //电压总谐波畸变率
//        for (Instant time:map4.keySet()) {
//            List<DataV> list = map4.get(time);
//            List<DataV> l = list.stream().filter(s->s.getVThd()>overlimit.getUaberrance()&&s.getVThd()>=0.0&&s.getVThd()<=30.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l)){
//                thd++;
//            }
//        }
//        //三相电压不平衡度
//        for (Instant time:map5.keySet()) {
//            List<DataV> list = map5.get(time);
//            List<DataV> l = list.stream().filter(s->s.getVUnbalance()>overlimit.getUbalance()&&s.getVUnbalance()>=0.0&&s.getVUnbalance()<=40.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l)){
//                uAberrance++;
//            }
//        }
//        //负序电流
//        for (Instant time:map6.keySet()) {
//            List<DataI> list = map6.get(time);
//            List<DataI> l = list.stream().filter(s->s.getINeg()>overlimit.getINeg()).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l)){
//                iNeg++;
//            }
//        }
//        //频率偏差
//        for (Instant time:map7.keySet()) {
//            List<DataV> list = map7.get(time);
//            List<DataV> l = list.stream().filter(s->s.getFreqDev()>overlimit.getFreqDev()&&Math.abs(s.getFreqDev())<=7.5).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l)){
//                freqDev++;
//            }
//        }
//        //电压上偏差、电压下偏差
//        for (Instant time:map8.keySet()) {
//            List<DataV> list = map8.get(time);
//            List<DataV> l1 = list.stream().filter(s->s.getVlDev()>=0.0&&s.getVlDev()<=20.0&&s.getVlDev()>overlimit.getVoltageDev()).collect(Collectors.toList());
//            List<DataV> l2 = list.stream().filter(s->s.getVuDev()>=-20.0&&s.getVuDev()<=0.0&&Math.abs(s.getVuDev())>Math.abs(overlimit.getUvoltageDev())).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l1) || !CollectionUtils.isEmpty(l2)){
//                uDev++;
//            }
//        }
//        //长时间闪变
//        for (Instant time:map9.keySet()) {
//            List<DataPlt> list = map9.get(time);
//            List<DataPlt> l = list.stream().filter(s->s.getPlt()>overlimit.getFlicker()&&s.getPlt()>=0.0&&s.getPlt()<=20.0).collect(Collectors.toList());
//            if (!CollectionUtils.isEmpty(l)){
//                flicker++;
//            }
//        }
//        limitRate.setLineId(lineId);
//        limitRate.setPhasicType("T");
//        limitRate.setAllTime(allTime);
//        limitRate.setFlickerAllTime(flickerAllTime);
//        limitRate.setUAberranceOverTime(thd);
//        limitRate.setINegOverTime(iNeg);
//        limitRate.setFreqDevOverTime(freqDev);
//        limitRate.setUHarm2OverTime(v2);
//        limitRate.setUHarm3OverTime(v3);
//        limitRate.setUHarm4OverTime(v4);
//        limitRate.setUHarm5OverTime(v5);
//        limitRate.setUHarm6OverTime(v6);
//        limitRate.setUHarm7OverTime(v7);
//        limitRate.setUHarm8OverTime(v8);
//        limitRate.setUHarm9OverTime(v9);
//        limitRate.setUHarm10OverTime(v10);
//        limitRate.setUHarm11OverTime(v11);
//        limitRate.setUHarm12OverTime(v12);
//        limitRate.setUHarm13OverTime(v13);
//        limitRate.setUHarm14OverTime(v14);
//        limitRate.setUHarm15OverTime(v15);
//        limitRate.setUHarm16OverTime(v16);
//        limitRate.setUHarm17OverTime(v17);
//        limitRate.setUHarm18OverTime(v18);
//        limitRate.setUHarm19OverTime(v19);
//        limitRate.setUHarm20OverTime(v20);
//        limitRate.setUHarm21OverTime(v21);
//        limitRate.setUHarm22OverTime(v22);
//        limitRate.setUHarm23OverTime(v23);
//        limitRate.setUHarm24OverTime(v24);
//        limitRate.setUHarm25OverTime(v25);
//        limitRate.setIHarm2OverTime(i2);
//        limitRate.setIHarm3OverTime(i3);
//        limitRate.setIHarm4OverTime(i4);
//        limitRate.setIHarm5OverTime(i5);
//        limitRate.setIHarm6OverTime(i6);
//        limitRate.setIHarm7OverTime(i7);
//        limitRate.setIHarm8OverTime(i8);
//        limitRate.setIHarm9OverTime(i9);
//        limitRate.setIHarm10OverTime(i10);
//        limitRate.setIHarm11OverTime(i11);
//        limitRate.setIHarm12OverTime(i12);
//        limitRate.setIHarm13OverTime(i13);
//        limitRate.setIHarm14OverTime(i14);
//        limitRate.setIHarm15OverTime(i15);
//        limitRate.setIHarm16OverTime(i16);
//        limitRate.setIHarm17OverTime(i17);
//        limitRate.setIHarm18OverTime(i18);
//        limitRate.setIHarm19OverTime(i19);
//        limitRate.setIHarm20OverTime(i20);
//        limitRate.setIHarm21OverTime(i21);
//        limitRate.setIHarm22OverTime(i22);
//        limitRate.setIHarm23OverTime(i23);
//        limitRate.setIHarm24OverTime(i24);
//        limitRate.setIHarm25OverTime(i25);
//        limitRate.setInuHarm1OverTime(uHarm1);
//        limitRate.setInuHarm2OverTime(uHarm2);
//        limitRate.setInuHarm3OverTime(uHarm3);
//        limitRate.setInuHarm4OverTime(uHarm4);
//        limitRate.setInuHarm5OverTime(uHarm5);
//        limitRate.setInuHarm6OverTime(uHarm6);
//        limitRate.setInuHarm7OverTime(uHarm7);
//        limitRate.setInuHarm8OverTime(uHarm8);
//        limitRate.setInuHarm9OverTime(uHarm9);
//        limitRate.setInuHarm10OverTime(uHarm10);
//        limitRate.setInuHarm11OverTime(uHarm11);
//        limitRate.setInuHarm12OverTime(uHarm12);
//        limitRate.setInuHarm13OverTime(uHarm13);
//        limitRate.setInuHarm14OverTime(uHarm14);
//        limitRate.setInuHarm15OverTime(uHarm15);
//        limitRate.setInuHarm16OverTime(uHarm16);
//        limitRate.setUBalanceOverTime(uAberrance);
//        limitRate.setVoltageDevOverTime(uDev);
//        limitRate.setFlickerOverTime(flicker);
//        return limitRate;
//    }
}
