From a4f62703a87ff7669cf4f6bf2c58f9b78d2eef3d Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Fri, 15 May 2020 13:31:47 +0800
Subject: [PATCH] add预测计算臭氧

---
 src/main/java/com/moral/task/HistoryTableInsertTask.java |  752 +++++++++++++--------------------------------------------
 1 files changed, 180 insertions(+), 572 deletions(-)

diff --git a/src/main/java/com/moral/task/HistoryTableInsertTask.java b/src/main/java/com/moral/task/HistoryTableInsertTask.java
index d325e38..c77ba4c 100644
--- a/src/main/java/com/moral/task/HistoryTableInsertTask.java
+++ b/src/main/java/com/moral/task/HistoryTableInsertTask.java
@@ -4,6 +4,7 @@
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -20,11 +21,15 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.moral.entity.Organization;
 import com.moral.service.DeviceService;
 import com.moral.service.HistoryDailyService;
 import com.moral.service.HistoryHourlyService;
 import com.moral.service.HistoryMinutelyService;
+import com.moral.service.HistoryService;
+import com.moral.service.OrganizationService;
 import com.moral.service.SensorService;
+import com.moral.util.WeatherUtil;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import com.xxl.job.core.log.XxlJobLogger;
@@ -40,6 +45,9 @@
     private DeviceService deviceService;
 
     @Resource
+    private HistoryService historyService;
+
+    @Resource
     private HistoryMinutelyService historyMinutelyService;
 
     @Resource
@@ -48,71 +56,29 @@
     @Resource
     private HistoryDailyService historyDailyService;
 
+    @Resource
+    private OrganizationService organizationService;
+
+    @Resource
+    private WeatherUtil weatherUtil;
+
+
     @XxlJob("historyMinutely")
     public ReturnT insertHistoryMinutelyTable(String params) {
         LocalDateTime time = LocalDateTime.now();
         int year = time.getYear();
         int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime endTime = time.truncatedTo(ChronoUnit.MINUTES);
-        LocalDateTime startTime = endTime.minusMinutes(1);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorData(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", startTime);
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyMinutelyZero")
-    public ReturnT insertHistoryMinutelyTableZero(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
         int day = time.getDayOfMonth();
+        int hour = time.getHour();
+        int minute = time.getMinute();
         if (day == 1) {
-            if (month == 1) {
-                month = 12;
-                year = year - 1;
-            } else {
-                month = month - 1;
+            if (hour == 0 && minute == 0) {
+                if (month == 1) {
+                    month = 12;
+                    year = year - 1;
+                } else {
+                    month = month - 1;
+                }
             }
         }
         String monthStr = month < 10 ? ("0" + month) : month + "";
@@ -134,330 +100,6 @@
                     JSONObject jo = new JSONObject(true);
                     minutelyDataMap.put("mac", deviceData.get("mac"));
                     minutelyDataMap.put("time", startTime);
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyMinutelyOne")
-    public ReturnT insertHistoryMinutelyTableOne(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime startTime = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime endTime = startTime.plusHours(1);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", deviceData.get("time"));
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyMinutelyTwo")
-    public ReturnT insertHistoryMinutelyTableTwo(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTime = value.plusHours(1);
-        LocalDateTime endTime = value.plusHours(2);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", deviceData.get("time"));
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyMinutelyThree")
-    public ReturnT insertHistoryMinutelyTableThree(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTime = value.plusHours(2);
-        LocalDateTime endTime = value.plusHours(3);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", deviceData.get("time"));
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyMinutelyFour")
-    public ReturnT insertHistoryMinutelyTableFour(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTime = value.plusHours(3);
-        LocalDateTime endTime = value.plusHours(4);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", deviceData.get("time"));
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyMinutelyFive")
-    public ReturnT insertHistoryMinutelyTableFive(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTime = value.plusHours(4);
-        LocalDateTime endTime = value.plusHours(5);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", deviceData.get("time"));
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyMinutelySix")
-    public ReturnT insertHistoryMinutelyTableSix(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTime = value.plusHours(5);
-        LocalDateTime SixOclock = value.plusHours(6);
-        LocalDateTime endTime = SixOclock.minusMinutes(1);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", deviceData.get("time"));
                     JSONArray jsonArray = new JSONArray();
                     for (String key : deviceData.keySet()) {
                         if (!key.equals("mac") && !key.startsWith("M")) {
@@ -492,6 +134,18 @@
         LocalDateTime time = LocalDateTime.now();
         int year = time.getYear();
         int month = time.getMonthValue();
+        int day = time.getDayOfMonth();
+        int hour = time.getHour();
+        if (day == 1) {
+            if (hour == 0) {
+                if (month == 1) {
+                    month = 12;
+                    year = year - 1;
+                } else {
+                    month = month - 1;
+                }
+            }
+        }
         String monthStr = month < 10 ? ("0" + month) : month + "";
         String yearAndMonth = year + monthStr;
         LocalDateTime endTime = time.truncatedTo(ChronoUnit.HOURS);
@@ -519,154 +173,34 @@
                         if (!key.equals("mac") && !key.startsWith("M")) {
                             List<Object> date = new ArrayList<>();
                             date.add(deviceData.get(key));
-                            date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
-                            date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    hourlyDataMap.put("json", jsonArray.get(0).toString());
-                    hourlyDataList.add(hourlyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(hourlyDataList)) {
-                historyHourlyService.insertHistoryHourly(hourlyDataList);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyHourlyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyHourlyZero")
-    public ReturnT insertHistoryHourlyTableZero(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        int day = time.getDayOfMonth();
-        if (day == 1) {
-            if (month == 1) {
-                month = 12;
-                year = year - 1;
-            } else {
-                month = month - 1;
-            }
-        }
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime endTime = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTime = endTime.minusHours(1);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        List<String> macs = deviceService.getMacs();
-        Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
-        devices.put("macs", macs);
-        devices.put("yearAndMonth", yearAndMonth);
-        try {
-            List<Map<String, Object>> hourlyData = historyMinutelyService.getMinutelySensorData(devices);
-            XxlJobLogger.log("historyHourlyData:" + hourlyData.size());
-            List<Map<String, Object>> hourlyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : hourlyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> hourlyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    hourlyDataMap.put("mac", deviceData.get("mac"));
-                    hourlyDataMap.put("time", startTime);
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
-                            date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    hourlyDataMap.put("json", jsonArray.get(0).toString());
-                    hourlyDataList.add(hourlyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(hourlyDataList)) {
-                historyHourlyService.insertHistoryHourly(hourlyDataList);
-                ReturnT returnT = new ReturnT(200, "���������������������");
-                return returnT;
-            }
-        } catch (Exception e) {
-            XxlJobLogger.log("historyHourlyException:" + e.getMessage());
-            logger.error(e.getMessage());
-            e.printStackTrace();
-        }
-        ReturnT returnT = new ReturnT(500, "���������������������");
-        return returnT;
-    }
-
-    @XxlJob("historyHourlyEveryHour")
-    public ReturnT insertHistoryHourlyTableEveryHour(String params) {
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
-        List<String> sensorKeys = sensorService.getSensorKeys();
-        List<String> macs = deviceService.getMacs();
-        for (int i = 0; i <= 5; i++) {
-            LocalDateTime startTime = value.plusHours(i);
-            LocalDateTime endTime = value.plusHours(i + 1);
-            Map<String, Object> devices = new HashMap<>();
-            devices.put("sensorKeys", sensorKeys);
-            devices.put("start", startTime);
-            devices.put("end", endTime);
-            devices.put("macs", macs);
-            devices.put("yearAndMonth", yearAndMonth);
-            try {
-                List<Map<String, Object>> hourlyData = historyMinutelyService.getMinutelySensorData(devices);
-                XxlJobLogger.log("historyHourlyData:" + hourlyData.size());
-                List<Map<String, Object>> hourlyDataList = new ArrayList<>();
-                for (Map<String, Object> deviceData : hourlyData) {
-                    if (!ObjectUtils.isEmpty(deviceData)) {
-                        Map<String, Object> hourlyDataMap = new LinkedHashMap<>();
-                        JSONObject jo = new JSONObject(true);
-                        hourlyDataMap.put("mac", deviceData.get("mac"));
-                        hourlyDataMap.put("time", startTime);
-                        JSONArray jsonArray = new JSONArray();
-                        for (String key : deviceData.keySet()) {
-                            if (!key.equals("mac") && !key.startsWith("M")) {
-                                List<Object> date = new ArrayList<>();
-                                date.add(deviceData.get(key));
+                            if (deviceData.get("MIN" + key) instanceof String) {
                                 date.add(new BigDecimal(deviceData.get("MIN" + key).toString()));
                                 date.add(new BigDecimal(deviceData.get("MAX" + key).toString()));
-                                jo.put(key, date);
+                            } else if (deviceData.get("MIN" + key) instanceof byte[]) {
+                                date.add(new BigDecimal(new String((byte[]) (deviceData.get("MIN" + key)))));
+                                date.add(new BigDecimal(new String((byte[]) (deviceData.get("MAX" + key)))));
                             }
+                            jo.put(key, date);
                         }
-                        jsonArray.add(jo);
-                        hourlyDataMap.put("json", jsonArray.get(0).toString());
-                        hourlyDataList.add(hourlyDataMap);
                     }
+                    jsonArray.add(jo);
+                    hourlyDataMap.put("json", jsonArray.get(0).toString());
+                    hourlyDataList.add(hourlyDataMap);
                 }
-                if (!CollectionUtils.isEmpty(hourlyDataList)) {
-                    historyHourlyService.insertHistoryHourly(hourlyDataList);
-                    ReturnT returnT = new ReturnT(200, "���������������������");
-                    return returnT;
-                }
-            } catch (Exception e) {
-                XxlJobLogger.log("historyHourlyException:" + e.getMessage());
-                logger.error(e.getMessage());
-                e.printStackTrace();
             }
+            if (!CollectionUtils.isEmpty(hourlyDataList)) {
+                historyHourlyService.insertHistoryHourly(hourlyDataList);
+                ReturnT returnT = new ReturnT(200, "���������������������");
+                return returnT;
+            }
+        } catch (Exception e) {
+            XxlJobLogger.log("historyHourlyException:" + e.getMessage());
+            logger.error(e.getMessage());
+            e.printStackTrace();
         }
         ReturnT returnT = new ReturnT(500, "���������������������");
         return returnT;
     }
-
 
     @XxlJob("historyDaily")
     public ReturnT insertHistoryDailyTable(String params) {
@@ -728,10 +262,22 @@
     public ReturnT insertHistoryMinutelyTableDelay(String params) {
         Map macMap = JSON.parseObject(params);
         List<String> macList = (List<String>) macMap.get("mac");
-        System.out.println("macList:" + macList);
         LocalDateTime time = LocalDateTime.now();
         int year = time.getYear();
         int month = time.getMonthValue();
+        int day = time.getDayOfMonth();
+        int hour = time.getHour();
+        int minute = time.getMinute();
+        if (day == 1) {
+            if (hour == 0 && minute <= 30) {
+                if (month == 1) {
+                    month = 12;
+                    year = year - 1;
+                } else {
+                    month = month - 1;
+                }
+            }
+        }
         String monthStr = month < 10 ? ("0" + month) : month + "";
         String yearAndMonth = year + monthStr;
         LocalDateTime value = time.truncatedTo(ChronoUnit.MINUTES);
@@ -782,68 +328,130 @@
         return returnT;
     }
 
-    @XxlJob("historyMinutelyDelayEleven")
-    public ReturnT insertHistoryMinutelyTableDelayEleven(String params) {
+    @XxlJob("historySpecial")
+    public ReturnT insertHistorySpecialTable(String params) {
         Map macMap = JSON.parseObject(params);
         List<String> macList = (List<String>) macMap.get("mac");
-        System.out.println("macList:" + macList);
-        LocalDateTime time = LocalDateTime.now();
-        int year = time.getYear();
-        int month = time.getMonthValue();
-        int day = time.getDayOfMonth();
-        if (day == 1) {
-            if (month == 1) {
-                month = 12;
-                year = year - 1;
-            } else {
-                month = month - 1;
-            }
-        }
-        String monthStr = month < 10 ? ("0" + month) : month + "";
-        String yearAndMonth = year + monthStr;
-        LocalDateTime endTime = time.truncatedTo(ChronoUnit.DAYS);
-        LocalDateTime startTime = endTime.minusMinutes(31);
-        List<String> sensorKeys = sensorService.getSensorKeys();
+        LocalDateTime value = LocalDateTime.now();
         Map<String, Object> devices = new HashMap<>();
-        devices.put("sensorKeys", sensorKeys);
-        devices.put("start", startTime);
-        devices.put("end", endTime);
+        devices.put("macList", macList);
+        devices.put("time", value);
         try {
-            List<Map<String, Object>> minutelyData = deviceService.getSensorDataOnce(devices);
-            XxlJobLogger.log("historyMinutelyData:" + minutelyData.size());
-            List<Map<String, Object>> minutelyDataList = new ArrayList<>();
-            for (Map<String, Object> deviceData : minutelyData) {
-                if (!ObjectUtils.isEmpty(deviceData)) {
-                    Map<String, Object> minutelyDataMap = new LinkedHashMap<>();
-                    JSONObject jo = new JSONObject(true);
-                    minutelyDataMap.put("mac", deviceData.get("mac"));
-                    minutelyDataMap.put("time", deviceData.get("time"));
-                    JSONArray jsonArray = new JSONArray();
-                    for (String key : deviceData.keySet()) {
-                        if (!key.equals("mac") && !key.startsWith("M")) {
-                            List<Object> date = new ArrayList<>();
-                            date.add(deviceData.get(key));
-                            date.add(deviceData.get("MIN" + key));
-                            date.add(deviceData.get("MAX" + key));
-                            jo.put(key, date);
-                        }
-                    }
-                    jsonArray.add(jo);
-                    minutelyDataMap.put("json", jsonArray.get(0).toString());
-                    minutelyDataList.add(minutelyDataMap);
-                }
-            }
-            if (!CollectionUtils.isEmpty(minutelyDataList)) {
-                historyMinutelyService.insertHistoryMinutely(minutelyDataList, yearAndMonth);
-                ReturnT returnT = new ReturnT(200, "���������������������");
+            int count = historyService.insertHistorySpecialTable(devices);
+            XxlJobLogger.log("insertHistorySpecialTable:" + count);
+            if (count > 0) {
+                ReturnT returnT = new ReturnT(200, "������historySpecial���������");
                 return returnT;
             }
         } catch (Exception e) {
-            XxlJobLogger.log("historyMinutelyException:" + e.getMessage());
+            XxlJobLogger.log("insertHistorySpecialTableException:" + e.getMessage());
             logger.error(e.getMessage());
             e.printStackTrace();
         }
-        ReturnT returnT = new ReturnT(500, "���������������������");
+        ReturnT returnT = new ReturnT(500, "������historySpecial���������");
+        return returnT;
+    }
+
+    @XxlJob("historyO3")
+    public ReturnT insertHistoryO3Table(String params) {
+        Map macMap = JSON.parseObject(params);
+        List<String> macList = (List<String>) macMap.get("mac");
+        String temperatureRatio = macMap.get("temperatureRatio").toString();
+        String illuminationRatio = macMap.get("illuminationRatio").toString();
+        String pressureRatio1 = macMap.get("pressureRatio1").toString();
+        String pressureRatio2 = macMap.get("pressureRatio2").toString();
+        String humidityRatio = macMap.get("humidityRatio").toString();
+        String windSpeedRatio = macMap.get("windSpeedRatio").toString();
+        LocalDateTime time = LocalDateTime.now();
+        LocalDateTime value = time.truncatedTo(ChronoUnit.HOURS);
+        LocalDateTime illuminationTime = value.minusHours(1);
+        LocalDateTime temperatureTime = value.minusHours(2);
+        LocalDateTime predictionTime = value.plusHours(2);
+        Integer predictionHour = predictionTime.getHour();
+        Map<String, Object> devices = new HashMap<>();
+        devices.put("sensorKeys", Arrays.asList("e7", "e12"));
+        devices.put("macList", macList);
+        devices.put("time", illuminationTime);
+        List<Map<String, Object>> hourlyIlluminationData = historyHourlyService.getHourlySensorDataToCalculateO3(devices);
+        XxlJobLogger.log("insertHistoryO3Table-IlluminationDataCount:" + hourlyIlluminationData.size());
+        devices.put("time", temperatureTime);
+        List<Map<String, Object>> hourlytemperatureData = historyHourlyService.getHourlySensorDataToCalculateO3(devices);
+        XxlJobLogger.log("insertHistoryO3Table-temperatureDataCount:" + hourlytemperatureData.size());
+        List<Map<String, Object>> hourlyDataList = new ArrayList<>();
+        BigDecimal temperature;
+        BigDecimal illumination;
+        BigDecimal pressure = new BigDecimal("0");
+        BigDecimal humidity = new BigDecimal("0");
+        BigDecimal windSpeed = new BigDecimal("0");
+        try {
+            for (Map<String, Object> IlluminationData : hourlyIlluminationData) {
+                if (!ObjectUtils.isEmpty(IlluminationData)) {
+                    Map<String, Object> hourlyDataMap = new LinkedHashMap<>();
+                    hourlyDataMap.put("mac", IlluminationData.get("mac"));
+                    hourlyDataMap.put("time", predictionTime);
+                    Organization organizationInfoByMac = organizationService.getOrganizationInfoByMac(IlluminationData.get("mac").toString());
+                    Map<String, Object> parameters = new HashMap<>();
+                    parameters.put("mac", IlluminationData.get("mac"));
+                    parameters.put("villageCode", organizationInfoByMac.getVillageCode());
+                    parameters.put("townCode", organizationInfoByMac.getTownCode());
+                    parameters.put("areaCode", organizationInfoByMac.getAreaCode());
+                    parameters.put("cityCode", organizationInfoByMac.getCityCode());
+                    parameters.put("provinceCode", organizationInfoByMac.getProvinceCode());
+                    List<Map<String, Object>> weatherByMac = weatherUtil.getWeatherByMac(parameters);
+                    for (Map<String, Object> stringObjectMap : weatherByMac) {
+                        Integer mjHour = Integer.valueOf(stringObjectMap.get("hour").toString());
+                        if (predictionHour == mjHour) {
+                            pressure = new BigDecimal(stringObjectMap.get("pressure").toString());
+                            humidity = new BigDecimal(stringObjectMap.get("humidity").toString());
+                            windSpeed = new BigDecimal(stringObjectMap.get("windSpeed").toString());
+                        }
+                    }
+                    JSONObject jo = new JSONObject(true);
+                    JSONArray jsonArray = new JSONArray();
+                    for (Map<String, Object> temperatureData : hourlytemperatureData) {
+                        if (!ObjectUtils.isEmpty(temperatureData)) {
+                            if (IlluminationData.get("mac").equals(temperatureData.get("mac"))) {
+                                if (temperatureData.get("e7") != null) {
+                                    temperature = new BigDecimal(temperatureData.get("e7").toString());
+                                } else {
+                                    temperature = new BigDecimal("0");
+                                }
+                                if (temperatureData.get("e12") != null) {
+                                    illumination = new BigDecimal(IlluminationData.get("e12").toString());
+                                } else {
+                                    illumination = new BigDecimal("0");
+                                }
+                                BigDecimal bignum1 = temperature.multiply(new BigDecimal(temperatureRatio));
+                                BigDecimal bignum2 = illumination.divide(new BigDecimal(illuminationRatio));
+                                BigDecimal bignum3 = new BigDecimal(pressureRatio1).divide(pressure.subtract(new BigDecimal(pressureRatio2)), 4, BigDecimal.ROUND_HALF_UP);
+                                BigDecimal bignum4 = humidity.multiply(new BigDecimal(humidityRatio));
+                                BigDecimal bignum5 = windSpeed.multiply(new BigDecimal(windSpeedRatio));
+                                BigDecimal result = bignum1.add(bignum2).add(bignum3).subtract(bignum4).subtract(bignum5).setScale(4, BigDecimal.ROUND_HALF_UP);
+                                jo.put("e15", result);
+                                jo.put("e6", humidity);
+                                jo.put("e7", temperature);
+                                jo.put("e12", illumination);
+                                jo.put("e18", windSpeed);
+                                jo.put("e28", pressure);
+                            }
+                        }
+                    }
+                    jsonArray.add(jo);
+                    hourlyDataMap.put("json", jsonArray.get(0).toString());
+                    hourlyDataList.add(hourlyDataMap);
+                }
+            }
+            if (!CollectionUtils.isEmpty(hourlyDataList)) {
+                historyHourlyService.insertHistoryO3Hourly(hourlyDataList);
+                ReturnT returnT = new ReturnT(200, "������������������");
+                return returnT;
+            }
+        } catch (Exception e) {
+            XxlJobLogger.log("insertHistoryO3TableException:" + e.getMessage());
+            logger.error(e.getMessage());
+            e.printStackTrace();
+        }
+        ReturnT returnT = new ReturnT(500, "������������������");
         return returnT;
     }
 

--
Gitblit v1.8.0