package com.njcn.prepare.harmonic.service.mysql.newalgorithm.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
import com.njcn.harmonic.pojo.po.*;
import com.njcn.harmonic.pojo.po.day.RStatDataVDPO;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.utils.PubUtils;
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatLimitRateDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.newalgorithm.RMpInfluenceMMapper;
import com.njcn.prepare.harmonic.pojo.param.LineParam;
import com.njcn.prepare.harmonic.service.mysql.day.IRStatDataVDService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.*;
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.po.Dept;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 影响特性-月表 服务实现类
 * </p>
 *
 * @author wr
 * @since 2023-10-17
 */
@Service
@RequiredArgsConstructor
public class RMpInfluenceMServiceImpl extends MppServiceImpl<RMpInfluenceMMapper, RMpInfluenceM> implements IRMpInfluenceMService {

    private final CommTerminalGeneralClient commTerminalGeneralClient;
    private final DeptFeignClient deptFeignClient;
    private final IRStatDataVDService dataVDService;
    private final RStatLimitRateDMapper rStatLimitRateDMapper;
    private final IRMpInfluenceVMService irMpInfluenceVMService;
    private final IRMpInfluenceVExcessRateMService irMpInfluenceVExcessRateMService;
    private final DicDataFeignClient dicDataFeignClient;

    @Override
    @Async("asyncExecutor")
    @Transactional(rollbackFor = {Exception.class})
    public void rMpInfluenceMHandler(LineParam jobParam) {
        List<RMpInfluenceM> rMpInfluenceMS = new ArrayList<>();
        List<RMpInfluenceVM> rMpInfluenceVMS = new ArrayList<>();
        List<RMpInfluenceVExcessRateM> rMpInfluenceVExcessRateMS = new ArrayList<>();

        Dept data = deptFeignClient.getRootDept().getData();
        DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
        deptGetLineParam.setDeptId(data.getId());
        List<DeptGetChildrenMoreDTO> data1 = commTerminalGeneralClient.deptGetLine(deptGetLineParam).getData();
        //获取监测点标签
        List<DictData> dictDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.MONITORING_LABELS.getCode()).getData();
        List<String> dicIdsList = dictDataList.stream().filter(x -> ObjectUtil.equals(x.getCode(), DicDataEnum.POWER_STATION.getCode()) ||
                ObjectUtil.equals(x.getCode(), DicDataEnum.WIND_FARM.getCode()) ||
                ObjectUtil.equals(x.getCode(), DicDataEnum.SMELT_LOAD.getCode()) ||
                ObjectUtil.equals(x.getCode(), DicDataEnum.ELECTRIFIED_RAILWAYS.getCode())
        ).map(DictData::getId).collect(Collectors.toList());
        //监测点id
        List<String> line;
        for (DeptGetChildrenMoreDTO deptGetChildrenMoreDTO : data1) {
            line = new ArrayList<>();
            Map<String, List<String>> lineBaseMap = new HashMap<>();

            List<LineDevGetDTO> lineBaseList = new ArrayList<>();
            if(CollUtil.isNotEmpty(deptGetChildrenMoreDTO.getLineBaseList())){
                lineBaseList.addAll(deptGetChildrenMoreDTO.getLineBaseList());
            }
            if(CollUtil.isNotEmpty(deptGetChildrenMoreDTO.getPwMonitorIds())){
                lineBaseList.addAll(deptGetChildrenMoreDTO.getPwMonitorIds());
            }

            if (CollUtil.isNotEmpty(lineBaseList)) {
                line.addAll(lineBaseList.stream().filter(x -> StrUtil.isNotBlank(x.getPointId()))
                        .filter(x->dicIdsList.contains(x.getLineTag()))
                        .map(LineDevGetDTO::getPointId).collect(Collectors.toList()));
                lineBaseMap.putAll(lineBaseList.stream().filter(x -> StrUtil.isNotBlank(x.getPointId()))
                        .filter(x->dicIdsList.contains(x.getLineTag()))
                        .collect(Collectors.groupingBy(LineDevGetDTO::getLineTag, Collectors.mapping(LineDevGetDTO::getPointId, Collectors.toList()))));
            }


            if (CollUtil.isNotEmpty(line)) {
                //获取data_v数据
                List<RStatDataVDPO> dataVDPOList = dataVDService.list(new LambdaQueryWrapper<RStatDataVDPO>()
                        .in(RStatDataVDPO::getLineId, line)
                        .eq(RStatDataVDPO::getPhaseType, "T")
                        .eq(RStatDataVDPO::getValueType, "CP95")
                        .ge(StrUtil.isNotBlank(jobParam.getBeginTime()), RStatDataVDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(jobParam.getBeginTime())))
                        .le(StrUtil.isNotBlank(jobParam.getEndTime()), RStatDataVDPO::getTime, DateUtil.endOfDay(DateUtil.parse(jobParam.getEndTime())))
                );

                //获取rStatLimitRate
                List<RStatLimitRateDPO> rStatLimitRateMS = rStatLimitRateDMapper.selectList(new LambdaQueryWrapper<RStatLimitRateDPO>().in(RStatLimitRateDPO::getLineId, line).eq(RStatLimitRateDPO::getPhasicType, "T").ge(StrUtil.isNotBlank(jobParam.getBeginTime()), RStatLimitRateDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(jobParam.getBeginTime()))).le(StrUtil.isNotBlank(jobParam.getEndTime()), RStatLimitRateDPO::getTime, DateUtil.endOfDay(DateUtil.parse(jobParam.getEndTime()))));

                //根据监测点进行分组
                for (String key : lineBaseMap.keySet()) {
                    //rMpEmissionMS  r_mp_influence_m
                    rMpInfluenceAdd(jobParam, rMpInfluenceMS, deptGetChildrenMoreDTO, lineBaseMap, dataVDPOList, rStatLimitRateMS, key);
                    //rMpEmissionIMS
                    rMpInfluenceVAdd(jobParam, rMpInfluenceVMS, deptGetChildrenMoreDTO, lineBaseMap,  rStatLimitRateMS, key);
                    //rMpInfluenceVExcessRateMS
                    rMpInfluenceRateAdd(jobParam, rMpInfluenceVExcessRateMS, deptGetChildrenMoreDTO, lineBaseMap,  rStatLimitRateMS, key);
                }

            }

        }

        if (CollUtil.isNotEmpty(rMpInfluenceMS)) {
            this.saveOrUpdateBatchByMultiId(rMpInfluenceMS, 500);
        }
        if (CollUtil.isNotEmpty(rMpInfluenceVMS)) {
            irMpInfluenceVMService.saveOrUpdateBatchByMultiId(rMpInfluenceVMS, 500);
        }
        if (CollUtil.isNotEmpty(rMpInfluenceVExcessRateMS)) {
            irMpInfluenceVExcessRateMService.saveOrUpdateBatchByMultiId(rMpInfluenceVExcessRateMS, 500);
        }
    }

    private void rMpInfluenceRateAdd(LineParam jobParam, List<RMpInfluenceVExcessRateM> rMpInfluenceVExcessRateMS, DeptGetChildrenMoreDTO deptGetChildrenMoreDTO, Map<String, List<String>> lineBaseMap, List<RStatLimitRateDPO> rStatLimitRateMS, String key) {
        RMpInfluenceVExcessRateM rMpInfluenceVExcessRateM = new RMpInfluenceVExcessRateM();
        rMpInfluenceVExcessRateM.setMonitorTag(key);
        rMpInfluenceVExcessRateM.setOrgNo(deptGetChildrenMoreDTO.getUnitId());
        rMpInfluenceVExcessRateM.setDataDate(DateUtil.parse(jobParam.getDataDate()));

        //获取监测点
        List<String> lineIds = lineBaseMap.get(key);
        List<RStatLimitRateDPO> rStatLimitRateDPOS = rStatLimitRateMS.stream().filter(x -> lineIds.contains(x.getLineId())).collect(Collectors.toList());

        if (CollUtil.isNotEmpty(rStatLimitRateDPOS)) {
            rMpInfluenceVExcessRateM.setVExcessRate2(iExcessRateI(rStatLimitRateDPOS,"uharm2Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate3(iExcessRateI(rStatLimitRateDPOS,"uharm3Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate4(iExcessRateI(rStatLimitRateDPOS,"uharm4Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate5(iExcessRateI(rStatLimitRateDPOS,"uharm5Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate6(iExcessRateI(rStatLimitRateDPOS,"uharm6Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate7(iExcessRateI(rStatLimitRateDPOS,"uharm7Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate8(iExcessRateI(rStatLimitRateDPOS,"uharm8Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate9(iExcessRateI(rStatLimitRateDPOS,"uharm9Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate10(iExcessRateI(rStatLimitRateDPOS,"uharm10Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate11(iExcessRateI(rStatLimitRateDPOS,"uharm11Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate12(iExcessRateI(rStatLimitRateDPOS,"uharm12Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate13(iExcessRateI(rStatLimitRateDPOS,"uharm13Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate14(iExcessRateI(rStatLimitRateDPOS,"uharm14Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate15(iExcessRateI(rStatLimitRateDPOS,"uharm15Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate16(iExcessRateI(rStatLimitRateDPOS,"uharm16Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate17(iExcessRateI(rStatLimitRateDPOS,"uharm17Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate18(iExcessRateI(rStatLimitRateDPOS,"uharm18Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate19(iExcessRateI(rStatLimitRateDPOS,"uharm19Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate20(iExcessRateI(rStatLimitRateDPOS,"uharm20Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate21(iExcessRateI(rStatLimitRateDPOS,"uharm21Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate22(iExcessRateI(rStatLimitRateDPOS,"uharm22Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate23(iExcessRateI(rStatLimitRateDPOS,"uharm23Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate24(iExcessRateI(rStatLimitRateDPOS,"uharm24Overtime","allTime"));
            rMpInfluenceVExcessRateM.setVExcessRate25(iExcessRateI(rStatLimitRateDPOS,"uharm25Overtime","allTime"));
        } else {
            rMpInfluenceVExcessRateM.setVExcessRate2(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate3(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate4(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate5(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate6(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate7(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate8(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate9(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate10(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate11(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate12(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate13(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate14(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate15(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate16(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate17(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate18(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate19(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate20(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate21(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate22(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate23(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate24(0.0);
            rMpInfluenceVExcessRateM.setVExcessRate25(0.0);

        }
        rMpInfluenceVExcessRateMS.add(rMpInfluenceVExcessRateM);
    }

    private void rMpInfluenceVAdd(LineParam jobParam, List<RMpInfluenceVM> rMpInfluenceVMS, DeptGetChildrenMoreDTO deptGetChildrenMoreDTO, Map<String, List<String>> lineBaseMap,  List<RStatLimitRateDPO> rStatLimitRateMS, String key) {
        RMpInfluenceVM rMpInfluenceVM = new RMpInfluenceVM();
        rMpInfluenceVM.setMonitorTag(key);
        rMpInfluenceVM.setOrgNo(deptGetChildrenMoreDTO.getUnitId());
        rMpInfluenceVM.setDataDate(DateUtil.parse(jobParam.getDataDate()));
        //获取监测点
        List<String> lineIds = lineBaseMap.get(key);
        List<RStatLimitRateDPO> rStatLimitRateDPOS = rStatLimitRateMS.stream().filter(x -> lineIds.contains(x.getLineId())).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(rStatLimitRateDPOS)) {
            rMpInfluenceVM.setVRate2(iRateV(rStatLimitRateDPOS, "uharm2Overtime"));
            rMpInfluenceVM.setVRate3(iRateV(rStatLimitRateDPOS, "uharm3Overtime"));
            rMpInfluenceVM.setVRate4(iRateV(rStatLimitRateDPOS, "uharm4Overtime"));
            rMpInfluenceVM.setVRate5(iRateV(rStatLimitRateDPOS, "uharm5Overtime"));
            rMpInfluenceVM.setVRate6(iRateV(rStatLimitRateDPOS, "uharm6Overtime"));
            rMpInfluenceVM.setVRate7(iRateV(rStatLimitRateDPOS, "uharm7Overtime"));
            rMpInfluenceVM.setVRate8(iRateV(rStatLimitRateDPOS, "uharm8Overtime"));
            rMpInfluenceVM.setVRate9(iRateV(rStatLimitRateDPOS, "uharm9Overtime"));
            rMpInfluenceVM.setVRate10(iRateV(rStatLimitRateDPOS, "uharm10Overtime"));
            rMpInfluenceVM.setVRate11(iRateV(rStatLimitRateDPOS, "uharm11Overtime"));
            rMpInfluenceVM.setVRate12(iRateV(rStatLimitRateDPOS, "uharm12Overtime"));
            rMpInfluenceVM.setVRate13(iRateV(rStatLimitRateDPOS, "uharm13Overtime"));
            rMpInfluenceVM.setVRate14(iRateV(rStatLimitRateDPOS, "uharm14Overtime"));
            rMpInfluenceVM.setVRate15(iRateV(rStatLimitRateDPOS, "uharm15Overtime"));
            rMpInfluenceVM.setVRate16(iRateV(rStatLimitRateDPOS, "uharm16Overtime"));
            rMpInfluenceVM.setVRate17(iRateV(rStatLimitRateDPOS, "uharm17Overtime"));
            rMpInfluenceVM.setVRate18(iRateV(rStatLimitRateDPOS, "uharm18Overtime"));
            rMpInfluenceVM.setVRate19(iRateV(rStatLimitRateDPOS, "uharm19Overtime"));
            rMpInfluenceVM.setVRate20(iRateV(rStatLimitRateDPOS, "uharm20Overtime"));
            rMpInfluenceVM.setVRate21(iRateV(rStatLimitRateDPOS, "uharm21Overtime"));
            rMpInfluenceVM.setVRate22(iRateV(rStatLimitRateDPOS, "uharm22Overtime"));
            rMpInfluenceVM.setVRate23(iRateV(rStatLimitRateDPOS, "uharm23Overtime"));
            rMpInfluenceVM.setVRate24(iRateV(rStatLimitRateDPOS, "uharm24Overtime"));
            rMpInfluenceVM.setVRate25(iRateV(rStatLimitRateDPOS, "uharm25Overtime"));
        } else {
            rMpInfluenceVM.setVRate2(0.0);
            rMpInfluenceVM.setVRate3(0.0);
            rMpInfluenceVM.setVRate4(0.0);
            rMpInfluenceVM.setVRate5(0.0);
            rMpInfluenceVM.setVRate6(0.0);
            rMpInfluenceVM.setVRate7(0.0);
            rMpInfluenceVM.setVRate8(0.0);
            rMpInfluenceVM.setVRate9(0.0);
            rMpInfluenceVM.setVRate10(0.0);
            rMpInfluenceVM.setVRate11(0.0);
            rMpInfluenceVM.setVRate12(0.0);
            rMpInfluenceVM.setVRate13(0.0);
            rMpInfluenceVM.setVRate14(0.0);
            rMpInfluenceVM.setVRate15(0.0);
            rMpInfluenceVM.setVRate16(0.0);
            rMpInfluenceVM.setVRate17(0.0);
            rMpInfluenceVM.setVRate18(0.0);
            rMpInfluenceVM.setVRate19(0.0);
            rMpInfluenceVM.setVRate20(0.0);
            rMpInfluenceVM.setVRate21(0.0);
            rMpInfluenceVM.setVRate22(0.0);
            rMpInfluenceVM.setVRate23(0.0);
            rMpInfluenceVM.setVRate24(0.0);
            rMpInfluenceVM.setVRate25(0.0);
        }
        rMpInfluenceVMS.add(rMpInfluenceVM);
    }

    /**
     * @param jobParam               查询参数
     * @param rMpEmissionMS          对象
     * @param deptGetChildrenMoreDTO 部门监测点对象
     * @param lineBaseMap            监测点id-监测点标签
     * @param dataVDPOList
     * @param rStatLimitRateMS
     * @param key
     * @Description: 发电特性对象赋值
     * @Author: wr
     * @Date: 2023/10/17 11:18
     */
    private void rMpInfluenceAdd(LineParam jobParam, List<RMpInfluenceM> rMpEmissionMS, DeptGetChildrenMoreDTO deptGetChildrenMoreDTO, Map<String, List<String>> lineBaseMap,  List<RStatDataVDPO> dataVDPOList,  List<RStatLimitRateDPO> rStatLimitRateMS, String key) {
        RMpInfluenceM rMpInfluenceM = new RMpInfluenceM();
        rMpInfluenceM.setOrgNo(deptGetChildrenMoreDTO.getUnitId());
        rMpInfluenceM.setMonitorTag(key);
        rMpInfluenceM.setDataDate(DateUtil.parse(jobParam.getDataDate()));

        //获取监测点
        List<String> lineIds = lineBaseMap.get(key);

        List<RStatDataVDPO> rStatDataVDPOS = dataVDPOList.stream().filter(x -> lineIds.contains(x.getLineId())).collect(Collectors.toList());
        //获取负序电流不平衡度
        if (CollUtil.isNotEmpty(rStatDataVDPOS)) {
            double asDouble = rStatDataVDPOS.stream().filter(x -> x.getVNeg() != null).mapToDouble(RStatDataVDPO::getVUnbalance).max().getAsDouble();
            rMpInfluenceM.setNegativeSequenceVoltageUnbalance(asDouble);
        } else {
            rMpInfluenceM.setNegativeSequenceVoltageUnbalance(0.0);
        }

        List<RStatLimitRateDPO> rStatLimitRateDPOS = rStatLimitRateMS.stream().filter(x -> lineIds.contains(x.getLineId())).collect(Collectors.toList());
        //获取负序电流不平衡度平均超标天数、占比，各次谐波电流平均超标天数
        if (CollUtil.isNotEmpty(rStatLimitRateDPOS)) {
            long iNegOverDay = rStatLimitRateDPOS.stream().filter(x -> x.getVoltageDevOvertime() > 0).count();
            rMpInfluenceM.setNegativeSequenceVoltageUnbalanceExcessDayAvg(iNegOverDay != 0 ? NumberUtil.round(iNegOverDay / rStatLimitRateDPOS.size() * 1.0, 2).doubleValue() : 0.0);
            //获取所有超标次数
            double sum = rStatLimitRateDPOS.stream().filter(x -> x.getVoltageDevOvertime() > 0).mapToDouble(RStatLimitRateDPO::getVoltageDevOvertime).sum();
            double allSum = rStatLimitRateDPOS.stream().filter(x -> x.getAllTime() > 0).mapToDouble(RStatLimitRateDPO::getVoltageDevOvertime).sum();
            rMpInfluenceM.setNegativeSequenceVoltageUnbalanceExcessRate(sum != 0 ? NumberUtil.round(allSum / allSum * 1.0, 2).doubleValue() : 0.0);
            long uHarmDay = rStatLimitRateDPOS.stream().filter(x -> filterNotQualifiedUharmData(x)).count();
            rMpInfluenceM.setVExcessDayAvg(uHarmDay != 0 ? NumberUtil.round(uHarmDay / rStatLimitRateDPOS.size() * 1.0, 2).doubleValue() : 0.0);
        } else {
            rMpInfluenceM.setNegativeSequenceVoltageUnbalanceExcessDayAvg(0.0);
            rMpInfluenceM.setNegativeSequenceVoltageUnbalanceExcessRate(0.0);
            rMpInfluenceM.setVExcessDayAvg(0.0);
        }
        rMpEmissionMS.add(rMpInfluenceM);
    }


    private boolean filterNotQualifiedUharmData(RStatLimitRateDPO t) {
        if (t.getUharm2Overtime() != 0 || t.getUharm3Overtime() != 0 || t.getUharm4Overtime() != 0 || t.getUharm5Overtime() != 0 || t.getUharm6Overtime() != 0 || t.getUharm7Overtime() != 0 || t.getUharm8Overtime() != 0 || t.getUharm9Overtime() != 0 || t.getUharm10Overtime() != 0 || t.getUharm11Overtime() != 0 || t.getUharm12Overtime() != 0 || t.getUharm13Overtime() != 0 || t.getUharm14Overtime() != 0 || t.getUharm15Overtime() != 0 || t.getUharm16Overtime() != 0 || t.getUharm17Overtime() != 0 || t.getUharm18Overtime() != 0 || t.getUharm19Overtime() != 0 || t.getUharm20Overtime() != 0 || t.getUharm21Overtime() != 0 || t.getUharm22Overtime() != 0 || t.getUharm23Overtime() != 0 || t.getUharm24Overtime() != 0 || t.getUharm25Overtime() != 0) {
            return true;
        }
        return false;
    }

    //获取平均超标天数
    private Double iRateV(List<RStatLimitRateDPO> value, String attribute) {
        int size = value.size();
        Field field;
        try {
            field = RStatLimitRateDPO.class.getDeclaredField(attribute);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        field.setAccessible(true);
        List<Integer> nums = value.stream().map(temp -> {
            Integer o;
            try {
                o = (Integer) field.get(temp);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            return o.intValue();
        }).collect(Collectors.toList());
        long num = nums.stream().filter(x -> x > 0).count();
        return num != 0 ? NumberUtil.round(num / size * 1.0, 2).doubleValue() : 0.0;
    }

    private Double iExcessRateI(List<RStatLimitRateDPO> value, String attribute,String allTime) {
        Field excessRateField;
        Field allTimeField;
        try {
            excessRateField = RStatLimitRateDPO.class.getDeclaredField(attribute);
            allTimeField = RStatLimitRateDPO.class.getDeclaredField(allTime);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        excessRateField.setAccessible(true);
        allTimeField.setAccessible(true);

        List<Double> nums = value.stream().map(x->{
            Double o;
            try {
                Integer rate = (Integer) excessRateField.get(x);
                Integer num = (Integer) allTimeField.get(x);
                o= rate != 0 ? NumberUtil.round(rate / num * 1.0, 2).doubleValue() : 0.0;
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            return o.doubleValue();

        }).collect(Collectors.toList());
        return PubUtils.dataLimits(nums.stream().collect(Collectors.averagingDouble(Double::doubleValue))*100);
    }
}
