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

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
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.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.*;
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 IDataIMapper dataIMapper;
    private final DataInHarmVMapper dataInHarmVMapper;

    /*********************************************新算法***********************************************************/
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public void limitRate(CalculatedParam calculatedParam) {
        log.info(LocalDateTime.now()+"r_stat_limit_rate_d开始执行=======》");
        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<>();
        List<String> lineIds = calculatedParam.getIdList();
        String startTime = LocalDateTimeUtil.format(
                LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)),
                DatePattern.NORM_DATETIME_PATTERN
        );
        String endTime = LocalDateTimeUtil.format(
                LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)),
                DatePattern.NORM_DATETIME_PATTERN
        );
        //获取所有监测点的限值
        List<Overlimit> overLimitList = commTerminalGeneralClient.getAllLineOverLimit().getData();
        Map<String,List<Overlimit>> overLimitMap = overLimitList.stream().collect(Collectors.groupingBy(Overlimit::getId));
        //以尺寸100分片,查询数据
        List<List<String>> pendingIds =  ListUtils.partition(lineIds,20);
        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));
        }
        //数据处理,按监测点分组
        Map<String,List<DataV>> map1 = list1.stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataPlt>> map2 = list2.stream().collect(Collectors.groupingBy(DataPlt::getLineId));
        Map<String,List<DataHarmRateV>> map3 = list3.stream().collect(Collectors.groupingBy(DataHarmRateV::getLineId));
        Map<String,List<DataI>> map4 = list4.stream().collect(Collectors.groupingBy(DataI::getLineId));
        Map<String,List<DataInHarmV>> map5 = list5.stream().collect(Collectors.groupingBy(DataInHarmV::getLineId));
        Map<String,List<DataV>> map6 = list6.stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataV>> map7 = list7.stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataI>> map8 = list8.stream().collect(Collectors.groupingBy(DataI::getLineId));
        Map<String,List<DataV>> map9 = list9.stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataV>> map10 = list10.stream().collect(Collectors.groupingBy(DataV::getLineId));
        Map<String,List<DataPlt>> map11 = list11.stream().collect(Collectors.groupingBy(DataPlt::getLineId));
        for (String item : lineIds) {
            List<LimitRate> result = getData(overLimitMap.get(item).get(0), 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)){
            /*插入mysql*/
            statLimitRateDService.saveOrUpdateBatchByMultiId(list,1000);
        }
    }

    /**
     * 功能描述:获取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::getPhasicType, 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.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.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.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.regular(DataV::getLineId, lineIndex)
                .eq(DataV::getValueType, InfluxDbSqlConstant.CP95)
                .regular(DataV::getPhasicType, 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.regular(DataV::getLineId, lineIndex)
                .regular(DataV::getValueType, Arrays.asList(InfluxDbSqlConstant.CP95,InfluxDbSqlConstant.MAX))
                .eq(DataV::getPhasicType, 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.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.regular(DataV::getLineId, lineIndex)
                .regular(DataV::getValueType, Arrays.asList(InfluxDbSqlConstant.MIN,InfluxDbSqlConstant.MAX))
                .eq(DataV::getPhasicType, 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.regular(DataV::getLineId, lineIndex)
                .eq(DataV::getValueType, InfluxDbSqlConstant.MAX)
                .regular(DataV::getPhasicType, 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.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));
        }
        if (!CollectionUtils.isEmpty (dataIPOList)) {
            dataIByPhaseType = dataIPOList.stream ( ).collect (Collectors.groupingBy (DataI::getPhaseType));
            dataIByTime = dataIPOList.stream ( ).collect (Collectors.groupingBy (DataI::getTime));
        }
        if (!CollectionUtils.isEmpty (dataInHarmVPOList)) {
            dataInHarmVPhaseType = dataInHarmVPOList.stream ( ).collect (Collectors.groupingBy (DataInHarmV::getPhaseType));
            dataInHarmVByTime = dataInHarmVPOList.stream ( ).collect (Collectors.groupingBy (DataInHarmV::getTime));
        }
        if (!CollectionUtils.isEmpty (dataVPOList)) {
            dataVPhaseType = dataVPOList.stream ( ).collect (Collectors.groupingBy (DataV::getPhasicType));
            dataVByTime = dataVPOList.stream ( ).collect (Collectors.groupingBy (DataV::getTime));
        }
        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::getPhasicType));
            dataVDevByTime = dataVPODevList.stream ( ).collect (Collectors.groupingBy (DataV::getTime));
        }
        if (!CollectionUtils.isEmpty (dataPltPOList)) {
            dataPltPhaseType = dataPltPOList.stream ( ).collect (Collectors.groupingBy (DataPlt::getPhaseType));
            dataPltByTime = dataPltPOList.stream ( ).collect (Collectors.groupingBy (DataPlt::getTime));
        }
        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;
    }


    /**
    * @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 ( ) > overlimit.getUharm2 ( )) {
                    v2++;
                }
                if (item.getV3 ( ) > overlimit.getUharm3 ( )) {
                    v3++;
                }
                if (item.getV4 ( ) > overlimit.getUharm4 ( )) {
                    v4++;
                }
                if (item.getV5 ( ) > overlimit.getUharm5 ( )) {
                    v5++;
                }
                if (item.getV6 ( ) > overlimit.getUharm6 ( )) {
                    v6++;
                }
                if (item.getV7 ( ) > overlimit.getUharm7 ( )) {
                    v7++;
                }
                if (item.getV8 ( ) > overlimit.getUharm8 ( )) {
                    v8++;
                }
                if (item.getV9 ( ) > overlimit.getUharm9 ( )) {
                    v9++;
                }
                if (item.getV10 ( ) > overlimit.getUharm10 ( )) {
                    v10++;
                }
                if (item.getV11 ( ) > overlimit.getUharm11 ( )) {
                    v11++;
                }
                if (item.getV12 ( ) > overlimit.getUharm12 ( )) {
                    v12++;
                }
                if (item.getV13 ( ) > overlimit.getUharm13 ( )) {
                    v13++;
                }
                if (item.getV14 ( ) > overlimit.getUharm14 ( )) {
                    v14++;
                }
                if (item.getV15 ( ) > overlimit.getUharm15 ( )) {
                    v15++;
                }
                if (item.getV16 ( ) > overlimit.getUharm16 ( )) {
                    v16++;
                }
                if (item.getV17 ( ) > overlimit.getUharm17 ( )) {
                    v17++;
                }
                if (item.getV18 ( ) > overlimit.getUharm18 ( )) {
                    v18++;
                }
                if (item.getV19 ( ) > overlimit.getUharm19 ( )) {
                    v19++;
                }
                if (item.getV20 ( ) > overlimit.getUharm20 ( )) {
                    v20++;
                }
                if (item.getV21 ( ) > overlimit.getUharm21 ( )) {
                    v21++;
                }
                if (item.getV22 ( ) > overlimit.getUharm22 ( )) {
                    v22++;
                }
                if (item.getV23 ( ) > overlimit.getUharm23 ( )) {
                    v23++;
                }
                if (item.getV24 ( ) > overlimit.getUharm24 ( )) {
                    v24++;
                }
                if (item.getV25 ( ) > overlimit.getUharm25 ( )) {
                    v25++;
                }
            }
        }
        //2-25次谐波电流
        if (!CollectionUtils.isEmpty (dataIPOList)) {
            for (DataI item : dataIPOList) {
                if (item.getI2 ( ) > overlimit.getIharm2 ( )) {
                    i2++;
                }
                if (item.getI3 ( ) > overlimit.getIharm3 ( )) {
                    i3++;
                }
                if (item.getI4 ( ) > overlimit.getIharm4 ( )) {
                    i4++;
                }
                if (item.getI5 ( ) > overlimit.getIharm5 ( )) {
                    i5++;
                }
                if (item.getI6 ( ) > overlimit.getIharm6 ( )) {
                    i6++;
                }
                if (item.getI7 ( ) > overlimit.getIharm7 ( )) {
                    i7++;
                }
                if (item.getI8 ( ) > overlimit.getIharm8 ( )) {
                    i8++;
                }
                if (item.getI9 ( ) > overlimit.getIharm9 ( )) {
                    i9++;
                }
                if (item.getI10 ( ) > overlimit.getIharm10 ( )) {
                    i10++;
                }
                if (item.getI11 ( ) > overlimit.getIharm11 ( )) {
                    i11++;
                }
                if (item.getI12 ( ) > overlimit.getIharm12 ( )) {
                    i12++;
                }
                if (item.getI13 ( ) > overlimit.getIharm13 ( )) {
                    i13++;
                }
                if (item.getI14 ( ) > overlimit.getIharm14 ( )) {
                    i14++;
                }
                if (item.getI15 ( ) > overlimit.getIharm15 ( )) {
                    i15++;
                }
                if (item.getI16 ( ) > overlimit.getIharm16 ( )) {
                    i16++;
                }
                if (item.getI17 ( ) > overlimit.getIharm17 ( )) {
                    i17++;
                }
                if (item.getI18 ( ) > overlimit.getIharm18 ( )) {
                    i18++;
                }
                if (item.getI19 ( ) > overlimit.getIharm19 ( )) {
                    i19++;
                }
                if (item.getI20 ( ) > overlimit.getIharm20 ( )) {
                    i20++;
                }
                if (item.getI21 ( ) > overlimit.getIharm21 ( )) {
                    i21++;
                }
                if (item.getI22 ( ) > overlimit.getIharm22 ( )) {
                    i22++;
                }
                if (item.getI23 ( ) > overlimit.getIharm23 ( )) {
                    i23++;
                }
                if (item.getI24 ( ) > overlimit.getIharm24 ( )) {
                    i24++;
                }
                if (item.getI25 ( ) > overlimit.getIharm25 ( )) {
                    i25++;
                }
            }
        }
        //0.5-15.5次间谐波电压含有率
        if (!CollectionUtils.isEmpty (dataInHarmVPOList)) {
            for (DataInHarmV item : dataInHarmVPOList) {
                if (item.getV1 ( ) > overlimit.getInuharm1 ( )) {
                    uHarm1++;
                }
                if (item.getV2 ( ) > overlimit.getInuharm2 ( )) {
                    uHarm2++;
                }
                if (item.getV3 ( ) > overlimit.getInuharm3 ( )) {
                    uHarm3++;
                }
                if (item.getV4 ( ) > overlimit.getInuharm4 ( )) {
                    uHarm4++;
                }
                if (item.getV5 ( ) > overlimit.getInuharm5 ( )) {
                    uHarm5++;
                }
                if (item.getV6 ( ) > overlimit.getInuharm6 ( )) {
                    uHarm6++;
                }
                if (item.getV7 ( ) > overlimit.getInuharm7 ( )) {
                    uHarm7++;
                }
                if (item.getV8 ( ) > overlimit.getInuharm8 ( )) {
                    uHarm8++;
                }
                if (item.getV9 ( ) > overlimit.getInuharm9 ( )) {
                    uHarm9++;
                }
                if (item.getV10 ( ) > overlimit.getInuharm10 ( )) {
                    uHarm10++;
                }
                if (item.getV11 ( ) > overlimit.getInuharm11 ( )) {
                    uHarm11++;
                }
                if (item.getV12 ( ) > overlimit.getInuharm12 ( )) {
                    uHarm12++;
                }
                if (item.getV13 ( ) > overlimit.getInuharm13 ( )) {
                    uHarm13++;
                }
                if (item.getV14 ( ) > overlimit.getInuharm14 ( )) {
                    uHarm14++;
                }
                if (item.getV15 ( ) > overlimit.getInuharm15 ( )) {
                    uHarm15++;
                }
                if (item.getV16 ( ) > overlimit.getInuharm16 ( )) {
                    uHarm16++;
                }
            }
        }
        //电压总谐波畸变率
        if (!CollectionUtils.isEmpty (dataVPOList)) {
            for (DataV item : dataVPOList) {
                if (item.getVThd ( ) > overlimit.getUaberrance ( )) {
                    thd++;
                }
            }
        }
        //电压上偏差、电压下偏差(根据vl_dev的正负判断是用哪个值判断越限)
        if (!CollectionUtils.isEmpty (dataVPODevList)) {
            for (DataV item : dataVPODevList) {
                if (item.getVlDev() >= 0){
                    if (item.getVlDev() > overlimit.getVoltageDev()){
                        uDev++;
                    }
                } else {
                    if (Math.abs(item.getVlDev()) > Math.abs(overlimit.getUvoltageDev())){
                        uDev++;
                    }
                }
            }
        }
        //长时间闪变
        if (!CollectionUtils.isEmpty (dataPltPOList)) {
            for (DataPlt item : dataPltPOList) {
                if (item.getPlt ( ) > overlimit.getFlicker ( )) {
                    flicker++;
                }
            }
        }
        limitRate.setLineId (lineId);
        limitRate.setPhasicType (phasicType);
        limitRate.setAllTime (allTime);
        limitRate.setFlickerAllTime (flickerAllTime);
        limitRate.setUAberranceOverTime (0);
        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 (thd);
        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()>overlimit.getUharm2()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l2)){
                v2++;
            }
            List<DataHarmRateV> l3 = list.stream().filter(s->s.getV3()>overlimit.getUharm3()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l3)){
                v3++;
            }
            List<DataHarmRateV> l4 = list.stream().filter(s->s.getV4()>overlimit.getUharm4()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l4)){
                v4++;
            }
            List<DataHarmRateV> l5 = list.stream().filter(s->s.getV5()>overlimit.getUharm5()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l5)){
                v5++;
            }
            List<DataHarmRateV> l6 = list.stream().filter(s->s.getV6()>overlimit.getUharm6()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l6)){
                v6++;
            }
            List<DataHarmRateV> l7 = list.stream().filter(s->s.getV7()>overlimit.getUharm7()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l7)){
                v7++;
            }
            List<DataHarmRateV> l8 = list.stream().filter(s->s.getV8()>overlimit.getUharm8()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l8)){
                v8++;
            }
            List<DataHarmRateV> l9 = list.stream().filter(s->s.getV9()>overlimit.getUharm9()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l9)){
                v9++;
            }
            List<DataHarmRateV> l10 = list.stream().filter(s->s.getV10()>overlimit.getUharm10()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l10)){
                v10++;
            }
            List<DataHarmRateV> l11 = list.stream().filter(s->s.getV11()>overlimit.getUharm11()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l11)){
                v11++;
            }
            List<DataHarmRateV> l12 = list.stream().filter(s->s.getV12()>overlimit.getUharm12()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l12)){
                v12++;
            }
            List<DataHarmRateV> l13 = list.stream().filter(s->s.getV13()>overlimit.getUharm13()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l13)){
                v13++;
            }
            List<DataHarmRateV> l14 = list.stream().filter(s->s.getV14()>overlimit.getUharm14()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l14)){
                v14++;
            }
            List<DataHarmRateV> l15 = list.stream().filter(s->s.getV15()>overlimit.getUharm15()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l15)){
                v15++;
            }
            List<DataHarmRateV> l16 = list.stream().filter(s->s.getV16()>overlimit.getUharm16()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l16)){
                v16++;
            }
            List<DataHarmRateV> l17 = list.stream().filter(s->s.getV17()>overlimit.getUharm17()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l17)){
                v17++;
            }
            List<DataHarmRateV> l18 = list.stream().filter(s->s.getV18()>overlimit.getUharm18()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l18)){
                v18++;
            }
            List<DataHarmRateV> l19 = list.stream().filter(s->s.getV19()>overlimit.getUharm19()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l19)){
                v19++;
            }
            List<DataHarmRateV> l20 = list.stream().filter(s->s.getV20()>overlimit.getUharm20()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l20)){
                v20++;
            }
            List<DataHarmRateV> l21 = list.stream().filter(s->s.getV21()>overlimit.getUharm21()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l21)){
                v21++;
            }
            List<DataHarmRateV> l22 = list.stream().filter(s->s.getV22()>overlimit.getUharm22()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l22)){
                v22++;
            }
            List<DataHarmRateV> l23 = list.stream().filter(s->s.getV23()>overlimit.getUharm23()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l23)){
                v23++;
            }
            List<DataHarmRateV> l24 = list.stream().filter(s->s.getV24()>overlimit.getUharm24()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l24)){
                v24++;
            }
            List<DataHarmRateV> l25 = list.stream().filter(s->s.getV25()>overlimit.getUharm25()).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()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l2)){
                i2++;
            }
            List<DataI> l3 = list.stream().filter(s->s.getI3()>overlimit.getIharm3()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l3)){
                i3++;
            }
            List<DataI> l4 = list.stream().filter(s->s.getI4()>overlimit.getIharm4()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l4)){
                i4++;
            }
            List<DataI> l5 = list.stream().filter(s->s.getI5()>overlimit.getIharm5()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l5)){
                i5++;
            }
            List<DataI> l6 = list.stream().filter(s->s.getI6()>overlimit.getIharm6()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l6)){
                i6++;
            }
            List<DataI> l7 = list.stream().filter(s->s.getI7()>overlimit.getIharm7()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l7)){
                i7++;
            }
            List<DataI> l8 = list.stream().filter(s->s.getI8()>overlimit.getIharm8()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l8)){
                i8++;
            }
            List<DataI> l9 = list.stream().filter(s->s.getI9()>overlimit.getIharm9()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l9)){
                i9++;
            }
            List<DataI> l10 = list.stream().filter(s->s.getI10()>overlimit.getIharm10()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l10)){
                i10++;
            }
            List<DataI> l11 = list.stream().filter(s->s.getI11()>overlimit.getIharm11()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l11)){
                i11++;
            }
            List<DataI> l12 = list.stream().filter(s->s.getI12()>overlimit.getIharm12()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l12)){
                i12++;
            }
            List<DataI> l13 = list.stream().filter(s->s.getI13()>overlimit.getIharm13()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l13)){
                i13++;
            }
            List<DataI> l14 = list.stream().filter(s->s.getI14()>overlimit.getIharm14()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l14)){
                i14++;
            }
            List<DataI> l15 = list.stream().filter(s->s.getI15()>overlimit.getIharm15()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l15)){
                i15++;
            }
            List<DataI> l16 = list.stream().filter(s->s.getI16()>overlimit.getIharm16()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l16)){
                i16++;
            }
            List<DataI> l17 = list.stream().filter(s->s.getI17()>overlimit.getIharm17()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l17)){
                i17++;
            }
            List<DataI> l18 = list.stream().filter(s->s.getI18()>overlimit.getIharm18()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l18)){
                i18++;
            }
            List<DataI> l19 = list.stream().filter(s->s.getI19()>overlimit.getIharm19()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l19)){
                i19++;
            }
            List<DataI> l20 = list.stream().filter(s->s.getI20()>overlimit.getIharm20()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l20)){
                i20++;
            }
            List<DataI> l21 = list.stream().filter(s->s.getI21()>overlimit.getIharm21()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l21)){
                i21++;
            }
            List<DataI> l22 = list.stream().filter(s->s.getI22()>overlimit.getIharm22()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l22)){
                i22++;
            }
            List<DataI> l23 = list.stream().filter(s->s.getI23()>overlimit.getIharm23()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l23)){
                i23++;
            }
            List<DataI> l24 = list.stream().filter(s->s.getI24()>overlimit.getIharm24()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l24)){
                i24++;
            }
            List<DataI> l25 = list.stream().filter(s->s.getI25()>overlimit.getIharm25()).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()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l2)){
                uHarm1++;
            }
            List<DataInHarmV> l3 = list3.stream().filter(s->s.getV2()>overlimit.getInuharm2()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l3)){
                uHarm2++;
            }
            List<DataInHarmV> l4 = list3.stream().filter(s->s.getV3()>overlimit.getInuharm3()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l4)){
                uHarm3++;
            }
            List<DataInHarmV> l5 = list3.stream().filter(s->s.getV4()>overlimit.getInuharm4()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l5)){
                uHarm4++;
            }
            List<DataInHarmV> l6 = list3.stream().filter(s->s.getV5()>overlimit.getInuharm5()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l6)){
                uHarm5++;
            }
            List<DataInHarmV> l7 = list3.stream().filter(s->s.getV6()>overlimit.getInuharm6()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l7)){
                uHarm6++;
            }
            List<DataInHarmV> l8 = list3.stream().filter(s->s.getV7()>overlimit.getInuharm7()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l8)){
                uHarm7++;
            }
            List<DataInHarmV> l9 = list3.stream().filter(s->s.getV8()>overlimit.getInuharm8()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l9)){
                uHarm8++;
            }
            List<DataInHarmV> l10 = list3.stream().filter(s->s.getV9()>overlimit.getInuharm9()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l10)){
                uHarm9++;
            }
            List<DataInHarmV> l11 = list3.stream().filter(s->s.getV10()>overlimit.getInuharm10()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l11)){
                uHarm10++;
            }
            List<DataInHarmV> l12 = list3.stream().filter(s->s.getV11()>overlimit.getInuharm11()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l12)){
                uHarm11++;
            }
            List<DataInHarmV> l13 = list3.stream().filter(s->s.getV12()>overlimit.getInuharm12()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l13)){
                uHarm12++;
            }
            List<DataInHarmV> l14 = list3.stream().filter(s->s.getV13()>overlimit.getInuharm13()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l14)){
                uHarm13++;
            }
            List<DataInHarmV> l15 = list3.stream().filter(s->s.getV14()>overlimit.getInuharm14()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l15)){
                uHarm14++;
            }
            List<DataInHarmV> l16 = list3.stream().filter(s->s.getV15()>overlimit.getInuharm15()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l16)){
                uHarm15++;
            }
            List<DataInHarmV> l17 = list3.stream().filter(s->s.getV16()>overlimit.getInuharm16()).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()).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()).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()).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&&s.getVlDev()>overlimit.getVoltageDev()).collect(Collectors.toList());
            List<DataV> l2 = list.stream().filter(s->s.getVlDev()<0&&Math.abs(s.getVlDev())>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()).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(l)){
                flicker++;
            }
        }
        limitRate.setLineId(lineId);
        limitRate.setPhasicType("T");
        limitRate.setAllTime(allTime);
        limitRate.setFlickerAllTime(flickerAllTime);
        limitRate.setUAberranceOverTime(uAberrance);
        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(thd);
        limitRate.setVoltageDevOverTime(uDev);
        limitRate.setFlickerOverTime(flicker);
        return limitRate;
    }
}
