src/main/java/com/moral/mapper/HistoryMapper.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/DeviceService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/DeviceServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/task/HistoryTableInsertTask.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/task/RabbitMQInsertTask.java | ●●●●● patch | view | raw | blame | history | |
src/main/resources/mapper/HistoryMapper.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/mapper/HistoryMapper.java
@@ -16,6 +16,8 @@ List<Map<String, Object>> getSensorData(Map<String,Object> parameters); List<Map<String, Object>> getSensorDataByMac(Map<String,Object> parameters); List<Map<String, Object>> getSensorDataOnce(Map<String,Object> parameters); Map<String, Object> getMinData(Map<String,Object> parameters); src/main/java/com/moral/service/DeviceService.java
@@ -7,6 +7,10 @@ List<Map<String, Object>> getSensorData(Map<String, Object> parameters); List<Map<String, Object>> getSensorDataOnce(Map<String, Object> parameters); List<Map<String, Object>> getSensorDataByMac(Map<String, Object> parameters); List<String> getMacs(); List<String> getMacByOrganizationid(List<Object> organizationIdList); src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -28,6 +28,16 @@ } @Override public List<Map<String, Object>> getSensorDataOnce(Map<String, Object> parameters) { return historyMapper.getSensorDataOnce(parameters); } @Override public List<Map<String, Object>> getSensorDataByMac(Map<String, Object> parameters) { return historyMapper.getSensorDataByMac(parameters); } @Override public List<String> getMacs() { return deviceMapper.getMacs(); } 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; } } src/main/java/com/moral/task/RabbitMQInsertTask.java
@@ -358,4 +358,472 @@ ReturnT returnT = new ReturnT(500, "RabbitMQ天数据存入失败"); 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")); } 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); 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("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")); } 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); 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("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")); } 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); 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("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")); } 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); XxlJobLogger.log("RabbitMQHourlyData:" + 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))); } } 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; } } src/main/resources/mapper/HistoryMapper.xml
@@ -99,6 +99,27 @@ h.mac </select> <select id="getSensorDataByMac" resultType="java.util.LinkedHashMap"> SELECT h.mac, <foreach collection="sensorKeys" separator="," item="sensorKey"> AVG(value->'$.${sensorKey}') AS '${sensorKey}', MAX(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MAX${sensorKey}', MIN(cast(h.value ->'$.${sensorKey}' as decimal(11,3))) AS 'MIN${sensorKey}' </foreach> FROM history h WHERE h.time >= #{start} AND h.time <![CDATA[<]]> #{end} and h.mac in <foreach collection="macList" index="index" item="mac" open="(" separator="," close=")"> #{mac} </foreach> group by h.mac </select> <select id="getSensorDataOnce" resultType="java.util.LinkedHashMap"> SELECT h.mac,DATE_FORMAT(time,'%Y-%m-%dT%H:%i') time,