package io.renren.modules.common;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.opencsv.CSVReader;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.aspen.dao.TDailyProductionReportDao;
import io.renren.modules.aspen.entity.TDailyProductionReport;
import io.renren.modules.aspen.entity.TDashboarddataEntity;
import io.renren.modules.aspen.service.TDashboarddataService;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
@Component
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class AspenController extends AbstractController {

    @Autowired
    private TDashboarddataService tDashboarddataService;
    @Autowired
    private TDailyProductionReportDao tDailyProductionReportDao;

//    @Scheduled(cron = "0 */1 * * * ?")
    @Scheduled(cron = "0 */15 * * * ?")
    public void getExcelData(){
        logger.info("实时获取数据");
//        String csvFile = "D://ssyFile/wuliao.csv";
        String csvFile = "C://dashboardAspen/wuliao.csv";
        TDashboarddataEntity dashboarddataEntity = new TDashboarddataEntity();
        CSVReader reader = null;
        try {
            reader = new CSVReader(new FileReader(csvFile));
            String[] line;
            //定义行数
            int i = 0;
            while ((line = reader.readNext()) != null) {
                if (i == 4) {
                    logger.info("第" + i + "行");
                    for (int j = 0; j < 16; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0.0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0.0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setEnergyYixi(line[0]);
                    dashboarddataEntity.setEnergyBingxi(line[1]);
                    dashboarddataEntity.setEnergyQingqi(line[2]);
                    dashboarddataEntity.setEnergyJiawan(line[3]);
                    dashboarddataEntity.setEnergyOffgas(line[4]);
                    dashboarddataEntity.setEnergyLpg(line[5]);
                    dashboarddataEntity.setEnergyCsi(line[6]);
                    dashboarddataEntity.setEnergyBenzene(line[7]);
                    dashboarddataEntity.setEnergyToluene(line[8]);
                    dashboarddataEntity.setEnergyXylene(line[9]);
                    dashboarddataEntity.setEnergyTanliu(line[10]);
                    dashboarddataEntity.setEnergyWashoil(line[11]);
                    dashboarddataEntity.setEnergyTanwu(line[12]);
                    dashboarddataEntity.setEnergyIma(line[13]);
                    dashboarddataEntity.setEnergyCjiu(line[14]);
                    dashboarddataEntity.setEnergyRpg(line[15]);
                }
                if (i == 11) {
                    logger.info("第" + i + "行");
                    for (int j = 0; j < 5; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0.0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0.0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setEnergyfeedNap(line[0]);
                    dashboarddataEntity.setEnergyfeedYiwan(line[1]);
                    dashboarddataEntity.setEnergyfeedTanwu(line[2]);
                    dashboarddataEntity.setEnergyfeedTanliu(line[3]);
                    dashboarddataEntity.setEnergyfeedLpg(line[4]);
                }
                if (i == 15) {
                    logger.info("第" + i + "行");
                    line[0] = rounding(line[0]);
                    line[2] = rounding(line[2]);
                    dashboarddataEntity.setOutputYixi(rounding(line[0]));
                    dashboarddataEntity.setInstantaneous(rounding(line[2]));
                    logger.info("===========================" + line[5]);
                    String annual = line[5];
                    annual = new BigDecimal(annual).toPlainString();
                    annual = new BigDecimal(annual).multiply(new BigDecimal("100")).toString();
                    dashboarddataEntity.setOutputAnnual(rounding(annual)+"%");
                }
                if (i == 16) {
                    logger.info("第" + i + "行");
                    for (int j = 7; j < 20; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setNapOne(line[7]);
                    dashboarddataEntity.setNapTwo(line[8]);
                    dashboarddataEntity.setNapThree(line[9]);
                    dashboarddataEntity.setEhtOne(line[10]);
                    dashboarddataEntity.setEhtTwo(line[11]);
                    dashboarddataEntity.setEhtThree(line[12]);
                    dashboarddataEntity.setEhtFour(line[13]);
                    dashboarddataEntity.setEhtFive(line[14]);
                    dashboarddataEntity.setAcrOne(line[15]);
                    dashboarddataEntity.setAcrTwo(line[16]);
                    dashboarddataEntity.setAcrThree(line[17]);
                    dashboarddataEntity.setAcrFour(line[18]);
                    dashboarddataEntity.setAcrZero(line[19]);
                }
                if (i == 19) {
                    logger.info("第" + i + "行");
                    for (int j = 0; j < 3; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0.0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0.0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setOutputBx(line[0]);
                    dashboarddataEntity.setCumulative(line[2]);
                }
                if (i == 20) {
                    logger.info("第" + i + "行");
                    for (int j = 7; j < 11; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setProTwo(line[7]);
                    dashboarddataEntity.setProOne(line[8]);
                    dashboarddataEntity.setProThree(line[9]);
                    dashboarddataEntity.setProFour(line[10]);
                }
                /* SS */
                if (i == 40) {
                    logger.info("第" + i + "行");
                    if (line[1].equals("")) {
                        line[1] = "0.0";
                    }else {
                        if (!Character.isDigit(line[1].charAt(0))) {
                            line[1] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[1]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[1] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamSsinfur(line[1]);
                }
                if (i == 41) {
                    logger.info("第" + i + "行");
                    if (line[6].equals("")) {
                        line[6] = "0.0";
                    }else {
                        if (!Character.isDigit(line[6].charAt(0))) {
                            line[6] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[6]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[6] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamSsoutlet(line[6]);
                }
                if (i == 42) {
                    logger.info("第" + i + "行");
                    if (line[6].equals("")) {
                        line[6] = "0.0";
                    }else {
                        if (!Character.isDigit(line[6].charAt(0))) {
                            line[6] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[6]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[6] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamSsoutesi(line[6]);
                }
                if (i == 43) {
                    logger.info("第" + i + "行");
                    if (line[6].equals("")) {
                        line[6] = "0.0";
                    }else {
                        if (!Character.isDigit(line[6].charAt(0))) {
                            line[6] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[6]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[6] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamSsoutaeu(line[6]);
                }
                if (i == 44) {
                    logger.info("第" + i + "行");
                    for (int j = 6; j < 9; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0.0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0.0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setSteamSsoutksan(line[6]);
                    dashboarddataEntity.setSteamHsinksan(line[8]);
                }
                if (i == 45) {
                    logger.info("第" + i + "行");
                    if (line[8].equals("")) {
                        line[8] = "0.0";
                    }else {
                        if (!Character.isDigit(line[8].charAt(0))) {
                            line[8] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[8]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[8] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamSsoutsc(line[8]);
                }
                /* HS */
                if (i == 55) {
                    logger.info("第" + i + "行");
                    if (line[1].equals("")) {
                        line[1] = "0.0";
                    }else {
                        if (!Character.isDigit(line[1].charAt(0))) {
                            line[1] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[1]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[1] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamHsinsub(line[1]);
                }
                if (i == 56) {
                    logger.info("第" + i + "行");
                    for (int j = 1; j < 10; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0.0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0.0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setSteamHhpsub(line[1]);
                    dashboarddataEntity.setSteamHsoutpjiu(line[4]);
                    dashboarddataEntity.setSteamHsouthwu(line[9]);
                }
                if (i == 57) {
                    logger.info("第" + i + "行");
                    for (int j = 1; j < 10; j++) {
                        logger.info("读数:" + line[j]);
                        if (line[j].equals("")) {
                            line[j] = "0.0";
                        }else {
                            if (!Character.isDigit(line[j].charAt(0))) {
                                line[j] = "0.0";
                            }else {
                                BigDecimal b = new BigDecimal(Double.parseDouble(line[j]));
                                double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                                line[j] = String.valueOf(f);
                            }
                        }
                        logger.info(line[j]);
                    }
                    dashboarddataEntity.setSteamHsinlet(line[1]);
                    dashboarddataEntity.setSteamHsoutaeu(line[4]);
                    dashboarddataEntity.setSteamHsouthc230(line[9]);
                }
                if (i == 58) {
                    logger.info("第" + i + "行");
                    if (line[4].equals("")) {
                        line[4] = "0.0";
                    }else {
                        if (!Character.isDigit(line[4].charAt(0))) {
                            line[4] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[4]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[4] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamHsoutlet(line[4]);
                }
                if (i == 59) {
                    logger.info("第" + i + "行");
                    if (line[4].equals("")) {
                        line[4] = "0.0";
                    }else {
                        if (!Character.isDigit(line[4].charAt(0))) {
                            line[4] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[4]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[4] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamHsoutesan(line[4]);
                }
                if (i == 60) {
                    logger.info("第" + i + "行");
                    if (line[4].equals("")) {
                        line[4] = "0.0";
                    }else {
                        if (!Character.isDigit(line[4].charAt(0))) {
                            line[4] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[4]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[4] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamHsoutphyi(line[4]);
                }
                if (i == 61) {
                    logger.info("第" + i + "行");
                    if (line[4].equals("")) {
                        line[4] = "0.0";
                    }else {
                        if (!Character.isDigit(line[4].charAt(0))) {
                            line[4] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[4]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[4] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamHsoutpher(line[4]);
                }
                if (i == 62) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamHsoutklz(rounding(line[4]));
                    dashboarddataEntity.setSteamMsinkliu(rounding(line[6]));
                }
                if (i == 63) {
                    logger.info("第" + i + "行");
                    if (line[6].equals("")) {
                        line[6] = "0.0";
                    }else {
                        if (!Character.isDigit(line[6].charAt(0))) {
                            line[6] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[6]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[6] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamHsoutsc(line[6]);
                }
                if (i == 64) {
                    logger.info("第" + i + "行");
                    if (line[4].equals("")) {
                        line[4] = "0.0";
                    }else {
                        if (!Character.isDigit(line[4].charAt(0))) {
                            line[4] = "0.0";
                        }else {
                            BigDecimal b = new BigDecimal(Double.parseDouble(line[4]));
                            double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                            line[4] = String.valueOf(f);
                        }
                    }
                    dashboarddataEntity.setSteamHsoutkliu(line[4]);
                }
                /* MS */
                if (i == 69) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamMsinaeu(rounding(line[1]));
                    dashboarddataEntity.setSteamMsoutflare(rounding(line[4]));
                    dashboarddataEntity.setSteamMsoutfur(rounding(line[7]));
                }
                if (i == 70) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamMsinphyi(rounding(line[1]));
                    dashboarddataEntity.setSteamMsoutaeu(rounding(line[4]));
                    dashboarddataEntity.setSteamMsoutva(rounding(line[7]));
                }
                if (i == 71) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamMsinlet(rounding(line[1]));
                    dashboarddataEntity.setSteamMsouttracing(rounding(line[7]));
                }
                if (i == 74) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamMsoutsctu(rounding(line[4]));
                }
                if (i == 79) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamMsouteer(rounding(line[4]));
                }
                /* LS */
                if (i == 84) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsinsub(rounding(line[1]));
                    dashboarddataEntity.setSteamLsoutsctu(rounding(line[5]));
                }
                if (i == 85) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsinpjiu(rounding(line[1]));
                    dashboarddataEntity.setSteamLsoutvjiu(rounding(line[5]));
                }
                if (i == 86) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsinaeu(rounding(line[1]));
                    dashboarddataEntity.setSteamLsoutewuliu(rounding(line[5]));
                }
                if (i == 87) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsineer(rounding(line[1]));
                    dashboarddataEntity.setSteamLsoutewusan(rounding(line[5]));
                }
                if (i == 88) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsinpher(rounding(line[1]));
                    dashboarddataEntity.setSteamLsouttracing(rounding(line[5]));
                }
                if (i == 89) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsoutesan(rounding(line[5]));
                }
                if (i == 90) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsoutesi(rounding(line[5]));
                }
                if (i == 91) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSteamLsoutother(rounding(line[5]));
                }
                /* 总需求 */
                if (i == 99) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setSsBcc(rounding(line[1]));
                    dashboarddataEntity.setSsSub(rounding(line[2]));
                    dashboarddataEntity.setSsEu(rounding(line[3]));
                    dashboarddataEntity.setSsPgu(rounding(line[4]));
                }
                if (i == 100) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setHhpBcc(rounding(line[1]));
                    dashboarddataEntity.setHhpSub(rounding(line[2]));
                }
                if (i == 101) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setHsBcc(rounding(line[1]));
                    dashboarddataEntity.setHsSub(rounding(line[2]));
                    dashboarddataEntity.setHsEu(rounding(line[3]));
                    dashboarddataEntity.setHsPgu(rounding(line[4]));
                }
                if (i == 102) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setMsBcc(rounding(line[1]));
                    dashboarddataEntity.setMsEu(rounding(line[3]));
                    dashboarddataEntity.setMsPgu(rounding(line[4]));
                }
                if (i == 103) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setLsBcc(rounding(line[1]));
                    dashboarddataEntity.setLsEu(rounding(line[3]));
                    dashboarddataEntity.setLsPgu(rounding(line[4]));
                }
                if (i == 104) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setTotalBcc(rounding(line[1]));
                    dashboarddataEntity.setTotalEu(rounding(line[3]));
                }
                if (i == 105) {
                    logger.info("第" + i + "行");
                    dashboarddataEntity.setZongBcc(rounding(line[1]));
                    dashboarddataEntity.setZongEu(rounding(line[3]));
                    dashboarddataEntity.setZongPgu(rounding(line[4]));
                }
                i++;
            }
            dashboarddataEntity.setCreatedate(new Date());
            //储罐的代码
            TDailyProductionReport report = tDailyProductionReportDao.selectOne( new QueryWrapper<TDailyProductionReport>()
                    .last("where REPORT_DATE = (select max(t2.REPORT_DATE) from t_daily_production_report t2)")
            );
            logger.info("TDailyProductionReport:" + JSON.toJSONString(report));
            dashboarddataEntity.setNapOne(rounding0(report.getSctfStorageCltf1621(), "33000" ));
            dashboarddataEntity.setNapTwo(rounding0(report.getSctfStorageCltf1622(), "33000" ));
            dashboarddataEntity.setNapThree(rounding0(report.getSctfStorageCltf1623(), "33000" ));
            dashboarddataEntity.setEhtOne(rounding0(report.getSctfStorageTk1061(), "517" ));
            dashboarddataEntity.setEhtTwo(rounding0(report.getSctfStorageTk1062(), "517" ));
            dashboarddataEntity.setEhtThree(rounding0(report.getSctfStorageTk1063(), "517" ));
            dashboarddataEntity.setEhtFour(rounding0(report.getSctfStorageTk1064(), "517" ));
            dashboarddataEntity.setEhtFive(rounding0(report.getSctfStorageTk1065Off(), "517" ));
            dashboarddataEntity.setAcrOne(rounding0(report.getSctfStorageTk1011(), "1200" ));
            dashboarddataEntity.setAcrTwo(rounding0(report.getSctfStorageTk1012(), "1200" ));
            dashboarddataEntity.setAcrThree(rounding0(report.getSctfStorageTk1013(), "1200" ));
            dashboarddataEntity.setAcrFour(rounding0(report.getSctfStorageTk1014(), "1200" ));
            dashboarddataEntity.setAcrZero(rounding0(report.getSctfStorageTk1040Off(), "1200" ));
            dashboarddataEntity.setProTwo(rounding0(report.getSctfStorageTk1520Rpg(), "13500" ));
            dashboarddataEntity.setProOne(rounding0(report.getSctfStorageTk1510B(), "3900" ));
            dashboarddataEntity.setProThree(rounding0(report.getSctfStorageTk1360T(), "3800" ));
            dashboarddataEntity.setProFour(rounding0(report.getSctfStorageTk1410X(), "1560" ));

            logger.info("dashboardData:" + dashboarddataEntity);
            tDashboarddataService.save(dashboarddataEntity);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

//    @Scheduled(cron = "0 */1 * * * ?")
    public void getDayTankData(){
         TDailyProductionReport report = tDailyProductionReportDao.selectOne( new QueryWrapper<TDailyProductionReport>()
                .last("where REPORT_DATE = (select max(t2.REPORT_DATE) from t_daily_production_report t2)")
        );
        logger.info(JSON.toJSONString(report));

        TDashboarddataEntity data = tDashboarddataService.getOne( new QueryWrapper<TDashboarddataEntity>()
              .eq("id" , "811")
        );
        data.setNapOne(rounding0(report.getSctfStorageCltf1621(), "33000" ));
        data.setNapTwo(rounding0(report.getSctfStorageCltf1622(), "33000" ));
        data.setNapThree(rounding0(report.getSctfStorageCltf1623(), "33000" ));
        data.setEhtOne(rounding0(report.getSctfStorageTk1061(), "517" ));
        data.setEhtTwo(rounding0(report.getSctfStorageTk1062(), "517" ));
        data.setEhtThree(rounding0(report.getSctfStorageTk1063(), "517" ));
        data.setEhtFour(rounding0(report.getSctfStorageTk1064(), "517" ));
        data.setEhtFive(rounding0(report.getSctfStorageTk1065Off(), "517" ));
        data.setAcrOne(rounding0(report.getSctfStorageTk1011(), "1200" ));
        data.setAcrTwo(rounding0(report.getSctfStorageTk1012(), "1200" ));
        data.setAcrThree(rounding0(report.getSctfStorageTk1013(), "1200" ));
        data.setAcrFour(rounding0(report.getSctfStorageTk1014(), "1200" ));
        data.setAcrZero(rounding0(report.getSctfStorageTk1040Off(), "1200" ));
        data.setProTwo(rounding0(report.getSctfStorageTk1520Rpg(), "13500" ));
        data.setProOne(rounding0(report.getSctfStorageTk1510B(), "3900" ));
        data.setProThree(rounding0(report.getSctfStorageTk1360T(), "3800" ));
        data.setProFour(rounding0(report.getSctfStorageTk1410X(), "1560" ));
        tDashboarddataService.saveOrUpdate(data);
    }

    public String rounding(String lineNum) {
        try {
            logger.info("读数:" + lineNum);
            if (lineNum.equals("")) {
                lineNum = "0.0";
            }else {
                if (!Character.isDigit(lineNum.charAt(0))) {
                    if ("-".equals(lineNum.substring(0,1))){
                        BigDecimal b = new BigDecimal(Double.parseDouble(lineNum));
                        double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                        lineNum = String.valueOf(f);
                    }else {
                        lineNum = "0.0";
                    }
                }else {
                    BigDecimal b = new BigDecimal(Double.parseDouble(lineNum));
                    double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    lineNum = String.valueOf(f);
                }
            }
            logger.info(lineNum);
            return lineNum;
        }catch (Exception e) {
            logger.error(String.valueOf(e));
            return "0.0";
        }
    };
    public String rounding0(String lineNum , String allNum) {
        try {
            logger.info("读数:" + lineNum);
            lineNum =  new BigDecimal(lineNum).divide(new BigDecimal(allNum),4, RoundingMode.CEILING).multiply(new BigDecimal("100")).toString();
            if (lineNum.equals("")) {
                lineNum = "0.0";
            }else {
                if (!Character.isDigit(lineNum.charAt(0))) {
                    if ("-".equals(lineNum.substring(0,1))){
                        BigDecimal b = new BigDecimal(Double.parseDouble(lineNum));
                        double f = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                        lineNum = String.valueOf(f);
                    }else {
                        lineNum = "0.0";
                    }
                }else {
                    BigDecimal b = new BigDecimal(Double.parseDouble(lineNum));
                    double f = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                    lineNum = String.valueOf(f);
                }
            }
            logger.info(lineNum);
            return lineNum;
        }catch (Exception e) {
            logger.error(String.valueOf(e));
            return "0.0";
        }
    }
}
