package com.ruoyi.project.production.service.impl.thread;

import com.ruoyi.project.production.domain.TDailyProductionReport;
import com.ruoyi.project.production.domain.TMonthlyProductionReport;
import com.ruoyi.project.production.mapper.TDailyProductionReportMapper;
import com.ruoyi.project.production.mapper.TMonthlyProductionReportMapper;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

/**
 * 修改日报后同步更新数据
 *
 * @author: Wang Zi Wen
 * @email: wangggziwen@163.com
 * @datetime: 2022/11/3 13:44
 */
public class SyncAfterDailyUpdateThread extends Thread {

    private Date reportDate;

    private TDailyProductionReportMapper tDailyProductionReportMapper;

    private TMonthlyProductionReportMapper tMonthlyProductionReportMapper;

    public SyncAfterDailyUpdateThread() {
        super();
    }

    public SyncAfterDailyUpdateThread(
            Date reportDate,
            TDailyProductionReportMapper tDailyProductionReportMapper,
            TMonthlyProductionReportMapper tMonthlyProductionReportMapper) {
        super();
        this.reportDate = reportDate;
        this.tDailyProductionReportMapper = tDailyProductionReportMapper;
        this.tMonthlyProductionReportMapper = tMonthlyProductionReportMapper;
    }

    @Override
    public void run() {
        this.syncMonthlyData();
    }

    /**
     * 同步更新月报数据
     */
    private void syncMonthlyData() {
        // 当前报告年份
        int reportYear = this.reportDate.getYear() + 1900;
        // 当前报告月份
        int reportMonth = this.reportDate.getMonth() + 1;
        // 计算日报各列总和
        TDailyProductionReport daily = tDailyProductionReportMapper.selectDailySum(reportYear, reportMonth);
        // 计算月报数据
        TMonthlyProductionReport monthly = new TMonthlyProductionReport();
        monthly.setReportYear((long)reportYear);
        monthly.setReportMonth((long)reportMonth);
        String napStr = daily.getNap();
        String c5Str = daily.getC5();
        String c6C8NaStr = daily.getC6C8Na();
        String wisonEthaneStr = daily.getWisonEthane();
        String lpgToFurnaceStr = daily.getLpgToFurnace();
        String raff3FrBdStr = daily.getRaff3FrBd();
        String raffinate2pFr2phStr = daily.getRaffinate2pFr2ph();
        String c2FrLdpeStr = daily.getC2FrLdpe();
        String c3FrOxoStr = daily.getC3FrOxo();
        String mixedC3C4Str = daily.getMixedC3C4();
        String hyC9Str = daily.getHyC9();
        String pguOffgasStr = daily.getPguOffgas();
        String washOilStr = daily.getWashOil();
        String tolueneStr = daily.getToluene();
        String hyC4FrR800Str = daily.getHyC4FrR800();
        BigDecimal nap = new BigDecimal(napStr == null ? "0" :napStr);
        BigDecimal c5 = new BigDecimal(c5Str == null ? "0" :c5Str);
        BigDecimal c6C8Na = new BigDecimal(c6C8NaStr == null ? "0" :c6C8NaStr);
        BigDecimal wisonEthane = new BigDecimal(wisonEthaneStr == null ? "0" :wisonEthaneStr);
        BigDecimal lpgToFurnace = new BigDecimal(lpgToFurnaceStr == null ? "0" :lpgToFurnaceStr);
        BigDecimal raff3FrBd = new BigDecimal(raff3FrBdStr == null ? "0" :raff3FrBdStr);
        BigDecimal raffinate2pFr2ph = new BigDecimal(raffinate2pFr2phStr == null ? "0" :raffinate2pFr2phStr);
        BigDecimal c2FrLdpe = new BigDecimal(c2FrLdpeStr == null ? "0" :c2FrLdpeStr);
        BigDecimal c3FrOxo = new BigDecimal(c3FrOxoStr == null ? "0" :c3FrOxoStr);
        BigDecimal mixedC3C4 = new BigDecimal(mixedC3C4Str == null ? "0" :mixedC3C4Str);
        BigDecimal hyC9 = new BigDecimal(hyC9Str == null ? "0" :hyC9Str);
        BigDecimal pguOffgas = new BigDecimal(pguOffgasStr == null ? "0" :pguOffgasStr);
        BigDecimal washOil = new BigDecimal(washOilStr == null ? "0" :washOilStr);
        BigDecimal toluene = new BigDecimal(tolueneStr == null ? "0" :tolueneStr);
        BigDecimal hyC4FrR800 = new BigDecimal(hyC4FrR800Str == null ? "0" :hyC4FrR800Str);
        monthly.setNap(nap.toString());
        monthly.setC5(c5.toString());
        monthly.setC6C8Na(c6C8Na.toString());
        monthly.setWisonEthane(wisonEthane.toString());
        monthly.setLpgToFurnace(lpgToFurnace.toString());
        BigDecimal raff3FrBdAnd2ph = new BigDecimal("0");
        raff3FrBdAnd2ph = raff3FrBdAnd2ph.add(raff3FrBd).add(raffinate2pFr2ph);
        monthly.setRaff3FrBdAnd2ph(raff3FrBdAnd2ph.toString());
        monthly.setC2FrLdpe(c2FrLdpe.toString());
        monthly.setC3FrOxo(c3FrOxo.toString());
        monthly.setMixedC3C4(mixedC3C4.toString());
        monthly.setHyC9(hyC9.toString());
        monthly.setPguOffgas(pguOffgas.toString());
        monthly.setWashOil(washOil.toString());
        monthly.setToluene(toluene.toString());
        monthly.setHyC4FrR800(hyC4FrR800.toString());
        BigDecimal crackerRawFeed = new BigDecimal("0");
        BigDecimal crackerRawInput = new BigDecimal("0");
        crackerRawFeed = crackerRawFeed.add(nap).add(c5).add(c6C8Na).add(wisonEthane)
                .add(lpgToFurnace).add(raff3FrBdAnd2ph).add(hyC4FrR800);
        crackerRawInput = crackerRawInput.add(crackerRawFeed).add(c2FrLdpe).add(c3FrOxo)
                .add(mixedC3C4).add(hyC9).add(pguOffgas).add(washOil).add(toluene);
        monthly.setCrackerRawInput(crackerRawInput.toString());
        monthly.setCrackerRawFeed(crackerRawFeed.toString());

        String h2ProducedStr = daily.getH2Produced();
        String ethylenProducedStr = daily.getEthylenProduced();
        String propyleneProducedStr = daily.getPropyleneProduced();
        String c3LpgProducedStr = daily.getC3LpgProduced();
        String c4LpgProducedStr = daily.getC4LpgProduced();
        String mixedC4sProducedStr = daily.getMixedC4sProduced();
        String rpgProducedStr = daily.getRpgProduced();
        String poFluxOilProducedStr = daily.getPoFluxOilProduced();
        String naphthaleneProducedStr = daily.getNaphthaleneProduced();
        String eboProducedStr = daily.getEboProduced();
        String residueOilProducedStr = daily.getResidueOilProduced();
        String methaneProducedStr = daily.getMethaneProduced();
        String offgasProducedStr = daily.getOffgasProduced();
        BigDecimal h2Produced = new BigDecimal(h2ProducedStr == null ? "0" : h2ProducedStr);
        BigDecimal ethylenProduced = new BigDecimal(ethylenProducedStr == null ? "0" : ethylenProducedStr);
        BigDecimal propyleneProduced = new BigDecimal(propyleneProducedStr == null ? "0" : propyleneProducedStr);
        BigDecimal c3LpgProduced = new BigDecimal(c3LpgProducedStr == null ? "0" : c3LpgProducedStr);
        BigDecimal c4LpgProduced = new BigDecimal(c4LpgProducedStr == null ? "0" : c4LpgProducedStr);
        BigDecimal mixedC4sProduced = new BigDecimal(mixedC4sProducedStr == null ? "0" : mixedC4sProducedStr);
        BigDecimal rpgProduced = new BigDecimal(rpgProducedStr == null ? "0" : rpgProducedStr);
        BigDecimal poFluxOilProduced = new BigDecimal(poFluxOilProducedStr == null ? "0" : poFluxOilProducedStr);
        BigDecimal naphthaleneProduced = new BigDecimal(naphthaleneProducedStr == null ? "0" : naphthaleneProducedStr);
        BigDecimal eboProduced = new BigDecimal(eboProducedStr == null ? "0" : eboProducedStr);
        BigDecimal residueOilProduced = new BigDecimal(residueOilProducedStr == null ? "0" : residueOilProducedStr);
        BigDecimal methaneProduced = new BigDecimal(methaneProducedStr == null ? "0" : methaneProducedStr);
        BigDecimal offgasProduced = new BigDecimal(offgasProducedStr == null ? "0" : offgasProducedStr);
        monthly.setH2Produced(h2Produced.toString());
        monthly.setEthylenProduced(ethylenProduced.toString());
        monthly.setPropyleneProduced(propyleneProduced.toString());
        BigDecimal c3C4LpgProduced = new BigDecimal("0");
        c3C4LpgProduced = c3C4LpgProduced.add(c3LpgProduced).add(c4LpgProduced);
        monthly.setC3C4LpgProduced(c3C4LpgProduced.toString());
        monthly.setMixedC4sProduced(mixedC4sProduced.toString());
        monthly.setRpgProduced(rpgProduced.toString());
        monthly.setPoFluxOilProduced(poFluxOilProduced.toString());
        monthly.setNaphthaleneProduced(naphthaleneProduced.toString());
        monthly.setEboProduced(eboProduced.toString());
        monthly.setResidueOilProduced(residueOilProduced.toString());
        monthly.setMethaneProduced(methaneProduced.toString());
        monthly.setOffgasProduced(offgasProduced.toString());
        BigDecimal crackerOutput = new BigDecimal("0");
        crackerOutput = crackerOutput.add(h2Produced).add(ethylenProduced).add(propyleneProduced).add(c3LpgProduced)
                .add(c4LpgProduced).add(mixedC4sProduced).add(rpgProduced).add(poFluxOilProduced).add(naphthaleneProduced)
                .add(eboProduced).add(residueOilProduced).add(methaneProduced).add(offgasProduced);
        crackerOutput = crackerOutput.divide(new BigDecimal("1"), 2, RoundingMode.HALF_UP);
        monthly.setCrackerOutput(crackerOutput.toString());

        String pguRpg2Str = daily.getPguRpg2();
        String pguH2Str = daily.getPguH2();
        String pguBtxProducedStr = daily.getPguBtxProduced();
        String pguBtxToAeuStr = daily.getPguBtxToAeu();
        BigDecimal pguRpg2 = new BigDecimal(pguRpg2Str == null ? "0" : pguRpg2Str);
        BigDecimal pguH2 = new BigDecimal(pguH2Str == null ? "0" : pguH2Str);
        BigDecimal pguBtxProduced = new BigDecimal(pguBtxProducedStr == null ? "0" : pguBtxProducedStr);
        BigDecimal pguBtxToAeu = new BigDecimal(pguBtxToAeuStr == null ? "0" : pguBtxToAeuStr);
        monthly.setPguRpg2(pguRpg2.toString());
        monthly.setPguH2(pguH2.toString());
        monthly.setPguBtxProduced(pguBtxProduced.toString());
        monthly.setPguBtxToAeu(pguBtxToAeu.toString());
        BigDecimal aromaticsRawInput = new BigDecimal("0");
        aromaticsRawInput = aromaticsRawInput.add(pguRpg2).add(pguH2);
        monthly.setAromaticsRawInput(aromaticsRawInput.toString());

        String aeuBenzeneProducedStr = daily.getAeuBenzeneProduced();
        String aeuTolueneProducedStr = daily.getAeuTolueneProduced();
        String aeuXyleneProducedStr = daily.getAeuXyleneProduced();
        String aeuC6C8NaProducedStr = daily.getAeuC6C8NaProduced();
        String pguC5ProducedStr = daily.getPguC5Produced();
        String pguC9ProducedStr = daily.getPguC9Produced();
        String pguWashoilProducedStr = daily.getPguWashoilProduced();
        String pguOffgasProducedStr = daily.getPguOffgasProduced();
        String pguBtxChangeStr = daily.getPguBtxChange();
        String aeuTolueneToEuStr = daily.getAeuTolueneToEu();
        BigDecimal aeuBenzeneProduced = new BigDecimal(aeuBenzeneProducedStr == null ? "0" : aeuBenzeneProducedStr);
        BigDecimal aeuTolueneProduced = new BigDecimal(aeuTolueneProducedStr == null ? "0" : aeuTolueneProducedStr);
        BigDecimal aeuXyleneProduced = new BigDecimal(aeuXyleneProducedStr == null ? "0" : aeuXyleneProducedStr);
        BigDecimal aeuC6C8NaProduced = new BigDecimal(aeuC6C8NaProducedStr == null ? "0" : aeuC6C8NaProducedStr);
        BigDecimal pguC5Produced = new BigDecimal(pguC5ProducedStr == null ? "0" : pguC5ProducedStr);
        BigDecimal pguC9Produced = new BigDecimal(pguC9ProducedStr == null ? "0" : pguC9ProducedStr);
        BigDecimal pguWashoilProduced = new BigDecimal(pguWashoilProducedStr == null ? "0" : pguWashoilProducedStr);
        BigDecimal pguOffgasProduced = new BigDecimal(pguOffgasProducedStr == null ? "0" : pguOffgasProducedStr);
        BigDecimal pguBtxChange = new BigDecimal(pguBtxChangeStr == null ? "0" : pguBtxChangeStr);
        monthly.setAeuBenzeneProduced(aeuBenzeneProduced.toString());
        monthly.setAeuTolueneProduced(aeuTolueneProduced.toString());
        monthly.setAeuXyleneProduced(aeuXyleneProduced.toString());
        monthly.setAeuC6C8NaProduced(aeuC6C8NaProduced.toString());
        monthly.setPguC5Produced(pguC5Produced.toString());
        monthly.setPguC9Produced(pguC9Produced.toString());
        monthly.setPguWashoilProduced(pguWashoilProduced.toString());
        monthly.setPguOffgasProduced(pguOffgasProduced.toString());
        monthly.setPguBtxChange(pguBtxChange.toString());
        monthly.setPguBtxProduced(pguBtxProduced.toString());
        BigDecimal aeuTolueneToEu = new BigDecimal(aeuTolueneToEuStr == null ? "0" : aeuTolueneToEuStr);
        BigDecimal aeuTolueneProducedMEu = new BigDecimal("0");
        aeuTolueneProducedMEu = aeuTolueneProduced.subtract(aeuTolueneToEu);
        monthly.setAeuTolueneProducedMEu(aeuTolueneProducedMEu.toString());
        BigDecimal aromaticsOutput = new BigDecimal("0");
        aromaticsOutput = aromaticsOutput.add(aeuBenzeneProduced).add(aeuTolueneProduced).add(aeuXyleneProduced)
                .add(aeuC6C8NaProduced).add(pguC5Produced).add(pguC9Produced).add(pguWashoilProduced)
                .add(pguOffgasProduced).add(pguBtxChange);
        monthly.setAromaticsOutput(aromaticsOutput.toString());

        BigDecimal gaseityYield = new BigDecimal("0");
        final BigDecimal hundred = new BigDecimal("100");
        gaseityYield = gaseityYield.add(h2Produced).add(ethylenProduced).add(propyleneProduced)
                .add(c3LpgProduced).add(c4LpgProduced).add(methaneProduced).add(offgasProduced).multiply(hundred);
        gaseityYield = gaseityYield.divide(crackerRawInput, 2, RoundingMode.HALF_UP);
        BigDecimal tatalYield = new BigDecimal("0");
        if (crackerRawInput.compareTo(BigDecimal.ZERO) != 0) {
            tatalYield = crackerOutput.multiply(hundred).divide(crackerRawInput, 2, RoundingMode.HALF_UP);
            if (tatalYield.compareTo(hundred) == 1) {
                tatalYield = new BigDecimal("100.00");
            }
        }
        BigDecimal c3C2Yield = new BigDecimal("0");
        if (ethylenProduced.compareTo(BigDecimal.ZERO) != 0) {
            c3C2Yield = propyleneProduced.divide(ethylenProduced, 3, RoundingMode.HALF_UP);
        }
        BigDecimal h2Yield = new BigDecimal("0");
        BigDecimal ethyleneYield = new BigDecimal("0");
        BigDecimal propyleneYield = new BigDecimal("0");
        BigDecimal c3C4LpgYield = new BigDecimal("0");
        BigDecimal c4sYield = new BigDecimal("0");
        BigDecimal poYield = new BigDecimal("0");
        BigDecimal naphthaleneYield = new BigDecimal("0");
        BigDecimal eboYield = new BigDecimal("0");
        BigDecimal wsYield = new BigDecimal("0");
        BigDecimal methaneYield = new BigDecimal("0");
        BigDecimal offageYield = new BigDecimal("0");
        BigDecimal rpgYield = new BigDecimal("0");
        if (crackerRawFeed.compareTo(BigDecimal.ZERO) != 0) {
            h2Yield = h2Produced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            ethyleneYield = ethylenProduced.subtract(c2FrLdpe.multiply(new BigDecimal("0.9")));
            ethyleneYield = ethyleneYield.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            propyleneYield = propyleneProduced.subtract(c3FrOxo.multiply(new BigDecimal("0.68")));
            propyleneYield = propyleneYield.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            c3C4LpgYield = c3C4LpgProduced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            c4sYield = mixedC4sProduced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            poYield = poFluxOilProduced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            naphthaleneYield = naphthaleneProduced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            eboYield = eboProduced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            wsYield = residueOilProduced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            methaneYield = methaneProduced.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            offageYield = offgasProduced.subtract(c2FrLdpe.multiply(new BigDecimal("0.1")))
            .subtract(c3FrOxo.multiply(new BigDecimal("0.32"))).subtract(mixedC3C4).subtract(pguOffgas);
            offageYield = offageYield.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            rpgYield = rpgProduced.subtract(hyC9).subtract(washOil).subtract(toluene);
            rpgYield = rpgYield.multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
        }
        BigDecimal benzeneYield = new BigDecimal("0");
        BigDecimal tolueneYield = new BigDecimal("0");
        BigDecimal xyleneYield = new BigDecimal("0");
        BigDecimal c6C8NaYield = new BigDecimal("0");
        if (pguRpg2.compareTo(BigDecimal.ZERO) != 0 &&
                pguBtxToAeu.compareTo(BigDecimal.ZERO) != 0 &&
                crackerRawFeed.compareTo(BigDecimal.ZERO) != 0) {
            benzeneYield = aeuBenzeneProduced
                    .multiply(rpgProduced.divide(pguRpg2, 3, RoundingMode.HALF_UP))
                    .multiply(pguBtxProduced.divide(pguBtxToAeu, 3, RoundingMode.HALF_UP))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            tolueneYield = (aeuTolueneProduced.subtract(toluene))
                    .multiply(rpgProduced.divide(pguRpg2, 3, RoundingMode.HALF_UP))
                    .multiply(pguBtxProduced.divide(pguBtxToAeu, 3, RoundingMode.HALF_UP))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            xyleneYield = aeuXyleneProduced
                    .multiply(rpgProduced.divide(pguRpg2, 3, RoundingMode.HALF_UP))
                    .multiply(pguBtxProduced.divide(pguBtxToAeu, 3, RoundingMode.HALF_UP))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            c6C8NaYield = aeuC6C8NaProduced
                    .multiply(rpgProduced.divide(pguRpg2, 3, RoundingMode.HALF_UP))
                    .multiply(pguBtxProduced.divide(pguBtxToAeu, 3, RoundingMode.HALF_UP))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
        }
        BigDecimal c5Yield = new BigDecimal("0");
        BigDecimal c9Yield = new BigDecimal("0");
        if (pguRpg2.compareTo(BigDecimal.ZERO) != 0 && crackerRawFeed.compareTo(BigDecimal.ZERO) != 0) {
            c5Yield = pguC5Produced
                    .divide(pguRpg2, 3, RoundingMode.HALF_UP)
                    .multiply(rpgProduced)
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
            c9Yield = (pguC9Produced
                    .divide(pguRpg2, 3, RoundingMode.HALF_UP)
                    .multiply(rpgProduced)
                    .subtract(hyC9))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
        }
        monthly.setGaseityYield(gaseityYield.toString());
        monthly.setTatalYield(tatalYield.toString());
        monthly.setC3C2Yield(c3C2Yield.toString());
        monthly.setH2Yield(h2Yield.toString());
        monthly.setEthyleneYield(ethyleneYield.toString());
        monthly.setPropyleneYield(propyleneYield.toString());
        monthly.setC3C4LpgYield(c3C4LpgYield.toString());
        monthly.setC4sYield(c4sYield.toString());
        monthly.setPoYield(poYield.toString());
        monthly.setNaphthaleneYield(naphthaleneYield.toString());
        monthly.setEboYield(eboYield.toString());
        monthly.setWsYield(wsYield.toString());
        monthly.setMethaneYield(methaneYield.toString());
        monthly.setOffageYield(offageYield.toString());
        monthly.setRpgYield(rpgYield.toString());
        monthly.setBenzeneYield(benzeneYield.toString());
        monthly.setTolueneYield(tolueneYield.toString());
        monthly.setXyleneYield(xyleneYield.toString());
        monthly.setC6C8NaYield(c6C8NaYield.toString());
        monthly.setC5Yield(c5Yield.toString());
        monthly.setC9Yield(c9Yield.toString());

        BigDecimal euLoss = new BigDecimal("0");
        euLoss = euLoss.subtract(crackerRawInput.subtract(crackerOutput));
        monthly.setEuLoss(euLoss.toString());
        BigDecimal euLossRate = new BigDecimal("0");
        if (crackerRawInput.compareTo(BigDecimal.ZERO) != 0) {
            euLossRate = euLoss.multiply(hundred).divide(crackerRawInput, 2, RoundingMode.HALF_UP);
        }
        monthly.setEuLossRate(euLossRate.toString());
        BigDecimal aeuLoss = new BigDecimal("0");
        aeuLoss = aromaticsRawInput.subtract(aromaticsOutput);
        monthly.setAeuLoss(aeuLoss.toString());
        BigDecimal aeuLossRate = new BigDecimal("0");
        if (aromaticsRawInput.compareTo(BigDecimal.ZERO) != 0) {
            aeuLossRate = aeuLoss.multiply(hundred).divide(aromaticsRawInput, 2, RoundingMode.HALF_UP);
        }
        monthly.setAeuLossRate(aeuLossRate.toString());
        BigDecimal totalLoss = new BigDecimal("0");
        totalLoss = euLoss.add(aeuLoss);
        monthly.setTotalLoss(totalLoss.toString());
        BigDecimal totalLossRate = new BigDecimal("0");
        if (crackerRawInput.compareTo(BigDecimal.ZERO) != 0) {
            totalLossRate = totalLoss.multiply(hundred).divide(crackerRawInput, 2, RoundingMode.HALF_UP);
        }
        monthly.setTotalLossRate(totalLossRate.toString());

        String fuelGasOffgasCrackerStr = daily.getFuelGasOffgasCracker();
        String shpCrackerStr = daily.getShpCracker();
        String hpCrackerStr = daily.getHpCracker();
        String mpCrackerStr = daily.getMpCracker();
        String lpCrackerStr = daily.getLpCracker();
        String electricityCrackerStr = daily.getElectricityCracker();
        String coolingWaterCrackerStr = daily.getCoolingWaterCracker();
        String paIaCrackerStr = daily.getPaIaCracker();
        String n2CrackerStr = daily.getN2Cracker();
        String hpBfwCrackerStr = daily.getHpBfwCracker();
        String polishedConCrackerStr = daily.getPolishedConCracker();
        String turbineConCrackerStr = daily.getTurbineConCracker();
        String prodWaterCrackerStr = daily.getProdWaterCracker();
        String shpPguAeuStr = daily.getShpPguAeu();
        String hpPguAeuStr = daily.getHpPguAeu();
        String mpPguAeuStr = daily.getMpPguAeu();
        String lpPguAeuStr = daily.getLpPguAeu();
        String electricityPguAeuStr = daily.getElectricityPguAeu();
        String coolingWaterPguAeuStr = daily.getCoolingWaterPguAeu();
        String prodWaterPguAeuStr = daily.getProdWaterPguAeu();
        String hpBfwPguAeuStr = daily.getHpBfwPguAeu();
        String n2PguAeuStr = daily.getN2PguAeu();
        String paIaPguAeuStr = daily.getPaIaPguAeu();
        String turbineConPguAeuStr = daily.getTurbineConPguAeu();
        BigDecimal fuelGasOffgasCracker = new BigDecimal(fuelGasOffgasCrackerStr == null ? "0" : fuelGasOffgasCrackerStr);
        BigDecimal shpCracker = new BigDecimal(shpCrackerStr == null ? "0" : shpCrackerStr);
        BigDecimal hpCracker = new BigDecimal(hpCrackerStr == null ? "0" : hpCrackerStr);
        BigDecimal mpCracker = new BigDecimal(mpCrackerStr == null ? "0" : mpCrackerStr);
        BigDecimal lpCracker = new BigDecimal(lpCrackerStr == null ? "0" : lpCrackerStr);
        BigDecimal electricityCracker = new BigDecimal(electricityCrackerStr == null ? "0" : electricityCrackerStr);
        BigDecimal coolingWaterCracker = new BigDecimal(coolingWaterCrackerStr == null ? "0" : coolingWaterCrackerStr);
        BigDecimal paIaCracker = new BigDecimal(paIaCrackerStr == null ? "0" : paIaCrackerStr);
        BigDecimal n2Cracker = new BigDecimal(n2CrackerStr == null ? "0" : n2CrackerStr);
        BigDecimal hpBfwCracker = new BigDecimal(hpBfwCrackerStr == null ? "0" : hpBfwCrackerStr);
        BigDecimal polishedConCracker = new BigDecimal(polishedConCrackerStr == null ? "0" : polishedConCrackerStr);
        BigDecimal turbineConCracker = new BigDecimal(turbineConCrackerStr == null ? "0" : turbineConCrackerStr);
        BigDecimal prodWaterCracker = new BigDecimal(prodWaterCrackerStr == null ? "0" : prodWaterCrackerStr);
        BigDecimal shpPguAeu = new BigDecimal(shpPguAeuStr == null ? "0" : shpPguAeuStr);
        BigDecimal hpPguAeu = new BigDecimal(hpPguAeuStr == null ? "0" : hpPguAeuStr);
        BigDecimal mpPguAeu = new BigDecimal(mpPguAeuStr == null ? "0" : mpPguAeuStr);
        BigDecimal lpPguAeu = new BigDecimal(lpPguAeuStr == null ? "0" : lpPguAeuStr);
        BigDecimal electricityPguAeu = new BigDecimal(electricityPguAeuStr == null ? "0" : electricityPguAeuStr);
        BigDecimal coolingWaterPguAeu = new BigDecimal(coolingWaterPguAeuStr == null ? "0" : coolingWaterPguAeuStr);
        BigDecimal prodWaterPguAeu = new BigDecimal(prodWaterPguAeuStr == null ? "0" : prodWaterPguAeuStr);
        BigDecimal hpBfwPguAeu = new BigDecimal(hpBfwPguAeuStr == null ? "0" : hpBfwPguAeuStr);
        BigDecimal n2PguAeu = new BigDecimal(n2PguAeuStr == null ? "0" : n2PguAeuStr);
        BigDecimal paIaPguAeu = new BigDecimal(paIaPguAeuStr == null ? "0" : paIaPguAeuStr);
        BigDecimal turbineConPguAeu = new BigDecimal(turbineConPguAeuStr == null ? "0" : turbineConPguAeuStr);
        BigDecimal aromaticsEnergyTeTeo = new BigDecimal("0");
        aromaticsEnergyTeTeo = (shpPguAeu.multiply(new BigDecimal("0.092")))
                .add(hpPguAeu.multiply(new BigDecimal("0.088")))
                .add(mpPguAeu.multiply(new BigDecimal("0.08")))
                .add(lpPguAeu.multiply(new BigDecimal("0.0666")))
                .add(electricityPguAeu.multiply(new BigDecimal("0.233")))
                .add(coolingWaterPguAeu.multiply(new BigDecimal("0.1")));
        aromaticsEnergyTeTeo = aromaticsEnergyTeTeo.divide(new BigDecimal("1"), 2, RoundingMode.HALF_UP);
        BigDecimal aromaticsEnergyTeTec = new BigDecimal("0");
        aromaticsEnergyTeTec = aromaticsEnergyTeTeo.divide(new BigDecimal("0.7"), 2, RoundingMode.HALF_UP);
        BigDecimal aromaticsEnergyEeKgeot = new BigDecimal("0");
        if (pguBtxProduced.compareTo(BigDecimal.ZERO) != 0) {
            aromaticsEnergyEeKgeot = aromaticsEnergyTeTeo.divide(pguBtxProduced, 2, RoundingMode.HALF_UP)
                    .multiply(new BigDecimal("1000"));
        }
        BigDecimal aromaticsEnergyEeKgect = new BigDecimal("0");
        aromaticsEnergyEeKgect = aromaticsEnergyEeKgeot.divide(new BigDecimal("0.7"), 2, RoundingMode.HALF_UP);
        monthly.setFuelGasOffgasCracker(fuelGasOffgasCracker.toString());
        monthly.setShpCracker(shpCracker.toString());
        monthly.setHpCracker(hpCracker.toString());
        monthly.setMpCracker(mpCracker.toString());
        monthly.setLpCracker(lpCracker.toString());
        monthly.setElectricityCracker(electricityCracker.toString());
        monthly.setCoolingWaterCracker(coolingWaterCracker.toString());
        monthly.setPaIaCracker(paIaCracker.toString());
        monthly.setN2Cracker(n2Cracker.toString());
        monthly.setHpBfwCracker(hpBfwCracker.toString());
        monthly.setPolishedConCracker(polishedConCracker.toString());
        monthly.setTurbineConCracker(turbineConCracker.toString());
        monthly.setProdWaterCracker(prodWaterCracker.toString());
        monthly.setCrackerConsumptionOffgas(offgasProduced.toString());
        monthly.setShpPguAeu(shpPguAeu.toString());
        monthly.setHpPguAeu(hpPguAeu.toString());
        monthly.setMpPguAeu(mpPguAeu.toString());
        monthly.setLpPguAeu(lpPguAeu.toString());
        monthly.setElectricityPguAeu(electricityPguAeu.toString());
        monthly.setCoolingWaterPguAeu(coolingWaterPguAeu.toString());
        monthly.setProdWaterPguAeu(prodWaterPguAeu.toString());
        monthly.setHpBfwPguAeu(hpBfwPguAeu.toString());
        monthly.setN2PguAeu(n2PguAeu.toString());
        monthly.setPaIaPguAeu(paIaPguAeu.toString());
        monthly.setTurbineConPguAeu(turbineConPguAeu.toString());
        monthly.setAromaticsEnergyTeTeo(aromaticsEnergyTeTeo.toString());
        monthly.setAromaticsEnergyTeTec(aromaticsEnergyTeTec.toString());
        monthly.setAromaticsEnergyEeKgeot(aromaticsEnergyEeKgeot.toString());
        monthly.setAromaticsEnergyEeKgect(aromaticsEnergyEeKgect.toString());

        String sctuConsumptionFgStr = daily.getFuelGasOffgasSctuFlare();
        String sctuConsumptionMpStr = daily.getMpSctuFlare();
        String sctuConsumptionLpStr = daily.getLpSctuFlare();
        String sctuConsumptionElectircStr = daily.getElectricitySctuFlare();
        String sctuConsumptionCwStr = daily.getCoolingWaterSctuFlare();
        String sctuConsumptionPaIaStr = daily.getPaIaSctuFlare();
        BigDecimal sctuConsumptionFg = new BigDecimal( sctuConsumptionFgStr == null ? "0" : sctuConsumptionFgStr);
        BigDecimal sctuConsumptionMp = new BigDecimal( sctuConsumptionMpStr == null ? "0" : sctuConsumptionMpStr);
        BigDecimal sctuConsumptionLp = new BigDecimal( sctuConsumptionLpStr == null ? "0" : sctuConsumptionLpStr);
        BigDecimal sctuConsumptionElectirc = new BigDecimal( sctuConsumptionElectircStr == null ? "0" : sctuConsumptionElectircStr);
        BigDecimal sctuConsumptionCw = new BigDecimal( sctuConsumptionCwStr == null ? "0" : sctuConsumptionCwStr);
        BigDecimal sctuConsumptionPaIa = new BigDecimal( sctuConsumptionPaIaStr == null ? "0" : sctuConsumptionPaIaStr);
        monthly.setSctuConsumptionFg(sctuConsumptionFg.toString());
        monthly.setSctuConsumptionMp(sctuConsumptionMp.toString());
        monthly.setSctuConsumptionLp(sctuConsumptionLp.toString());
        monthly.setSctuConsumptionElectirc(sctuConsumptionElectirc.toString());
        monthly.setSctuConsumptionCw(sctuConsumptionCw.toString());
        monthly.setSctuConsumptionPaIa(sctuConsumptionPaIa.toString());

        String subConElectricStr = daily.getElectricitySub();
        String subConNgStr = daily.getNgSub();
        String subConFgFrEuStr = daily.getFuelGasOffgasSub();
        String subConHhpSteamStr = daily.getHhpSub();
        String subConMpSteamStr = daily.getMpSub();
        String subConLpSteamStr = daily.getLpSub();
        String subConPCondensateStr = daily.getPolishedConSub();
        String subConCwStr = daily.getCoolingWaterSub();
        String subConN2Str = daily.getN2Sub();
        String subConIaPaStr = daily.getPaIaSub();
        String subConProductionWaterStr = daily.getProdWaterSub();
        String subConBfwStr = daily.getHpBfwSub();
        String subConTotalNgFc3702Str = daily.getNgSub();
        BigDecimal subConElectric = new BigDecimal( subConElectricStr == null ? "0" : subConElectricStr);
        BigDecimal subConNg = new BigDecimal( subConNgStr == null ? "0" : subConNgStr);
        BigDecimal subConFgFrEu = new BigDecimal( subConFgFrEuStr == null ? "0" : subConFgFrEuStr);
        BigDecimal subConHhpSteam = new BigDecimal( subConHhpSteamStr == null ? "0" : subConHhpSteamStr);
        BigDecimal subConMpSteam = new BigDecimal( subConMpSteamStr == null ? "0" : subConMpSteamStr);
        BigDecimal subConLpSteam = new BigDecimal( subConLpSteamStr == null ? "0" : subConLpSteamStr);
        BigDecimal subConPCondensate = new BigDecimal( subConPCondensateStr == null ? "0" : subConPCondensateStr);
        BigDecimal subConCw = new BigDecimal( subConCwStr == null ? "0" : subConCwStr);
        BigDecimal subConN2 = new BigDecimal( subConN2Str == null ? "0" : subConN2Str);
        BigDecimal subConIaPa = new BigDecimal( subConIaPaStr == null ? "0" : subConIaPaStr);
        BigDecimal subConProductionWater = new BigDecimal( subConProductionWaterStr == null ? "0" : subConProductionWaterStr);
        BigDecimal subConBfw = new BigDecimal( subConBfwStr == null ? "0" : subConBfwStr);
        BigDecimal subConTotalNgFc3702 = new BigDecimal( subConTotalNgFc3702Str == null ? "0" : subConTotalNgFc3702Str);
        monthly.setSubConElectric(subConElectric.toString());
        monthly.setSubConNg(subConNg.toString());
        monthly.setSubConFgFrEu(subConFgFrEu.toString());
        monthly.setSubConHhpSteam(subConHhpSteam.toString());
        monthly.setSubConMpSteam(subConMpSteam.toString());
        monthly.setSubConLpSteam(subConLpSteam.toString());
        monthly.setSubConPCondensate(subConPCondensate.toString());
        monthly.setSubConCw(subConCw.toString());
        monthly.setSubConN2(subConN2.toString());
        monthly.setSubConIaPa(subConIaPa.toString());
        monthly.setSubConProductionWater(subConProductionWater.toString());
        monthly.setSubConBfw(subConBfw.toString());
        monthly.setSubConTotalNgFc3702(subConTotalNgFc3702.toString());

        BigDecimal kbiPepc = new BigDecimal("0");
        if (crackerRawFeed.compareTo(BigDecimal.ZERO) != 0) {
            kbiPepc = (ethylenProduced.add(propyleneProduced).add(c4LpgProduced))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
        }
        BigDecimal kbiC2C3Production = ethylenProduced.add(propyleneProduced);
        BigDecimal kbiYepbf = new BigDecimal("0");
        if (crackerRawFeed.compareTo(BigDecimal.ZERO) != 0) {
            kbiYepbf = (ethylenProduced
                    .subtract(c2FrLdpe.multiply(new BigDecimal("0.9")))
                    .add(propyleneProduced)
                    .subtract(c3FrOxo.multiply(new BigDecimal("0.68"))))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
        }
        BigDecimal kbiYebf = new BigDecimal("0");
        if (crackerRawFeed.compareTo(BigDecimal.ZERO) != 0) {
            kbiYebf = (ethylenProduced
                    .subtract(c2FrLdpe.multiply(new BigDecimal("0.9"))))
                    .multiply(hundred).divide(crackerRawFeed, 2, RoundingMode.HALF_UP);
        }
        monthly.setKbiPepc(kbiPepc.toString());
        monthly.setKbiC2C3Production(kbiC2C3Production.toString());
        monthly.setKbiYepbf(kbiYepbf.toString());
        monthly.setKbiYebf(kbiYebf.toString());
        monthly.setKbiBtxProduction(pguBtxProduced.toString());

        BigDecimal summaryClYb = ethylenProduced.add(propyleneProduced);
        BigDecimal summaryClYxjy = new BigDecimal("0").subtract(eboProduced);
        BigDecimal summaryClHhc4 = new BigDecimal("0").subtract(mixedC4sProduced);
        BigDecimal summaryClSb = toluene.subtract(aeuBenzeneProduced).subtract(aeuTolueneProduced).subtract(aeuXyleneProduced);
        BigDecimal summaryClZqzh = shpCracker.add(hpCracker).add(mpCracker).add(lpCracker)
                .add(shpPguAeu).add(hpPguAeu).add(mpPguAeu).add(lpPguAeu)
                .add(sctuConsumptionMp).add(sctuConsumptionLp);
        BigDecimal summaryClLqs = (coolingWaterCracker.add(coolingWaterPguAeu).add(sctuConsumptionCw))
                .multiply(new BigDecimal("1000"));
        BigDecimal summaryClD = (electricityCracker.add(electricityPguAeu).add(sctuConsumptionElectirc))
                .multiply(new BigDecimal("1000"));
        monthly.setSummaryClYb(summaryClYb.toString());
        monthly.setSummaryClSny(nap.toString());
        monthly.setSummaryClC5Raff(c5.toString());
        monthly.setSummaryClYw(wisonEthane.toString());
        monthly.setSummaryClJqtj(hyC9.toString());
        monthly.setSummaryClYxjy(summaryClYxjy.toString());
        monthly.setSummaryClHhc4(summaryClHhc4.toString());
        monthly.setSummaryClSb(summaryClSb.toString());
        BigDecimal clLjtw = new BigDecimal("0").subtract(pguC5Produced);
        BigDecimal clLjtj = new BigDecimal("0").subtract(pguC9Produced);
        BigDecimal clCzssy = new BigDecimal("0").subtract(aeuC6C8NaProduced);
        monthly.setSummaryClLjtw(clLjtw.toString());
        monthly.setSummaryClLjtj(clLjtj.toString());
        monthly.setSummaryClCcsny(clCzssy.toString());
        monthly.setSummaryClZqzh(summaryClZqzh.toString());
        monthly.setSummaryClLqs(summaryClLqs.toString());
        monthly.setSummaryClD(summaryClD.toString());
        monthly.setSummaryClRlq(fuelGasOffgasCracker.toString());
        monthly.setSummaryClJzs(polishedConCracker.toString());
        monthly.setSummaryClTpny(turbineConCracker.toString());
        BigDecimal summarySlYb = ethyleneYield.add(propyleneYield);
        BigDecimal summarySlSny = new BigDecimal("0");
        BigDecimal summarySlC5Raff = new BigDecimal("0");
        BigDecimal summarySlYw = new BigDecimal("0");
        BigDecimal summarySlJqtj = new BigDecimal("0");
        BigDecimal summarySlYxjy = new BigDecimal("0");
        BigDecimal summarySlHhc4 = new BigDecimal("0");
        BigDecimal summarySlSb = new BigDecimal("0");
        BigDecimal summarySlLjtw = new BigDecimal("0");
        BigDecimal summarySlLjtj = new BigDecimal("0");
        BigDecimal summarySlCcsny = new BigDecimal("0");
        BigDecimal summarySlZqzh = new BigDecimal("0");
        BigDecimal summarySlLqs = new BigDecimal("0");
        BigDecimal summarySlD = new BigDecimal("0");
        BigDecimal summarySlRlq = new BigDecimal("0");
        BigDecimal summarySlJzs = new BigDecimal("0");
        BigDecimal summarySlTpny = new BigDecimal("0");
        if (summaryClYb.compareTo(BigDecimal.ZERO) != 0) {
            summarySlSny = nap.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlC5Raff = c5.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlYw = wisonEthane.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlJqtj = hyC9.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlYxjy = summaryClYxjy.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlHhc4 = summaryClHhc4.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlSb = summaryClSb.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlLjtw = new BigDecimal("0").subtract(pguC5Produced.divide(summaryClYb, 3, RoundingMode.HALF_UP));
            summarySlLjtj = new BigDecimal("0").subtract(pguC9Produced.divide(summaryClYb, 3, RoundingMode.HALF_UP));
            summarySlCcsny = new BigDecimal("0").subtract(aeuC6C8NaProduced.divide(summaryClYb, 3, RoundingMode.HALF_UP));
            summarySlZqzh = summaryClZqzh.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlLqs = summaryClLqs.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlD = summaryClD.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlRlq = fuelGasOffgasCracker.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlJzs = polishedConCracker.divide(summaryClYb, 3, RoundingMode.HALF_UP);
            summarySlTpny = turbineConCracker.divide(summaryClYb, 3, RoundingMode.HALF_UP);
        }
        monthly.setSummarySlYb(summarySlYb.toString());
        monthly.setSummarySlSny(summarySlSny.toString());
        monthly.setSummarySlC5Raff(summarySlC5Raff.toString());
        monthly.setSummarySlYw(summarySlYw.toString());
        monthly.setSummarySlJqtj(summarySlJqtj.toString());
        monthly.setSummarySlYxjy(summarySlYxjy.toString());
        monthly.setSummarySlHhc4(summarySlHhc4.toString());
        monthly.setSummarySlSb(summarySlSb.toString());
        monthly.setSummarySlLjtw(summarySlLjtw.toString());
        monthly.setSummarySlLjtj(summarySlLjtj.toString());
        monthly.setSummarySlCcsny(summarySlCcsny.toString());
        monthly.setSummarySlZqzh(summarySlZqzh.toString());
        monthly.setSummarySlLqs(summarySlLqs.toString());
        monthly.setSummarySlD(summarySlD.toString());
        monthly.setSummarySlRlq(summarySlRlq.toString());
        monthly.setSummarySlJzs(summarySlJzs.toString());
        monthly.setSummarySlTpny(summarySlTpny.toString());

        // 查询年份=reportYear，月份=reportMonth的月报数据
        int count = tMonthlyProductionReportMapper.selectTMonthlyProductionReportCountByDate(reportYear, reportMonth);
        if (count == 0) {   // 新增月报数据
            tMonthlyProductionReportMapper.insertTMonthlyProductionReport(monthly);
        } else {    // 更新月报数据
            tMonthlyProductionReportMapper.updateTMonthlyProductionReport(monthly);
        }
    }

}
