| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | String startTime = now.format(execformatter); |
| | | RBucket<List<GasCategory>> bucket = redissonClient.getBucket("gas_category_cache_info"); |
| | | List<GasCategory> gasCategories = bucket.get(); |
| | | //logger.info("【##】开始生成日报 ,时间:"+startTime); |
| | | logger.info("【##】开始生成日报 ,时间:"+startTime); |
| | | OPCPackage opcPackage = null; |
| | | //加载文档 |
| | | 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) { |
| | | //获取段落的文本对象 |
| | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<GasConcentration> gasConcentrations = gasConcentrationService.listDatabyTimeSlot(LocalDateTime.now().minusDays(2).with(LocalDate.MIN), LocalDateTime.now()); |
| | | List<GasConcentration> gasConcentrations = gasConcentrationService.listDatabyTimeSlot(LocalDateTime.of(now.minusDays(1).toLocalDate(), LocalTime.MIN) |
| | | , LocalDateTime.of(now.minusDays(1).toLocalDate(), LocalTime.MAX)); |
| | | if (!CollectionUtils.isEmpty(gasConcentrations)) { |
| | | for (int i = 0; i < 30; i++) { |
| | | String series = gasCategories.get(i).getMolecularFormula() + "浓度观测结果"; |
| | |
| | | drawLineChart(gasConcentrations, fileurl, series, title, gasCategories.get(i).getMolecularFormula(), i); |
| | | } |
| | | } |
| | | |
| | | List<GasFlux> gasFluxes = gasFluxService.listYesterday(); |
| | | //List<GasFlux> gasFluxes = gasFluxService.listYesterday(); |
| | | List<GasFlux> gasFluxes = gasFluxService.listYesterdayTenAmToSixPm(); |
| | | List<Integer> areaNum = gasFluxes.stream().map(GasFlux::getAreaId).distinct().collect(Collectors.toList()); |
| | | |
| | | List<Region> allRegion = regionService.findAll(); |
| | |
| | | Map<Integer, String> regionMap = allRegion.stream() |
| | | .collect(Collectors.toMap(Region::getId, Region::getName)); |
| | | if (!CollectionUtils.isEmpty(gasFluxes)) { |
| | | for (int i = 1; i <= 1; i++) { |
| | | for (int j = 0; j < 1; j++) { |
| | | for (int i = 1; i <= areaNum.size(); i++) { |
| | | for (int j = 0; j < 20; j++) { |
| | | drawBarChart(gasFluxes, fileurl, regionMap.get(i), "柱形图" + gasCategories.get(j).getMolecularFormula(), i, j + 1); |
| | | } |
| | | } |
| | |
| | | MonitorDailyReport save = monitorDailyReportService.save(report); |
| | | if (save == null) |
| | | throw new BusinessException(this.getClass(), ResultCode.SYSTEM_ERROR_DATABASE_FAIL,"日常报表保存失败"); |
| | | //logger.info("【##】日报生成成功!!! ,时间:"+endTime+",所耗时间: "+execTime+"s"); |
| | | logger.info("【##】日报生成成功!!! ,时间:"+endTime+",所耗时间: "+execTime+"s"); |
| | | } |
| | | |
| | | public void drawBarChart(List<GasFlux> gasFluxes,String fileurl,String series,String molecularFormula,Integer i,Integer j) { |
| | |
| | | private Map<String, Object> dataMap(List<GasCategory> gasCategories){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | String today = now.format(formatter); |
| | | String yesterday = LocalDateTime.now().plusDays(1).format(formatter); |
| | | String yesterday = LocalDateTime.now().minusDays(1).format(formatter); |
| | | //要替换的map,key为占位符,value为要被替换的值 |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("${today}", today); |