huangzhen
2023-10-20 5c72b20bee11513c06cdfb30c52cd0a4016a7102
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/DailyReportSchedule.java
@@ -1,6 +1,7 @@
package com.gkhy.fourierSpecialGasMonitor.schedule;
import com.alibaba.fastjson.JSON;
import com.gkhy.fourierSpecialGasMonitor.Application;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.ForeignResultCode;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.ResultCode;
import com.gkhy.fourierSpecialGasMonitor.commons.exception.BusinessException;
@@ -26,6 +27,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -39,6 +42,7 @@
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.lang.reflect.Field;
import java.net.URL;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -98,18 +102,38 @@
        //加载文档
        XWPFDocument doc = null;
        try {
            FileInputStream originalFileInputStream = new FileInputStream("src/main/resources/template/dailyReportTemplate.docx");
            FileOutputStream copyFileOutputStream = new FileOutputStream("src/main/resources/temp/dailyReportTemplate.docx");
            // 创建副本文件
            ClassLoader classLoader = Application.class.getClassLoader();
            InputStream originalFileInputStream = classLoader.getResourceAsStream("template/dailyReportTemplate.docx");
            String copyFileUrl = reportFilePathConfig.getDcPath()+"temp/dailyReportTemplate.docx";
            File file = new File(copyFileUrl);
            if (!file.exists()){
                try {
                    // 获取文件所在的文件夹路径
                    String folderPath = file.getParent();
                    // 创建文件夹(包括父目录)
                    File folder = new File(folderPath);
                    if (!folder.exists()){
                        folder.mkdirs();
                    }
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            FileOutputStream copyFileOutputStream = new FileOutputStream(copyFileUrl);
            IOUtils.copy(originalFileInputStream, copyFileOutputStream);
            opcPackage = POIXMLDocument.openPackage("src/main/resources/temp/dailyReportTemplate.docx");
            opcPackage = POIXMLDocument.openPackage(copyFileUrl);
            //FileInputStream originalFileInputStream = new FileInputStream("src/main/resources/template/dailyReportTemplate.docx");
            //FileOutputStream copyFileOutputStream = new FileOutputStream("src/main/resources/temp/dailyReportTemplate.docx");
            //// 创建副本文件
            //IOUtils.copy(originalFileInputStream, copyFileOutputStream);
            //opcPackage = POIXMLDocument.openPackage("src/main/resources/temp/dailyReportTemplate.docx");
            doc = new XWPFDocument(opcPackage);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Map<String, Object> map = dataMap(gasCategories);
        List<XWPFParagraph> paragraphList = doc.getParagraphs();
        for (XWPFParagraph par : paragraphList) {
            //获取段落的文本对象
@@ -173,7 +197,6 @@
                drawLineChart(gasConcentrations, fileurl, series, title, gasCategories.get(i).getMolecularFormula(), i);
            }
        }
        //List<GasFlux> gasFluxes = gasFluxService.listYesterday();
        List<GasFlux> gasFluxes = gasFluxService.listYesterdayTenAmToSixPm();
        List<Integer> areaNum = gasFluxes.stream().map(GasFlux::getAreaId).distinct().collect(Collectors.toList());