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

import cn.hutool.core.date.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.device.biz.pojo.dto.LineDevGetBandDTO;
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.po.*;
import com.njcn.harmonic.pojo.po.day.*;
import com.njcn.prepare.harmonic.mapper.mysql.line.*;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.pojo.dto.PollutionDTO;
import com.njcn.prepare.harmonic.service.mysql.day.*;
import com.njcn.prepare.harmonic.service.mysql.line.PollutionService;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.*;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 监测点污染指标
 *
 * @author xiaoyao
 * @version 1.0.0
 * @createTime 2022/10/18 9:16
 */

@Slf4j
@Service
@AllArgsConstructor
public class PollutionServiceImpl implements PollutionService {

    private final DicDataFeignClient dicDataFeignClient;

    private final RStatPollutionOrgDMapper rStatPollutionOrgDMapper;

    private final RStatPollutionOrgMMapper rStatPollutionOrgMMapper;

    private final RStatPollutionOrgQMapper rStatPollutionOrgQMapper;

    private final RStatPollutionOrgYMapper rStatPollutionOrgYMapper;

    private final RStatPollutionSubstationDMapper rStatPollutionSubstationDMapper;

    private final RStatPollutionSubstationMMapper rStatPollutionSubstationMMapper;

    private final RStatPollutionSubstationQMapper rStatPollutionSubstationQMapper;

    private final RStatPollutionSubstationYMapper rStatPollutionSubstationYMapper;

    private final RMpPollutionDMapper rMpPollutionDMapper;

    private final CommTerminalGeneralClient commTerminalGeneralClient;

    private final IRStatDataVDService dataVDService;
    private final IRStatDataHarmRateVDService harmRateVDService;
    private final IRStatDataIDService dataIDService;
    private final IRStatDataInharmVDService inharmVDService;
    private final IRStatDataPltDService pltDService;
    /**-------------------------------监测点污区图-----------------------------------**/
    @Override
    public void handleDay(CalculatedParam calculatedParam) {
        List<PollutionDTO> pollutionList ;

        List<DictData> dictData = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.POLLUTION_STATIS.getCode()).getData();
        LocalDate local = LocalDateTimeUtil.parseDate(calculatedParam.getDataDate());
        String  beginDay =LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)),DatePattern.NORM_DATETIME_PATTERN);
        String endDay = LocalDateTimeUtil.format(LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.parse(calculatedParam.getDataDate(), DatePattern.NORM_DATE_PATTERN)),DatePattern.NORM_DATETIME_PATTERN);
        List<String> idList = calculatedParam.getIdList();
        List<Overlimit> overLimitList = new ArrayList<>();
        for (String lineId :idList){
            Overlimit overlimit = commTerminalGeneralClient.getOverLimitData(lineId).getData();
            overLimitList.add(overlimit);
        }
        //指标数据获取
        List<PublicDTO> harmonicVoltageList = getHarmonicVoltage(overLimitList,beginDay,endDay);
        List<PublicDTO> harmonicCurrentList = getHarmonicCurrent(overLimitList,beginDay,endDay);
        List<PublicDTO> frequencyDeviationList = getFrequencyDeviation(overLimitList,beginDay,endDay);
        List<PublicDTO> voltageDeviationList = getVoltageDeviation(overLimitList,beginDay,endDay);
        List<PublicDTO> threePhaseVoltageList = getThreePhaseVoltageUnbalance(overLimitList,beginDay,endDay);
        List<PublicDTO> negativeSequenceList = getNegativeSequenceCurrent(overLimitList,beginDay,endDay);
        List<PublicDTO> interHarmonicVoltageList = getInterharmonicVoltage(overLimitList,beginDay,endDay);
        List<PublicDTO> voltageFlickerList = getVoltageFlicker(overLimitList,beginDay,endDay);

        List<PollutionDTO> lineIdList = new ArrayList<>();
        idList.forEach(item->{
            PollutionDTO pollutionDTO = new PollutionDTO();
            pollutionDTO.setLineId(item);
            lineIdList.add(pollutionDTO);
        });
        pollutionList = processPollutionList(lineIdList,harmonicVoltageList,harmonicCurrentList,frequencyDeviationList,voltageDeviationList,threePhaseVoltageList,negativeSequenceList,interHarmonicVoltageList,voltageFlickerList);
        insertPollutionDayMySql(pollutionList, dictData, local);
    }
    /*-------------------------------单位污区图------------------------------------*/
    @Override
    public void handleOrgDay(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
        LocalDate local = LocalDateTimeUtil.parseDate(calculatedParam.getDataDate());

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

        for (DeptGetChildrenMoreDTO deptGetChildrenMoreDTO : calculatedParam.getIdList()) {
            Collection<LineDevGetDTO> union = CollectionUtils.union(Optional.ofNullable(deptGetChildrenMoreDTO.getLineBaseList()).orElse(new ArrayList<LineDevGetDTO>()),
                    Optional.ofNullable(deptGetChildrenMoreDTO.getPwMonitorIds()).orElse(new ArrayList<LineDevGetDTO>()));
            List<String> collect = union.stream().map(LineDevGetDTO::getPointId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(collect)){
                continue;

            }
            queryWrapper.clear();
            queryWrapper.in(
                    "line_id",collect
            ).eq("data_date",local);
            List<RMpPollutionDPO> rMpPollutionDPOS = rMpPollutionDMapper.selectList(queryWrapper);
            Map<String, List<RMpPollutionDPO>> collect1 = rMpPollutionDPOS.stream().collect(Collectors.groupingBy(RMpPollutionDPO::getPollutionType));
            collect1.forEach((k,v)->{
                Map<String, Object> inMap = new HashMap<>();
                inMap.put("orgId",deptGetChildrenMoreDTO.getUnitId());
                inMap.put("dataDate",local);
                inMap.put("pollutionType",k);
                inMap.put("value",v.stream().max(Comparator.comparing(RMpPollutionDPO::getValue)).get().getValue());
                rStatPollutionOrgDMapper.insertPollution(inMap);
            });
        }

    }

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

        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);

        List<RStatPollutionOrgDPO> substationD = rStatPollutionOrgDMapper.selectList(new LambdaQueryWrapper<RStatPollutionOrgDPO>()
                .ge(RStatPollutionOrgDPO::getDataDate, begin)
                .le(RStatPollutionOrgDPO::getDataDate, end)
        );
        Map<String, List<RStatPollutionOrgDPO>> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getOrgId() +"_"+ temp.getPollutionType()));
        substationDMap.forEach((key,value)->{
            String[] split = key.split("_");
            Map<String, Object> inMap = new HashMap<>();
            inMap.put("orgId",split[0]);
            inMap.put("dataDate",localDate);
            inMap.put("pollutionType",split[1]);
            inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionOrgDPO::getValue)).get().getValue());
            rStatPollutionOrgMMapper.insertPollution(inMap);
        });

    }

    @Override
    public void handleOrgQtr(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
        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);        /*获取监测点类型类型*/

        List<RStatPollutionOrgMPO> substationD = rStatPollutionOrgMMapper.selectList(new LambdaQueryWrapper<RStatPollutionOrgMPO>()
                .ge(RStatPollutionOrgMPO::getDataDate, begin)
                .le(RStatPollutionOrgMPO::getDataDate, end)
        );
        Map<String, List<RStatPollutionOrgMPO>> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getOrgId() +"_"+ temp.getPollutionType()));
        substationDMap.forEach((key,value)->{
            String[] split = key.split("_");
            Map<String, Object> inMap = new HashMap<>();
            inMap.put("orgId",split[0]);
            inMap.put("dataDate",localDate);
            inMap.put("pollutionType",split[1]);
            inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionOrgMPO::getValue)).get().getValue());
            rStatPollutionOrgQMapper.insertPollution(inMap);
        });
    }

    @Override
    public void handleOrgYear(CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam) {
        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);        /*获取监测点类型类型*/

        List<RStatPollutionOrgQPO> substationD = rStatPollutionOrgQMapper.selectList(new LambdaQueryWrapper<RStatPollutionOrgQPO>()
                .ge(RStatPollutionOrgQPO::getDataDate, begin)
                .le(RStatPollutionOrgQPO::getDataDate, end)
        );
        Map<String, List<RStatPollutionOrgQPO>> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getOrgId() +"_"+ temp.getPollutionType()));
        substationDMap.forEach((key,value)->{
            String[] split = key.split("_");
            Map<String, Object> inMap = new HashMap<>();
            inMap.put("orgId",split[0]);
            inMap.put("dataDate",localDate);
            inMap.put("pollutionType",split[1]);
            inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionOrgQPO::getValue)).get().getValue());
            rStatPollutionOrgYMapper.insertPollution(inMap);
        });

    }



    /*----------------------------------------------变电站污区图----------------------------------------------------*/
    @Override
    public void handleSubstationDay(CalculatedParam<String> calculatedParam) {
        LocalDate local = LocalDateTimeUtil.parseDate(calculatedParam.getDataDate());

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

        for (String substationId : calculatedParam.getIdList()) {
            LineDevGetBandDTO data = commTerminalGeneralClient.substationGetLine(substationId).getData();
            Collection<LineDevGetDTO> union = CollectionUtils.union(Optional.ofNullable(data.getPwList()).orElse(new ArrayList<>()),
                    Optional.ofNullable(data.getZwList()).orElse(new ArrayList<>()));
            List<String> collect = union.stream().map(LineDevGetDTO::getPointId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(collect)){
                continue;
            }
            queryWrapper.clear();
            queryWrapper.in(
                    "line_id",collect
            ).eq("data_date",local);
            List<RMpPollutionDPO> rMpPollutionDPOS = rMpPollutionDMapper.selectList(queryWrapper);
            Map<String, List<RMpPollutionDPO>> collect1 = rMpPollutionDPOS.stream().collect(Collectors.groupingBy(RMpPollutionDPO::getPollutionType));
            collect1.forEach((k,v)->{
                Map<String, Object> inMap = new HashMap<>();
                inMap.put("substationId",substationId);
                inMap.put("dataDate",local);
                inMap.put("pollutionType",k);
                inMap.put("value",v.stream().max(Comparator.comparing(RMpPollutionDPO::getValue)).get().getValue());
                rStatPollutionSubstationDMapper.insertPollution(inMap);
            });
        }

    }

    @Override
    public void handleSubstationMonth(CalculatedParam<String> calculatedParam) {


        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);

        List<RStatPollutionSubstationDPO> substationD = rStatPollutionSubstationDMapper.selectList(new LambdaQueryWrapper<RStatPollutionSubstationDPO>()
                .ge(RStatPollutionSubstationDPO::getDataDate, begin)
                .le(RStatPollutionSubstationDPO::getDataDate, end)
        );
        Map<String, List<RStatPollutionSubstationDPO>> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getSubstationId() +"_"+ temp.getPollutionType()));
        substationDMap.forEach((key,value)->{
            String[] split = key.split("_");
            Map<String, Object> inMap = new HashMap<>();
            inMap.put("substationId",split[0]);
            inMap.put("dataDate",localDate);
            inMap.put("pollutionType",split[1]);
            inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionSubstationDPO::getValue)).get().getValue());
            rStatPollutionSubstationMMapper.insertPollution(inMap);

        });

    }

    @Override
    public void handleSubstationQtr(CalculatedParam<String> calculatedParam) {

        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);        /*获取监测点类型类型*/


        List<RStatPollutionSubstationM> substationM = rStatPollutionSubstationMMapper.selectList(new LambdaQueryWrapper<RStatPollutionSubstationM>()
                .ge(RStatPollutionSubstationM::getDataDate, begin)
                .le(RStatPollutionSubstationM::getDataDate, end)
        );
        Map<String, List<RStatPollutionSubstationM>> substationDMap = substationM.stream().collect(Collectors.groupingBy(temp -> temp.getSubstationId() +"_"+ temp.getPollutionType()));
        substationDMap.forEach((key,value)->{
            String[] split = key.split("_");
            Map<String, Object> inMap = new HashMap<>();
            inMap.put("substationId",split[0]);
            inMap.put("dataDate",localDate);
            inMap.put("pollutionType",split[1]);
            inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionSubstationM::getValue)).get().getValue());
            rStatPollutionSubstationQMapper.insertPollution(inMap);

        });

    }

    @Override
    public void handleSubstationYear(CalculatedParam<String> calculatedParam) {

        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);

        List<RStatPollutionSubstationQPO> substationM = rStatPollutionSubstationQMapper.selectList(new LambdaQueryWrapper<RStatPollutionSubstationQPO>()
                .ge(RStatPollutionSubstationQPO::getDataDate, begin)
                .le(RStatPollutionSubstationQPO::getDataDate, end)
        );
        Map<String, List<RStatPollutionSubstationQPO>> substationDMap = substationM.stream().collect(Collectors.groupingBy(temp -> temp.getSubstationId() +"_"+ temp.getPollutionType()));
        substationDMap.forEach((key,value)->{
            String[] split = key.split("_");
            Map<String, Object> inMap = new HashMap<>();
            inMap.put("substationId",split[0]);
            inMap.put("dataDate",localDate);
            inMap.put("pollutionType",split[1]);
            inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionSubstationQPO::getValue)).get().getValue());
            rStatPollutionSubstationYMapper.insertPollution(inMap);
        });
    }


    /*--------------------------------------------原始代码------------------------------------------------------*/




    /*MySql入表 r_mp_pollution_d*/
    private void insertPollutionDayMySql(List<PollutionDTO> pollutionList,List<DictData> dictDataList, LocalDate local){
        for (PollutionDTO pollution : pollutionList){
            Map<String, Object> inMap = new HashMap<>();
            inMap.put("lineId",pollution.getLineId());
            inMap.put("dataDate",local);
            for (DictData dictData : dictDataList){
                processDataLineId(dictData, pollution, inMap);
                rMpPollutionDMapper.insertPollution(inMap);
            }
        }
    }

    private void processDataLineId(DictData dictData, PollutionDTO pollution, Map<String, Object> map){
        if ("Freq_Dev".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getFreqDev());
        }
        if ("V_Dev".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getVDev());
        }
        if ("V_Unbalance".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getVUnbalance());
        }
        if ("V_All".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getVAll());
        }
        if ("Plt".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getPlt());
        }
        if ("I_All".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getIAll());
        }
        if ("I_Neg".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getINeg());
        }
        if ("V_Inharm".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getVInharm());
        }
        if ("V_Harmonic".equals(dictData.getCode())){
            map.put("pollutionType",dictData.getId());
            map.put("value",pollution.getVHarmonic());
        }
    }

    /**
     * 谐波电压：取监测点最新的A、B、C三相数据，再取电压总谐波畸变率、各次谐波电压含有率（2~25次）中的最大值，作为结果
     */
    private List<PublicDTO> getHarmonicVoltage(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<PublicDTO> list = new ArrayList<>();
        Map<String, Optional<PublicDTO>> threePhase = getThreePhaseData(overLimitList,beginTime,endTime);
        Map<String, Optional<PublicDTO>> distortionRate = getDistortionRateData(overLimitList,beginTime,endTime);
        for (String key : threePhase.keySet()) {
            list.add(threePhase.get(key).get());
        }
        for (String key : distortionRate.keySet()) {
            list.add(distortionRate.get(key).get());
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = list.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    private Map<String, Optional<PublicDTO>> getThreePhaseData(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataVDPO> threePhaseList = dataVDService.list(new LambdaQueryWrapper<RStatDataVDPO>()
                .eq(RStatDataVDPO::getValueType, "CP95")
                .in(RStatDataVDPO::getPhaseType, Arrays.asList("A", "B", "C"))
                .ge(RStatDataVDPO::getTime, beginTime)
                .le(RStatDataVDPO::getTime, endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
//        String sql = "SELECT * FROM day_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') " + processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +" group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//        QueryResult threePhaseSqlResult = influxDbUtils.query(sql);
//        List<DayVPO> threePhaseList = resultMapper.toPOJO(threePhaseSqlResult, DayVPO.class);

        for (RStatDataVDPO item1 : threePhaseList) {
            for (Overlimit item2 : overLimitList) {
                if (Objects.equals(item1.getLineId(),item2.getId())){
                    double vUnbalance = item1.getVThd()/item2.getUaberrance();
                    data = Stream.of(vUnbalance).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(item1.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
    }

    private Map<String, Optional<PublicDTO>> getDistortionRateData(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataHarmrateVDPO> distortionRateList = harmRateVDService.list(new LambdaQueryWrapper<RStatDataHarmrateVDPO>()
                .eq(RStatDataHarmrateVDPO::getValueType, "CP95")
                .in(RStatDataHarmrateVDPO::getPhaseType, Arrays.asList("A", "B", "C"))
                .ge(RStatDataHarmrateVDPO::getTime, beginTime)
                .le(RStatDataHarmrateVDPO::getTime, endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
//        String sql = "SELECT * FROM day_harmrate_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') "+ processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +"group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//
//        QueryResult distortionRateSqlResult = influxDbUtils.query(sql);
//        List<DayHarmrateVPO> distortionRateList = resultMapper.toPOJO(distortionRateSqlResult, DayHarmrateVPO.class);
        for (RStatDataHarmrateVDPO dayHarmrateV : distortionRateList) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayHarmrateV.getLineId(),overlimit.getId())){
                    double v2 = dayHarmrateV.getV2()/overlimit.getUharm2();
                    double v3 = dayHarmrateV.getV3()/overlimit.getUharm3();
                    double v4 = dayHarmrateV.getV4()/overlimit.getUharm4();
                    double v5 = dayHarmrateV.getV5()/overlimit.getUharm5();
                    double v6 = dayHarmrateV.getV6()/overlimit.getUharm6();
                    double v7 = dayHarmrateV.getV7()/overlimit.getUharm7();
                    double v8 = dayHarmrateV.getV8()/overlimit.getUharm8();
                    double v9 = dayHarmrateV.getV9()/overlimit.getUharm9();
                    double v10 = dayHarmrateV.getV10()/overlimit.getUharm10();
                    double v11 = dayHarmrateV.getV11()/overlimit.getUharm11();
                    double v12 = dayHarmrateV.getV12()/overlimit.getUharm12();
                    double v13 = dayHarmrateV.getV13()/overlimit.getUharm13();
                    double v14 = dayHarmrateV.getV14()/overlimit.getUharm14();
                    double v15 = dayHarmrateV.getV15()/overlimit.getUharm15();
                    double v16 = dayHarmrateV.getV16()/overlimit.getUharm16();
                    double v17 = dayHarmrateV.getV17()/overlimit.getUharm17();
                    double v18 = dayHarmrateV.getV18()/overlimit.getUharm18();
                    double v19 = dayHarmrateV.getV19()/overlimit.getUharm19();
                    double v20 = dayHarmrateV.getV20()/overlimit.getUharm20();
                    double v21 = dayHarmrateV.getV21()/overlimit.getUharm21();
                    double v22 = dayHarmrateV.getV22()/overlimit.getUharm22();
                    double v23 = dayHarmrateV.getV23()/overlimit.getUharm23();
                    double v24 = dayHarmrateV.getV24()/overlimit.getUharm24();
                    double v25 = dayHarmrateV.getV25()/overlimit.getUharm25();
                    data = Stream.of(v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayHarmrateV.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
    }

    /**
     * 谐波电流：各次谐波电流（2~25次），取各监测点最新的A、B、C三相数据。
     */
    private List<PublicDTO> getHarmonicCurrent(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataIDPO> list = dataIDService.list(new LambdaQueryWrapper<RStatDataIDPO>()
                .eq(RStatDataIDPO::getValueType, "CP95")
                .in(RStatDataIDPO::getPhaseType, Arrays.asList("A", "B", "C"))
                .ge(RStatDataIDPO::getTime, beginTime)
                .le(RStatDataIDPO::getTime, endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
        for (RStatDataIDPO dayI : list) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayI.getLineId(),overlimit.getId())){
                    double v2 = dayI.getI2()/overlimit.getIharm2();
                    double v3 = dayI.getI3()/overlimit.getIharm3();
                    double v4 = dayI.getI4()/overlimit.getIharm4();
                    double v5 = dayI.getI5()/overlimit.getIharm5();
                    double v6 = dayI.getI6()/overlimit.getIharm6();
                    double v7 = dayI.getI7()/overlimit.getIharm7();
                    double v8 = dayI.getI8()/overlimit.getIharm8();
                    double v9 = dayI.getI9()/overlimit.getIharm9();
                    double v10 = dayI.getI10()/overlimit.getIharm10();
                    double v11 = dayI.getI11()/overlimit.getIharm11();
                    double v12 = dayI.getI12()/overlimit.getIharm12();
                    double v13 = dayI.getI13()/overlimit.getIharm13();
                    double v14 = dayI.getI14()/overlimit.getIharm14();
                    double v15 = dayI.getI15()/overlimit.getIharm15();
                    double v16 = dayI.getI16()/overlimit.getIharm16();
                    double v17 = dayI.getI17()/overlimit.getIharm17();
                    double v18 = dayI.getI18()/overlimit.getIharm18();
                    double v19 = dayI.getI19()/overlimit.getIharm19();
                    double v20 = dayI.getI20()/overlimit.getIharm20();
                    double v21 = dayI.getI21()/overlimit.getIharm21();
                    double v22 = dayI.getI22()/overlimit.getIharm22();
                    double v23 = dayI.getI23()/overlimit.getIharm23();
                    double v24 = dayI.getI24()/overlimit.getIharm24();
                    double v25 = dayI.getI25()/overlimit.getIharm25();
                    data = Stream.of(v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayI.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    /**
     * 频率偏差：各监测点最新的T相数据，取频率上下偏差的绝对值中的最大值。
     */
    private List<PublicDTO> getFrequencyDeviation(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataVDPO> threePhaseList = dataVDService.list(new QueryWrapper<RStatDataVDPO>()
                .select("line_id","abs(freq_dev) as freq_dev ")
                .in("value_type", Arrays.asList("MIN","MAX"))
                .in("phasic_type", Arrays.asList("T"))
                .ge("time", beginTime)
                .le("time",endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
//        String sql = "SELECT line_id,abs(freq_dev) AS freq_dev FROM day_v where phasic_type = 'T' and (value_type = 'MIN' or value_type = 'MAX') "+ processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +"group by line_id order by time desc limit 2 tz('Asia/Shanghai')";
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//
//        QueryResult sqlResult = influxDbUtils.query(sql);
//        List<DayVPO> list = resultMapper.toPOJO(sqlResult, DayVPO.class);
        for (RStatDataVDPO dayV : threePhaseList) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayV.getLineId(),overlimit.getId())){
                    double freqDev = dayV.getFreqDev()/overlimit.getFreqDev();
                    data = Stream.of(freqDev).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayV.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    /**
     * 电压偏差：各监测点最新的A、B、C三相数据，取电压上下偏差的绝对值中的最大值。
     */
    private List<PublicDTO> getVoltageDeviation(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataVDPO> list = dataVDService.list(new QueryWrapper<RStatDataVDPO>()
                .select("line_id","vu_dev","vl_dev","value_type")
                .in("value_type", Arrays.asList("MIN","MAX"))
                .in("phasic_type", Arrays.asList("A","B","C"))
                .ge("time", beginTime)
                .le("time", endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
//        String sql = "SELECT line_id,vu_dev,vl_dev,value_type FROM day_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and (value_type = 'MIN' or value_type = 'MAX') "+ processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +" group by line_id order by time desc limit 6 tz('Asia/Shanghai')";
//        QueryResult sqlResult = influxDbUtils.query(sql);
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//
//        List<DayVPO> list = resultMapper.toPOJO(sqlResult, DayVPO.class);
        for (RStatDataVDPO dayV : list) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayV.getLineId(),overlimit.getId())){
                    double vlDev = Math.abs(dayV.getVlDev()/overlimit.getUvoltageDev());
                    double vuDev = Math.abs(dayV.getVuDev()/overlimit.getVoltageDev());
                    data = Stream.of(vuDev,vlDev).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayV.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    /**
     * 三相电压不平衡度：各监测点最新的T相数据。
     */
    private List<PublicDTO> getThreePhaseVoltageUnbalance(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataVDPO> list = dataVDService.list(new QueryWrapper<RStatDataVDPO>()
                .select("line_id","v_unbalance","value_type")
                .in("value_type", Arrays.asList("CP95","MAX"))
                .in("phasic_type", Arrays.asList("T"))
                .ge("time", beginTime)
                .le("time", endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
//        String sql = "SELECT line_id,v_unbalance,value_type FROM day_v where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') "+ processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +" group by line_id order by time desc limit 2 tz('Asia/Shanghai')";
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//
//        QueryResult sqlResult = influxDbUtils.query(sql);
//        List<DayVPO> list = resultMapper.toPOJO(sqlResult, DayVPO.class);
        for (RStatDataVDPO dayV : list) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayV.getLineId(),overlimit.getId())){
                    double vUnbalance = Math.abs(dayV.getVUnbalance()/overlimit.getUbalance());
                    data = Stream.of(vUnbalance).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayV.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    /**
     * 负序电流：各监测点最新的T相数据。
     */
    private List<PublicDTO> getNegativeSequenceCurrent(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataIDPO> list = dataIDService.list(new QueryWrapper<RStatDataIDPO>()
                .select("line_id","i_neg","value_type")
                .in("value_type", Arrays.asList("CP95","MAX"))
                .in("phasic_type", Arrays.asList("T"))
                .ge("time", beginTime)
                .le("time", endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
//        String sql = "SELECT line_id,i_neg,value_type FROM day_i where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') "+ processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +" group by line_id order by time desc limit 2 tz('Asia/Shanghai')";
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//
//        QueryResult sqlResult = influxDbUtils.query(sql);
//        List<DayIPO> list = resultMapper.toPOJO(sqlResult, DayIPO.class);
        for (RStatDataIDPO dayI : list) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayI.getLineId(),overlimit.getId()) && overlimit.getINeg() != 0){
                    BigDecimal dayiNeg = BigDecimal.valueOf(dayI.getINeg());
                    BigDecimal overNeg = BigDecimal.valueOf(overlimit.getINeg());
                    double outNeg = dayiNeg.divide(overNeg,9,RoundingMode.HALF_UP).doubleValue();
                    double iNeg = Math.abs(outNeg);
                    data = Stream.of(iNeg).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayI.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    /**
     * 间谐波电压含有率：各监测点最新的A、B、C三相数据。
     */
    private List<PublicDTO> getInterharmonicVoltage(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataInharmVDPO> list = inharmVDService.list(new QueryWrapper<RStatDataInharmVDPO>()
                .in("value_type", Arrays.asList("CP95"))
                .in("phasic_type", Arrays.asList("A","B","C"))
                .ge("time", beginTime)
                .le("time", endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();
//        String sql = "SELECT * FROM day_inharm_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' "+ processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +" group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//
//        QueryResult sqlResult = influxDbUtils.query(sql);
//        List<DayInharmVPO> list = resultMapper.toPOJO(sqlResult, DayInharmVPO.class);
        for (RStatDataInharmVDPO dayInharmV : list) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayInharmV.getLineId(),overlimit.getId())){
                    double v1 = Math.abs(dayInharmV.getV1()/overlimit.getInuharm1());
                    double v2 = Math.abs(dayInharmV.getV2()/overlimit.getInuharm2());
                    double v3 = Math.abs(dayInharmV.getV3()/overlimit.getInuharm3());
                    double v4 = Math.abs(dayInharmV.getV4()/overlimit.getInuharm4());
                    double v5 = Math.abs(dayInharmV.getV5()/overlimit.getInuharm5());
                    double v6 = Math.abs(dayInharmV.getV6()/overlimit.getInuharm6());
                    double v7 = Math.abs(dayInharmV.getV7()/overlimit.getInuharm7());
                    double v8 = Math.abs(dayInharmV.getV8()/overlimit.getInuharm8());
                    double v9 = Math.abs(dayInharmV.getV9()/overlimit.getInuharm9());
                    double v10 = Math.abs(dayInharmV.getV10()/overlimit.getInuharm10());
                    double v11 = Math.abs(dayInharmV.getV11()/overlimit.getInuharm11());
                    double v12 = Math.abs(dayInharmV.getV12()/overlimit.getInuharm12());
                    double v13 = Math.abs(dayInharmV.getV13()/overlimit.getInuharm13());
                    double v14 = Math.abs(dayInharmV.getV14()/overlimit.getInuharm14());
                    double v15 = Math.abs(dayInharmV.getV15()/overlimit.getInuharm15());
                    double v16 = Math.abs(dayInharmV.getV16()/overlimit.getInuharm16());
                    data = Stream.of(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayInharmV.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    /**
     * 长时电压闪变：各监测点最新的A、B、C三相数据。
     */
    private List<PublicDTO> getVoltageFlicker(List<Overlimit> overLimitList,String beginTime,String endTime){
        List<RStatDataPltDPO> list = pltDService.list(new QueryWrapper<RStatDataPltDPO>()
                .in("value_type", Arrays.asList("CP95"))
                .in("phasic_type", Arrays.asList("A","B","C"))
                .ge("time", beginTime)
                .le("time", endTime)
        );
        List<Double> data;
        PublicDTO publicDTO;
        List<PublicDTO> lineData = new ArrayList<>();

//        String sql = "SELECT * FROM day_plt where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' "+ processDate(dataDate,Integer.valueOf(BizParamConstant.STAT_BIZ_DAY)) +" group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
//        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
//
//        QueryResult sqlResult = influxDbUtils.query(sql);
//        List<DayPltPO> list = resultMapper.toPOJO(sqlResult, DayPltPO.class);
        for (RStatDataPltDPO dayPlt : list) {
            for (Overlimit overlimit : overLimitList) {
                if (Objects.equals(dayPlt.getLineId(),overlimit.getId())){
                    double plt = Math.abs(dayPlt.getPlt()/overlimit.getFlicker());
                    data = Stream.of(plt).collect(Collectors.toList());
                    double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
                    publicDTO = new PublicDTO();
                    publicDTO.setId(dayPlt.getLineId());
                    publicDTO.setData(result);
                    lineData.add(publicDTO);
                }
            }
        }
        Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
        Map<String, Optional<PublicDTO>> outMap = lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
        return process(outMap);
    }

    /**
     * 参数拼装处理
     */
    private List<PollutionDTO> processPollutionList(List<PollutionDTO> pollutionList,List<PublicDTO> harmonicVoltageList,List<PublicDTO> harmonicCurrentList,List<PublicDTO> frequencyDeviationList,List<PublicDTO> voltageDeviationList,List<PublicDTO> threePhaseVoltageList,List<PublicDTO> negativeSequenceList,List<PublicDTO> interharmonicVoltageList,List<PublicDTO> voltageFlickerList){
        for (PollutionDTO pollution : pollutionList) {
            for (PublicDTO item : harmonicVoltageList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setVHarmonic(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                    pollution.setVAll(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());

                }
            }
            for (PublicDTO item : harmonicCurrentList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setIAll(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                }
            }
            for (PublicDTO item : frequencyDeviationList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setFreqDev(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                }
            }
            for (PublicDTO item : voltageDeviationList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setVDev(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                }
            }
            for (PublicDTO item : threePhaseVoltageList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setVUnbalance(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                }
            }
            for (PublicDTO item : negativeSequenceList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setINeg(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                }
            }
            for (PublicDTO item : interharmonicVoltageList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setVInharm(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                }
            }
            for (PublicDTO item : voltageFlickerList) {
                if (Objects.equals(pollution.getLineId(),item.getId())){
                    pollution.setPlt(BigDecimal.valueOf(item.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
                }
            }
        }
        return pollutionList;
    }

    /**
     * 出参处理
     */
    private List<PublicDTO> process(Map<String, Optional<PublicDTO>> outMap){
        List<PublicDTO> outList = new ArrayList<>();
        for (String key : outMap.keySet()) {
            outList.add(outMap.get(key).get());
        }
        return outList;
    }


}
