package cn.cecep.talroad.data.analyse.task.execute.report.specifications.month;

import cn.cecep.talroad.domain.BStatTableZxbgGasEmission;
import cn.cecep.talroad.domain.SEnvGasMonHour;
import cn.cecep.talroad.domain.SEnvWaterMonDay;
import cn.cecep.talroad.domain.analysis.SRaActionReportsAuditResult;
import cn.cecep.talroad.mapper.BStatTableZxbgGasEmissionMapper;
import cn.cecep.talroad.mapper.SEnvGasMonHourMapper;
import cn.cecep.talroad.mapper.SEnvGasMonRealMapper;
import cn.cecep.talroad.mapper.SEnvWaterMonDayMapper;
import cn.cecep.talroad.mapper.analysis.SRaActionReportsAuditResultMapper;
import cn.cecep.talroad.util.DateUtil;
import cn.cecep.talroad.util.NumberUtils;
import cn.cecep.talroad.vo.SEnvGasMonRealVo;
import cn.cecep.talroad.vo.analysis.FactoryOutletStaticsVo;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import io.seata.common.util.StringUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
@Slf4j
public class ExhaustExceedingProcessImpl implements ExhaustExceedingProcessService {

    private final BStatTableZxbgGasEmissionMapper statTableZxbgGasEmissionMapper;

    private final SRaActionReportsAuditResultMapper sRaActionReportsAuditResultMapper;
    private final SEnvGasMonHourMapper sEnvGasMonHourMapper;

    private final SEnvWaterMonDayMapper sEnvWaterMonDayMapper;

    private final SEnvGasMonRealMapper sEnvGasMonRealMapper;


    @Override
    public void exceededRateProcess() {
        List<SRaActionReportsAuditResult> queryActionReportsAuditResults = getAuditResultData();
        List<SRaActionReportsAuditResult> resultList = Lists.newArrayList();
        resultList.addAll(exhaustGasExceededRateProcess(queryActionReportsAuditResults));
        resultList.addAll(exhaustWaterExceededRateProcess(queryActionReportsAuditResults));
        auditResultChange(resultList);


    }

    @Override
    public void exhaustGasEmissionProcess() {
        List<SRaActionReportsAuditResult> queryActionReportsAuditResults = getAuditResultData();
        auditResultChange(gasEmissionProcess(queryActionReportsAuditResults));
    }

    private List<SRaActionReportsAuditResult> gasEmissionProcess(List<SRaActionReportsAuditResult> queryActionReportsAuditResults) {
        List<SRaActionReportsAuditResult> resultList = Lists.newArrayList();
        List<String> factoryIdList = queryActionReportsAuditResults.stream().map(SRaActionReportsAuditResult::getFactoryId).collect(Collectors.toList());
        List<BStatTableZxbgGasEmission> dataList = getDataList(factoryIdList);
        Set<String> outletCodes = dataList.stream().map(BStatTableZxbgGasEmission::getOutletCode).collect(Collectors.toSet());
        List<SEnvGasMonRealVo.EmissionAvgAndMax> emissionAvgAndMaxes = sEnvGasMonRealMapper.selectEmissionAvgAndMax(DateUtil.format(DateUtil.getFirstDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss")
                , DateUtil.format(DateUtil.getLastDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss"), outletCodes);
        Map<String, SEnvGasMonRealVo.EmissionAvgAndMax> emissionAvgAndMaxMap = emissionAvgAndMaxes.stream().collect(Collectors.toMap(SEnvGasMonRealVo.EmissionAvgAndMax::getOutletId, o -> o));
        for (SRaActionReportsAuditResult queryActionReportsAuditResult : queryActionReportsAuditResults) {
            checkGasMaxAndAvg(emissionAvgAndMaxMap, dataList, resultList, queryActionReportsAuditResult);
        }
        for (SRaActionReportsAuditResult queryActionReportsAuditResult : queryActionReportsAuditResults) {
            Map<String, BigDecimal> emissionDataMap = getGasEmissionDataMap(factoryIdList, dataList);
            checkExceededData(dataList, resultList, queryActionReportsAuditResult, emissionDataMap);
        }

        return resultList;
    }

    private void checkExceededData(List<BStatTableZxbgGasEmission> dataList, List<SRaActionReportsAuditResult> resultList,
                                   SRaActionReportsAuditResult queryActionReportsAuditResult, Map<String, BigDecimal> emissionDataMap) {
        for (BStatTableZxbgGasEmission statTableZxbgGasEmission : dataList) {
            String pollutantName = statTableZxbgGasEmission.getPollutantName();
            String exceededData = statTableZxbgGasEmission.getExceededData();
            String key = statTableZxbgGasEmission.getFactoryId() + pollutantName;
            BigDecimal exceededNumber = emissionDataMap.get(key);
            BigDecimal computeExceededRateNumber = NumberUtils.getBigDecimalDefaultNull(exceededData).divide(exceededNumber).multiply(new BigDecimal("100"));
            BigDecimal multiply = computeExceededRateNumber.multiply(exceededNumber);
            if (new BigDecimal(exceededData).compareTo(multiply) != 0) {
                SRaActionReportsAuditResult sRaActionReportsAuditResult = new SRaActionReportsAuditResult();
                sRaActionReportsAuditResult.setId(queryActionReportsAuditResult.getId());
                sRaActionReportsAuditResult.setOrganizedGasMonitoringData("根据有组织废气污染物超标时段小时均值报表中填报的数据，" + statTableZxbgGasEmission.getOutletCode() +
                        pollutantName + "超标数据数量应为" + multiply + ",企业填报数据为" + exceededData + "数据不符。");
                resultList.add(sRaActionReportsAuditResult);
            }
        }


    }


    private void checkGasMaxAndAvg(Map<String, SEnvGasMonRealVo.EmissionAvgAndMax> emissionAvgAndMaxMap, List<BStatTableZxbgGasEmission> dataList,
                                   List<SRaActionReportsAuditResult> resultList, SRaActionReportsAuditResult queryActionReportsAuditResult) {
        for (BStatTableZxbgGasEmission statTableZxbgGasEmission : dataList) {

            String outletCode = statTableZxbgGasEmission.getOutletCode();
            String pollutantName = statTableZxbgGasEmission.getPollutantName();
            String detectionMaxHour = statTableZxbgGasEmission.getDetectionMaxHour();
            String detectionAvgHour = statTableZxbgGasEmission.getDetectionAvgHour();

            if (emissionAvgAndMaxMap.containsKey(outletCode)) {
                SEnvGasMonRealVo.EmissionAvgAndMax emissionAvgAndMax = emissionAvgAndMaxMap.get(outletCode);
                if (Objects.nonNull(emissionAvgAndMax)) {
                    StringBuilder allMessage = new StringBuilder();
                    BigDecimal gasEmissionMax = getGasEmissionMax(pollutantName, emissionAvgAndMax);
                    BigDecimal gasEmissionAvg = getGasEmissionAvg(pollutantName, emissionAvgAndMax);
                    StringBuilder message = new StringBuilder();
                    if (NumberUtils.getBigDecimalDefaultZero(detectionMaxHour).compareTo(gasEmissionMax) < 0) {
                        log.info("企业ID:{},提示语句:{}", queryActionReportsAuditResult.getFactoryId(), "企业填报数值不应低于平台核算数值。");
                        message.append("排口编号:" + outletCode + "污染物种类:" + pollutantName +
                                "最大值平台根据其他系统数据核算为" + gasEmissionMax + ",企业填报数据为" + detectionMaxHour + "企业填报数值不应低于平台核算数值。");
                        allMessage.append(message);
                        allMessage.append(";");
                    }

                    if (NumberUtils.getBigDecimalDefaultZero(detectionAvgHour).compareTo(new BigDecimal("0.80").multiply(gasEmissionAvg)) < 0) {
                        log.info("企业ID:{},提示语句:{}", queryActionReportsAuditResult.getFactoryId(), "企业填报数值低于平台核算数值的80%。");
                        message.append("排口编号:" + outletCode + "污染物种类:" + pollutantName +
                                "平均值平台根据其他系统数据核算为" + gasEmissionAvg + ",企业填报数据为" + detectionAvgHour + "企业填报数值低于平台核算数值的80%。");
                        allMessage.append(message);
                        allMessage.append(";");
                    }
                    SRaActionReportsAuditResult sRaActionReportsAuditResult = new SRaActionReportsAuditResult();
                    sRaActionReportsAuditResult.setId(queryActionReportsAuditResult.getId());
                    sRaActionReportsAuditResult.setWaterPreventionFacilities(allMessage.toString());
                    resultList.add(sRaActionReportsAuditResult);
                }
            }

        }
    }



    private List<SRaActionReportsAuditResult> waterEmissionProcess(List<SRaActionReportsAuditResult> queryActionReportsAuditResults) {
        List<SRaActionReportsAuditResult> resultList = Lists.newArrayList();
        List<String> factoryIdList = queryActionReportsAuditResults.stream().map(SRaActionReportsAuditResult::getFactoryId).collect(Collectors.toList());
        List<BStatTableZxbgGasEmission> dataList = getDataList(factoryIdList);
        Set<String> outletCodes = dataList.stream().map(BStatTableZxbgGasEmission::getOutletCode).collect(Collectors.toSet());
        List<FactoryOutletStaticsVo.EmissionAvgAndMax> emissionAvgAndMaxes = sEnvWaterMonDayMapper.selectEmissionAvgAndMax(DateUtil.format(DateUtil.getFirstDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss")
                , DateUtil.format(DateUtil.getLastDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss"), outletCodes);
        Map<String, FactoryOutletStaticsVo.EmissionAvgAndMax> emissionAvgAndMaxMap = emissionAvgAndMaxes.stream().collect(Collectors.toMap(FactoryOutletStaticsVo.EmissionAvgAndMax::getOutletId, o -> o));
        for (SRaActionReportsAuditResult queryActionReportsAuditResult : queryActionReportsAuditResults) {
            checkWaterMaxAndAvg(emissionAvgAndMaxMap, dataList, resultList, queryActionReportsAuditResult);
        }
        for (SRaActionReportsAuditResult queryActionReportsAuditResult : queryActionReportsAuditResults) {
            Map<String, BigDecimal> emissionDataMap = getGasEmissionDataMap(factoryIdList, dataList);
            checkExceededData(dataList, resultList, queryActionReportsAuditResult, emissionDataMap);
        }

        return resultList;
    }

    private void checkWaterMaxAndAvg(Map<String, FactoryOutletStaticsVo.EmissionAvgAndMax> emissionAvgAndMaxMap, List<BStatTableZxbgGasEmission> dataList, List<SRaActionReportsAuditResult> resultList, SRaActionReportsAuditResult queryActionReportsAuditResult) {
        for (BStatTableZxbgGasEmission statTableZxbgGasEmission : dataList) {

            String outletCode = statTableZxbgGasEmission.getOutletCode();
            String pollutantName = statTableZxbgGasEmission.getPollutantName();
            String detectionMaxHour = statTableZxbgGasEmission.getDetectionMaxHour();
            String detectionAvgHour = statTableZxbgGasEmission.getDetectionAvgHour();

            if (emissionAvgAndMaxMap.containsKey(outletCode)) {
                FactoryOutletStaticsVo.EmissionAvgAndMax emissionAvgAndMax = emissionAvgAndMaxMap.get(outletCode);
                if (Objects.nonNull(emissionAvgAndMax)) {
                    StringBuilder allMessage = new StringBuilder();
                    BigDecimal gasEmissionMax = getWaterEmissionMax(pollutantName, emissionAvgAndMax);
                    BigDecimal gasEmissionAvg = getWaterEmissionAvg(pollutantName, emissionAvgAndMax);
                    StringBuilder message = new StringBuilder();
                    if (NumberUtils.getBigDecimalDefaultZero(detectionMaxHour).compareTo(gasEmissionMax) < 0) {
                        log.info("企业ID:{},提示语句:{}", queryActionReportsAuditResult.getFactoryId(), "企业填报数值不应低于平台核算数值。");
                        message.append("排口编号:" + outletCode + "污染物种类:" + pollutantName +
                                "最大值平台根据其他系统数据核算为" + gasEmissionMax + ",企业填报数据为" + detectionMaxHour + "企业填报数值不应低于平台核算数值。");
                        allMessage.append(message);
                        allMessage.append(";");
                    }

                    if (NumberUtils.getBigDecimalDefaultZero(detectionAvgHour).compareTo(new BigDecimal("0.80").multiply(gasEmissionAvg)) < 0) {
                        log.info("企业ID:{},提示语句:{}", queryActionReportsAuditResult.getFactoryId(), "企业填报数值低于平台核算数值的80%。");
                        message.append("排口编号:" + outletCode + "污染物种类:" + pollutantName +
                                "平均值平台根据其他系统数据核算为" + gasEmissionAvg + ",企业填报数据为" + detectionAvgHour + "企业填报数值低于平台核算数值的80%。");
                        allMessage.append(message);
                        allMessage.append(";");
                    }
                    SRaActionReportsAuditResult sRaActionReportsAuditResult = new SRaActionReportsAuditResult();
                    sRaActionReportsAuditResult.setId(queryActionReportsAuditResult.getId());
                    sRaActionReportsAuditResult.setWaterPreventionFacilities(allMessage.toString());
                    resultList.add(sRaActionReportsAuditResult);
                }
            }

        }

    }

    private BigDecimal getWaterEmissionAvg(String pollutantName, FactoryOutletStaticsVo.EmissionAvgAndMax emissionAvgAndMax) {
        if ("污水".equals(pollutantName)) {
            return emissionAvgAndMax.getSewageEmissionAvg();
        }
        if ("化学需氧量".equals(pollutantName)) {
            return emissionAvgAndMax.getCodEmissionAvg();
        }
        if ("氨氮".equals(pollutantName)) {
            return emissionAvgAndMax.getAmmoniaNitrogenEmissionAvg();
        }
        if ("总氮浓度".equals(pollutantName)) {
            return emissionAvgAndMax.getNitrogenConcentrationEmissionAvg();
        }
        if ("总磷浓度".equals(pollutantName)) {
            return emissionAvgAndMax.getPhosphorusConcentrationEmissionAvg();
        }
        return BigDecimal.ZERO;
    }

    @Override
    public void exhaustWaterEmissionProcess() {
        List<SRaActionReportsAuditResult> queryActionReportsAuditResults = getAuditResultData();
        auditResultChange(waterEmissionProcess(queryActionReportsAuditResults));
    }

    private List<SRaActionReportsAuditResult> getAuditResultData() {
        String period = LocalDate.now().toString().substring(0, 4);
        SRaActionReportsAuditResult queryResult = new SRaActionReportsAuditResult();
        queryResult.setReportTime(period);
        return sRaActionReportsAuditResultMapper.selectSRaActionReportsAuditResultList(queryResult);
    }

    private void auditResultChange(List<SRaActionReportsAuditResult> resultList) {
        if (CollUtil.isNotEmpty(resultList)) {
            List<List<SRaActionReportsAuditResult>> partition = ListUtils.partition(resultList, 10);
            for (List<SRaActionReportsAuditResult> sRaActionReportsAuditResultList : partition) {
                sRaActionReportsAuditResultMapper.batchUpdate(sRaActionReportsAuditResultList);
            }
        }
    }

    private List<SRaActionReportsAuditResult> exhaustWaterExceededRateProcess(List<SRaActionReportsAuditResult> queryActionReportsAuditResults) {
        List<String> factoryIdList = queryActionReportsAuditResults.stream().map(SRaActionReportsAuditResult::getFactoryId).collect(Collectors.toList());
        List<BStatTableZxbgGasEmission> dataList = getDataList(factoryIdList);
        Map<String, BigDecimal> emissionDataMap = getWaterEmissionDataMap(factoryIdList, dataList);
        List<SRaActionReportsAuditResult> resultList = Lists.newArrayList();
        for (SRaActionReportsAuditResult queryActionReportsAuditResult : queryActionReportsAuditResults) {
            fifterExceedingData(queryActionReportsAuditResult, dataList, resultList, emissionDataMap);
        }
        return resultList;
    }

    private List<SRaActionReportsAuditResult> exhaustGasExceededRateProcess(List<SRaActionReportsAuditResult> queryActionReportsAuditResults) {
        List<String> factoryIdList = queryActionReportsAuditResults.stream().map(SRaActionReportsAuditResult::getFactoryId).collect(Collectors.toList());
        List<BStatTableZxbgGasEmission> dataList = getDataList(factoryIdList);
        Map<String, BigDecimal> emissionDataMap = getGasEmissionDataMap(factoryIdList, dataList);
        List<SRaActionReportsAuditResult> resultList = Lists.newArrayList();
        for (SRaActionReportsAuditResult queryActionReportsAuditResult : queryActionReportsAuditResults) {
            fifterExceedingData(queryActionReportsAuditResult, dataList, resultList, emissionDataMap);
        }
        return resultList;
    }

    private Map<String, BigDecimal> getGasEmissionDataMap(List<String> factoryIdList, List<BStatTableZxbgGasEmission> dataList) {
        List<String> outletCodes = dataList.stream().map(BStatTableZxbgGasEmission::getOutletCode).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
        LambdaQueryWrapper<SEnvGasMonHour> queryWrapper = new QueryWrapper<SEnvGasMonHour>().lambda().
                eq(SEnvGasMonHour::getDataType, "h")
                .in(SEnvGasMonHour::getFactoryId, factoryIdList)
                .in(SEnvGasMonHour::getOutletId, outletCodes)
                .ge(SEnvGasMonHour::getMonitoringTime, DateUtil.format(DateUtil.getFirstDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss"))
                .le(SEnvGasMonHour::getMonitoringTime, DateUtil.format(DateUtil.getLastDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss"));
        List<SEnvGasMonHour> sEnvGasMonHours = sEnvGasMonHourMapper.selectList(queryWrapper);
        HashMap<String, BigDecimal> dataMap = Maps.newHashMap();
        if (CollUtil.isNotEmpty(sEnvGasMonHours)) {
            for (SEnvGasMonHour sEnvGasMonHour : sEnvGasMonHours) {
                for (BStatTableZxbgGasEmission statTableZxbgGasEmission : dataList) {
                    String pollutantName = statTableZxbgGasEmission.getPollutantName();
                    String emission = getGasEmission(pollutantName, sEnvGasMonHour);
                    String key = sEnvGasMonHour.getFactoryId() + pollutantName;
                    dataMap.put(key, NumberUtils.getBigDecimalDefaultNull(emission));
                }
            }
        }
        return dataMap;
    }

    private Map<String, BigDecimal> getWaterEmissionDataMap(List<String> factoryIdList, List<BStatTableZxbgGasEmission> dataList) {
        List<String> outletCodes = dataList.stream().map(BStatTableZxbgGasEmission::getOutletCode).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
        LambdaQueryWrapper<SEnvWaterMonDay> queryWrapper = new QueryWrapper<SEnvWaterMonDay>().lambda().
                eq(SEnvWaterMonDay::getDataType, "d")
                .in(SEnvWaterMonDay::getFactoryId, factoryIdList)
                .in(SEnvWaterMonDay::getOutletId, outletCodes)
                .ge(SEnvWaterMonDay::getMonitoringTime, DateUtil.format(DateUtil.getFirstDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss"))
                .le(SEnvWaterMonDay::getMonitoringTime, DateUtil.format(DateUtil.getLastDayOfMonth(-1), "yyyy-MM-dd HH:mm:ss"));
        List<SEnvWaterMonDay> sEnvWaterMonDays = sEnvWaterMonDayMapper.selectList(queryWrapper);
        HashMap<String, BigDecimal> dataMap = Maps.newHashMap();
        if (CollUtil.isNotEmpty(sEnvWaterMonDays)) {
            for (SEnvWaterMonDay sEnvWaterMonDay : sEnvWaterMonDays) {
                for (BStatTableZxbgGasEmission statTableZxbgGasEmission : dataList) {
                    String pollutantName = statTableZxbgGasEmission.getPollutantName();
                    String emission = getWaterEmission(pollutantName, sEnvWaterMonDay);
                    String key = sEnvWaterMonDay.getFactoryId() + pollutantName;
                    dataMap.put(key, NumberUtils.getBigDecimalDefaultNull(emission));
                }
            }
        }
        return dataMap;
    }


    private void fifterExceedingData(SRaActionReportsAuditResult queryActionReportsAuditResult, List<BStatTableZxbgGasEmission> dataList,
                                     List<SRaActionReportsAuditResult> resultList, Map<String, BigDecimal> emissionDataMap) {
        String factoryId = queryActionReportsAuditResult.getFactoryId();
        List<BStatTableZxbgGasEmission> filteredList = dataList.stream()
                .filter(item -> item.getFactoryId().equals(factoryId))
                .collect(Collectors.toList());
        if (CollUtil.isEmpty(filteredList)) return;
        for (BStatTableZxbgGasEmission bStatTableZxbgGasEmission : filteredList) {

            String exceededData = bStatTableZxbgGasEmission.getExceededData(); //企业填报超标数据个数
            String fillExceededRate = bStatTableZxbgGasEmission.getExceededRate();  //企业填报超标率
            String key = bStatTableZxbgGasEmission.getFactoryId() + bStatTableZxbgGasEmission.getPollutantName();
            BigDecimal exceededNumber = emissionDataMap.get(key);
            BigDecimal computeExceededRateNumber = NumberUtils.getBigDecimalDefaultNull(exceededData).divide(exceededNumber).multiply(new BigDecimal("100"));
            if (computeExceededRateNumber.compareTo(new BigDecimal(fillExceededRate)) != 0) {
                SRaActionReportsAuditResult sRaActionReportsAuditResult = new SRaActionReportsAuditResult();
                sRaActionReportsAuditResult.setId(queryActionReportsAuditResult.getId());
                sRaActionReportsAuditResult.setExceedingRate(buildMessage(bStatTableZxbgGasEmission, computeExceededRateNumber));
                resultList.add(sRaActionReportsAuditResult);
            }
        }

    }

    private String buildMessage(BStatTableZxbgGasEmission bStatTableZxbgGasEmission, BigDecimal computeExceededRateNumber) {

        log.info("企业ID:{},提示语句:{}", bStatTableZxbgGasEmission.getFactoryId(), String.format("根据企业填报数值%s  %s ,超标率计算应为%s,实际填报为%s,计算不正确。",
                bStatTableZxbgGasEmission.getOutletCode(),
                bStatTableZxbgGasEmission.getPollutantName(),
                computeExceededRateNumber.toString(),
                bStatTableZxbgGasEmission.getExceededRate()));
        //根据企业填报数值，“排口编号”“污染物种类”“超标率”计算应为“xxx"，实际填报为"xxx”，计算不正确。
        return String.format("根据企业填报数值%s  %s ,超标率计算应为%s,实际填报为%s,计算不正确。",
                bStatTableZxbgGasEmission.getOutletCode(),
                bStatTableZxbgGasEmission.getPollutantName(),
                computeExceededRateNumber,
                bStatTableZxbgGasEmission.getExceededRate()
        );
    }


    private List<BStatTableZxbgGasEmission> getDataList(List<String> factoryIdList) {
        //TODO 执行周期暂定为月
        String period = LocalDate.now().minusMonths(1).toString().substring(0, 7);
        LambdaQueryWrapper<BStatTableZxbgGasEmission> queryWrapper =
                new QueryWrapper<BStatTableZxbgGasEmission>().lambda()
                        .in(BStatTableZxbgGasEmission::getFactoryId, factoryIdList)
                        .eq(BStatTableZxbgGasEmission::getZxbgType, 0)
                        .eq(BStatTableZxbgGasEmission::getZxbgPeriod, period);
        List<BStatTableZxbgGasEmission> dataList = statTableZxbgGasEmissionMapper.selectList(queryWrapper);
        log.info("ExhaustGasExceedingProcessService->getDataList:{}", JSON.toJSONString(dataList));
        return dataList;
    }


    private BigDecimal getGasEmissionMax(String pollutantName, SEnvGasMonRealVo.EmissionAvgAndMax emissionAvgAndMax) {
        if ("二氧化硫".equals(pollutantName)) {
            return emissionAvgAndMax.getS02EmissionMax();
        }
        if ("氮氧化物".equals(pollutantName)) {
            return emissionAvgAndMax.getNoxEmissionMax();
        }
        if ("一氧化氮".equals(pollutantName)) {
            return emissionAvgAndMax.getNoEmissionMax();
        }
        if ("二氧化氮".equals(pollutantName)) {
            return emissionAvgAndMax.getNo2EmissionMax();
        }
        if ("烟尘".equals(pollutantName)) {
            return emissionAvgAndMax.getSmokeDustEmissionMax();
        }
        if ("颗粒物实测".equals(pollutantName)) {
            return emissionAvgAndMax.getPmEmissionMax();
        }
        if ("vocs实测".equals(pollutantName)) {
            return emissionAvgAndMax.getVocsEmissionMax();
        }
        if ("废气".equals(pollutantName)) {
            return emissionAvgAndMax.getOxygenEmissionMax();
        }
        return BigDecimal.ZERO;
    }

    private BigDecimal getWaterEmissionMax(String pollutantName, FactoryOutletStaticsVo.EmissionAvgAndMax emissionAvgAndMax) {
        if ("污水".equals(pollutantName)) {
            return emissionAvgAndMax.getSewageEmissionMax();
        }
        if ("化学需氧量".equals(pollutantName)) {
            return emissionAvgAndMax.getCodEmissionMax();
        }
        if ("氨氮".equals(pollutantName)) {
            return emissionAvgAndMax.getAmmoniaNitrogenEmissionMax();
        }
        if ("总氮浓度".equals(pollutantName)) {
            return emissionAvgAndMax.getNitrogenConcentrationEmissionMax();
        }
        if ("总磷浓度".equals(pollutantName)) {
            return emissionAvgAndMax.getPhosphorusConcentrationEmissionMax();
        }
        return BigDecimal.ZERO;
    }

    private BigDecimal getGasEmissionAvg(String pollutantName, SEnvGasMonRealVo.EmissionAvgAndMax emissionAvgAndMax) {
        if ("二氧化硫".equals(pollutantName)) {
            return emissionAvgAndMax.getS02EmissionAvg();
        }
        if ("氮氧化物".equals(pollutantName)) {
            return emissionAvgAndMax.getNoxEmissionAvg();
        }
        if ("一氧化氮".equals(pollutantName)) {
            return emissionAvgAndMax.getNoEmissionAvg();
        }
        if ("二氧化氮".equals(pollutantName)) {
            return emissionAvgAndMax.getNo2EmissionAvg();
        }
        if ("烟尘".equals(pollutantName)) {
            return emissionAvgAndMax.getSmokeDustEmissionAvg();
        }
        if ("颗粒物实测".equals(pollutantName)) {
            return emissionAvgAndMax.getPmEmissionAvg();
        }
        if ("vocs实测".equals(pollutantName)) {
            return emissionAvgAndMax.getVocsEmissionAvg();
        }
        if ("废气".equals(pollutantName)) {
            return emissionAvgAndMax.getOxygenEmissionAvg();
        }
        return BigDecimal.ZERO;
    }

    private String getWaterEmission(String pollutantName, SEnvWaterMonDay sEnvWaterMonDay) {
        if ("污水".equals(pollutantName)) {
            return sEnvWaterMonDay.getSewageEmission();
        }
        if ("化学需氧量".equals(pollutantName)) {
            return sEnvWaterMonDay.getCodEmission();
        }
        if ("氨氮".equals(pollutantName)) {
            return sEnvWaterMonDay.getAmmoniaNitrogenEmission();
        }
        if ("总氮浓度".equals(pollutantName)) {
            return sEnvWaterMonDay.getNitrogenConcentrationEmission();
        }
        if ("总磷浓度".equals(pollutantName)) {
            return sEnvWaterMonDay.getPhosphorusConcentrationEmission();
        }
        return "";
    }

    private String getGasEmission(String pollutantName, SEnvGasMonHour sEnvGasMonHour) {
        if ("二氧化硫".equals(pollutantName)) {
            return sEnvGasMonHour.getSo2Emission();
        }
        if ("氮氧化物".equals(pollutantName)) {
            return sEnvGasMonHour.getNoxEmission();
        }
        if ("一氧化氮".equals(pollutantName)) {
            return sEnvGasMonHour.getNoEmission();
        }
        if ("二氧化氮".equals(pollutantName)) {
            return sEnvGasMonHour.getNo2Emission();
        }
        if ("烟尘".equals(pollutantName)) {
            return sEnvGasMonHour.getSmokeDustEmission();
        }
        if ("颗粒物实测".equals(pollutantName)) {
            return sEnvGasMonHour.getPmEmission();
        }
        if ("vocs实测".equals(pollutantName)) {
            return sEnvGasMonHour.getVocsEmission();
        }
        if ("废气".equals(pollutantName)) {
            return sEnvGasMonHour.getOxygenEmission();
        }
        return "";
    }


}