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.device.pq.pojo.po.DeptLine;
import com.njcn.harmonic.pojo.po.RMpEmissionIExcessRateM;
import com.njcn.harmonic.pojo.po.RMpEmissionIM;
import com.njcn.harmonic.pojo.po.RMpEmissionM;
import com.njcn.harmonic.pojo.po.day.RStatDataIDPO;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
import com.njcn.harmonic.utils.PubUtils;
import com.njcn.prepare.harmonic.mapper.mysql.day.RStatLimitRateDMapper;
import com.njcn.prepare.harmonic.mapper.mysql.newalgorithm.RMpEmissionIMMapper;
import com.njcn.prepare.harmonic.mapper.mysql.newalgorithm.RMpEmissionMMapper;
import com.njcn.prepare.harmonic.pojo.param.LineParam;
import com.njcn.prepare.harmonic.service.mysql.day.IRStatDataIDService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.IRMpEmissionIExcessRateMService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.IRMpEmissionIMService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.IRMpEmissionMService;
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 java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



/**
 * <p>
 * 发射特性-月表 服务实现类
 * </p>
 *
 * @author wr
 * @since 2023-10-16
 */
@Service
@RequiredArgsConstructor
public class RMpEmissionMServiceImpl extends MppServiceImpl<RMpEmissionMMapper, RMpEmissionM> implements IRMpEmissionMService {

    private final CommTerminalGeneralClient commTerminalGeneralClient;
    private final DeptFeignClient deptFeignClient;
    private final IRStatDataIDService dataIVService;
    private final RStatLimitRateDMapper rStatLimitRateDMapper;
    private final IRMpEmissionIMService irMpEmissionIMService;
    private final IRMpEmissionIExcessRateMService irMpEmissionIExcessRateMService;
    private final DicDataFeignClient dicDataFeignClient;

    @Override
    @Async("asyncExecutor")
    @Transactional(rollbackFor = {Exception.class})
    public void rMpEmissionMHandler(LineParam jobParam) {
        List<RMpEmissionM> rMpEmissionMS = new ArrayList<>();
        List<RMpEmissionIM> rMpEmissionIMS = new ArrayList<>();
        List<RMpEmissionIExcessRateM> rMpEmissionIExcessRateMS = 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)) {
                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()))));
                line.addAll(lineBaseList.stream().filter(x -> StrUtil.isNotBlank(x.getPointId()))
                        .filter(x->dicIdsList.contains(x.getLineTag()))
                        .map(LineDevGetDTO::getPointId).collect(Collectors.toList()));
            }


            if (CollUtil.isNotEmpty(line)) {
                //获取data_I数据
                List<RStatDataIDPO> dataIDPOList = dataIVService.list(new LambdaQueryWrapper<RStatDataIDPO>().in(RStatDataIDPO::getLineId, line).eq(RStatDataIDPO::getPhaseType, "T").eq(RStatDataIDPO::getValueType, "CP95").ge(StrUtil.isNotBlank(jobParam.getBeginTime()), RStatDataIDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(jobParam.getBeginTime()))).le(StrUtil.isNotBlank(jobParam.getEndTime()), RStatDataIDPO::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
                    rMpEmissionAdd(jobParam, rMpEmissionMS, deptGetChildrenMoreDTO, lineBaseMap, dataIDPOList, rStatLimitRateMS, key);
                    //rMpEmissionIMS
                    rMpEmissionIAdd(jobParam, rMpEmissionIMS, deptGetChildrenMoreDTO, lineBaseMap,  rStatLimitRateMS, key);
                    //rMpEmissionIExcessRateMS
                    rMpEmissionIExcessRateAdd(jobParam, rMpEmissionIExcessRateMS, deptGetChildrenMoreDTO, lineBaseMap,  rStatLimitRateMS, key);
                }

            }

        }

        if (CollUtil.isNotEmpty(rMpEmissionMS)) {
            this.saveOrUpdateBatchByMultiId(rMpEmissionMS, 500);
        }
        if (CollUtil.isNotEmpty(rMpEmissionIMS)) {
            irMpEmissionIMService.saveOrUpdateBatchByMultiId(rMpEmissionIMS, 500);
        }
        if (CollUtil.isNotEmpty(rMpEmissionIExcessRateMS)) {
            irMpEmissionIExcessRateMService.saveOrUpdateBatchByMultiId(rMpEmissionIExcessRateMS, 500);
        }
    }

    private void rMpEmissionIExcessRateAdd(LineParam jobParam, List<RMpEmissionIExcessRateM> rMpEmissionIExcessRateMS, DeptGetChildrenMoreDTO deptGetChildrenMoreDTO, Map<String, List<String>> lineBaseMap, List<RStatLimitRateDPO> rStatLimitRateMS, String key) {
        RMpEmissionIExcessRateM rMpEmissionIExcessRateM = new RMpEmissionIExcessRateM();
        rMpEmissionIExcessRateM.setMonitorTag(key);
        rMpEmissionIExcessRateM.setOrgNo(deptGetChildrenMoreDTO.getUnitId());
        rMpEmissionIExcessRateM.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)) {
            rMpEmissionIExcessRateM.setIExcessRate2(iExcessRateI(rStatLimitRateDPOS,"iharm2Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate3(iExcessRateI(rStatLimitRateDPOS,"iharm3Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate4(iExcessRateI(rStatLimitRateDPOS,"iharm4Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate5(iExcessRateI(rStatLimitRateDPOS,"iharm5Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate6(iExcessRateI(rStatLimitRateDPOS,"iharm6Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate7(iExcessRateI(rStatLimitRateDPOS,"iharm7Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate8(iExcessRateI(rStatLimitRateDPOS,"iharm8Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate9(iExcessRateI(rStatLimitRateDPOS,"iharm9Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate10(iExcessRateI(rStatLimitRateDPOS,"iharm10Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate11(iExcessRateI(rStatLimitRateDPOS,"iharm11Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate12(iExcessRateI(rStatLimitRateDPOS,"iharm12Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate13(iExcessRateI(rStatLimitRateDPOS,"iharm13Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate14(iExcessRateI(rStatLimitRateDPOS,"iharm14Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate15(iExcessRateI(rStatLimitRateDPOS,"iharm15Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate16(iExcessRateI(rStatLimitRateDPOS,"iharm16Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate17(iExcessRateI(rStatLimitRateDPOS,"iharm17Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate18(iExcessRateI(rStatLimitRateDPOS,"iharm18Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate19(iExcessRateI(rStatLimitRateDPOS,"iharm19Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate20(iExcessRateI(rStatLimitRateDPOS,"iharm20Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate21(iExcessRateI(rStatLimitRateDPOS,"iharm21Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate22(iExcessRateI(rStatLimitRateDPOS,"iharm22Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate23(iExcessRateI(rStatLimitRateDPOS,"iharm23Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate24(iExcessRateI(rStatLimitRateDPOS,"iharm24Overtime","allTime"));
            rMpEmissionIExcessRateM.setIExcessRate25(iExcessRateI(rStatLimitRateDPOS,"iharm25Overtime","allTime"));
        } else {
            rMpEmissionIExcessRateM.setIExcessRate2(0.0);
            rMpEmissionIExcessRateM.setIExcessRate3(0.0);
            rMpEmissionIExcessRateM.setIExcessRate4(0.0);
            rMpEmissionIExcessRateM.setIExcessRate5(0.0);
            rMpEmissionIExcessRateM.setIExcessRate6(0.0);
            rMpEmissionIExcessRateM.setIExcessRate7(0.0);
            rMpEmissionIExcessRateM.setIExcessRate8(0.0);
            rMpEmissionIExcessRateM.setIExcessRate9(0.0);
            rMpEmissionIExcessRateM.setIExcessRate10(0.0);
            rMpEmissionIExcessRateM.setIExcessRate11(0.0);
            rMpEmissionIExcessRateM.setIExcessRate12(0.0);
            rMpEmissionIExcessRateM.setIExcessRate13(0.0);
            rMpEmissionIExcessRateM.setIExcessRate14(0.0);
            rMpEmissionIExcessRateM.setIExcessRate15(0.0);
            rMpEmissionIExcessRateM.setIExcessRate16(0.0);
            rMpEmissionIExcessRateM.setIExcessRate17(0.0);
            rMpEmissionIExcessRateM.setIExcessRate18(0.0);
            rMpEmissionIExcessRateM.setIExcessRate19(0.0);
            rMpEmissionIExcessRateM.setIExcessRate20(0.0);
            rMpEmissionIExcessRateM.setIExcessRate21(0.0);
            rMpEmissionIExcessRateM.setIExcessRate22(0.0);
            rMpEmissionIExcessRateM.setIExcessRate23(0.0);
            rMpEmissionIExcessRateM.setIExcessRate24(0.0);
            rMpEmissionIExcessRateM.setIExcessRate25(0.0);

        }
        rMpEmissionIExcessRateMS.add(rMpEmissionIExcessRateM);
    }

    private void rMpEmissionIAdd(LineParam jobParam, List<RMpEmissionIM> rMpEmissionIMS, DeptGetChildrenMoreDTO deptGetChildrenMoreDTO, Map<String, List<String>> lineBaseMap,  List<RStatLimitRateDPO> rStatLimitRateMS, String key) {
        RMpEmissionIM rMpEmissionIM = new RMpEmissionIM();
        rMpEmissionIM.setMonitorTag(key);
        rMpEmissionIM.setOrgNo(deptGetChildrenMoreDTO.getUnitId());
        rMpEmissionIM.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)) {
            rMpEmissionIM.setIRate2(iRateI(rStatLimitRateDPOS, "iharm2Overtime"));
            rMpEmissionIM.setIRate3(iRateI(rStatLimitRateDPOS, "iharm3Overtime"));
            rMpEmissionIM.setIRate4(iRateI(rStatLimitRateDPOS, "iharm4Overtime"));
            rMpEmissionIM.setIRate5(iRateI(rStatLimitRateDPOS, "iharm5Overtime"));
            rMpEmissionIM.setIRate6(iRateI(rStatLimitRateDPOS, "iharm6Overtime"));
            rMpEmissionIM.setIRate7(iRateI(rStatLimitRateDPOS, "iharm7Overtime"));
            rMpEmissionIM.setIRate8(iRateI(rStatLimitRateDPOS, "iharm8Overtime"));
            rMpEmissionIM.setIRate9(iRateI(rStatLimitRateDPOS, "iharm9Overtime"));
            rMpEmissionIM.setIRate10(iRateI(rStatLimitRateDPOS, "iharm10Overtime"));
            rMpEmissionIM.setIRate11(iRateI(rStatLimitRateDPOS, "iharm11Overtime"));
            rMpEmissionIM.setIRate12(iRateI(rStatLimitRateDPOS, "iharm12Overtime"));
            rMpEmissionIM.setIRate13(iRateI(rStatLimitRateDPOS, "iharm13Overtime"));
            rMpEmissionIM.setIRate14(iRateI(rStatLimitRateDPOS, "iharm14Overtime"));
            rMpEmissionIM.setIRate15(iRateI(rStatLimitRateDPOS, "iharm15Overtime"));
            rMpEmissionIM.setIRate16(iRateI(rStatLimitRateDPOS, "iharm16Overtime"));
            rMpEmissionIM.setIRate17(iRateI(rStatLimitRateDPOS, "iharm17Overtime"));
            rMpEmissionIM.setIRate18(iRateI(rStatLimitRateDPOS, "iharm18Overtime"));
            rMpEmissionIM.setIRate19(iRateI(rStatLimitRateDPOS, "iharm19Overtime"));
            rMpEmissionIM.setIRate20(iRateI(rStatLimitRateDPOS, "iharm20Overtime"));
            rMpEmissionIM.setIRate21(iRateI(rStatLimitRateDPOS, "iharm21Overtime"));
            rMpEmissionIM.setIRate22(iRateI(rStatLimitRateDPOS, "iharm22Overtime"));
            rMpEmissionIM.setIRate23(iRateI(rStatLimitRateDPOS, "iharm23Overtime"));
            rMpEmissionIM.setIRate24(iRateI(rStatLimitRateDPOS, "iharm24Overtime"));
            rMpEmissionIM.setIRate25(iRateI(rStatLimitRateDPOS, "iharm25Overtime"));
        } else {
            rMpEmissionIM.setIRate2(0.0);
            rMpEmissionIM.setIRate3(0.0);
            rMpEmissionIM.setIRate4(0.0);
            rMpEmissionIM.setIRate5(0.0);
            rMpEmissionIM.setIRate6(0.0);
            rMpEmissionIM.setIRate7(0.0);
            rMpEmissionIM.setIRate8(0.0);
            rMpEmissionIM.setIRate9(0.0);
            rMpEmissionIM.setIRate10(0.0);
            rMpEmissionIM.setIRate11(0.0);
            rMpEmissionIM.setIRate12(0.0);
            rMpEmissionIM.setIRate13(0.0);
            rMpEmissionIM.setIRate14(0.0);
            rMpEmissionIM.setIRate15(0.0);
            rMpEmissionIM.setIRate16(0.0);
            rMpEmissionIM.setIRate17(0.0);
            rMpEmissionIM.setIRate18(0.0);
            rMpEmissionIM.setIRate19(0.0);
            rMpEmissionIM.setIRate20(0.0);
            rMpEmissionIM.setIRate21(0.0);
            rMpEmissionIM.setIRate22(0.0);
            rMpEmissionIM.setIRate23(0.0);
            rMpEmissionIM.setIRate24(0.0);
            rMpEmissionIM.setIRate25(0.0);
        }
        rMpEmissionIMS.add(rMpEmissionIM);
    }

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

        List<RStatDataIDPO> rStatDataIDPOS = dataIDPOList.stream().filter(x -> lineIds.contains(x.getLineId())).collect(Collectors.toList());
        //获取负序电流不平衡度
        if (CollUtil.isNotEmpty(rStatDataIDPOS)) {
            double asDouble = rStatDataIDPOS.stream().filter(x -> x.getINeg() != null).mapToDouble(RStatDataIDPO::getIUnbalance).max().getAsDouble();
            rMpEmissionM.setNegativeSequenceCurrentUnbalance(asDouble);
        } else {
            rMpEmissionM.setNegativeSequenceCurrentUnbalance(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.getINegOvertime() > 0).count();
            rMpEmissionM.setNegativeSequenceCurrentUnbalanceExcessDayAvg(iNegOverDay != 0 ? NumberUtil.round(iNegOverDay / rStatLimitRateDPOS.size() * 1.0, 2).doubleValue() : 0.0);
            //获取所有超标次数
            double sum = rStatLimitRateDPOS.stream().filter(x -> x.getINegOvertime() > 0).mapToDouble(RStatLimitRateDPO::getINegOvertime).sum();
            double allSum = rStatLimitRateDPOS.stream().filter(x -> x.getAllTime() > 0).mapToDouble(RStatLimitRateDPO::getINegOvertime).sum();
            rMpEmissionM.setNegativeSequenceCurrentUnbalanceExcessRate(sum != 0 ? NumberUtil.round(allSum / allSum * 1.0, 2).doubleValue() : 0.0);
            long uHarmDay = rStatLimitRateDPOS.stream().filter(x -> filterNotQualifiedIharmData(x)).count();
            rMpEmissionM.setIExcessDayAvg(uHarmDay != 0 ? NumberUtil.round(uHarmDay / rStatLimitRateDPOS.size() * 1.0, 2).doubleValue() : 0.0);
        } else {
            rMpEmissionM.setNegativeSequenceCurrentUnbalanceExcessDayAvg(0.0);
            rMpEmissionM.setNegativeSequenceCurrentUnbalanceExcessRate(0.0);
            rMpEmissionM.setIExcessDayAvg(0.0);
        }
        rMpEmissionMS.add(rMpEmissionM);
    }


    private boolean filterNotQualifiedIharmData(RStatLimitRateDPO t) {
        int i = t.getIharm2Overtime() + t.getIharm3Overtime() + t.getIharm4Overtime() + t.getIharm5Overtime() + t.getIharm6Overtime() + t.getIharm7Overtime() + t.getIharm8Overtime() + t.getIharm9Overtime() + t.getIharm10Overtime() + t.getIharm11Overtime() + t.getIharm12Overtime() + t.getIharm13Overtime() + t.getIharm14Overtime() + t.getIharm15Overtime() + t.getIharm16Overtime() + t.getIharm17Overtime() + t.getIharm18Overtime() + t.getIharm19Overtime() + t.getIharm20Overtime() + t.getIharm21Overtime() + t.getIharm22Overtime() + t.getIharm23Overtime() + t.getIharm24Overtime() + t.getIharm25Overtime();
        if (i > 0) {
            return true;
        }
        return false;
    }

    //获取平均超标天数
    private Double iRateI(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);
    }
}
