package com.njcn.harmonic.service.majornetwork.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.param.StatisticsBizBaseParam;
import com.njcn.harmonic.pojo.param.OverviewParam;
import com.njcn.harmonic.pojo.param.RStatHarmonicMParam;
import com.njcn.harmonic.pojo.po.RStatHarmonicOrgM;
import com.njcn.harmonic.mapper.StatHarmonicOrgMMapper;
import com.njcn.harmonic.pojo.vo.OverviewVO;
import com.njcn.harmonic.pojo.vo.RArrayVO;
import com.njcn.harmonic.pojo.vo.RIconVO;
import com.njcn.harmonic.pojo.vo.RStatHarmonicMVO;
import com.njcn.harmonic.service.majornetwork.RStatHarmonicOrgMService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.harmonic.utils.DeptUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
import com.njcn.user.pojo.po.Dept;
import com.njcn.web.utils.WebUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author rui.wu
 * @since 2022-10-14
 */
@Service
@RequiredArgsConstructor
public class RStatHarmonicOrgMServiceImpl extends ServiceImpl<StatHarmonicOrgMMapper, RStatHarmonicOrgM> implements RStatHarmonicOrgMService {

    private final DeptFeignClient deptFeignClient;
    private final DicDataFeignClient dicDataFeignClient;
    private final StatHarmonicOrgMMapper statHarmonicOrgMMapper;

    @Override
    public List<RArrayVO> getRStatHarmonicMAll(StatisticsBizBaseParam param) {
        //子节点 获取所有得各单位类型
        List<DeptDTO> deptList = deptFeignClient.getDeptDescendantIndexes(param.getId(), WebUtil.filterDeptType()).getData();
        List<DeptDTO> deptDTOList = DeptUtil.getDeptSubsetVOList(deptList, param.getId());

        //获取部门id集合
        List<String> deptIds = deptDTOList.stream().map(DeptDTO::getCode).collect(Collectors.toList());
        Map<String, DeptDTO> deptMap = deptDTOList.stream().collect(Collectors.toMap(DeptDTO::getCode, Function.identity()));

        //对象主节点 获取所有得指标类型
        List<DictData> lineTypeData = dicDataFeignClient.getDicDataByTypeCode
                (DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
        Map<String, DictData> lineTypeMap = lineTypeData.stream()
                .collect(Collectors.toMap(DictData::getId, Function.identity()));
        //获取主网id信息
        DictData mainnetData = dicDataFeignClient.getDicDataByCode(DicDataEnum.MAINNET_POINT.getCode()).getData();

        //数据库查询
        List<RStatHarmonicOrgM> list = statHarmonicOrgMMapper.selectList(new LambdaQueryWrapper<RStatHarmonicOrgM>()
                .eq(RStatHarmonicOrgM::getDataType, mainnetData.getId())
                .in(RStatHarmonicOrgM::getOrgNo, deptIds)
                .ge(StrUtil.isNotBlank(param.getStartTime()), RStatHarmonicOrgM::getDataDate, param.getStartTime())
                .le(StrUtil.isNotBlank(param.getEndTime()), RStatHarmonicOrgM::getDataDate, param.getEndTime()));

        //初始化指标类型（横向）
        List<RArrayVO> arrayVOList = new ArrayList<>();
        List<RStatHarmonicMVO> rm = new ArrayList<>();
        for (DeptDTO deptDTO : deptDTOList) {
            RStatHarmonicMVO r = new RStatHarmonicMVO();
            r.setHarmonicName(deptDTO.getName());
            r.setSort(deptDTO.getSort());
            r.setOverLimitMeasurementAverage(0.0F);
            r.setOverLimitMeasurementAccrued(0);
            r.setAverageOverDay(0.0F);
            r.setOverDay(0);
            r.setOverLimitMeasurementRatioAverage(0.0F);
            r.setOverLimitMeasurementRatioAccrued(0.0F);
            rm.add(r);
        }
        for (DictData lineTypeDatum : lineTypeData) {
            RArrayVO r = new RArrayVO();
            r.setRowName(lineTypeDatum.getName());
            r.setColumns(rm);
            r.setSort(lineTypeDatum.getSort());
            arrayVOList.add(r);
        }
        //根据检测点对象分组
        Map<String, List<RStatHarmonicOrgM>> MeasurementTypeClassMap = list.stream().collect(Collectors.groupingBy(RStatHarmonicOrgM::getHarmonicType));
        //重新生成数据结构
        MeasurementTypeClassMap.forEach((key, value) -> {
            if (lineTypeMap.containsKey(key)) {
                RArrayVO arrayVO = new RArrayVO();
                DictData data = lineTypeMap.get(key);
                arrayVO.setRowName(data.getName());
                arrayVO.setSort(data.getSort());
                List<RStatHarmonicMVO> b = new ArrayList<>();
                b.addAll(rm);
                for (RStatHarmonicOrgM orgY : value) {
                    RStatHarmonicMVO r = BeanUtil.copyProperties(orgY, RStatHarmonicMVO.class);
                    DeptDTO data1 = deptMap.get(orgY.getOrgNo());
                    if (ObjectUtil.isNotNull(data1)) {
                        r.setHarmonicName(data1.getName());
                        r.setSort(data1.getSort());
                        if(r.getOverDay()!=0&&r.getOverLimitMeasurementAccrued()!=0){
                            DecimalFormat df = new DecimalFormat("###.00");
                            Float averageOverDay = Float.parseFloat(
                                    df.format(r.getOverDay() / (r.getOverLimitMeasurementAccrued() * 1.0)));
                            r.setAverageOverDay(averageOverDay);
                        }else{
                            r.setAverageOverDay(0.0f);
                        }
                        b.add(r);
                    }
                }
                Map<String, RStatHarmonicMVO> linkedHashMap = new LinkedHashMap<>();
                for (RStatHarmonicMVO harmonicMVO : b) {
                    linkedHashMap.put(harmonicMVO.getHarmonicName(), harmonicMVO);
                }
                List<RStatHarmonicMVO> aa = new ArrayList<>(linkedHashMap.values());
                aa.sort(Comparator.comparing(rStatHarmonicMVO -> rStatHarmonicMVO.getSort()));
                arrayVO.setColumns(aa);
                arrayVOList.add(arrayVO);
            }

        });
        Map<String, RArrayVO> linkedHashMap = new LinkedHashMap<>();
        for (RArrayVO rStatHarmonicMVO : arrayVOList) {
            linkedHashMap.put(rStatHarmonicMVO.getRowName(), rStatHarmonicMVO);
        }
        List<RArrayVO> aa = new ArrayList<>(linkedHashMap.values());
        arrayVOList.sort(Comparator.comparing(rArrayVO -> rArrayVO.getSort()));
        return aa;
    }

    @Override
    public List<RIconVO> getRStatHarmonicOrgMIcon(RStatHarmonicMParam param) {
        //子节点 获取所有得各单位类型
        List<DeptDTO> deptList = deptFeignClient.getDeptDescendantIndexes(param.getId(), WebUtil.filterDeptType()).getData();
        List<DeptDTO> deptDTOList = DeptUtil.getDeptSubsetVOList(deptList, param.getId());

        Map<String, DeptDTO> deptMap = deptDTOList.stream().collect(Collectors.toMap(DeptDTO::getCode, Function.identity()));
        //获取部门id集合
        List<String> deptIds = deptDTOList.stream().map(DeptDTO::getCode).collect(Collectors.toList());
        //指标对象类型属性
        DictData harmonicData;
        //判断是是否传入检测点信息值（电压）
        if (StrUtil.isBlank(param.getStasisID()) && StrUtil.isBlank(param.getMonitorID())) {
            //指标对象类型
            List<DictData> indicatorTypeDate = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
            indicatorTypeDate.sort(Comparator.comparing(data -> data.getSort()));
            harmonicData = indicatorTypeDate.get(0);
        } else {
            //获取指标对象（频率偏差）
            harmonicData = dicDataFeignClient.getDicDataById(
                    param.getStasisID()).getData();
        }
        //反防止参数查询数据报错
        Assert.isTrue(
                CollUtil.isNotEmpty(deptDTOList) || ObjectUtil.isNotNull(harmonicData)
                , "各单位或者指标类型为空,请检查入参是否准确");
        //获取主网id信息
        DictData mainnetData = dicDataFeignClient.getDicDataByCode(DicDataEnum.MAINNET_POINT.getCode()).getData();

        //初始化对象
        List<RIconVO> arrayVOList = new ArrayList<>();
        List<RStatHarmonicOrgM> rStatHarmonicVoltageMS = statHarmonicOrgMMapper.selectList(new LambdaQueryWrapper<RStatHarmonicOrgM>()
                .eq(RStatHarmonicOrgM::getDataType, mainnetData.getId())
                .in(RStatHarmonicOrgM::getOrgNo, deptIds)
                .eq(RStatHarmonicOrgM::getHarmonicType, harmonicData.getId())
                .ge(StrUtil.isNotBlank(param.getStartTime()), RStatHarmonicOrgM::getDataDate, param.getStartTime())
                .le(StrUtil.isNotBlank(param.getEndTime()), RStatHarmonicOrgM::getDataDate, param.getEndTime())
        );
        //将数据转换为map进行便利
        Map<String, List<RStatHarmonicOrgM>> voltageMMap = rStatHarmonicVoltageMS.stream()
                .collect(Collectors.groupingBy(RStatHarmonicOrgM::getOrgNo));
        //对象
        if (CollUtil.isNotEmpty(rStatHarmonicVoltageMS)) {
            voltageMMap.forEach((key, value) -> {
                if (deptMap.containsKey(key)) {
                    DeptDTO data = deptMap.get(key);
                    for (RStatHarmonicOrgM orgM : value) {
                        RIconVO rIconVO = new RIconVO();
                        rIconVO.setRowName(data.getName());
                        rIconVO.setSort(data.getSort());
                        rIconVO.setOverLimitMeasurementAccrued(orgM.getOverLimitMeasurementAccrued());
                        rIconVO.setOverLimitMeasurementAverage(orgM.getOverLimitMeasurementAverage());
                        rIconVO.setOverLimitMeasurementRatioAccrued(orgM.getOverLimitMeasurementRatioAccrued());
                        rIconVO.setOverLimitMeasurementRatioAverage(orgM.getOverLimitMeasurementRatioAverage());
                        DecimalFormat df = new DecimalFormat("###.00");
                        if(orgM.getOverDay()!=0&&orgM.getOverLimitMeasurementAccrued()!=0){
                            Float averageOverDay = Float.parseFloat(
                                    df.format(orgM.getOverDay() / (orgM.getOverLimitMeasurementAccrued() * 1.0)));
                            rIconVO.setAverageOverDay(averageOverDay);
                        }else{
                            rIconVO.setAverageOverDay(0f);
                        }

                        arrayVOList.add(rIconVO);
                    }

                }
            });
        }
        //处理主节点不存在的集合
        List<DeptDTO> notMeasurementList = deptDTOList.stream().filter(r -> !voltageMMap.containsKey(r.getCode()))
                .collect(Collectors.toList());
        for (DeptDTO notData : notMeasurementList) {
            RIconVO iconVO = new RIconVO();
            iconVO.setRowName(notData.getName());
            iconVO.setSort(notData.getSort());
            iconVO.setOverLimitMeasurementAverage(0.0F);
            iconVO.setOverLimitMeasurementAccrued(0);
            iconVO.setOverLimitMeasurementRatioAverage(0.0F);
            iconVO.setOverLimitMeasurementRatioAccrued(0.0F);
            iconVO.setAverageOverDay(0.0F);
            arrayVOList.add(iconVO);
        }
        arrayVOList.sort(Comparator.comparing(rIconVO -> rIconVO.getSort()));
        return arrayVOList;
    }

    @Override
    public List<RArrayVO> getPwRStatHarmonicMAll(StatisticsBizBaseParam param) {
        //对象主节点 获取所有的稳态类型
        List<DictData> steadyData = dicDataFeignClient.getDicDataByTypeCode(
                DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
        Map<String, DictData> steadyMap = steadyData.stream()
                .collect(Collectors.toMap(DictData::getId, Function.identity()));

        //子节点 获取所有得各单位类型
        List<DeptDTO> deptList = deptFeignClient.getDeptDescendantIndexes(param.getId(), WebUtil.filterDeptType()).getData();
        List<DeptDTO> deptDTOList = DeptUtil.getDeptSubsetVOList(deptList, param.getId());

        //获取部门id集合
        List<String> deptIds = deptDTOList.stream().map(DeptDTO::getCode).collect(Collectors.toList());
        Map<String, DeptDTO> deptMap = deptDTOList.stream().collect(Collectors.toMap(DeptDTO::getCode, Function.identity()));

        //获取配网信息
        DictData distributionData = dicDataFeignClient.getDicDataByCode(DicDataEnum.DISTRIBUTION_POINT.getCode()).getData();
        //初始化指标类型（横向）
        List<RArrayVO> arrayVOList = new ArrayList<>();
        //数据库查询
        List<RStatHarmonicOrgM> list = statHarmonicOrgMMapper.selectList(new LambdaQueryWrapper<RStatHarmonicOrgM>()
                .eq(RStatHarmonicOrgM::getDataType, distributionData.getId())
                .in(RStatHarmonicOrgM::getOrgNo, deptIds)
                .ge(StrUtil.isNotBlank(param.getStartTime()), RStatHarmonicOrgM::getDataDate, param.getStartTime())
                .le(StrUtil.isNotBlank(param.getEndTime()), RStatHarmonicOrgM::getDataDate, param.getEndTime()));
        //根据稳态指标分组
        Map<String, List<RStatHarmonicOrgM>> measurementMap = list.stream().collect(Collectors.groupingBy(RStatHarmonicOrgM::getHarmonicType));
        //判断对象是否为空
        if (CollUtil.isNotEmpty(list)) {
            //重新生成数据结构
            measurementMap.forEach((key, value) -> {
                List<RStatHarmonicMVO> eventVO = new ArrayList<>();
                if (steadyMap.containsKey(key)) {
                    RArrayVO arrayVO = new RArrayVO();
                    DictData data = steadyMap.get(key);
                    arrayVO.setRowName(data.getName());
                    arrayVO.setSort(data.getSort());
                    for (RStatHarmonicOrgM statHarmonic : value) {
                        if (deptMap.containsKey(statHarmonic.getOrgNo())) {
                            RStatHarmonicMVO r = BeanUtil.copyProperties(statHarmonic, RStatHarmonicMVO.class);
                            DeptDTO deptDTO = deptMap.get(statHarmonic.getOrgNo());
                            r.setHarmonicName(deptDTO.getName());
                            r.setSort(deptDTO.getSort());
                            if(r.getOverDay()!=0&&r.getOverLimitMeasurementAccrued()!=0){
                                DecimalFormat df = new DecimalFormat("###.00");
                                Float averageOverDay = Float.parseFloat(
                                        df.format(r.getOverDay() / (r.getOverLimitMeasurementAccrued() * 1.0)));
                                r.setAverageOverDay(averageOverDay);
                            }else{
                                r.setAverageOverDay(0f);
                            }
                            eventVO.add(r);
                        }

                    }
                    //根据监测点类别获取差集
                    Map<String, List<RStatHarmonicOrgM>> listMap = value.stream().collect(Collectors.groupingBy(RStatHarmonicOrgM::getOrgNo));
                    List<DeptDTO> notDeptDTOS = deptDTOList.stream().filter(r -> !listMap.containsKey(r.getCode()))
                            .collect(Collectors.toList());
                    this.assignDict(notDeptDTOS, eventVO, arrayVO);
                    eventVO.sort(Comparator.comparing(statHarmonic -> statHarmonic.getSort()));
                    arrayVOList.add(arrayVO);
                }
            });
        }
        //处理主节点不存在的集合
        List<DictData> notMeasurementList = steadyData.stream().filter(r -> !measurementMap.containsKey(r.getId()))
                .collect(Collectors.toList());
        for (DictData notData : notMeasurementList) {
            List<RStatHarmonicMVO> statharmonicVO = new ArrayList<>();
            RArrayVO arrayVO = new RArrayVO();
            arrayVO.setRowName(notData.getName());
            arrayVO.setSort(notData.getSort());
            this.assignDict(deptDTOList, statharmonicVO, arrayVO);
            statharmonicVO.sort(Comparator.comparing(statHarmonic -> statHarmonic.getSort()));
            arrayVOList.add(arrayVO);
        }
        arrayVOList.sort(Comparator.comparing(rArrayVO -> rArrayVO.getSort()));
        return arrayVOList;
    }

    @Override
    public List<RIconVO> getPwRStatHarmonicOrgMIcon(RStatHarmonicMParam param) {
        //各单位类型
        List<DeptDTO> deptList = deptFeignClient.getDeptDescendantIndexes(param.getId(), WebUtil.filterDeptType()).getData();
        List<DeptDTO> deptDTOList = DeptUtil.getDeptSubsetVOList(deptList, param.getId());

        Map<String, DeptDTO> deptMap = deptDTOList.stream().collect(Collectors.toMap(DeptDTO::getCode, Function.identity()));
        //获取部门id集合
        List<String> deptIds = deptDTOList.stream().map(DeptDTO::getCode).collect(Collectors.toList());
        //指标对象类型属性
        DictData harmonicData;
        //判断是是否传入检测点信息值（电压）
        if (StrUtil.isBlank(param.getStasisID()) && StrUtil.isBlank(param.getMonitorID())) {
            //指标对象类型
            List<DictData> indicatorTypeDate = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
            indicatorTypeDate.sort(Comparator.comparing(data -> data.getSort()));
            harmonicData = indicatorTypeDate.get(0);
        } else {
            //获取指标对象（频率偏差）
            harmonicData = dicDataFeignClient.getDicDataById(
                    param.getStasisID()).getData();
        }
        //反防止参数查询数据报错
        Assert.isTrue(
                CollUtil.isNotEmpty(deptDTOList) || ObjectUtil.isNotNull(harmonicData)
                , "各单位或者指标类型为空,请检查入参是否准确");
        //获取主网id信息
        DictData distributionData = dicDataFeignClient.getDicDataByCode(DicDataEnum.DISTRIBUTION_POINT.getCode()).getData();

        //初始化对象
        List<RIconVO> arrayVOList = new ArrayList<>();
        List<RStatHarmonicOrgM> rStatHarmonicVoltageMS = statHarmonicOrgMMapper.selectList(new LambdaQueryWrapper<RStatHarmonicOrgM>()
                .eq(RStatHarmonicOrgM::getDataType, distributionData.getId())
                .in(RStatHarmonicOrgM::getOrgNo, deptIds)
                .eq(RStatHarmonicOrgM::getHarmonicType, harmonicData.getId())
                .ge(StrUtil.isNotBlank(param.getStartTime()), RStatHarmonicOrgM::getDataDate, param.getStartTime())
                .le(StrUtil.isNotBlank(param.getEndTime()), RStatHarmonicOrgM::getDataDate, param.getEndTime())
        );
        //将数据转换为map进行便利
        Map<String, List<RStatHarmonicOrgM>> voltageMMap = rStatHarmonicVoltageMS.stream()
                .collect(Collectors.groupingBy(RStatHarmonicOrgM::getOrgNo));
        //对象
        if (CollUtil.isNotEmpty(rStatHarmonicVoltageMS)) {
            voltageMMap.forEach((key, value) -> {
                if (deptMap.containsKey(key)) {
                    DeptDTO data = deptMap.get(key);
                    for (RStatHarmonicOrgM orgM : value) {
                        RIconVO rIconVO = new RIconVO();
                        rIconVO.setRowName(data.getName());
                        rIconVO.setSort(data.getSort());
                        rIconVO.setOverLimitMeasurementAccrued(orgM.getOverLimitMeasurementAccrued());
                        rIconVO.setOverLimitMeasurementAverage(orgM.getOverLimitMeasurementAverage());
                        rIconVO.setOverLimitMeasurementRatioAccrued(orgM.getOverLimitMeasurementRatioAccrued());
                        rIconVO.setOverLimitMeasurementRatioAverage(orgM.getOverLimitMeasurementRatioAverage());
                        if(orgM.getOverDay()!=0&&orgM.getOverLimitMeasurementAccrued()!=0){
                            DecimalFormat df = new DecimalFormat("###.00");
                            Float averageOverDay = Float.parseFloat(
                                    df.format(orgM.getOverDay() / (orgM.getOverLimitMeasurementAccrued() * 1.0)));
                            rIconVO.setAverageOverDay(averageOverDay);
                        }else{
                            rIconVO.setAverageOverDay(0f);
                        }
                        arrayVOList.add(rIconVO);
                    }

                }
            });
        }
        //处理主节点不存在的集合
        List<DeptDTO> notMeasurementList = deptDTOList.stream().filter(r -> !voltageMMap.containsKey(r.getCode()))
                .collect(Collectors.toList());
        for (DeptDTO notData : notMeasurementList) {
            RIconVO iconVO = new RIconVO();
            iconVO.setRowName(notData.getName());
            iconVO.setSort(notData.getSort());
            iconVO.setOverLimitMeasurementAverage(0.0F);
            iconVO.setOverLimitMeasurementAccrued(0);
            iconVO.setOverLimitMeasurementRatioAverage(0.0F);
            iconVO.setOverLimitMeasurementRatioAccrued(0.0F);
            iconVO.setAverageOverDay(0.0F);
            arrayVOList.add(iconVO);
        }
        arrayVOList.sort(Comparator.comparing(rIconVO -> rIconVO.getSort()));
        return arrayVOList;
    }

    @Override
    public List<OverviewVO.ExcessiveVO> getExcessiveProportion(OverviewParam param) {
        List<OverviewVO.ExcessiveVO> info =new ArrayList<>();
        //指标类型
        List<DictData> steadyData = dicDataFeignClient.getDicDataByTypeCode
                (DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
        List<DictData> steadyTypeData = steadyData.stream().filter(dictData ->
                        DicDataEnum.VOLTAGE_DEV.getCode().equals(dictData.getCode()) ||
                        DicDataEnum.FLICKER.getCode().equals(dictData.getCode()) ||
                        DicDataEnum.HARMONIC_VOLTAGE.getCode().equals(dictData.getCode())
        ).collect(Collectors.toList());


        Map<String, DictData> steadyTypeMap = steadyTypeData.stream().collect(Collectors.toMap(DictData::getId, Function.identity()));

        //监测点类型
        List<DictData> lineData = dicDataFeignClient.getDicDataByTypeCode
                (DicDataTypeEnum.LINE_SORT.getCode()).getData();
        List<String> lineDataIds = lineData.stream().map(DictData::getId).collect(Collectors.toList());

        //获取部门数据
        List<String> deptCodes = getDeptListCode(param.getId());

        //获取配网数据类型
        DictData data = dicDataFeignClient.getDicDataByCode(DicDataEnum.DISTRIBUTION_POINT.getCode()).getData();
        List<OverviewVO> overviewVOS = statHarmonicOrgMMapper.selectYoY(param, deptCodes,lineDataIds, data.getId());

        Map<String, List<OverviewVO>> overviewVOMap = overviewVOS.stream().collect(
                Collectors.groupingBy(OverviewVO::getMonitorSort));


        overviewVOMap.forEach((key,value)->{
            OverviewVO.ExcessiveVO excessiveVO=new OverviewVO.ExcessiveVO();
            excessiveVO.setMonitorSort(key);
            excessiveVO.setHarmonic("0.0");
            excessiveVO.setHarmonicTb("0.0");
            excessiveVO.setVoltage("0.0");
            excessiveVO.setVoltageTb("0.0");
            excessiveVO.setFlicker("0.0");
            excessiveVO.setFlickerTb("0.0");
            for (OverviewVO overviewVO : value) {
                if(steadyTypeMap.containsKey(overviewVO.getHarmonicType())){
                    DictData dictData = steadyTypeMap.get(overviewVO.getHarmonicType());
                    if(DicDataEnum.HARMONIC_VOLTAGE.getCode().equals(dictData.getCode())){
                        excessiveVO.setHarmonic(overviewVO.getSumNum());
                        excessiveVO.setHarmonicTb(overviewVO.getSameNum());
                    }
                    if(DicDataEnum.FLICKER.getCode().equals(dictData.getCode())){
                        excessiveVO.setFlicker(overviewVO.getSumNum());
                        excessiveVO.setFlickerTb(overviewVO.getSameNum());
                    }
                    if(DicDataEnum.VOLTAGE_DEV.getCode().equals(dictData.getCode())){
                        excessiveVO.setVoltage(overviewVO.getSumNum());
                        excessiveVO.setVoltageTb(overviewVO.getSameNum());
                    }
                }

            }
            info.add(excessiveVO);
        });
        Map<String, List<OverviewVO.ExcessiveVO>>  excessiveMap= info.stream().collect(Collectors.groupingBy(OverviewVO.ExcessiveVO::getMonitorSort));
        List<DictData> notDict = lineData.stream().filter(r -> !excessiveMap.containsKey(r.getId()))
                .collect(Collectors.toList());
        if(CollectionUtil.isNotEmpty(notDict)){
            OverviewVO.ExcessiveVO excessiveVO;
            for (DictData dictData : notDict) {
                excessiveVO=new OverviewVO.ExcessiveVO();
                excessiveVO.setMonitorSort(dictData.getId());
                excessiveVO.setHarmonic("0.0");
                excessiveVO.setHarmonicTb("0.0");
                excessiveVO.setVoltage("0.0");
                excessiveVO.setVoltageTb("0.0");
                excessiveVO.setFlicker("0.0");
                excessiveVO.setFlickerTb("0.0");
               info.add(excessiveVO);
            }
        }
        return  info;
    }

    /**
     * 便利赋值
     *
     * @param deptDTOList    部门信息集合
     * @param statharmonicVO 暂态监测点
     * @param arrayVO        初始化对象
     */
    private void assignDict(List<DeptDTO> deptDTOList, List<RStatHarmonicMVO> statharmonicVO, RArrayVO arrayVO) {
        for (DeptDTO dictData : deptDTOList) {
            RStatHarmonicMVO notStatHarmonicVO = new RStatHarmonicMVO();
            notStatHarmonicVO.setHarmonicName(dictData.getName());
            notStatHarmonicVO.setSort(dictData.getSort());
            notStatHarmonicVO.setOverLimitMeasurementAverage(0.0F);
            notStatHarmonicVO.setOverLimitMeasurementAccrued(0);
            notStatHarmonicVO.setOverDay(0);
            notStatHarmonicVO.setOverLimitMeasurementRatioAverage(0.0F);
            notStatHarmonicVO.setOverLimitMeasurementRatioAccrued(0.0F);
            notStatHarmonicVO.setAverageOverDay(0.0F);
            statharmonicVO.add(notStatHarmonicVO);
        }
        arrayVO.setColumns(statharmonicVO);
    }

    /**
     * 部门通用方法
     * @param id
     * @return
     */
    public List<String> getDeptListCode(String id){
        //获取部门数据
        Dept data = deptFeignClient.getDeptById(id).getData();
        if(ObjectUtil.isNotNull(data)){
            return Arrays.asList(data.getCode());
        }
        return new ArrayList<>();
    }
}
