ZhuDongming
2020-04-02 0188e1e69bbbd794af99cba71496e25aba18ed98
src/main/java/com/moral/task/RabbitMQInsertTask.java
@@ -66,6 +66,15 @@
        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;
        Map organizationIdMap = JSON.parseObject(params);
@@ -127,6 +136,15 @@
        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;
        Map organizationIdMap = JSON.parseObject(params);
@@ -188,6 +206,15 @@
        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;
        Map organizationIdMap = JSON.parseObject(params);
@@ -378,6 +405,7 @@
            for (Map<String, Object> map : macAndOrganizationIdMap) {
                kv.put(map.get("mac").toString(), map.get("organizationId"));
            }
            int count = 0;
            for (int i = 0; i <= 358; i++) {
                LocalDateTime startTime = value.plusMinutes(i);
                LocalDateTime endTime = value.plusMinutes(i + 1);
@@ -388,7 +416,7 @@
                devices.put("macs", macList);
                devices.put("yearAndMonth", yearAndMonth);
                List<Map<String, Object>> realtimeData = historyMinutelyService.getMinutelySensorData(devices);
                XxlJobLogger.log("RabbitMQRealtimeMinutelyData:" + realtimeData.size());
                count += realtimeData.size();
                if (!CollectionUtils.isEmpty(realtimeData)) {
                    for (Map<String, Object> deviceData : realtimeData) {
                        if (!ObjectUtils.isEmpty(deviceData)) {
@@ -410,10 +438,12 @@
                            intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(deviceData)));
                        }
                    }
                    ReturnT returnT = new ReturnT(200, "RabbitMQ分钟实时数据存入成功");
                    return returnT;
                }
            }
            XxlJobLogger.log("RabbitMQRealtimeMinutelyData:" + count);
            ReturnT returnT = new ReturnT(200, "RabbitMQ分钟实时数据存入成功");
            return returnT;
        } catch (Exception e) {
            XxlJobLogger.log("RabbitMQRealtimeMinutelyException:" + e.getMessage());
            logger.error(e.getMessage());
@@ -512,6 +542,7 @@
            for (Map<String, Object> map : macAndOrganizationIdMap) {
                kv.put(map.get("mac").toString(), map.get("organizationId"));
            }
            int count = 0;
            for (int i = 0; i <= 350; i = i + 5) {
                LocalDateTime startTime = value.plusMinutes(i);
                LocalDateTime endTime = value.plusMinutes(i + 5);
@@ -522,7 +553,7 @@
                devices.put("macs", macList);
                devices.put("yearAndMonth", yearAndMonth);
                List<Map<String, Object>> realtimeData = historyMinutelyService.getMinutelySensorData(devices);
                XxlJobLogger.log("RabbitMQRealtimeEveryFiveMinutesData:" + realtimeData.size());
                count += realtimeData.size();
                if (!CollectionUtils.isEmpty(realtimeData)) {
                    for (Map<String, Object> deviceData : realtimeData) {
                        if (!ObjectUtils.isEmpty(deviceData)) {
@@ -544,10 +575,11 @@
                            intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(deviceData)));
                        }
                    }
                    ReturnT returnT = new ReturnT(200, "RabbitMQ每5分钟实时数据存入成功");
                    return returnT;
                }
            }
            XxlJobLogger.log("RabbitMQRealtimeEveryFiveMinutesData:" + count);
            ReturnT returnT = new ReturnT(200, "RabbitMQ每5分钟实时数据存入成功");
            return returnT;
        } catch (Exception e) {
            XxlJobLogger.log("RabbitMQRealtimeEveryFiveMinutesException:" + e.getMessage());
            logger.error(e.getMessage());
@@ -647,6 +679,7 @@
            for (Map<String, Object> map : macAndOrganizationIdMap) {
                kv.put(map.get("mac").toString(), map.get("organizationId"));
            }
            int count = 0;
            for (int i = 0; i <= 340; i = i + 10) {
                LocalDateTime startTime = value.plusMinutes(i);
                LocalDateTime endTime = value.plusMinutes(i + 1);
@@ -657,7 +690,7 @@
                devices.put("macs", macList);
                devices.put("yearAndMonth", yearAndMonth);
                List<Map<String, Object>> minutelyDataList = historyMinutelyService.getMinutelySensorData(devices);
                XxlJobLogger.log("RabbitMQMinutelyData:" + minutelyDataList.size());
                count += minutelyDataList.size();
                if (!CollectionUtils.isEmpty(minutelyDataList)) {
                    for (Map<String, Object> deviceData : minutelyDataList) {
                        if (!ObjectUtils.isEmpty(deviceData)) {
@@ -680,10 +713,11 @@
                            intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(minutelyData)));
                        }
                    }
                    ReturnT returnT = new ReturnT(200, "RabbitMQ分钟数据存入成功");
                    return returnT;
                }
            }
            XxlJobLogger.log("RabbitMQMinutelyData:" + count);
            ReturnT returnT = new ReturnT(200, "RabbitMQ分钟数据存入成功");
            return returnT;
        } catch (Exception e) {
            XxlJobLogger.log("RabbitMQMinutelyException:" + e.getMessage());
            logger.error(e.getMessage());
@@ -780,6 +814,7 @@
            for (Map<String, Object> map : macAndOrganizationIdMap) {
                kv.put(map.get("mac").toString(), map.get("organizationId"));
            }
            int count = 0;
            for (int i = 0; i <= 6; i++) {
                LocalDateTime startTime = value.plusHours(i);
                LocalDateTime endTime = value.plusHours(i + 1);
@@ -789,7 +824,7 @@
                devices.put("end", endTime);
                devices.put("macs", macList);
                List<Map<String, Object>> hourlyDataList = historyHourlyService.getHourlySensorData(devices);
                XxlJobLogger.log("RabbitMQHourlyData:" + hourlyDataList.size());
                count += hourlyDataList.size();
                if (!CollectionUtils.isEmpty(hourlyDataList)) {
                    for (Map<String, Object> deviceData : hourlyDataList) {
                        if (!ObjectUtils.isEmpty(deviceData)) {
@@ -812,10 +847,11 @@
                            intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(hourlyData)));
                        }
                    }
                    ReturnT returnT = new ReturnT(200, "RabbitMQ小时数据存入成功");
                    return returnT;
                }
            }
            XxlJobLogger.log("RabbitMQHourlyData:" + count);
            ReturnT returnT = new ReturnT(200, "RabbitMQ小时数据存入成功");
            return returnT;
        } catch (Exception e) {
            XxlJobLogger.log("RabbitMQHourlyException:" + e.getMessage());
            logger.error(e.getMessage());