From b267036e505d752accca9aea0cc29fec48e1da25 Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Fri, 27 Mar 2020 16:32:55 +0800
Subject: [PATCH] 任务拆分

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

diff --git a/src/main/java/com/moral/task/HistoryTableInsertTask.java b/src/main/java/com/moral/task/HistoryTableInsertTask.java
index 8225048..d325e38 100644
--- a/src/main/java/com/moral/task/HistoryTableInsertTask.java
+++ b/src/main/java/com/moral/task/HistoryTableInsertTask.java
@@ -17,6 +17,7 @@
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.moral.service.DeviceService;
@@ -71,6 +72,392 @@
                     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();
+        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.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("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")) {
@@ -156,6 +543,131 @@
         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));
+                                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("historyDaily")
     public ReturnT insertHistoryDailyTable(String params) {
         LocalDateTime time = LocalDateTime.now();
@@ -211,4 +723,128 @@
         ReturnT returnT = new ReturnT(500, "������������������");
         return returnT;
     }
+
+    @XxlJob("historyMinutelyDelay")
+    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();
+        String monthStr = month < 10 ? ("0" + month) : month + "";
+        String yearAndMonth = year + monthStr;
+        LocalDateTime value = time.truncatedTo(ChronoUnit.MINUTES);
+        LocalDateTime startTime = value.minusMinutes(31);
+        LocalDateTime endTime = value.minusMinutes(30);
+        List<String> sensorKeys = sensorService.getSensorKeys();
+        Map<String, Object> devices = new HashMap<>();
+        devices.put("sensorKeys", sensorKeys);
+        devices.put("macList", macList);
+        devices.put("start", startTime);
+        devices.put("end", endTime);
+        try {
+            List<Map<String, Object>> minutelyData = deviceService.getSensorDataByMac(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("historyMinutelyDelayEleven")
+    public ReturnT insertHistoryMinutelyTableDelayEleven(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();
+        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;
+    }
+
 }

--
Gitblit v1.8.0