package com.njcn.harmonic.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.enums.LineBaseEnum;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.mapper.SteadyQualifyMapper;
import com.njcn.harmonic.pojo.dto.SteadyQualifyDTO;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.pojo.vo.SteadyQualifyCensusVO;
import com.njcn.harmonic.pojo.vo.SteadyQualifyVO;
import com.njcn.harmonic.service.IRStatLimitRateDService;
import com.njcn.harmonic.service.SteadyQualifyService;
import com.njcn.harmonic.utils.PubUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: chenchao
 * @date: 2022/04/01 16:10
 * @Description: <描述>
 */
@Service
@AllArgsConstructor
public class SteadyQualifyServiceImpl implements SteadyQualifyService {

    private final GeneralDeviceInfoClient generalDeviceInfoClient;

    private final SteadyQualifyMapper steadyQualifyMapper;

    private final IRStatLimitRateDService rateDService;

    @Override
    public List<SteadyQualifyVO> getSteadyQualifyData(DeviceInfoParam.BusinessParam steadyParam) {
        List<SteadyQualifyVO> steadyQualifyList = new ArrayList<>();

        //按照条件获取实际运行终端综合信息
        List<GeneralDeviceDTO> deviceDataList = generalDeviceInfoClient.getPracticalRunDeviceInfo(steadyParam).getData();
        //组装监测点Top层集合
        for (GeneralDeviceDTO generalDeviceDTO : deviceDataList) {
            List<String> lineIndexes = generalDeviceDTO.getLineIndexes();
            if (CollectionUtils.isEmpty(lineIndexes)) {
                continue;
            }
            SteadyQualifyVO steadyQualifyVO = new SteadyQualifyVO();
            steadyQualifyVO.setId(generalDeviceDTO.getIndex());
            steadyQualifyVO.setName(generalDeviceDTO.getName());
            // List<SteadyQualifyVO> lineData = steadyQualifyMapper.getSteadyQualifyData(lineIndexes);
            List<SteadyQualifyDTO> qualifiesRate = getQualifiesRate(lineIndexes, steadyParam.getSearchBeginTime(), steadyParam.getSearchEndTime());
            //组装子集级数据树
            List<SteadyQualifyVO> treeList = getTreeData(qualifiesRate, lineIndexes);
            if (CollectionUtil.isNotEmpty(treeList)) {
                List<SteadyQualifyVO> flicker = treeList.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> freqOffset = treeList.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> voltageOffset = treeList.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> voltageUnbalance = treeList.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> negativeCurrent = treeList.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> harmonicVoltage = treeList.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> harmonicCurrent = treeList.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> interHarmonic = treeList.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
                //求各项平均值
                if (!CollectionUtils.isEmpty(flicker)) {
                    steadyQualifyVO.setFlicker(PubUtils.dataLimits(NumberUtil.round(flicker.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(freqOffset)) {
                    steadyQualifyVO.setFreqOffset(PubUtils.dataLimits(NumberUtil.round(freqOffset.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(voltageOffset)) {
                    steadyQualifyVO.setVoltageOffset(PubUtils.dataLimits(NumberUtil.round(voltageOffset.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(voltageUnbalance)) {
                    steadyQualifyVO.setVoltageUnbalance(PubUtils.dataLimits(NumberUtil.round(voltageUnbalance.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(negativeCurrent)) {
                    steadyQualifyVO.setNegativeCurrent(PubUtils.dataLimits(NumberUtil.round(negativeCurrent.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(harmonicVoltage)) {
                    steadyQualifyVO.setHarmonicVoltage(PubUtils.dataLimits(NumberUtil.round(harmonicVoltage.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(harmonicCurrent)) {
                    steadyQualifyVO.setHarmonicCurrent(PubUtils.dataLimits(NumberUtil.round(harmonicCurrent.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(interHarmonic)) {
                    steadyQualifyVO.setInterHarmonic(PubUtils.dataLimits(NumberUtil.round(interHarmonic.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue()));
                }
            }
            steadyQualifyVO.setChildren(treeList);
            steadyQualifyList.add(steadyQualifyVO);
        }
        return steadyQualifyList;
    }

    @Override
    public SteadyQualifyCensusVO getSteadyQualifyCensus(DeviceInfoParam.BusinessParam steadyCensusParam) {
        SteadyQualifyCensusVO steadyQualifyCensusVO = new SteadyQualifyCensusVO();
        List<String> type = new ArrayList<>();
        //按照条件获取实际运行终端综合信息
        List<GeneralDeviceDTO> deviceDataList = generalDeviceInfoClient.getPracticalRunDeviceInfo(steadyCensusParam).getData();
        List<Double> harmonicVoltage = new ArrayList<>(), voltageOffset = new ArrayList<>(),
                VoltageUnbalance = new ArrayList<>(), interHarmonic = new ArrayList<>(),
                harmonicCurrent = new ArrayList<>(), negativeCurrent = new ArrayList<>(),
                freqOffset = new ArrayList<>(), flicker = new ArrayList<>();
        if (!CollectionUtils.isEmpty(deviceDataList)) {
            for (GeneralDeviceDTO generalDeviceDTO : deviceDataList) {
                List<String> lineIndexes = generalDeviceDTO.getLineIndexes();
                if (CollectionUtils.isEmpty(lineIndexes)) {
                    continue;
                }
                type.add(generalDeviceDTO.getName()+"\n("+generalDeviceDTO.getLineIndexes().size()+")");
                List<SteadyQualifyDTO> qualifiesRate = getQualifiesRate(lineIndexes, steadyCensusParam.getSearchBeginTime(), steadyCensusParam.getSearchEndTime());
                SteadyQualifyVO dataMoreMonitorMoreDay = getDataMoreMonitorMoreDay(qualifiesRate);
                harmonicVoltage.add(dataMoreMonitorMoreDay.getHarmonicVoltage());
                voltageOffset.add(dataMoreMonitorMoreDay.getVoltageOffset());
                VoltageUnbalance.add(dataMoreMonitorMoreDay.getVoltageUnbalance());
                interHarmonic.add(dataMoreMonitorMoreDay.getInterHarmonic());
                harmonicCurrent.add(dataMoreMonitorMoreDay.getHarmonicCurrent());
                negativeCurrent.add(dataMoreMonitorMoreDay.getNegativeCurrent());
                freqOffset.add(dataMoreMonitorMoreDay.getFreqOffset());
                flicker.add(dataMoreMonitorMoreDay.getFlicker());
            }
        }
        steadyQualifyCensusVO.setHarmonicVoltage(harmonicVoltage);
        steadyQualifyCensusVO.setVoltageOffset(voltageOffset);
        steadyQualifyCensusVO.setVoltageUnbalance(VoltageUnbalance);
        steadyQualifyCensusVO.setInterHarmonic(interHarmonic);
        steadyQualifyCensusVO.setHarmonicCurrent(harmonicCurrent);
        steadyQualifyCensusVO.setNegativeCurrent(negativeCurrent);
        steadyQualifyCensusVO.setFreqOffset(freqOffset);
        steadyQualifyCensusVO.setFlicker(flicker);
        steadyQualifyCensusVO.setType(type);

        return steadyQualifyCensusVO;
    }

    @Override
    public List<SteadyQualifyVO> getEnterpriseSteadyQualify(DeviceInfoParam.BusinessParam steadyParam) {
        List<SteadyQualifyVO> steadyQualifyList = new ArrayList<>();

        //按照条件获取实际运行终端综合信息
        List<GeneralDeviceDTO> deviceDataList = generalDeviceInfoClient.getPracticalRunDeviceInfo(steadyParam).getData();
        //组装监测点Top层集合
        for (GeneralDeviceDTO generalDeviceDTO : deviceDataList) {
            List<String> lineIndexes = generalDeviceDTO.getLineIndexes();
            if (CollectionUtils.isEmpty(lineIndexes)) {
                continue;
            }
            SteadyQualifyVO steadyQualifyVO = new SteadyQualifyVO();
            steadyQualifyVO.setId(generalDeviceDTO.getIndex());
            steadyQualifyVO.setName(generalDeviceDTO.getName());
            List<SteadyQualifyDTO> qualifiesRate = getQualifiesRate(lineIndexes, steadyParam.getSearchBeginTime(), steadyParam.getSearchEndTime());
            //组装子集级数据树
            List<SteadyQualifyVO> treeList = getCompanyTreeData(qualifiesRate, lineIndexes);
            if (CollectionUtil.isNotEmpty(treeList)) {
                List<SteadyQualifyVO> flicker = treeList.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> freqOffset = treeList.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> voltageOffset = treeList.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> voltageUnbalance = treeList.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> negativeCurrent = treeList.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> harmonicVoltage = treeList.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> harmonicCurrent = treeList.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> interHarmonic = treeList.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
                //求各项平均值
                if (!CollectionUtils.isEmpty(flicker)) {
                    steadyQualifyVO.setFlicker(PubUtils.dataLimits(NumberUtil.round(flicker.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(freqOffset)) {
                    steadyQualifyVO.setFreqOffset(PubUtils.dataLimits(NumberUtil.round(freqOffset.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(voltageOffset)) {
                    steadyQualifyVO.setVoltageOffset(PubUtils.dataLimits(NumberUtil.round(voltageOffset.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(voltageUnbalance)) {
                    steadyQualifyVO.setVoltageUnbalance(PubUtils.dataLimits(NumberUtil.round(voltageUnbalance.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(negativeCurrent)) {
                    steadyQualifyVO.setNegativeCurrent(PubUtils.dataLimits(NumberUtil.round(negativeCurrent.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(harmonicVoltage)) {
                    steadyQualifyVO.setHarmonicVoltage(PubUtils.dataLimits(NumberUtil.round(harmonicVoltage.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(harmonicCurrent)) {
                    steadyQualifyVO.setHarmonicCurrent(PubUtils.dataLimits(NumberUtil.round(harmonicCurrent.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue()));
                }
                if (!CollectionUtils.isEmpty(interHarmonic)) {
                    steadyQualifyVO.setInterHarmonic(PubUtils.dataLimits(NumberUtil.round(interHarmonic.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue()));
                }
            }
            steadyQualifyVO.setChildren(treeList);
            steadyQualifyList.add(steadyQualifyVO);
        }
        return steadyQualifyList;
    }

    /**
     * 获取父级每层数据
     */
    private List<SteadyQualifyVO> getTreeData(List<SteadyQualifyDTO> qualifiesRate, List<String> lineIndexes) {
        //监测点集合
        List<SteadyQualifyVO> monitorList = steadyQualifyMapper.getSteadyQualifyData(lineIndexes);
        //母线集合
        List<SteadyQualifyVO> busBarList = steadyQualifyMapper.getLineInfoByList(monitorList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));
        //终端集合
        List<SteadyQualifyVO> deviceList = steadyQualifyMapper.getLineInfoByList(busBarList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));
        //变电站集合
        List<SteadyQualifyVO> substationList = steadyQualifyMapper.getLineInfoByList(deviceList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));
        //供电公司集合
        List<SteadyQualifyVO> powerCompanyList = steadyQualifyMapper.getLineInfoByList(substationList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));

//        List<SteadyQualifyDTO> qualifiesRate = getQualifiesRate(lineIndexes, steadyParam.getSearchBeginTime(), steadyParam.getSearchEndTime());
        monitorList.forEach(steadyQualifyVO -> {
            SteadyQualifyVO dataSingleMonitorMoreDay = getDataSingleMonitorMoreDay(qualifiesRate, steadyQualifyVO.getId());
            steadyQualifyVO.setFlicker(PubUtils.dataLimits(dataSingleMonitorMoreDay.getFlicker()));
            steadyQualifyVO.setFreqOffset(PubUtils.dataLimits(dataSingleMonitorMoreDay.getFreqOffset()));
            steadyQualifyVO.setVoltageOffset(PubUtils.dataLimits(dataSingleMonitorMoreDay.getVoltageOffset()));
            steadyQualifyVO.setVoltageUnbalance(PubUtils.dataLimits(dataSingleMonitorMoreDay.getVoltageUnbalance()));
            steadyQualifyVO.setNegativeCurrent(PubUtils.dataLimits(dataSingleMonitorMoreDay.getNegativeCurrent()));
            steadyQualifyVO.setHarmonicVoltage(PubUtils.dataLimits(dataSingleMonitorMoreDay.getHarmonicVoltage()));
            steadyQualifyVO.setHarmonicCurrent(PubUtils.dataLimits(dataSingleMonitorMoreDay.getHarmonicCurrent()));
            steadyQualifyVO.setInterHarmonic(PubUtils.dataLimits(dataSingleMonitorMoreDay.getInterHarmonic()));
        });
        setChildesList(substationList, monitorList);
        setFatherDistortion(substationList);

        powerCompanyList.stream().peek(item -> item.setChildren(getChildCategoryList(item, substationList))).collect(Collectors.toList());
        setFatherDistortion(powerCompanyList);

        return powerCompanyList;
    }

    /**
     * 计算父级合格率
     */
    private void setFatherDistortion(List<SteadyQualifyVO> list) {
        list.forEach(steadyQualifyVO -> {
            List<SteadyQualifyVO> children = steadyQualifyVO.getChildren();
            List<SteadyQualifyVO> flicker = children.stream().filter(child -> !Objects.equals(child.getFlicker(), 3.14159)).collect(Collectors.toList());
            List<SteadyQualifyVO> freqOffset = children.stream().filter(child -> !Objects.equals(child.getFreqOffset(), 3.14159)).collect(Collectors.toList());
            List<SteadyQualifyVO> voltageOffset = children.stream().filter(child -> !Objects.equals(child.getVoltageOffset(), 3.14159)).collect(Collectors.toList());
            List<SteadyQualifyVO> voltageUnbalance = children.stream().filter(child -> !Objects.equals(child.getVoltageUnbalance(), 3.14159)).collect(Collectors.toList());
            List<SteadyQualifyVO> negativeCurrent = children.stream().filter(child -> !Objects.equals(child.getNegativeCurrent(), 3.14159)).collect(Collectors.toList());
            List<SteadyQualifyVO> harmonicVoltage = children.stream().filter(child -> !Objects.equals(child.getHarmonicVoltage(), 3.14159)).collect(Collectors.toList());
            List<SteadyQualifyVO> harmonicCurrent = children.stream().filter(child -> !Objects.equals(child.getHarmonicCurrent(), 3.14159)).collect(Collectors.toList());
            List<SteadyQualifyVO> InterHarmonic = children.stream().filter(child -> !Objects.equals(child.getInterHarmonic(), 3.14159)).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(flicker)) {
                steadyQualifyVO.setFlicker(PubUtils.dataLimits(NumberUtil.round(flicker.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(freqOffset)) {
                steadyQualifyVO.setFreqOffset(PubUtils.dataLimits(NumberUtil.round(freqOffset.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(voltageOffset)) {
                steadyQualifyVO.setVoltageOffset(PubUtils.dataLimits(NumberUtil.round(voltageOffset.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(voltageUnbalance)) {
                steadyQualifyVO.setVoltageUnbalance(PubUtils.dataLimits(NumberUtil.round(voltageUnbalance.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(negativeCurrent)) {
                steadyQualifyVO.setNegativeCurrent(PubUtils.dataLimits(NumberUtil.round(negativeCurrent.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(harmonicVoltage)) {
                steadyQualifyVO.setHarmonicVoltage(PubUtils.dataLimits(NumberUtil.round(harmonicVoltage.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(harmonicCurrent)) {
                steadyQualifyVO.setHarmonicCurrent(PubUtils.dataLimits(NumberUtil.round(harmonicCurrent.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(InterHarmonic)) {
                steadyQualifyVO.setInterHarmonic(PubUtils.dataLimits(NumberUtil.round(InterHarmonic.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue()));
            }
        });
    }

    /**
     * 组装树层级
     */
    private List<SteadyQualifyVO> getChildCategoryList(SteadyQualifyVO item, List<SteadyQualifyVO> child) {
        return child.stream().filter(allItem -> allItem.getPid().equals(item.getId())).collect(Collectors.toList());
    }

    private void setChildesList(List<SteadyQualifyVO> item, List<SteadyQualifyVO> childes) {
        Map<String, List<SteadyQualifyVO>> groupLine;
        groupLine = childes.stream().collect(Collectors.groupingBy(steadyQualifyVO -> {
            String[] pid = steadyQualifyVO.getPidS().split(",");
            return pid[LineBaseEnum.SUB_LEVEL.getCode()];
        }));
        item.stream().peek(steadyQualifyVO -> {
            if (!CollectionUtils.isEmpty(groupLine.get(steadyQualifyVO.getId()))) {
                steadyQualifyVO.setChildren(groupLine.get(steadyQualifyVO.getId()));
            }
        }).collect(Collectors.toList());
    }

    /**
     * 计算监测点日统计合格率
     */
    public List<SteadyQualifyVO> getDataSingleMonitorSingeDay(List<SteadyQualifyDTO> qualifiesRate) {
        List<SteadyQualifyVO> list = new ArrayList<>();
        SteadyQualifyVO steadyQualifyVO = new SteadyQualifyVO();

        if (!CollectionUtil.isEmpty(qualifiesRate)) {
            for (SteadyQualifyDTO steadyQualifyDTO : qualifiesRate) {
                steadyQualifyVO = new SteadyQualifyVO();
                //闪变合格率
                steadyQualifyVO.setFlicker(calculate(steadyQualifyDTO.getFlicker_AllTime(), steadyQualifyDTO.getFlicker_OverTime()));
                //频率偏差合格率
                steadyQualifyVO.setFreqOffset(calculate(steadyQualifyDTO.getAllTime(), steadyQualifyDTO.getFreq_Dev_OverTime()));
                //计算电压偏差
                steadyQualifyVO.setVoltageOffset(calculate(steadyQualifyDTO.getAllTime(), steadyQualifyDTO.getVoltage_Dev_OverTime()));
                //相电压不平衡度
                steadyQualifyVO.setVoltageUnbalance(calculate(steadyQualifyDTO.getAllTime(), steadyQualifyDTO.getUBalance_OverTime()));
                //负序电流
                steadyQualifyVO.setNegativeCurrent(calculate(steadyQualifyDTO.getAllTime(), steadyQualifyDTO.getI_Neg_OverTime()));
                //谐波电压
                steadyQualifyVO.setHarmonicVoltage(calculateV(steadyQualifyDTO.getAllTime(), (steadyQualifyDTO.getUAberrance_OverTime() + steadyQualifyDTO.getUHarm_2_OverTime() + steadyQualifyDTO.getUHarm_3_OverTime() + steadyQualifyDTO.getUHarm_4_OverTime() + steadyQualifyDTO.getUHarm_5_OverTime() + steadyQualifyDTO.getUHarm_6_OverTime() + steadyQualifyDTO.getUHarm_7_OverTime() + steadyQualifyDTO.getUHarm_8_OverTime() + steadyQualifyDTO.getUHarm_9_OverTime() + steadyQualifyDTO.getUHarm_10_OverTime() + steadyQualifyDTO.getUHarm_11_OverTime() + steadyQualifyDTO.getUHarm_12_OverTime() + steadyQualifyDTO.getUHarm_13_OverTime() + steadyQualifyDTO.getUHarm_14_OverTime() + steadyQualifyDTO.getUHarm_15_OverTime() + steadyQualifyDTO.getUHarm_16_OverTime() + steadyQualifyDTO.getUHarm_17_OverTime() + steadyQualifyDTO.getUHarm_18_OverTime() + steadyQualifyDTO.getUHarm_19_OverTime() + steadyQualifyDTO.getUHarm_20_OverTime() + steadyQualifyDTO.getUHarm_21_OverTime() + steadyQualifyDTO.getUHarm_22_OverTime() + steadyQualifyDTO.getUHarm_23_OverTime() + steadyQualifyDTO.getUHarm_24_OverTime() + steadyQualifyDTO.getUHarm_25_OverTime())));
                //谐波电流
                steadyQualifyVO.setHarmonicCurrent(calculateI(steadyQualifyDTO.getAllTime(), (steadyQualifyDTO.getIHarm_2_OverTime() + steadyQualifyDTO.getIHarm_3_OverTime() + steadyQualifyDTO.getIHarm_4_OverTime() + steadyQualifyDTO.getIHarm_5_OverTime() + steadyQualifyDTO.getIHarm_6_OverTime() + steadyQualifyDTO.getIHarm_7_OverTime() + steadyQualifyDTO.getIHarm_8_OverTime() + steadyQualifyDTO.getIHarm_9_OverTime() + steadyQualifyDTO.getIHarm_10_OverTime() + steadyQualifyDTO.getIHarm_11_OverTime() + steadyQualifyDTO.getIHarm_12_OverTime() + steadyQualifyDTO.getIHarm_13_OverTime() + steadyQualifyDTO.getIHarm_14_OverTime() + steadyQualifyDTO.getIHarm_15_OverTime() + steadyQualifyDTO.getIHarm_16_OverTime() + steadyQualifyDTO.getIHarm_17_OverTime() + steadyQualifyDTO.getIHarm_18_OverTime() + steadyQualifyDTO.getIHarm_19_OverTime() + steadyQualifyDTO.getIHarm_20_OverTime() + steadyQualifyDTO.getIHarm_21_OverTime() + steadyQualifyDTO.getIHarm_22_OverTime() + steadyQualifyDTO.getIHarm_23_OverTime() + steadyQualifyDTO.getIHarm_24_OverTime() + steadyQualifyDTO.getIHarm_25_OverTime())));
                //间谐波电压含有率
                steadyQualifyVO.setInterHarmonic(calculateIN(steadyQualifyDTO.getAllTime(), (steadyQualifyDTO.getInUHARM_1_OverTime() + steadyQualifyDTO.getInUHARM_2_OverTime() + steadyQualifyDTO.getInUHARM_3_OverTime() + steadyQualifyDTO.getInUHARM_4_OverTime() + steadyQualifyDTO.getInUHARM_5_OverTime() + steadyQualifyDTO.getInUHARM_6_OverTime() + steadyQualifyDTO.getInUHARM_7_OverTime() + steadyQualifyDTO.getInUHARM_8_OverTime() + steadyQualifyDTO.getInUHARM_9_OverTime() + steadyQualifyDTO.getInUHARM_10_OverTime() + steadyQualifyDTO.getInUHARM_11_OverTime() + steadyQualifyDTO.getInUHARM_12_OverTime() + steadyQualifyDTO.getInUHARM_13_OverTime() + steadyQualifyDTO.getInUHARM_14_OverTime() + steadyQualifyDTO.getInUHARM_15_OverTime() + steadyQualifyDTO.getInUHARM_16_OverTime())));
                list.add(steadyQualifyVO);
            }
        }
        return list;
    }

    /**
     * 监测点时间范围统计合格率
     */
    public SteadyQualifyVO getDataSingleMonitorMoreDay(List<SteadyQualifyDTO> qualifiesRate, String lineId) {
        SteadyQualifyVO steadyQualifyVO = new SteadyQualifyVO();
        //从数据里筛选出指定监测点的数据
        List<SteadyQualifyDTO> steadyQualifyDTOList = qualifiesRate.stream().filter(
                temp -> temp.getMYINDEX().equalsIgnoreCase(lineId)).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(steadyQualifyDTOList)) {
            List<SteadyQualifyVO> steadyQualifyVOS = new ArrayList<>();
            //获取出时间和id，调用第一个方法(改展示一条数据，可以不用每天都统计)
            steadyQualifyVOS.addAll(getDataSingleMonitorSingeDay(steadyQualifyDTOList));
            if (CollectionUtil.isNotEmpty(steadyQualifyVOS)) {
                List<SteadyQualifyVO> flicker = steadyQualifyVOS.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> freqOffset = steadyQualifyVOS.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> voltageOffset = steadyQualifyVOS.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> voltageUnbalance = steadyQualifyVOS.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> negativeCurrent = steadyQualifyVOS.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> harmonicVoltage = steadyQualifyVOS.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> harmonicCurrent = steadyQualifyVOS.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
                List<SteadyQualifyVO> interHarmonic = steadyQualifyVOS.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
                //求各项平均值
                if (!CollectionUtils.isEmpty(flicker)) {
                    steadyQualifyVO.setFlicker(NumberUtil.round(flicker.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
                }
                if (!CollectionUtils.isEmpty(freqOffset)) {
                    steadyQualifyVO.setFreqOffset(NumberUtil.round(freqOffset.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
                }
                if (!CollectionUtils.isEmpty(voltageOffset)) {
                    steadyQualifyVO.setVoltageOffset(NumberUtil.round(voltageOffset.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
                }
                if (!CollectionUtils.isEmpty(voltageUnbalance)) {
                    steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(voltageUnbalance.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
                }
                if (!CollectionUtils.isEmpty(negativeCurrent)) {
                    steadyQualifyVO.setNegativeCurrent(NumberUtil.round(negativeCurrent.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
                }
                if (!CollectionUtils.isEmpty(harmonicVoltage)) {
                    steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(harmonicVoltage.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
                }
                if (!CollectionUtils.isEmpty(harmonicCurrent)) {
                    steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(harmonicCurrent.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
                }
                if (!CollectionUtils.isEmpty(flicker)) {
                    steadyQualifyVO.setInterHarmonic(NumberUtil.round(interHarmonic.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
                }
            }
        }
        return steadyQualifyVO;
    }

    /**
     * 计算区域监测点时间范围统计合格率
     */
    public SteadyQualifyVO getDataMoreMonitorMoreDay(List<SteadyQualifyDTO> qualifiesRate) {
        SteadyQualifyVO steadyQualifyVO = new SteadyQualifyVO();
        List<SteadyQualifyVO> steadyResults = new ArrayList<>();
        //获取所有监测点每天信息(根本不需要时间分组，只是要所有的统计)
        steadyResults.addAll(getDataSingleMonitorSingeDay(qualifiesRate));
        if (CollectionUtil.isNotEmpty(steadyResults)) {
            List<SteadyQualifyVO> flicker = steadyResults.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
            List<SteadyQualifyVO> freqOffset = steadyResults.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
            List<SteadyQualifyVO> voltageOffset = steadyResults.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
            List<SteadyQualifyVO> voltageUnbalance = steadyResults.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
            List<SteadyQualifyVO> negativeCurrent = steadyResults.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
            List<SteadyQualifyVO> harmonicVoltage = steadyResults.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
            List<SteadyQualifyVO> harmonicCurrent = steadyResults.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
            List<SteadyQualifyVO> interHarmonic = steadyResults.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
            //求各项平均值
            if (!CollectionUtils.isEmpty(flicker)) {
                steadyQualifyVO.setFlicker(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(freqOffset)) {
                steadyQualifyVO.setFreqOffset(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(voltageOffset)) {
                steadyQualifyVO.setVoltageOffset(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(voltageUnbalance)) {
                steadyQualifyVO.setVoltageUnbalance(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(negativeCurrent)) {
                steadyQualifyVO.setNegativeCurrent(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(harmonicVoltage)) {
                steadyQualifyVO.setHarmonicVoltage(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(harmonicCurrent)) {
                steadyQualifyVO.setHarmonicCurrent(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue()));
            }
            if (!CollectionUtils.isEmpty(interHarmonic)) {
                steadyQualifyVO.setInterHarmonic(PubUtils.dataLimits(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue()));
            }
        }
        return steadyQualifyVO;
    }

    /**
     * 计算区域监测点日统计合格率
     */
//    public SteadyQualifyVO getDataMoreMonitorSingleDay(List<SteadyQualifyDTO> qualifiesRate, List<String> lineIds, String time) {
//        SteadyQualifyVO steadyQualifyVO = new SteadyQualifyVO();
//        List<SteadyQualifyVO> steadyResults = new ArrayList<>();
//        for (String lineId : lineIds) {
//            steadyResults.addAll(getDataSingleMonitorSingeDay(qualifiesRate, lineId, time));
//        }
//        if (CollectionUtil.isNotEmpty(steadyResults)) {
//            List<SteadyQualifyVO> flicker = steadyResults.stream().filter(s -> s.getFlicker() != 3.14159).collect(Collectors.toList());
//            List<SteadyQualifyVO> freqOffset = steadyResults.stream().filter(s -> s.getFreqOffset() != 3.14159).collect(Collectors.toList());
//            List<SteadyQualifyVO> voltageOffset = steadyResults.stream().filter(s -> s.getVoltageOffset() != 3.14159).collect(Collectors.toList());
//            List<SteadyQualifyVO> voltageUnbalance = steadyResults.stream().filter(s -> s.getVoltageUnbalance() != 3.14159).collect(Collectors.toList());
//            List<SteadyQualifyVO> negativeCurrent = steadyResults.stream().filter(s -> s.getNegativeCurrent() != 3.14159).collect(Collectors.toList());
//            List<SteadyQualifyVO> harmonicVoltage = steadyResults.stream().filter(s -> s.getHarmonicVoltage() != 3.14159).collect(Collectors.toList());
//            List<SteadyQualifyVO> harmonicCurrent = steadyResults.stream().filter(s -> s.getHarmonicCurrent() != 3.14159).collect(Collectors.toList());
//            List<SteadyQualifyVO> interHarmonic = steadyResults.stream().filter(s -> s.getInterHarmonic() != 3.14159).collect(Collectors.toList());
//            //求各项平均值
//            if (!CollectionUtils.isEmpty(flicker)) {
//                steadyQualifyVO.setFlicker(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFlicker).average().orElse(100), 2).doubleValue());
//            }
//            if (!CollectionUtils.isEmpty(freqOffset)) {
//                steadyQualifyVO.setFreqOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getFreqOffset).average().orElse(100), 2).doubleValue());
//            }
//            if (!CollectionUtils.isEmpty(voltageOffset)) {
//                steadyQualifyVO.setVoltageOffset(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageOffset).average().orElse(100), 2).doubleValue());
//            }
//            if (!CollectionUtils.isEmpty(voltageUnbalance)) {
//                steadyQualifyVO.setVoltageUnbalance(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getVoltageUnbalance).average().orElse(100), 2).doubleValue());
//            }
//            if (!CollectionUtils.isEmpty(negativeCurrent)) {
//                steadyQualifyVO.setNegativeCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getNegativeCurrent).average().orElse(100), 2).doubleValue());
//            }
//            if (!CollectionUtils.isEmpty(harmonicVoltage)) {
//                steadyQualifyVO.setHarmonicVoltage(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicVoltage).average().orElse(100), 2).doubleValue());
//            }
//            if (!CollectionUtils.isEmpty(harmonicCurrent)) {
//                steadyQualifyVO.setHarmonicCurrent(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getHarmonicCurrent).average().orElse(100), 2).doubleValue());
//            }
//            if (!CollectionUtils.isEmpty(interHarmonic)) {
//                steadyQualifyVO.setInterHarmonic(NumberUtil.round(steadyResults.stream().mapToDouble(SteadyQualifyVO::getInterHarmonic).average().orElse(100), 2).doubleValue());
//            }
//        }
//        return steadyQualifyVO;
//    }


    /**
     * influxDB查询稳态监测点相关信息
     *
     * @param lineIndexes
     * @param startTime
     * @param endTime
     */
    private List<SteadyQualifyDTO> getQualifiesRate(List<String> lineIndexes, String startTime, String endTime) {
        List<SteadyQualifyDTO> qualifyDTOList = new ArrayList<>();
        List<RStatLimitRateDPO> limitRates = rateDService.list(new LambdaQueryWrapper<RStatLimitRateDPO>()
                .in(RStatLimitRateDPO::getLineId, lineIndexes)
                .eq(RStatLimitRateDPO::getPhasicType, "T")
                .ge(StrUtil.isNotBlank(startTime), RStatLimitRateDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime)))
                .le(StrUtil.isNotBlank(endTime), RStatLimitRateDPO::getTime, DateUtil.endOfDay(DateUtil.parse(endTime)))
        );
        if (CollUtil.isNotEmpty(limitRates)) {
            limitRates.forEach(list -> {
                SteadyQualifyDTO steadyQualifyDTO = new SteadyQualifyDTO();
                steadyQualifyDTO.setTime(list.getTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
                steadyQualifyDTO.setMYINDEX(list.getLineId());
                steadyQualifyDTO.setPhasic_Type(list.getPhasicType());
                steadyQualifyDTO.setAllTime(Double.parseDouble(list.getAllTime().toString()));
                steadyQualifyDTO.setFlicker_AllTime(Double.parseDouble(list.getFlickerAllTime().toString()));
                steadyQualifyDTO.setFlicker_OverTime(Double.parseDouble(list.getFlickerOvertime().toString()));
                steadyQualifyDTO.setFreq_Dev_OverTime(Double.parseDouble(list.getFreqDevOvertime().toString()));
                steadyQualifyDTO.setIHarm_2_OverTime(Double.parseDouble(list.getIharm2Overtime().toString()));
                steadyQualifyDTO.setIHarm_3_OverTime(Double.parseDouble(list.getIharm3Overtime().toString()));
                steadyQualifyDTO.setIHarm_4_OverTime(Double.parseDouble(list.getIharm4Overtime().toString()));
                steadyQualifyDTO.setIHarm_5_OverTime(Double.parseDouble(list.getIharm5Overtime().toString()));
                steadyQualifyDTO.setIHarm_6_OverTime(Double.parseDouble(list.getIharm6Overtime().toString()));
                steadyQualifyDTO.setIHarm_7_OverTime(Double.parseDouble(list.getIharm7Overtime().toString()));
                steadyQualifyDTO.setIHarm_8_OverTime(Double.parseDouble(list.getIharm8Overtime().toString()));
                steadyQualifyDTO.setIHarm_9_OverTime(Double.parseDouble(list.getIharm9Overtime().toString()));
                steadyQualifyDTO.setIHarm_10_OverTime(Double.parseDouble(list.getIharm10Overtime().toString()));
                steadyQualifyDTO.setIHarm_11_OverTime(Double.parseDouble(list.getIharm11Overtime().toString()));
                steadyQualifyDTO.setIHarm_12_OverTime(Double.parseDouble(list.getIharm12Overtime().toString()));
                steadyQualifyDTO.setIHarm_13_OverTime(Double.parseDouble(list.getIharm13Overtime().toString()));
                steadyQualifyDTO.setIHarm_14_OverTime(Double.parseDouble(list.getIharm14Overtime().toString()));
                steadyQualifyDTO.setIHarm_15_OverTime(Double.parseDouble(list.getIharm15Overtime().toString()));
                steadyQualifyDTO.setIHarm_16_OverTime(Double.parseDouble(list.getIharm16Overtime().toString()));
                steadyQualifyDTO.setIHarm_17_OverTime(Double.parseDouble(list.getIharm17Overtime().toString()));
                steadyQualifyDTO.setIHarm_18_OverTime(Double.parseDouble(list.getIharm18Overtime().toString()));
                steadyQualifyDTO.setIHarm_19_OverTime(Double.parseDouble(list.getIharm19Overtime().toString()));
                steadyQualifyDTO.setIHarm_20_OverTime(Double.parseDouble(list.getIharm20Overtime().toString()));
                steadyQualifyDTO.setIHarm_21_OverTime(Double.parseDouble(list.getIharm21Overtime().toString()));
                steadyQualifyDTO.setIHarm_22_OverTime(Double.parseDouble(list.getIharm22Overtime().toString()));
                steadyQualifyDTO.setIHarm_23_OverTime(Double.parseDouble(list.getIharm23Overtime().toString()));
                steadyQualifyDTO.setIHarm_24_OverTime(Double.parseDouble(list.getIharm24Overtime().toString()));
                steadyQualifyDTO.setIHarm_25_OverTime(Double.parseDouble(list.getIharm25Overtime().toString()));
                steadyQualifyDTO.setI_Neg_OverTime(Double.parseDouble(list.getINegOvertime().toString()));
                steadyQualifyDTO.setInUHARM_1_OverTime(Double.parseDouble(list.getInuharm1Overtime().toString()));
                steadyQualifyDTO.setInUHARM_2_OverTime(Double.parseDouble(list.getInuharm2Overtime().toString()));
                steadyQualifyDTO.setInUHARM_3_OverTime(Double.parseDouble(list.getInuharm3Overtime().toString()));
                steadyQualifyDTO.setInUHARM_4_OverTime(Double.parseDouble(list.getInuharm4Overtime().toString()));
                steadyQualifyDTO.setInUHARM_5_OverTime(Double.parseDouble(list.getInuharm5Overtime().toString()));
                steadyQualifyDTO.setInUHARM_6_OverTime(Double.parseDouble(list.getInuharm6Overtime().toString()));
                steadyQualifyDTO.setInUHARM_7_OverTime(Double.parseDouble(list.getInuharm7Overtime().toString()));
                steadyQualifyDTO.setInUHARM_8_OverTime(Double.parseDouble(list.getInuharm8Overtime().toString()));
                steadyQualifyDTO.setInUHARM_9_OverTime(Double.parseDouble(list.getInuharm9Overtime().toString()));
                steadyQualifyDTO.setInUHARM_10_OverTime(Double.parseDouble(list.getInuharm10Overtime().toString()));
                steadyQualifyDTO.setInUHARM_11_OverTime(Double.parseDouble(list.getInuharm11Overtime().toString()));
                steadyQualifyDTO.setInUHARM_12_OverTime(Double.parseDouble(list.getInuharm12Overtime().toString()));
                steadyQualifyDTO.setInUHARM_13_OverTime(Double.parseDouble(list.getInuharm13Overtime().toString()));
                steadyQualifyDTO.setInUHARM_14_OverTime(Double.parseDouble(list.getInuharm14Overtime().toString()));
                steadyQualifyDTO.setInUHARM_15_OverTime(Double.parseDouble(list.getInuharm15Overtime().toString()));
                steadyQualifyDTO.setInUHARM_16_OverTime(Double.parseDouble(list.getInuharm16Overtime().toString()));
                steadyQualifyDTO.setUAberrance_OverTime(Double.parseDouble(list.getUaberranceOvertime().toString()));
                steadyQualifyDTO.setUBalance_OverTime(Double.parseDouble(list.getUbalanceOvertime().toString()));
                steadyQualifyDTO.setUHarm_2_OverTime(Double.parseDouble(list.getUharm2Overtime().toString()));
                steadyQualifyDTO.setUHarm_3_OverTime(Double.parseDouble(list.getUharm3Overtime().toString()));
                steadyQualifyDTO.setUHarm_4_OverTime(Double.parseDouble(list.getUharm4Overtime().toString()));
                steadyQualifyDTO.setUHarm_5_OverTime(Double.parseDouble(list.getUharm5Overtime().toString()));
                steadyQualifyDTO.setUHarm_6_OverTime(Double.parseDouble(list.getUharm6Overtime().toString()));
                steadyQualifyDTO.setUHarm_7_OverTime(Double.parseDouble(list.getUharm7Overtime().toString()));
                steadyQualifyDTO.setUHarm_8_OverTime(Double.parseDouble(list.getUharm8Overtime().toString()));
                steadyQualifyDTO.setUHarm_9_OverTime(Double.parseDouble(list.getUharm9Overtime().toString()));
                steadyQualifyDTO.setUHarm_10_OverTime(Double.parseDouble(list.getUharm10Overtime().toString()));
                steadyQualifyDTO.setUHarm_11_OverTime(Double.parseDouble(list.getUharm11Overtime().toString()));
                steadyQualifyDTO.setUHarm_12_OverTime(Double.parseDouble(list.getUharm12Overtime().toString()));
                steadyQualifyDTO.setUHarm_13_OverTime(Double.parseDouble(list.getUharm13Overtime().toString()));
                steadyQualifyDTO.setUHarm_14_OverTime(Double.parseDouble(list.getUharm14Overtime().toString()));
                steadyQualifyDTO.setUHarm_15_OverTime(Double.parseDouble(list.getUharm15Overtime().toString()));
                steadyQualifyDTO.setUHarm_16_OverTime(Double.parseDouble(list.getUharm16Overtime().toString()));
                steadyQualifyDTO.setUHarm_17_OverTime(Double.parseDouble(list.getUharm17Overtime().toString()));
                steadyQualifyDTO.setUHarm_18_OverTime(Double.parseDouble(list.getUharm18Overtime().toString()));
                steadyQualifyDTO.setUHarm_19_OverTime(Double.parseDouble(list.getUharm19Overtime().toString()));
                steadyQualifyDTO.setUHarm_20_OverTime(Double.parseDouble(list.getUharm20Overtime().toString()));
                steadyQualifyDTO.setUHarm_21_OverTime(Double.parseDouble(list.getUharm21Overtime().toString()));
                steadyQualifyDTO.setUHarm_22_OverTime(Double.parseDouble(list.getUharm22Overtime().toString()));
                steadyQualifyDTO.setUHarm_23_OverTime(Double.parseDouble(list.getUharm23Overtime().toString()));
                steadyQualifyDTO.setUHarm_24_OverTime(Double.parseDouble(list.getUharm24Overtime().toString()));
                steadyQualifyDTO.setUHarm_25_OverTime(Double.parseDouble(list.getUharm25Overtime().toString()));
                steadyQualifyDTO.setVoltage_Dev_OverTime(Double.parseDouble(list.getVoltageDevOvertime().toString()));
                qualifyDTOList.add(steadyQualifyDTO);
            });
        }
        return qualifyDTOList;

    }


    private static double calculate(Double allTime, Double overTime) {
        if (allTime == 0) {
            return 3.14159;
        } else {
            if (allTime >= overTime) {
                return NumberUtil.round((allTime - overTime) / allTime * 100, 2).doubleValue();
            }
            return 0.0;
        }
    }

    /**
     * 电压
     *
     * @param allTime  总条数
     * @param overTime 相加
     * @return
     */
    private static double calculateV(Double allTime, Double overTime) {
        if (allTime == 0) {
            return 3.14159;
        } else {
            if (allTime >= overTime) {
                return NumberUtil.round((1 - (overTime / (allTime * 25))) * 100, 2).doubleValue();
            }
            return 0.0;
        }
    }

    /**
     * 电流
     *
     * @param allTime
     * @param overTime
     * @return
     */
    private static double calculateI(Double allTime, Double overTime) {
        if (allTime == 0) {
            return 3.14159;
        } else {
            if (allTime >= overTime) {
                return NumberUtil.round((1 - (overTime / (allTime * 24))) * 100, 2).doubleValue();
            }
            return 0.0;
        }
    }

    /**
     * 间谐波
     *
     * @param allTime
     * @param overTime
     * @return
     */
    private static double calculateIN(Double allTime, Double overTime) {
        if (allTime == 0) {
            return 3.14159;
        } else {
            if (allTime >= overTime) {
                return NumberUtil.round((1 - (overTime / (allTime * 16))) * 100, 2).doubleValue();
            }
            return 0.0;
        }
    }


    /**
     * 获取父级每层数据
     */
    private List<SteadyQualifyVO> getCompanyTreeData(List<SteadyQualifyDTO> qualifiesRate, List<String> lineIndexes) {
        //监测点集合
        List<SteadyQualifyVO> monitorList = steadyQualifyMapper.getSteadyQualifyData(lineIndexes);
        //母线集合
        List<SteadyQualifyVO> busBarList = steadyQualifyMapper.getLineInfoByList(monitorList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));
        //终端集合
        List<SteadyQualifyVO> deviceList = steadyQualifyMapper.getLineInfoByList(busBarList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));
        //变电站集合
        List<SteadyQualifyVO> substationList = steadyQualifyMapper.getLineInfoByList(deviceList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));
        //供电公司集合
        List<SteadyQualifyVO> powerCompanyList = steadyQualifyMapper.getLineInfoByList(substationList.stream().map(SteadyQualifyVO::getPid).distinct().collect(Collectors.toList()));

//        List<SteadyQualifyDTO> qualifiesRate = getQualifiesRate(lineIndexes, steadyParam.getSearchBeginTime(), steadyParam.getSearchEndTime());
        monitorList.forEach(steadyQualifyVO -> {
            SteadyQualifyVO dataSingleMonitorMoreDay = getDataSingleMonitorMoreDay(qualifiesRate, steadyQualifyVO.getId());
            steadyQualifyVO.setFlicker(PubUtils.dataLimits(dataSingleMonitorMoreDay.getFlicker()));
            steadyQualifyVO.setFreqOffset(PubUtils.dataLimits(dataSingleMonitorMoreDay.getFreqOffset()));
            steadyQualifyVO.setVoltageOffset(PubUtils.dataLimits(dataSingleMonitorMoreDay.getVoltageOffset()));
            steadyQualifyVO.setVoltageUnbalance(PubUtils.dataLimits(dataSingleMonitorMoreDay.getVoltageUnbalance()));
            steadyQualifyVO.setNegativeCurrent(PubUtils.dataLimits(dataSingleMonitorMoreDay.getNegativeCurrent()));
            steadyQualifyVO.setHarmonicVoltage(PubUtils.dataLimits(dataSingleMonitorMoreDay.getHarmonicVoltage()));
            steadyQualifyVO.setHarmonicCurrent(PubUtils.dataLimits(dataSingleMonitorMoreDay.getHarmonicCurrent()));
            steadyQualifyVO.setInterHarmonic(PubUtils.dataLimits(dataSingleMonitorMoreDay.getInterHarmonic()));
        });
        setChildesList(substationList, monitorList);
        setFatherDistortion(substationList);


        return substationList;
    }

}
