huangzhen
2023-12-20 25a1cd1e6f6be895cdf19d49286969cbbca59eb9
完善日报生成规则
已修改3个文件
456 ■■■■ 文件已修改
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/DailyReportSchedule.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/TestSchedule.java 406 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/template/dailyReportTemplate.docx 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/DailyReportSchedule.java
@@ -69,6 +69,8 @@
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private static int serialNumber = 4;
    @Autowired
    private GasWarnLogService gasWarnLogService;
@@ -90,13 +92,15 @@
    @Autowired
    private MonitorDailyReportService monitorDailyReportService;
    @Scheduled(cron = "0 0 2 * * ?") //每天两点执行一次
    //@Scheduled(cron = "0 0 2 * * ?") //每天两点执行一次
    @Scheduled(cron = "0/30 * * * * ?")
    @Async(value = "SocketTaskExecutor")
    public void generateDailyReport() {
        LocalDateTime now = LocalDateTime.now();
        String startTime = now.format(execformatter);
        RBucket<List<GasCategory>> bucket = redissonClient.getBucket("gas_category_cache_info");
        List<GasCategory> gasCategories = bucket.get();
        serialNumber = 4;
        logger.info("【##】开始生成日报 ,时间:"+startTime);
        OPCPackage opcPackage = null;
        //加载文档
@@ -191,9 +195,10 @@
        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++) {
            //for (int i = 0; i < 30; i++) {
            for (int i = 0; i < gasCategories.size(); i++) {
                String series = gasCategories.get(i).getMolecularFormula() + "浓度观测结果";
                String title = "—" + gasCategories.get(i).getMolecularFormula();
                String title = gasCategories.get(i).getMolecularFormula();
                drawLineChart(gasConcentrations, fileurl, series, title, gasCategories.get(i).getMolecularFormula(), i);
            }
        }
@@ -207,9 +212,13 @@
        Map<Integer, String> regionMap = allRegion.stream()
                .collect(Collectors.toMap(Region::getId, Region::getName));
        if (!CollectionUtils.isEmpty(gasFluxes)) {
            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);
            for (int j = 0; j < gasCategories.size(); j++) {
                for (int i = 1; i <= areaNum.size(); i++) {
                    //for (int j = 0; j < 20; j++) {
                    int finalI = i;
                    List<GasFlux> gasFluxesByArea = gasFluxes.stream().filter(gasFlux -> gasFlux.getAreaId() == finalI)
                            .collect(Collectors.toList());
                    drawBarChart(gasFluxesByArea, fileurl, regionMap.get(i), gasCategories.get(j).getMolecularFormula(), i, j + 1);
                }
            }
        }
@@ -265,6 +274,7 @@
        value2.add(n);
        List<XWPFChart> charts = doc.getCharts();
        serialNumber++;
        for (int k = 0; k < charts.size(); k++) {
            XWPFChart xwpfChart = charts.get(k);
            XDDFTitle xddfTitletitle = xwpfChart.getTitle();
@@ -283,9 +293,9 @@
                    Element aT = (Element) root.getElementsByTagName("a:t").item(0);
                    // 获取 <a:t> 元素的文本内容 获取标题具体内容
                    String value = aT.getTextContent();
                    String chartTitle = "图"+(31 + i * j)+" "+i+"号厂区排放"+molecularFormula+"通量反演结果";
                    if ((i+"-"+j).equals(value)) {
                        drawBarChartExec(charts.get(k), series2, x2, value2, chartTitle);
                    String chartTitle = "图"+serialNumber+" "+i+"号厂区排放"+molecularFormula+"通量反演结果";
                    if ((j+"-"+i).equals(value)) {
                        drawBarChartExec(charts.get(k), series2, x2, value2, chartTitle,molecularFormula);
                    }
                } catch (ParserConfigurationException e) {
                    e.printStackTrace();
@@ -393,12 +403,12 @@
    public void drawBarChartExec(XWPFChart chart, String[] series, String[] categories,
                                  List<Number[]> values, String chartTitle) {
                                  List<Number[]> values, String chartTitle,String molecularFormula) {
        final List<XDDFChartData> data = chart.getChartSeries();
        final XDDFBarChartData line = (XDDFBarChartData) data.get(0);//这里一般获取第一个,我们这里是折线图就是XDDFLineChartData
        line.getCategoryAxis().setTitle(chartTitle);
        line.getValueAxes().get(0).setTitle("C2H2 Emission Rate (ug/m^2/s)");
        line.getValueAxes().get(0).setTitle(molecularFormula+" Emission Rate (ug/m^2/s)");
        final int numOfPoints = categories.length;
        final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
@@ -462,8 +472,8 @@
        Map<String, Object> map = new HashMap<>();
        map.put("${today}", today);
        map.put("${yesterday}", yesterday);
        map.put("${generalradius}","10");
        map.put("${generalradiu}","20");
        map.put("${generalradius}","1km");
        map.put("${generalradiu}","300m");
        List<GasWarnLog> gasWarnLogs = gasWarnLogService.listYesterday();
        if (!CollectionUtils.isEmpty(gasWarnLogs)){
@@ -482,21 +492,21 @@
        }
        String fiveGas = "";
        String sixGas = "";
        for (int i = 0; i < 6; i++) {
        for (int i = 0; i < 3; i++) {
            String name = gasCategories.get(i).getMolecularFormula()+"("+gasCategories.get(i).getName()+")";
            name = name + "、";
            if (i < 5){
            if (i < 3){
                fiveGas = fiveGas + name;
                if (i == 4){
                if (i == 2){
                    int index = fiveGas.lastIndexOf("、");
                    fiveGas =  fiveGas.substring(0, index)+"共五种";
                    fiveGas =  fiveGas.substring(0, index)+"共三种";
                }
            }
            if (i < 6){
            if (i < 3){
                sixGas = sixGas + name;
                if (i == 5){
                if (i == 2){
                    int index = sixGas.lastIndexOf("、");
                    sixGas =  sixGas.substring(0, index)+"共六种";
                    sixGas =  sixGas.substring(0, index)+"共三种";
                }
            }
        }
src/main/java/com/gkhy/fourierSpecialGasMonitor/schedule/TestSchedule.java
@@ -1,203 +1,203 @@
package com.gkhy.fourierSpecialGasMonitor.schedule;
import com.gkhy.fourierSpecialGasMonitor.controller.DataReceiveController;
import com.gkhy.fourierSpecialGasMonitor.entity.req.DeviceMonitorReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.req.UploadGasConcentrationReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.req.UploadGasFluxReqDTO;
import com.gkhy.fourierSpecialGasMonitor.service.DataReceiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
/**
 * @author Mr.huang
 * @decription
 * @date 2023/8/22 13:49
 */
@Component
public class TestSchedule {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private DataReceiveService dataReceiveService;
    private static final DateTimeFormatter execformatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    //@Scheduled(cron = "1 * * * * ?")
    //@Async(value = "SocketTaskExecutor")
    //public void testDeviceMonitor() {
    //    logger.info("【硬件设备一分钟一次推送测试】:" + LocalDateTime.now().format(execformatter));
    //    DeviceMonitorReqDTO deviceMonitorReqDTO = new DeviceMonitorReqDTO();
    //    deviceMonitorReqDTO.setTime(LocalDateTime.now());
    //    deviceMonitorReqDTO.setConState(0);
    //    deviceMonitorReqDTO.setFluxState(0);
    //    List<Integer> list = new ArrayList<>();
    //    list.add(0);
    //    deviceMonitorReqDTO.setHardwareState(list);
    //    dataReceiveService.deviceMonitor(deviceMonitorReqDTO);
    //}
    //@Scheduled(cron = "0/30 * * * * ?")
    //@Async(value = "SocketTaskExecutor")
    //public void testGasConcentration() {
    //    logger.info("【气体实时浓度推送测试】:"+LocalDateTime.now().format(execformatter));
    //    Random random = new Random();
    //    double randomDouble = random.nextDouble() * 99.9 + 1;  // 生成1到100之间的随机双精度数
    //    DecimalFormat decimalFormat = new DecimalFormat("0.0");
    //    String formattedDouble = decimalFormat.format(randomDouble);
    //    double result = Double.parseDouble(formattedDouble);
    //    UploadGasConcentrationReqDTO dto = new UploadGasConcentrationReqDTO();
    //    dto.setEquipmentId("No-123456");
    //    dto.setTime(LocalDateTime.now());
    //    dto.setType(1);
    //    dto.setLng("东经43");
    //    dto.setLat("北纬53");
    //    dto.setAngle("60");
    //    dto.setTemp(26.9);
    //    dto.setHumidity(63.3);
    //    dto.setWindSpeed(12.3);
    //    dto.setWindDirection(56);
    //    dto.setPressure(200.0);
    //    dto.setGasName01(1);
    //    dto.setGasValue01(result);
    //    dto.setGasName02(2);
    //    dto.setGasValue02(result);
    //    dto.setGasName03(3);
    //    dto.setGasValue03(result);
    //    dto.setGasName04(4);
    //    dto.setGasValue04(result);
    //    dto.setGasName05(5);
    //    dto.setGasValue05(result);
    //    dto.setGasName06(6);
    //    dto.setGasValue06(result);
    //    dto.setGasName07(7);
    //    dto.setGasValue07(result);
    //    dto.setGasName08(8);
    //    dto.setGasValue08(result);
    //    dto.setGasName09(9);
    //    dto.setGasValue09(result);
    //    dto.setGasName10(10);
    //    dto.setGasValue10(result);
    //    dto.setGasName11(11);
    //    dto.setGasValue11(result);
    //    dto.setGasName12(12);
    //    dto.setGasValue12(result);
    //    dto.setGasName13(13);
    //    dto.setGasValue13(result);
    //    dto.setGasName14(14);
    //    dto.setGasValue14(result);
    //    dto.setGasName15(15);
    //    dto.setGasValue15(result);
    //    dto.setGasName16(16);
    //    dto.setGasValue16(result);
    //    dto.setGasName17(17);
    //    dto.setGasValue17(result);
    //    dto.setGasName18(18);
    //    dto.setGasValue18(result);
    //    dto.setGasName19(19);
    //    dto.setGasValue19(result);
    //    dto.setGasName20(20);
    //    dto.setGasValue20(result);
    //    dto.setGasName21(21);
    //    dto.setGasValue21(result);
    //    dto.setGasName22(22);
    //    dto.setGasValue22(result);
    //    dto.setGasName23(23);
    //    dto.setGasValue23(result);
    //    dto.setGasName24(24);
    //    dto.setGasValue24(result);
    //    dto.setGasName25(25);
    //    dto.setGasValue25(result);
    //    dto.setGasName26(26);
    //    dto.setGasValue26(result);
    //    dto.setGasName27(27);
    //    dto.setGasValue27(result);
    //    dto.setGasName28(28);
    //    dto.setGasValue28(result);
    //    dto.setGasName29(29);
    //    dto.setGasValue29(result);
    //    dto.setGasName30(30);
    //    dto.setGasValue30(result);
    //    dataReceiveService.uploadGasConcentration(dto);
    //}
    @Autowired
    private DataReceiveController dataReceiveController;
    @Scheduled(cron = "0/30 * * * * ?")
    //@Scheduled(cron = "0 0/15 * * * ?")
    @Async(value = "SocketTaskExecutor")
    public void testGasFlux() {
        logger.info("【气体通量推送测试】:"+LocalDateTime.now().format(execformatter));
        for (int i = 1; i <= 6 ; i++) {
            Random random = new Random();
            double randomDouble = random.nextDouble() * 99.9 + 1;  // 生成1到100之间的随机双精度数
            DecimalFormat decimalFormat = new DecimalFormat("0.0");
            String formattedDouble = decimalFormat.format(randomDouble);
            double result = Double.parseDouble(formattedDouble);
            UploadGasFluxReqDTO dto = new UploadGasFluxReqDTO();
            dto.setEquipmentId("No-123456");
            dto.setTime(LocalDateTime.now());
            dto.setAreaId(i);
            dto.setType(1);
            dto.setWindSpeed(12.3);
            dto.setWindDirection(56);
            dto.setGasName01(1);
            dto.setGasValue01(result);
            dto.setGasName02(2);
            dto.setGasValue02(result);
            dto.setGasName03(3);
            dto.setGasValue03(result);
            dto.setGasName04(4);
            dto.setGasValue04(result);
            dto.setGasName05(5);
            dto.setGasValue05(result);
            dto.setGasName06(6);
            dto.setGasValue06(result);
            dto.setGasName07(7);
            dto.setGasValue07(result);
            dto.setGasName08(8);
            dto.setGasValue08(result);
            dto.setGasName09(9);
            dto.setGasValue09(result);
            dto.setGasName10(10);
            dto.setGasValue10(result);
            dto.setGasName11(11);
            dto.setGasValue11(result);
            dto.setGasName12(12);
            dto.setGasValue12(result);
            dto.setGasName13(13);
            dto.setGasValue13(result);
            dto.setGasName14(14);
            dto.setGasValue14(result);
            dto.setGasName15(15);
            dto.setGasValue15(result);
            dto.setGasName16(16);
            dto.setGasValue16(result);
            dto.setGasName17(17);
            dto.setGasValue17(result);
            dto.setGasName18(18);
            dto.setGasValue18(result);
            dto.setGasName19(19);
            dto.setGasValue19(result);
            dto.setGasName20(20);
            dto.setGasValue20(result);
            dataReceiveController.uploadGasFlux(dto);
        }
    }
}
//package com.gkhy.fourierSpecialGasMonitor.schedule;
//
//import com.gkhy.fourierSpecialGasMonitor.controller.DataReceiveController;
//import com.gkhy.fourierSpecialGasMonitor.entity.req.DeviceMonitorReqDTO;
//import com.gkhy.fourierSpecialGasMonitor.entity.req.UploadGasConcentrationReqDTO;
//import com.gkhy.fourierSpecialGasMonitor.entity.req.UploadGasFluxReqDTO;
//import com.gkhy.fourierSpecialGasMonitor.service.DataReceiveService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.text.DecimalFormat;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Random;
//import java.util.concurrent.TimeUnit;
//
///**
// * @author Mr.huang
// * @decription
// * @date 2023/8/22 13:49
// */
//@Component
//public class TestSchedule {
//
//    private final Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Autowired
//    private DataReceiveService dataReceiveService;
//
//    private static final DateTimeFormatter execformatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//
//
//    //@Scheduled(cron = "1 * * * * ?")
//    //@Async(value = "SocketTaskExecutor")
//    //public void testDeviceMonitor() {
//    //    logger.info("【硬件设备一分钟一次推送测试】:" + LocalDateTime.now().format(execformatter));
//    //    DeviceMonitorReqDTO deviceMonitorReqDTO = new DeviceMonitorReqDTO();
//    //    deviceMonitorReqDTO.setTime(LocalDateTime.now());
//    //    deviceMonitorReqDTO.setConState(0);
//    //    deviceMonitorReqDTO.setFluxState(0);
//    //    List<Integer> list = new ArrayList<>();
//    //    list.add(0);
//    //    deviceMonitorReqDTO.setHardwareState(list);
//    //    dataReceiveService.deviceMonitor(deviceMonitorReqDTO);
//    //}
//
//
//    //@Scheduled(cron = "0/30 * * * * ?")
//    //@Async(value = "SocketTaskExecutor")
//    //public void testGasConcentration() {
//    //    logger.info("【气体实时浓度推送测试】:"+LocalDateTime.now().format(execformatter));
//    //    Random random = new Random();
//    //    double randomDouble = random.nextDouble() * 99.9 + 1;  // 生成1到100之间的随机双精度数
//    //    DecimalFormat decimalFormat = new DecimalFormat("0.0");
//    //    String formattedDouble = decimalFormat.format(randomDouble);
//    //    double result = Double.parseDouble(formattedDouble);
//    //    UploadGasConcentrationReqDTO dto = new UploadGasConcentrationReqDTO();
//    //    dto.setEquipmentId("No-123456");
//    //    dto.setTime(LocalDateTime.now());
//    //    dto.setType(1);
//    //    dto.setLng("东经43");
//    //    dto.setLat("北纬53");
//    //    dto.setAngle("60");
//    //    dto.setTemp(26.9);
//    //    dto.setHumidity(63.3);
//    //    dto.setWindSpeed(12.3);
//    //    dto.setWindDirection(56);
//    //    dto.setPressure(200.0);
//    //    dto.setGasName01(1);
//    //    dto.setGasValue01(result);
//    //    dto.setGasName02(2);
//    //    dto.setGasValue02(result);
//    //    dto.setGasName03(3);
//    //    dto.setGasValue03(result);
//    //    dto.setGasName04(4);
//    //    dto.setGasValue04(result);
//    //    dto.setGasName05(5);
//    //    dto.setGasValue05(result);
//    //    dto.setGasName06(6);
//    //    dto.setGasValue06(result);
//    //    dto.setGasName07(7);
//    //    dto.setGasValue07(result);
//    //    dto.setGasName08(8);
//    //    dto.setGasValue08(result);
//    //    dto.setGasName09(9);
//    //    dto.setGasValue09(result);
//    //    dto.setGasName10(10);
//    //    dto.setGasValue10(result);
//    //    dto.setGasName11(11);
//    //    dto.setGasValue11(result);
//    //    dto.setGasName12(12);
//    //    dto.setGasValue12(result);
//    //    dto.setGasName13(13);
//    //    dto.setGasValue13(result);
//    //    dto.setGasName14(14);
//    //    dto.setGasValue14(result);
//    //    dto.setGasName15(15);
//    //    dto.setGasValue15(result);
//    //    dto.setGasName16(16);
//    //    dto.setGasValue16(result);
//    //    dto.setGasName17(17);
//    //    dto.setGasValue17(result);
//    //    dto.setGasName18(18);
//    //    dto.setGasValue18(result);
//    //    dto.setGasName19(19);
//    //    dto.setGasValue19(result);
//    //    dto.setGasName20(20);
//    //    dto.setGasValue20(result);
//    //    dto.setGasName21(21);
//    //    dto.setGasValue21(result);
//    //    dto.setGasName22(22);
//    //    dto.setGasValue22(result);
//    //    dto.setGasName23(23);
//    //    dto.setGasValue23(result);
//    //    dto.setGasName24(24);
//    //    dto.setGasValue24(result);
//    //    dto.setGasName25(25);
//    //    dto.setGasValue25(result);
//    //    dto.setGasName26(26);
//    //    dto.setGasValue26(result);
//    //    dto.setGasName27(27);
//    //    dto.setGasValue27(result);
//    //    dto.setGasName28(28);
//    //    dto.setGasValue28(result);
//    //    dto.setGasName29(29);
//    //    dto.setGasValue29(result);
//    //    dto.setGasName30(30);
//    //    dto.setGasValue30(result);
//    //    dataReceiveService.uploadGasConcentration(dto);
//    //}
//
//    @Autowired
//    private DataReceiveController dataReceiveController;
//
//    @Scheduled(cron = "0/30 * * * * ?")
//    //@Scheduled(cron = "0 0/15 * * * ?")
//    @Async(value = "SocketTaskExecutor")
//    public void testGasFlux() {
//        logger.info("【气体通量推送测试】:"+LocalDateTime.now().format(execformatter));
//        for (int i = 1; i <= 6 ; i++) {
//            Random random = new Random();
//            double randomDouble = random.nextDouble() * 99.9 + 1;  // 生成1到100之间的随机双精度数
//            DecimalFormat decimalFormat = new DecimalFormat("0.0");
//            String formattedDouble = decimalFormat.format(randomDouble);
//            double result = Double.parseDouble(formattedDouble);
//            UploadGasFluxReqDTO dto = new UploadGasFluxReqDTO();
//            dto.setEquipmentId("No-123456");
//            dto.setTime(LocalDateTime.now());
//            dto.setAreaId(i);
//            dto.setType(1);
//            dto.setWindSpeed(12.3);
//            dto.setWindDirection(56);
//            dto.setGasName01(1);
//            dto.setGasValue01(result);
//            dto.setGasName02(2);
//            dto.setGasValue02(result);
//            dto.setGasName03(3);
//            dto.setGasValue03(result);
//            dto.setGasName04(4);
//            dto.setGasValue04(result);
//            dto.setGasName05(5);
//            dto.setGasValue05(result);
//            dto.setGasName06(6);
//            dto.setGasValue06(result);
//            dto.setGasName07(7);
//            dto.setGasValue07(result);
//            dto.setGasName08(8);
//            dto.setGasValue08(result);
//            dto.setGasName09(9);
//            dto.setGasValue09(result);
//            dto.setGasName10(10);
//            dto.setGasValue10(result);
//            dto.setGasName11(11);
//            dto.setGasValue11(result);
//            dto.setGasName12(12);
//            dto.setGasValue12(result);
//            dto.setGasName13(13);
//            dto.setGasValue13(result);
//            dto.setGasName14(14);
//            dto.setGasValue14(result);
//            dto.setGasName15(15);
//            dto.setGasValue15(result);
//            dto.setGasName16(16);
//            dto.setGasValue16(result);
//            dto.setGasName17(17);
//            dto.setGasValue17(result);
//            dto.setGasName18(18);
//            dto.setGasValue18(result);
//            dto.setGasName19(19);
//            dto.setGasValue19(result);
//            dto.setGasName20(20);
//            dto.setGasValue20(result);
//            dataReceiveController.uploadGasFlux(dto);
//        }
//    }
//}
src/main/resources/template/dailyReportTemplate.docx
Binary files differ