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

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.harmonic.pojo.po.RStatOrgMPO;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.mapper.mysql.area.*;
import com.njcn.prepare.harmonic.pojo.mysql.po.RStatHarmonicDPO;
import com.njcn.prepare.harmonic.pojo.mysql.po.RStatHarmonicMPO;

import com.njcn.prepare.harmonic.pojo.mysql.po.RStatOrgQPO;
import com.njcn.prepare.harmonic.pojo.mysql.po.RStatOrgYPO;
import com.njcn.prepare.harmonic.pojo.po.*;
import com.njcn.prepare.harmonic.service.mysql.area.RStatHarmonicOrgService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatHarmonicOrgDPOService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatHarmonicOrgMPOService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatHarmonicOrgQPOService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatHarmonicOrgYPOService;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Description:
 * Date: 2023/7/19  9:07【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Service
@RequiredArgsConstructor
public class RStatHarmonicOrgServiceImpl implements RStatHarmonicOrgService {

    private final
    DicDataFeignClient dicDataFeignClient;

    private final RStatOrgDMapper rStatOrgDMapper;
    private final RStatOrgQMapper rStatOrgQMapper;
    private final RStatOrgYMapper rStatOrgYMapper;



    private final RStatHarmonicDPOMapper rStatHarmonicDPOMapper;
    private final RStatHarmonicOrgDPOService rStatHarmonicDPOService;

    private final RStatOrgMMapper rStatOrgMMapper;
    private final RStatHarmonicMPOMapper rStatHarmonicMPOMapper;
    private final RStatHarmonicOrgMPOService rStatHarmonicMPOService;


    private final RStatHarmonicOrgQPOService rStatHarmonicQPOService;
    private final RStatHarmonicOrgYPOService rStatHarmonicYPOService;

    DecimalFormat df = new DecimalFormat("0.00000");



    @Override
    public void handleDay(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
        List<RStatHarmonicOrgDPO> rStatHarmonicOrgDPOList = new ArrayList<>();

        LocalDate localDate = LocalDateTimeUtil.parseDate(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN);


        QueryWrapper<RStatHarmonicDPO> queryWrapper = new QueryWrapper<>();

        /*获取稳态统计指标*/
        List<DictData> steadyStatis = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
        /*获取数据类型*/

        List<DictData> dataTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DATA_TYPE.getCode()).getData();
        Map<String, DictData> dataTypeMap = dataTypeList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        ;
        /*获取监测点类型类型*/
        List<DictData> lineSortList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_SORT.getCode()).getData();
        Map<String, DictData> lineSortMap = lineSortList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        calculatedParam.getIdList().stream().forEach(temp->{
            int sumEffectiveMeasurement =0;
            List<RStatOrgDVO> rStatOrgDVOS = rStatOrgDMapper.listAll( LocalDateTimeUtil.format(localDate,DatePattern.NORM_DATE_PATTERN), temp.getUnitId());
            if(CollectionUtils.isEmpty(rStatOrgDVOS)){
                sumEffectiveMeasurement=0;
            }else {
                sumEffectiveMeasurement = rStatOrgDVOS.stream().mapToInt(RStatOrgDVO::getEffectiveMeasurement).sum();
            }
            int finalSumEffectiveMeasurement = sumEffectiveMeasurement;
            dataTypeMap.forEach((k, v)->{
                steadyStatis.forEach(dictData -> {
                    if (Objects.equals(dictData.getCode(), DicDataEnum.TOTAL_INDICATOR.getCode())) {
                        return;
                    }
                    queryWrapper.clear();
                    queryWrapper.select("over_limit_measurement").
                            eq("org_no",temp.getUnitId()).
                            eq("data_type",v.getId()).
                            eq("harmonic_type",dictData.getId()).
                            eq("data_date",localDate);
                    List<RStatHarmonicDPO> rStatHarmonicDPOList = rStatHarmonicDPOMapper.selectList(queryWrapper);
                    int sumOverLimitMeasurement =0;

                    if(CollectionUtils.isEmpty(rStatHarmonicDPOList)){
                        sumOverLimitMeasurement=0;
                    }else {
                        sumOverLimitMeasurement = rStatHarmonicDPOList.stream().mapToInt(RStatHarmonicDPO::getOverLimitMeasurement).sum();
                    }
                    RStatHarmonicOrgDPO rStatHarmonicOrgDPO = new RStatHarmonicOrgDPO();
                    rStatHarmonicOrgDPO.setOrgNo(temp.getUnitId());
                    rStatHarmonicOrgDPO.setDataDate(localDate);
                    rStatHarmonicOrgDPO.setHarmonicType(dictData.getId());
                    rStatHarmonicOrgDPO.setDataType(v.getId());
                    rStatHarmonicOrgDPO.setOverLimitMeasurementAverage(sumOverLimitMeasurement);
                    if(finalSumEffectiveMeasurement ==0){
                        rStatHarmonicOrgDPO.setOverLimitMeasurementRatioAverage(0.00);
                    }else {
                        rStatHarmonicOrgDPO.setOverLimitMeasurementRatioAverage(Double.parseDouble(df.format((float)sumOverLimitMeasurement / finalSumEffectiveMeasurement)));
                    }
                    rStatHarmonicOrgDPOList.add(rStatHarmonicOrgDPO);


                });
            });

        });

        if(!CollectionUtils.isEmpty(rStatHarmonicOrgDPOList)){
            rStatHarmonicDPOService.saveOrUpdateBatchByMultiId(rStatHarmonicOrgDPOList,500);
        }
    }

    @Override
    public void handleMonth(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
        List<RStatHarmonicOrgMPO> rStatHarmonicOrgMPOList = new ArrayList<>();
        DateTime begin = DateUtil.beginOfMonth(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        DateTime end = DateUtil.endOfMonth(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        LocalDate localDate = LocalDateTimeUtil.parseDate( DateUtil.format(begin, DatePattern.NORM_DATE_PATTERN), DatePattern.NORM_DATE_PATTERN);

        QueryWrapper<RStatHarmonicMPO> queryWrapper = new QueryWrapper<>();
        QueryWrapper<RStatOrgMPO> rStatOrgMPOQueryWrapper = new QueryWrapper<>();


        /*获取稳态统计指标*/
        List<DictData> steadyStatis = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
        /*获取数据类型*/

        List<DictData> dataTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DATA_TYPE.getCode()).getData();
        Map<String, DictData> dataTypeMap = dataTypeList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        ;
        /*获取监测点类型类型*/
        List<DictData> lineSortList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_SORT.getCode()).getData();
        Map<String, DictData> lineSortMap = lineSortList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        calculatedParam.getIdList().stream().forEach(temp->{
            int sumEffectiveMeasurement =0;
            rStatOrgMPOQueryWrapper.clear();
            rStatOrgMPOQueryWrapper.select("effective_measurement_accrued").
                    eq("org_no",temp.getUnitId()).
                    between("data_date",begin,end);
            List<RStatOrgMPO> rStatOrgMPOS = rStatOrgMMapper.selectList(rStatOrgMPOQueryWrapper);
            if(CollectionUtils.isEmpty(rStatOrgMPOS)){
                sumEffectiveMeasurement=0;
            }else {
                sumEffectiveMeasurement = rStatOrgMPOS.stream().mapToInt(o->Objects.isNull(o.getEffectiveMeasurementAccrued())?0:o.getEffectiveMeasurementAccrued()).sum();
            }
            int finalSumEffectiveMeasurement = sumEffectiveMeasurement;
            dataTypeMap.forEach((k, v)->{
                steadyStatis.forEach(dictData -> {
                    if (Objects.equals(dictData.getCode(), DicDataEnum.TOTAL_INDICATOR.getCode())) {
                        return;
                    }
                    queryWrapper.clear();
                    queryWrapper.eq("org_no",temp.getUnitId()).
                            eq("harmonic_type",dictData.getId()).
                            eq("data_type",v.getId()).
                            between("data_date",begin,end);
                    List<RStatHarmonicMPO> rStatHarmonicMPOS = rStatHarmonicMPOMapper.selectList(queryWrapper);
                    double overLimitMeasurementAverage =0.00;
                    int overDay =0;
                    int overLimitMeasurementAccrued=0;
                    double overLimitMeasurementRatioAverage=0.00;
                    double overLimitMeasurementRatioAccrued=0.00;
                    if(!CollectionUtils.isEmpty(rStatHarmonicMPOS)){
                        overDay = rStatHarmonicMPOS.stream().mapToInt(o->Objects.isNull(o.getOverDay())?0:o.getOverDay()).sum();
                        overLimitMeasurementAccrued = rStatHarmonicMPOS.stream().mapToInt(o->Objects.isNull(o.getOverLimitMeasurementAccrued())?0:o.getOverLimitMeasurementAccrued()).sum();
                        double asDouble = rStatHarmonicMPOS.stream().mapToDouble(o->Objects.isNull(o.getOverLimitMeasurementAverage())?0.0:o.getOverLimitMeasurementAverage()).average().getAsDouble();
                        overLimitMeasurementAverage = Double.parseDouble(df.format(asDouble));
                        double asDouble1 = rStatHarmonicMPOS.stream().mapToDouble(o->Objects.isNull(o.getOverLimitMeasurementRatioAverage())?0.0:o.getOverLimitMeasurementRatioAverage()).average().getAsDouble();
                        overLimitMeasurementRatioAverage = Double.parseDouble(df.format(asDouble1));
                        if(finalSumEffectiveMeasurement ==0){
                            overLimitMeasurementRatioAccrued=0.00;
                        }else {
                            overLimitMeasurementRatioAccrued=Double.parseDouble(df.format((float)overLimitMeasurementAccrued / finalSumEffectiveMeasurement));
                        }
                    }
                    RStatHarmonicOrgMPO rStatHarmonicOrgMPO = new RStatHarmonicOrgMPO();
                    rStatHarmonicOrgMPO.setOrgNo(temp.getUnitId());
                    rStatHarmonicOrgMPO.setDataDate(localDate);
                    rStatHarmonicOrgMPO.setHarmonicType(dictData.getId());
                    rStatHarmonicOrgMPO.setDataType(v.getId());
                    rStatHarmonicOrgMPO.setOverDay(overDay);
                    rStatHarmonicOrgMPO.setOverLimitMeasurementAccrued(overLimitMeasurementAccrued);
                    rStatHarmonicOrgMPO.setOverLimitMeasurementAverage(overLimitMeasurementAverage);
                    rStatHarmonicOrgMPO.setOverLimitMeasurementRatioAccrued(overLimitMeasurementRatioAccrued);
                    rStatHarmonicOrgMPO.setOverLimitMeasurementRatioAverage(overLimitMeasurementRatioAverage);

                    rStatHarmonicOrgMPOList.add(rStatHarmonicOrgMPO);


                });

            });
        });

        if(!CollectionUtils.isEmpty(rStatHarmonicOrgMPOList)){
            rStatHarmonicMPOService.saveOrUpdateBatchByMultiId(rStatHarmonicOrgMPOList,500);
        }

    }

    @Override
    public void handleQtr(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
        List<RStatHarmonicOrgQPO> rStatHarmonicOrgQPOList = new ArrayList<>();

        DateTime begin = DateUtil.beginOfQuarter(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        DateTime end = DateUtil.endOfQuarter(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        LocalDate localDate = LocalDateTimeUtil.parseDate( DateUtil.format(begin, DatePattern.NORM_DATE_PATTERN), DatePattern.NORM_DATE_PATTERN);

        QueryWrapper<RStatHarmonicMPO> queryWrapper = new QueryWrapper<>();
        QueryWrapper<RStatOrgQPO> rStatOrgQPOQueryWrapper = new QueryWrapper<>();


        /*获取稳态统计指标*/
        List<DictData> steadyStatis = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
        /*获取数据类型*/

        List<DictData> dataTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DATA_TYPE.getCode()).getData();
        Map<String, DictData> dataTypeMap = dataTypeList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        ;
        /*获取监测点类型类型*/
        List<DictData> lineSortList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_SORT.getCode()).getData();
        Map<String, DictData> lineSortMap = lineSortList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        calculatedParam.getIdList().stream().forEach(temp->{
            int sumEffectiveMeasurement =0;
            rStatOrgQPOQueryWrapper.clear();
            rStatOrgQPOQueryWrapper.select("effective_measurement_accrued").
                    eq("org_no",temp.getUnitId()).
                    between("data_date",begin,end);

            List<RStatOrgQPO> rStatOrgQPOS = rStatOrgQMapper.selectList(rStatOrgQPOQueryWrapper);
            if(CollectionUtils.isEmpty(rStatOrgQPOS)){
                sumEffectiveMeasurement=0;
            }else {
                sumEffectiveMeasurement = rStatOrgQPOS.stream().mapToInt(RStatOrgQPO::getEffectiveMeasurementAccrued).sum();
            }
            int finalSumEffectiveMeasurement = sumEffectiveMeasurement;
            dataTypeMap.forEach((k, v)->{
                steadyStatis.forEach(dictData -> {
                    if (Objects.equals(dictData.getCode(), DicDataEnum.TOTAL_INDICATOR.getCode())) {
                        return;
                    }
                    queryWrapper.clear();
                    queryWrapper.eq("org_no",temp.getUnitId()).
                            eq("harmonic_type",dictData.getId()).
                            eq("data_type",v.getId()).
                            between("data_date",begin,end);
                    List<RStatHarmonicMPO> rStatHarmonicMPOS = rStatHarmonicMPOMapper.selectList(queryWrapper);
                    Double overLimitMeasurementAverage =0.00;
                    int overDay =0;
                    int overLimitMeasurementAccrued=0;
                    Double averageOverDay =0.00;
                    Double overLimitMeasurementRatioAverage=0.00;
                    Double overLimitMeasurementRatioAccrued=0.00;
                    if(!CollectionUtils.isEmpty(rStatHarmonicMPOS)){

                        overDay = rStatHarmonicMPOS.stream().mapToInt(RStatHarmonicMPO::getOverDay).sum();
                        overLimitMeasurementAccrued = rStatHarmonicMPOS.stream().mapToInt(RStatHarmonicMPO::getOverLimitMeasurementAccrued).sum();
                        double asDouble = rStatHarmonicMPOS.stream().mapToDouble(RStatHarmonicMPO::getOverLimitMeasurementAverage).average().getAsDouble();
                        overLimitMeasurementAverage = Double.parseDouble(df.format(asDouble));
                        double asDouble1 = rStatHarmonicMPOS.stream().mapToDouble(RStatHarmonicMPO::getOverLimitMeasurementRatioAverage).average().getAsDouble();

                        overLimitMeasurementRatioAverage = Double.parseDouble(df.format(asDouble1));
                        if(finalSumEffectiveMeasurement ==0){
                            overLimitMeasurementRatioAccrued=0.00;
                        }else {
                            overLimitMeasurementRatioAccrued=Double.parseDouble(df.format((float)overLimitMeasurementAccrued / finalSumEffectiveMeasurement));
                        }
                        if(!(overLimitMeasurementAccrued==0)){
                            averageOverDay = Double.parseDouble(df.format((float)overDay / overLimitMeasurementAccrued));
                        }
                    }
                    RStatHarmonicOrgQPO rStatHarmonicOrgQPO = new RStatHarmonicOrgQPO();
                    rStatHarmonicOrgQPO.setOrgNo(temp.getUnitId());
                    rStatHarmonicOrgQPO.setDataDate(localDate);
                    rStatHarmonicOrgQPO.setHarmonicType(dictData.getId());
                    rStatHarmonicOrgQPO.setDataType(v.getId());
                    rStatHarmonicOrgQPO.setAverageOverDay(averageOverDay);
                    rStatHarmonicOrgQPO.setOverLimitMeasurementAccrued(overLimitMeasurementAccrued);
                    rStatHarmonicOrgQPO.setOverLimitMeasurementAverage(overLimitMeasurementAverage);
                    rStatHarmonicOrgQPO.setOverLimitMeasurementRatioAccrued(overLimitMeasurementRatioAccrued);
                    rStatHarmonicOrgQPO.setOverLimitMeasurementRatioAverage(overLimitMeasurementRatioAverage);

                    rStatHarmonicOrgQPOList.add(rStatHarmonicOrgQPO);


                });

            });
        });

        if(!CollectionUtils.isEmpty(rStatHarmonicOrgQPOList)){
            rStatHarmonicQPOService.saveOrUpdateBatchByMultiId(rStatHarmonicOrgQPOList,500);
        }
    }

    @Override
    public void handleYear(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {

        List<RStatHarmonicOrgYPO> rStatHarmonicOrgYPOList = new ArrayList<>();
        DateTime begin = DateUtil.beginOfYear(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        DateTime end = DateUtil.endOfYear(DateUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN));
        LocalDate localDate = LocalDateTimeUtil.parseDate( DateUtil.format(begin, DatePattern.NORM_DATE_PATTERN), DatePattern.NORM_DATE_PATTERN);

        QueryWrapper<RStatHarmonicMPO> queryWrapper = new QueryWrapper<>();
        QueryWrapper<RStatOrgYPO> rStatOrgYPOQueryWrapper = new QueryWrapper<>();


        /*获取稳态统计指标*/
        List<DictData> steadyStatis = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
        /*获取数据类型*/

        List<DictData> dataTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DATA_TYPE.getCode()).getData();
        Map<String, DictData> dataTypeMap = dataTypeList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        ;
        /*获取监测点类型类型*/
        List<DictData> lineSortList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.LINE_SORT.getCode()).getData();
        Map<String, DictData> lineSortMap = lineSortList.stream().collect(Collectors.toMap(DictData::getCode, dictData -> dictData));
        calculatedParam.getIdList().stream().forEach(temp->{
            int sumEffectiveMeasurement =0;
            rStatOrgYPOQueryWrapper.clear();
            rStatOrgYPOQueryWrapper.select("effective_measurement_accrued").
                    eq("org_no",temp.getUnitId()).
                    between("data_date",begin,end);


            List<RStatOrgYPO> rStatOrgYPOS = rStatOrgYMapper.selectList(rStatOrgYPOQueryWrapper);
            if(CollectionUtils.isEmpty(rStatOrgYPOS)){
                sumEffectiveMeasurement=0;
            }else {
                sumEffectiveMeasurement = rStatOrgYPOS.stream().mapToInt(RStatOrgYPO::getEffectiveMeasurementAccrued).sum();
            }
            int finalSumEffectiveMeasurement = sumEffectiveMeasurement;
            dataTypeMap.forEach((k, v)->{
                steadyStatis.forEach(dictData -> {
                    if (Objects.equals(dictData.getCode(), DicDataEnum.TOTAL_INDICATOR.getCode())) {
                        return;
                    }
                    queryWrapper.clear();
                    queryWrapper.eq("org_no",temp.getUnitId()).
                            eq("harmonic_type",dictData.getId()).
                            eq("data_type",v.getId()).
                            between("data_date",begin,end);
                    List<RStatHarmonicMPO> rStatHarmonicMPOS = rStatHarmonicMPOMapper.selectList(queryWrapper);
                    Double overLimitMeasurementAverage =0.00;
                    int overDay =0;
                    int overLimitMeasurementAccrued=0;
                    Double averageOverDay =0.00;
                    Double overLimitMeasurementRatioAverage=0.00;
                    Double overLimitMeasurementRatioAccrued=0.00;
                    if(!CollectionUtils.isEmpty(rStatHarmonicMPOS)){

                        overDay = rStatHarmonicMPOS.stream().mapToInt(RStatHarmonicMPO::getOverDay).sum();
                        overLimitMeasurementAccrued = rStatHarmonicMPOS.stream().mapToInt(RStatHarmonicMPO::getOverLimitMeasurementAccrued).sum();
                        double asDouble = rStatHarmonicMPOS.stream().mapToDouble(RStatHarmonicMPO::getOverLimitMeasurementAverage).average().getAsDouble();
                        overLimitMeasurementAverage = Double.parseDouble(df.format(asDouble));
                        double asDouble1 = rStatHarmonicMPOS.stream().mapToDouble(RStatHarmonicMPO::getOverLimitMeasurementRatioAverage).average().getAsDouble();

                        overLimitMeasurementRatioAverage = Double.parseDouble(df.format(asDouble1));
                        if(finalSumEffectiveMeasurement ==0){
                            overLimitMeasurementRatioAccrued=0.00;
                        }else {
                            overLimitMeasurementRatioAccrued=Double.parseDouble(df.format((float)overLimitMeasurementAccrued / finalSumEffectiveMeasurement));
                        }
                        if(!(overLimitMeasurementAccrued==0)){
                            averageOverDay = Double.parseDouble(df.format((float)overDay / overLimitMeasurementAccrued));
                        }
                    }
                    RStatHarmonicOrgYPO rStatHarmonicOrgYPO = new RStatHarmonicOrgYPO();
                    rStatHarmonicOrgYPO.setOrgNo(temp.getUnitId());
                    rStatHarmonicOrgYPO.setDataDate(localDate);
                    rStatHarmonicOrgYPO.setHarmonicType(dictData.getId());
                    rStatHarmonicOrgYPO.setDataType(v.getId());
                    rStatHarmonicOrgYPO.setAverageOverDay(averageOverDay);
                    rStatHarmonicOrgYPO.setOverLimitMeasurementAccrued(overLimitMeasurementAccrued);
                    rStatHarmonicOrgYPO.setOverLimitMeasurementAverage(overLimitMeasurementAverage);
                    rStatHarmonicOrgYPO.setOverLimitMeasurementRatioAccrued(overLimitMeasurementRatioAccrued);
                    rStatHarmonicOrgYPO.setOverLimitMeasurementRatioAverage(overLimitMeasurementRatioAverage);

                    rStatHarmonicOrgYPOList.add(rStatHarmonicOrgYPO);


                });

            });
        });

        if(!CollectionUtils.isEmpty(rStatHarmonicOrgYPOList)){
            rStatHarmonicYPOService.saveOrUpdateBatchByMultiId(rStatHarmonicOrgYPOList,500);
        }

    }

}
