From 2ef66767cc7c0eca9cff04893fc735b0435086bd Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 02 Dec 2020 13:09:16 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/task/RabbitMQInsertTask.java | 549 +++++++-----------------------------------------------
1 files changed, 70 insertions(+), 479 deletions(-)
diff --git a/src/main/java/com/moral/task/RabbitMQInsertTask.java b/src/main/java/com/moral/task/RabbitMQInsertTask.java
index c87ce5b..6ee61ff 100644
--- a/src/main/java/com/moral/task/RabbitMQInsertTask.java
+++ b/src/main/java/com/moral/task/RabbitMQInsertTask.java
@@ -3,15 +3,12 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
+import com.moral.util.AlarmUtils_2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.TopicExchange;
@@ -66,6 +63,19 @@
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 == 0) {
+ 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 +137,19 @@
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 == 0) {
+ 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 +211,19 @@
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 == 0) {
+ 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);
@@ -269,6 +305,35 @@
List<Map<String, Object>> hourlyDataList = historyHourlyService.getHourlySensorData(devices);
XxlJobLogger.log("RabbitMQHourlyData:" + hourlyDataList.size());
if (!CollectionUtils.isEmpty(hourlyDataList)) {
+ if(!(hourlyDataList.size()==macList.size())){
+ List<String> macList_copy = macList;
+ if (hourlyDataList.size()<macList.size()){
+ for (Map hourData: hourlyDataList) {
+ for (int k=0;k<macList_copy.size();k++){
+ if (hourData.get("mac").equals(macList_copy.get(k))){
+ macList_copy.remove(k);
+ }
+ }
+ }
+ }
+ List<String> ignoreMacList = new ArrayList();
+ ignoreMacList.add("p5dnd7a0392130");
+ for (String ignoreMac:ignoreMacList) {
+ for (int d=0;d<macList_copy.size();d++){
+ if (macList_copy.get(d).equals(ignoreMac)){
+ macList_copy.remove(d);
+ }
+ }
+ }
+ if (macList_copy.size()!=0){
+ List<Map<String, Object>> deviceList = deviceService.getAllByMacList(macList_copy);
+ List<String> de = new ArrayList<>();
+ for (Map deviceMap:deviceList) {
+ de.add(deviceMap.get("name").toString());
+ }
+ AlarmUtils_2.sendMail("276999030@qq.com,1vv_zkk6ji3kln@dingtalk.com,liumiao_love@126.com","������������",de.toString()+"���������������������");
+ }
+ }
for (Map<String, Object> deviceData : hourlyDataList) {
if (!ObjectUtils.isEmpty(deviceData)) {
Map<String, Object> hourlyData = new LinkedHashMap<>();
@@ -359,480 +424,6 @@
return returnT;
}
- @XxlJob("RabbitMQRealtimeMinutelySixHours")
- public ReturnT insertRabbitMQRealtimeMinutelySixHours(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;
- Map organizationIdMap = JSON.parseObject(params);
- List<Integer> parentIdList = (List<Integer>) organizationIdMap.get("orgId");
- LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
- List<Object> organizationIdList = organizationRelationService.getChildIdByParentId(parentIdList);
- try {
- List<String> macList = deviceService.getMacByOrganizationid(organizationIdList);
- List<String> sensorKeys = sensorService.getSensorKeyByMac(macList);
- List<Map<String, Object>> macAndOrganizationIdMap = deviceService.macAndOrganizationIdMap(macList);
- Map<String, Object> kv = new LinkedHashMap<>();
- 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);
- Map<String, Object> devices = new HashMap<>();
- devices.put("sensorKeys", sensorKeys);
- devices.put("start", startTime);
- devices.put("end", endTime);
- devices.put("macs", macList);
- devices.put("yearAndMonth", yearAndMonth);
- List<Map<String, Object>> realtimeData = historyMinutelyService.getMinutelySensorData(devices);
- count += realtimeData.size();
- if (!CollectionUtils.isEmpty(realtimeData)) {
- for (Map<String, Object> deviceData : realtimeData) {
- if (!ObjectUtils.isEmpty(deviceData)) {
- Iterator<String> iterator = deviceData.keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- if (key.startsWith("M")) {
- iterator.remove();
- }
- }
- deviceData.put("time", startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- deviceData.put("timeType", "realtime");
- String mac = deviceData.get("mac").toString();
- Object o1 = kv.get(mac);
- List<Integer> parentIds = organizationRelationService.getParentIdListByChildId((Integer) o1);
- Map organizationIdMapNew = JSON.parseObject(params);
- List<Integer> parentIdListNew = (List<Integer>) organizationIdMapNew.get("orgId");
- List<Integer> intersection = parentIdListNew.stream().filter(item -> parentIds.contains(item)).collect(Collectors.toList());
- intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(deviceData)));
- }
- }
-
- }
- }
- XxlJobLogger.log("RabbitMQRealtimeMinutelyData:" + count);
- ReturnT returnT = new ReturnT(200, "RabbitMQ������������������������������");
- return returnT;
- } catch (Exception e) {
- XxlJobLogger.log("RabbitMQRealtimeMinutelyException:" + e.getMessage());
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- ReturnT returnT = new ReturnT(500, "RabbitMQ������������������������������");
- return returnT;
- }
-
- @XxlJob("RabbitMQRealtimeMinutelyZero")
- public ReturnT insertRabbitMQRealtimeMinutelyZero(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;
- Map organizationIdMap = JSON.parseObject(params);
- List<Integer> parentIdList = (List<Integer>) organizationIdMap.get("orgId");
- LocalDateTime endTime = time.truncatedTo(ChronoUnit.DAYS);
- LocalDateTime startTime = endTime.minusMinutes(1);
- List<Object> organizationIdList = organizationRelationService.getChildIdByParentId(parentIdList);
- try {
- List<String> macList = deviceService.getMacByOrganizationid(organizationIdList);
- List<String> sensorKeys = sensorService.getSensorKeyByMac(macList);
- List<Map<String, Object>> macAndOrganizationIdMap = deviceService.macAndOrganizationIdMap(macList);
- Map<String, Object> kv = new LinkedHashMap<>();
- for (Map<String, Object> map : macAndOrganizationIdMap) {
- kv.put(map.get("mac").toString(), map.get("organizationId"));
- }
- Map<String, Object> devices = new HashMap<>();
- devices.put("sensorKeys", sensorKeys);
- devices.put("start", startTime);
- devices.put("end", endTime);
- devices.put("macs", macList);
- devices.put("yearAndMonth", yearAndMonth);
- List<Map<String, Object>> realtimeData = historyMinutelyService.getMinutelySensorData(devices);
- XxlJobLogger.log("RabbitMQRealtimeMinutelyData:" + realtimeData.size());
- if (!CollectionUtils.isEmpty(realtimeData)) {
- for (Map<String, Object> deviceData : realtimeData) {
- if (!ObjectUtils.isEmpty(deviceData)) {
- Iterator<String> iterator = deviceData.keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- if (key.startsWith("M")) {
- iterator.remove();
- }
- }
- deviceData.put("time", startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- deviceData.put("timeType", "realtime");
- String mac = deviceData.get("mac").toString();
- Object o1 = kv.get(mac);
- List<Integer> parentIds = organizationRelationService.getParentIdListByChildId((Integer) o1);
- Map organizationIdMapNew = JSON.parseObject(params);
- List<Integer> parentIdListNew = (List<Integer>) organizationIdMapNew.get("orgId");
- List<Integer> intersection = parentIdListNew.stream().filter(item -> parentIds.contains(item)).collect(Collectors.toList());
- intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(deviceData)));
- }
- }
- ReturnT returnT = new ReturnT(200, "RabbitMQ������������������������������");
- return returnT;
- }
- } catch (Exception e) {
- XxlJobLogger.log("RabbitMQRealtimeMinutelyException:" + e.getMessage());
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- ReturnT returnT = new ReturnT(500, "RabbitMQ������������������������������");
- return returnT;
- }
-
- @XxlJob("RabbitMQRealtimeEveryFiveMinutesSixHours")
- public ReturnT insertRabbitMQRealtimeEveryFiveMinutesSixHours(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;
- Map organizationIdMap = JSON.parseObject(params);
- List<Integer> parentIdList = (List<Integer>) organizationIdMap.get("orgId");
- LocalDateTime value = time.truncatedTo(ChronoUnit.DAYS);
- List<Object> organizationIdList = organizationRelationService.getChildIdByParentId(parentIdList);
- try {
- List<String> macList = deviceService.getMacByOrganizationid(organizationIdList);
- List<String> sensorKeys = sensorService.getSensorKeyByMac(macList);
- List<Map<String, Object>> macAndOrganizationIdMap = deviceService.macAndOrganizationIdMap(macList);
- Map<String, Object> kv = new LinkedHashMap<>();
- 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);
- Map<String, Object> devices = new HashMap<>();
- devices.put("sensorKeys", sensorKeys);
- devices.put("start", startTime);
- devices.put("end", endTime);
- devices.put("macs", macList);
- devices.put("yearAndMonth", yearAndMonth);
- List<Map<String, Object>> realtimeData = historyMinutelyService.getMinutelySensorData(devices);
- count += realtimeData.size();
- if (!CollectionUtils.isEmpty(realtimeData)) {
- for (Map<String, Object> deviceData : realtimeData) {
- if (!ObjectUtils.isEmpty(deviceData)) {
- Iterator<String> iterator = deviceData.keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- if (key.startsWith("M")) {
- iterator.remove();
- }
- }
- deviceData.put("time", startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- deviceData.put("timeType", "realtime");
- String mac = deviceData.get("mac").toString();
- Object o1 = kv.get(mac);
- List<Integer> parentIds = organizationRelationService.getParentIdListByChildId((Integer) o1);
- Map organizationIdMapNew = JSON.parseObject(params);
- List<Integer> parentIdListNew = (List<Integer>) organizationIdMapNew.get("orgId");
- List<Integer> intersection = parentIdListNew.stream().filter(item -> parentIds.contains(item)).collect(Collectors.toList());
- intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(deviceData)));
- }
- }
- }
- }
- 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());
- e.printStackTrace();
- }
- ReturnT returnT = new ReturnT(500, "RabbitMQ���5������������������������������");
- return returnT;
- }
-
- @XxlJob("RabbitMQRealtimeEveryFiveMinutesZero")
- public ReturnT insertRabbitMQRealtimeEveryFiveMinutesZero(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;
- Map organizationIdMap = JSON.parseObject(params);
- List<Integer> parentIdList = (List<Integer>) organizationIdMap.get("orgId");
- LocalDateTime endTime = time.truncatedTo(ChronoUnit.DAYS);
- LocalDateTime startTime = endTime.minusMinutes(5);
- List<Object> organizationIdList = organizationRelationService.getChildIdByParentId(parentIdList);
- try {
- List<String> macList = deviceService.getMacByOrganizationid(organizationIdList);
- List<String> sensorKeys = sensorService.getSensorKeyByMac(macList);
- List<Map<String, Object>> macAndOrganizationIdMap = deviceService.macAndOrganizationIdMap(macList);
- Map<String, Object> kv = new LinkedHashMap<>();
- for (Map<String, Object> map : macAndOrganizationIdMap) {
- kv.put(map.get("mac").toString(), map.get("organizationId"));
- }
- Map<String, Object> devices = new HashMap<>();
- devices.put("sensorKeys", sensorKeys);
- devices.put("start", startTime);
- devices.put("end", endTime);
- devices.put("macs", macList);
- devices.put("yearAndMonth", yearAndMonth);
- List<Map<String, Object>> realtimeData = historyMinutelyService.getMinutelySensorData(devices);
- XxlJobLogger.log("RabbitMQRealtimeEveryFiveMinutesData:" + realtimeData.size());
- if (!CollectionUtils.isEmpty(realtimeData)) {
- for (Map<String, Object> deviceData : realtimeData) {
- if (!ObjectUtils.isEmpty(deviceData)) {
- Iterator<String> iterator = deviceData.keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- if (key.startsWith("M")) {
- iterator.remove();
- }
- }
- deviceData.put("time", startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- deviceData.put("timeType", "realtime");
- String mac = deviceData.get("mac").toString();
- Object o1 = kv.get(mac);
- List<Integer> parentIds = organizationRelationService.getParentIdListByChildId((Integer) o1);
- Map organizationIdMapNew = JSON.parseObject(params);
- List<Integer> parentIdListNew = (List<Integer>) organizationIdMapNew.get("orgId");
- List<Integer> intersection = parentIdListNew.stream().filter(item -> parentIds.contains(item)).collect(Collectors.toList());
- intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(deviceData)));
- }
- }
- ReturnT returnT = new ReturnT(200, "RabbitMQ���5������������������������������");
- return returnT;
- }
- } catch (Exception e) {
- XxlJobLogger.log("RabbitMQRealtimeEveryFiveMinutesException:" + e.getMessage());
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- ReturnT returnT = new ReturnT(500, "RabbitMQ���5������������������������������");
- return returnT;
- }
-
- @XxlJob("RabbitMQMinutelySixHours")
- public ReturnT insertRabbitMQMinutelySixHours(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;
- Map organizationIdMap = JSON.parseObject(params);
- List<Integer> parentIdList = (List<Integer>) organizationIdMap.get("orgId");
- LocalDateTime zeroClock = time.truncatedTo(ChronoUnit.DAYS);
- LocalDateTime value = zeroClock.plusMinutes(9);
- List<Object> organizationIdList = organizationRelationService.getChildIdByParentId(parentIdList);
- try {
- List<String> macList = deviceService.getMacByOrganizationid(organizationIdList);
- List<String> sensorKeys = sensorService.getSensorKeyByMac(macList);
- List<Map<String, Object>> macAndOrganizationIdMap = deviceService.macAndOrganizationIdMap(macList);
- Map<String, Object> kv = new LinkedHashMap<>();
- 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);
- Map<String, Object> devices = new HashMap<>();
- devices.put("sensorKeys", sensorKeys);
- devices.put("start", startTime);
- devices.put("end", endTime);
- devices.put("macs", macList);
- devices.put("yearAndMonth", yearAndMonth);
- List<Map<String, Object>> minutelyDataList = historyMinutelyService.getMinutelySensorData(devices);
- count += minutelyDataList.size();
- if (!CollectionUtils.isEmpty(minutelyDataList)) {
- for (Map<String, Object> deviceData : minutelyDataList) {
- if (!ObjectUtils.isEmpty(deviceData)) {
- Map<String, Object> minutelyData = new LinkedHashMap<>();
- minutelyData.put("mac", deviceData.get("mac"));
- minutelyData.put("time", startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- minutelyData.put("timeType", "minutely");
- for (String key : deviceData.keySet()) {
- if (!key.equals("mac") && !key.startsWith("M")) {
- String date = deviceData.get(key).toString() + "," + deviceData.get("MIN" + key).toString() + "," + deviceData.get("MAX" + key).toString();
- minutelyData.put(key, date);
- }
- }
- String mac = minutelyData.get("mac").toString();
- Object o1 = kv.get(mac);
- List<Integer> parentIds = organizationRelationService.getParentIdListByChildId((Integer) o1);
- Map organizationIdMapNew = JSON.parseObject(params);
- List<Integer> parentIdListNew = (List<Integer>) organizationIdMapNew.get("orgId");
- List<Integer> intersection = parentIdListNew.stream().filter(item -> parentIds.contains(item)).collect(Collectors.toList());
- intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(minutelyData)));
- }
- }
- }
- }
- XxlJobLogger.log("RabbitMQMinutelyData:" + count);
- ReturnT returnT = new ReturnT(200, "RabbitMQ������������������������");
- return returnT;
- } catch (Exception e) {
- XxlJobLogger.log("RabbitMQMinutelyException:" + e.getMessage());
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- ReturnT returnT = new ReturnT(500, "RabbitMQ������������������������");
- return returnT;
- }
-
- @XxlJob("RabbitMQMinutelyZero")
- public ReturnT insertRabbitMQMinutelyZero(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;
- Map organizationIdMap = JSON.parseObject(params);
- List<Integer> parentIdList = (List<Integer>) organizationIdMap.get("orgId");
- LocalDateTime endTime = time.truncatedTo(ChronoUnit.DAYS);
- LocalDateTime startTime = endTime.minusMinutes(1);
- List<Object> organizationIdList = organizationRelationService.getChildIdByParentId(parentIdList);
- try {
- List<String> macList = deviceService.getMacByOrganizationid(organizationIdList);
- List<String> sensorKeys = sensorService.getSensorKeyByMac(macList);
- List<Map<String, Object>> macAndOrganizationIdMap = deviceService.macAndOrganizationIdMap(macList);
- Map<String, Object> kv = new LinkedHashMap<>();
- for (Map<String, Object> map : macAndOrganizationIdMap) {
- kv.put(map.get("mac").toString(), map.get("organizationId"));
- }
- Map<String, Object> devices = new HashMap<>();
- devices.put("sensorKeys", sensorKeys);
- devices.put("start", startTime);
- devices.put("end", endTime);
- devices.put("macs", macList);
- devices.put("yearAndMonth", yearAndMonth);
- List<Map<String, Object>> minutelyDataList = historyMinutelyService.getMinutelySensorData(devices);
- XxlJobLogger.log("RabbitMQMinutelyData:" + minutelyDataList.size());
- if (!CollectionUtils.isEmpty(minutelyDataList)) {
- for (Map<String, Object> deviceData : minutelyDataList) {
- if (!ObjectUtils.isEmpty(deviceData)) {
- Map<String, Object> minutelyData = new LinkedHashMap<>();
- minutelyData.put("mac", deviceData.get("mac"));
- minutelyData.put("time", startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- minutelyData.put("timeType", "minutely");
- for (String key : deviceData.keySet()) {
- if (!key.equals("mac") && !key.startsWith("M")) {
- String date = deviceData.get(key).toString() + "," + deviceData.get("MIN" + key).toString() + "," + deviceData.get("MAX" + key).toString();
- minutelyData.put(key, date);
- }
- }
- String mac = minutelyData.get("mac").toString();
- Object o1 = kv.get(mac);
- List<Integer> parentIds = organizationRelationService.getParentIdListByChildId((Integer) o1);
- Map organizationIdMapNew = JSON.parseObject(params);
- List<Integer> parentIdListNew = (List<Integer>) organizationIdMapNew.get("orgId");
- List<Integer> intersection = parentIdListNew.stream().filter(item -> parentIds.contains(item)).collect(Collectors.toList());
- intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(minutelyData)));
- }
- }
- ReturnT returnT = new ReturnT(200, "RabbitMQ������������������������");
- return returnT;
- }
- } catch (Exception e) {
- XxlJobLogger.log("RabbitMQMinutelyException:" + e.getMessage());
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- ReturnT returnT = new ReturnT(500, "RabbitMQ������������������������");
- return returnT;
- }
-
- @XxlJob("RabbitMQHourlySixHours")
- public ReturnT insertRabbitMQHourlySixHours(String params) {
- LocalDateTime time = LocalDateTime.now();
- Map organizationIdMap = JSON.parseObject(params);
- List<Integer> parentIdList = (List<Integer>) organizationIdMap.get("orgId");
- LocalDateTime zeroClock = time.truncatedTo(ChronoUnit.DAYS);
- LocalDateTime value = zeroClock.minusHours(1);
- List<Object> organizationIdList = organizationRelationService.getChildIdByParentId(parentIdList);
- try {
- List<String> macList = deviceService.getMacByOrganizationid(organizationIdList);
- List<String> sensorKeys = sensorService.getSensorKeyByMac(macList);
- List<Map<String, Object>> macAndOrganizationIdMap = deviceService.macAndOrganizationIdMap(macList);
- Map<String, Object> kv = new LinkedHashMap<>();
- 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);
- Map<String, Object> devices = new HashMap<>();
- devices.put("sensorKeys", sensorKeys);
- devices.put("start", startTime);
- devices.put("end", endTime);
- devices.put("macs", macList);
- List<Map<String, Object>> hourlyDataList = historyHourlyService.getHourlySensorData(devices);
- count += hourlyDataList.size();
- if (!CollectionUtils.isEmpty(hourlyDataList)) {
- for (Map<String, Object> deviceData : hourlyDataList) {
- if (!ObjectUtils.isEmpty(deviceData)) {
- Map<String, Object> hourlyData = new LinkedHashMap<>();
- hourlyData.put("mac", deviceData.get("mac"));
- hourlyData.put("time", startTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
- hourlyData.put("timeType", "hourly");
- for (String key : deviceData.keySet()) {
- if (!key.equals("mac") && !key.startsWith("M")) {
- String date = deviceData.get(key).toString() + "," + deviceData.get("MIN" + key).toString() + "," + deviceData.get("MAX" + key).toString();
- hourlyData.put(key, date);
- }
- }
- String mac = hourlyData.get("mac").toString();
- Object o1 = kv.get(mac);
- List<Integer> parentIds = organizationRelationService.getParentIdListByChildId((Integer) o1);
- Map organizationIdMapNew = JSON.parseObject(params);
- List<Integer> parentIdListNew = (List<Integer>) organizationIdMapNew.get("orgId");
- List<Integer> intersection = parentIdListNew.stream().filter(item -> parentIds.contains(item)).collect(Collectors.toList());
- intersection.stream().forEach(parentId -> rabbitTemplate.convertAndSend(organization_data.getName(), parentId + "." + mac, JSON.toJSONString(hourlyData)));
- }
- }
- }
- }
- XxlJobLogger.log("RabbitMQHourlyData:" + count);
- ReturnT returnT = new ReturnT(200, "RabbitMQ������������������������");
- return returnT;
- } catch (Exception e) {
- XxlJobLogger.log("RabbitMQHourlyException:" + e.getMessage());
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- ReturnT returnT = new ReturnT(500, "RabbitMQ������������������������");
- return returnT;
- }
}
--
Gitblit v1.8.0