From 4d7d1d0844b60c28c6c6c55635e3d68b009248bc Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Wed, 29 Apr 2020 09:48:00 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/controller/ScreenController.java | 277 +++++-----
src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java | 1176 +++++++++++++++++++++++-----------------------
2 files changed, 729 insertions(+), 724 deletions(-)
diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java
index e9183f9..829aabe 100644
--- a/src/main/java/com/moral/controller/ScreenController.java
+++ b/src/main/java/com/moral/controller/ScreenController.java
@@ -823,139 +823,139 @@
return new ResultBean<List<Map<String, Object>>>(list);
}
- @GetMapping("report_avg_AreaData")
- @ApiOperation(value = "������������������������������������������", notes = "������������������������������������������")
- @ApiImplicitParams(value = {
- @ApiImplicitParam(name = "monitorPoint", value = "���������id", required = true, paramType = "query", dataType = "String"),
- @ApiImplicitParam(name = "mac", value = "������mac", required = false, paramType = "query", dataType = "String"),
- @ApiImplicitParam(name = "areaCode", value = "������������", required = true, paramType = "query", dataType = "String"),
- @ApiImplicitParam(name = "sensorKey", value = "���������key", required = true, paramType = "query", dataType = "String"),
- @ApiImplicitParam(name = "time", value = "������,������(���������2018-03)", required = true, paramType = "query", dataType = "String"),})
- public ResultBean<List<Map<String, Object>>> getAreaAvgDataByAreaCode(HttpServletRequest request)
- throws Exception {
- Map<String, Object> parameters = getParametersStartingWith(request, null);
- ParameterUtils.getTimeType4Time(parameters);
- parameters.put("monitorPointId", parameters.remove("monitorPoint"));
- parameters.put("areaCode", parameters.remove("areaCode"));
- String[] sensorKeys = parameters.remove("sensorKey").toString().split(",");
- String s=sensorKeys[0];
- parameters.put("sensors", Arrays.asList(sensorKeys));
- parameters.put("sensors2", s);
- List<Map<String, Object>> monitorList = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
- for (Map<String, Object> monitorMap : monitorList) {
- String time = monitorMap.get("time").toString();
- time = time.substring(time.length() - 2);
- monitorMap.put("time", Integer.valueOf(time));
- }
- Integer maxTime = 0;
- Integer max1 = 0;
- if (monitorList.size() != 0) {
- Map<String, Object> monitorMap = monitorList.get(monitorList.size() - 1);
- max1 = Integer.valueOf(monitorMap.get("time").toString());
- } else {
- max1 = 0;
- }
- String sensorKey1 = s;
- switch (s) {
- case "e1":
- sensorKey1 = "PM2_5";
- break;
- case "e2":
- sensorKey1 = "PM10";
- break;
- case "e10":
- sensorKey1 = "CO";
- break;
- case "e11":
- sensorKey1 = "SO2";
- break;
- case "e15":
- sensorKey1 = "O3";
- break;
- case "e16":
- sensorKey1 = "NO2";
- break;
- default:
- break;
- }
-
- parameters.put("sensors1", sensorKey1);
-
- List<Map<String, Object>> areaList = historyMinutelyService.getAreaAvgDataByAreaCode(parameters);
- if (areaList.isEmpty()) {
- Integer areaCode = Integer.valueOf(request.getParameter("areaCode"));
- areaCode = hangzhouAqiService.queryCityCode(areaCode);
- parameters.remove("areaCode");
- parameters.put("areaCode", String.valueOf(areaCode));
- areaList = historyMinutelyService.getAreaAvgDataByAreaCode(parameters);
- }
-
- for (Map<String, Object> areaMap : areaList) {
- String time = areaMap.get("time").toString();
- time = time.substring(time.length() - 2);
- areaMap.put("time", Integer.valueOf(time));
- }
-
- Integer max = 0;
- if (areaList.size() != 0) {
- Map<String, Object> areaMap = areaList.get(areaList.size() - 1);
- max = Integer.valueOf(areaMap.get("time").toString());
- } else {
- max = 0;
- }
-
- if (max1 >= max) {
- maxTime = max1;
- } else {
- maxTime = max;
- }
-
- ArrayList<Map<String, Object>> resultList = new ArrayList<>();
-
- for (int i = 0; i <= maxTime; i++) {
- resultList.add(null);
- }
-
- for (Map<String, Object> areaMap : areaList) {
- Integer time = Integer.valueOf(areaMap.get("time").toString());
- resultList.set(time, areaMap);
- }
-
- for (Map<String, Object> resultMap : resultList) {
- for (Map<String, Object> monitorMap : monitorList) {
- ArrayList<String> values = new ArrayList<>();
- String monitorTime = monitorMap.get("time").toString();
- if (resultMap != null) {
- String resultTime = resultMap.get("time").toString();
- if (resultTime.equals(monitorTime)) {
- String value = resultMap.remove(s).toString();
- String value1 = monitorMap.remove(s).toString();
- values.add(value);
- values.add(value1);
- resultMap.put("values", values);
- }
- } else {
- String value1 = monitorMap.get(s).toString();
- values.add(null);
- values.add(value1);
+ @GetMapping("report_avg_AreaData")
+ @ApiOperation(value = "������������������������������������������", notes = "������������������������������������������")
+ @ApiImplicitParams(value = {
+ @ApiImplicitParam(name = "monitorPoint", value = "���������id", required = true, paramType = "query", dataType = "String"),
+ @ApiImplicitParam(name = "mac", value = "������mac", required = false, paramType = "query", dataType = "String"),
+ @ApiImplicitParam(name = "areaCode", value = "������������", required = true, paramType = "query", dataType = "String"),
+ @ApiImplicitParam(name = "sensorKey", value = "���������key", required = true, paramType = "query", dataType = "String"),
+ @ApiImplicitParam(name = "time", value = "������,������(���������2018-03)", required = true, paramType = "query", dataType = "String"),})
+ public ResultBean<List<Map<String, Object>>> getAreaAvgDataByAreaCode(HttpServletRequest request)
+ throws Exception {
+ Map<String, Object> parameters = getParametersStartingWith(request, null);
+ ParameterUtils.getTimeType4Time(parameters);
+ parameters.put("monitorPointId", parameters.remove("monitorPoint"));
+ parameters.put("areaCode", parameters.remove("areaCode"));
+ String[] sensorKeys = parameters.remove("sensorKey").toString().split(",");
+ String s = sensorKeys[0];
+ parameters.put("sensors", Arrays.asList(sensorKeys));
+ parameters.put("sensors2", s);
+ List<Map<String, Object>> monitorList = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters);
+ for (Map<String, Object> monitorMap : monitorList) {
+ String time = monitorMap.get("time").toString();
+ time = time.substring(time.length() - 2);
+ monitorMap.put("time", Integer.valueOf(time));
}
- }
+ Integer maxTime = 0;
+ Integer max1 = 0;
+ if (monitorList.size() != 0) {
+ Map<String, Object> monitorMap = monitorList.get(monitorList.size() - 1);
+ max1 = Integer.valueOf(monitorMap.get("time").toString());
+ } else {
+ max1 = 0;
+ }
+ String sensorKey1 = s;
+ switch (s) {
+ case "e1":
+ sensorKey1 = "PM2_5";
+ break;
+ case "e2":
+ sensorKey1 = "PM10";
+ break;
+ case "e10":
+ sensorKey1 = "CO";
+ break;
+ case "e11":
+ sensorKey1 = "SO2";
+ break;
+ case "e15":
+ sensorKey1 = "O3";
+ break;
+ case "e16":
+ sensorKey1 = "NO2";
+ break;
+ default:
+ break;
+ }
+
+ parameters.put("sensors1", sensorKey1);
+
+ List<Map<String, Object>> areaList = historyMinutelyService.getAreaAvgDataByAreaCode(parameters);
+ if (areaList.isEmpty()) {
+ Integer areaCode = Integer.valueOf(request.getParameter("areaCode"));
+ areaCode = hangzhouAqiService.queryCityCode(areaCode);
+ parameters.remove("areaCode");
+ parameters.put("areaCode", String.valueOf(areaCode));
+ areaList = historyMinutelyService.getAreaAvgDataByAreaCode(parameters);
+ }
+
+ for (Map<String, Object> areaMap : areaList) {
+ String time = areaMap.get("time").toString();
+ time = time.substring(time.length() - 2);
+ areaMap.put("time", Integer.valueOf(time));
+ }
+
+ Integer max = 0;
+ if (areaList.size() != 0) {
+ Map<String, Object> areaMap = areaList.get(areaList.size() - 1);
+ max = Integer.valueOf(areaMap.get("time").toString());
+ } else {
+ max = 0;
+ }
+
+ if (max1 >= max) {
+ maxTime = max1;
+ } else {
+ maxTime = max;
+ }
+
+ ArrayList<Map<String, Object>> resultList = new ArrayList<>();
+
+ for (int i = 0; i <= maxTime; i++) {
+ resultList.add(null);
+ }
+
+ for (Map<String, Object> areaMap : areaList) {
+ Integer time = Integer.valueOf(areaMap.get("time").toString());
+ resultList.set(time, areaMap);
+ }
+
+ for (Map<String, Object> resultMap : resultList) {
+ for (Map<String, Object> monitorMap : monitorList) {
+ ArrayList<String> values = new ArrayList<>();
+ String monitorTime = monitorMap.get("time").toString();
+ if (resultMap != null) {
+ String resultTime = resultMap.get("time").toString();
+ if (resultTime.equals(monitorTime)) {
+ String value = resultMap.remove(s).toString();
+ String value1 = monitorMap.remove(s).toString();
+ values.add(value);
+ values.add(value1);
+ resultMap.put("values", values);
+ }
+ } else {
+ String value1 = monitorMap.get(s).toString();
+ values.add(null);
+ values.add(value1);
+ }
+ }
+ }
+
+ resultList.removeAll(Collections.singleton(null));
+
+ for (Map<String, Object> resultMap : resultList) {
+ if (resultMap.containsKey(s)) {
+ ArrayList<String> values = new ArrayList<>();
+ values.add(resultMap.remove(s).toString());
+ values.add(null);
+ resultMap.put("values", values);
+ }
+ }
+
+ return new ResultBean<List<Map<String, Object>>>(resultList);
+
}
-
- resultList.removeAll(Collections.singleton(null));
-
- for (Map<String, Object> resultMap : resultList) {
- if (resultMap.containsKey(s)) {
- ArrayList<String> values = new ArrayList<>();
- values.add(resultMap.remove(s).toString());
- values.add(null);
- resultMap.put("values", values);
- }
- }
-
- return new ResultBean<List<Map<String, Object>>>(resultList);
-
- }
@GetMapping("getmpoint-byid")
@ApiOperation(value = "���������������������", notes = "���������������������,���������������������������������������������")
@@ -1342,7 +1342,12 @@
String et = parameters.get("endTime").toString();
String endYearAndDay = et.substring(0, et.lastIndexOf("-"));
String endHour = et.substring(et.lastIndexOf("-") + 1);
- String endTime = endYearAndDay + " " + endHour + ":00:00";
+ int endHourValue = Integer.valueOf(endHour);
+ int startHourValue = Integer.valueOf(startHour);
+ if (endHourValue <= startHourValue) {
+ endHourValue = startHourValue + 1;
+ }
+ String endTime = startYearAndDay + " " + endHourValue + ":00:00";
parameters.put("startTime", startTime);
parameters.put("endTime", endTime);
String mac = parameters.get("mac").toString();
@@ -1475,10 +1480,10 @@
String startTime = startYearAndDay + " " + startHour + ":00:00";
String et = parameters.get("endTime").toString();
String endHour = et.substring(et.lastIndexOf("-") + 1);
- int endHourValue =Integer.valueOf(endHour);
- int startHourValue =Integer.valueOf(startHour);
- if(endHourValue<=startHourValue){
- endHourValue=23;
+ int endHourValue = Integer.valueOf(endHour);
+ int startHourValue = Integer.valueOf(startHour);
+ if (endHourValue <= startHourValue) {
+ endHourValue = startHourValue + 1;
}
String endTime = startYearAndDay + " " + endHourValue + ":00:00";
parameters.put("startTime", startTime);
diff --git a/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java
index 21f7b13..d5f11cb 100644
--- a/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java
@@ -59,390 +59,390 @@
@SuppressWarnings({"unchecked", "unused", "rawtypes"})
public class HistoryMinutelyServiceImpl implements HistoryMinutelyService {
- @Resource
- private HistoryMinutelyMapper historyMinutelyMapper;
+ @Resource
+ private HistoryMinutelyMapper historyMinutelyMapper;
- @Resource
- private HistoryMapper historyMapper;
+ @Resource
+ private HistoryMapper historyMapper;
- @Resource
- private DeviceMapper deviceMapper;
+ @Resource
+ private DeviceMapper deviceMapper;
- @Resource
- private SensorMapper sensorMapper;
+ @Resource
+ private SensorMapper sensorMapper;
- @Resource
- private AlarmDailyMapper alarmDailyMapper;
+ @Resource
+ private AlarmDailyMapper alarmDailyMapper;
- @Override
- public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) {
- //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
- LocalDate time = LocalDate.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;
- // ������00:00:00
- parameters.put("start", time.minusDays(1));
-
- // ������00:00:00
- parameters.put("end", time);
- parameters.put("yearAndMonth", yearAndMonth);
- parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
- Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
- return getAQIByDataMap(average);
- }
-
- @Override
- public Map<String, Object> getHourAQIByDevice(Map<String, Object> parameters) {
- //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
- LocalDate localDate = LocalDate.now();
- // ������00:00:00
- //parameters.put("start", localDate.minusDays(1));
-
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(new Date());
- calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1);
- int hour = calendar.get(Calendar.HOUR) - 1;
-
- // ������00:00:00
- parameters.put("end", localDate);
- parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
- Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
- return getAQIByDataMap(average);
- }
-
- private Map<String, Object> getAQIByDataMap(Map<String, Double> average) {
- Map<String, Object> resultMap = new HashMap<String, Object>();
- if (isEmpty(average)) {
- resultMap.put("AQI", "N/V");
- } else {
- String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
- Set<Double> IAQIs = new HashSet<Double>();
- for (Map.Entry<String, Double> entry : average.entrySet()) {
- double minMacKey = 0, maxMacKey = 0, minIAQI = 0, maxIAQI = 0;
- String[] macKeyValues = ResourceUtil.getArrValue(entry.getKey());
- Double avg = entry.getValue();
- if (isEmpty(avg)) {
- IAQIs.add(null);
- } else {
- int index = -1;
- for (int i = 0; i < macKeyValues.length; i++) {
- if (avg <= Double.valueOf(macKeyValues[i])) {
- if (i == 0) {
- index = i;
- } else {
- index = i - 1;
- }
- break;
+ @Override
+ public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) {
+ //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
+ LocalDate time = LocalDate.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;
}
- }
- if (index == -1) {
- IAQIs.add(Double.MAX_VALUE);
- } else {
- minMacKey = Double.valueOf(macKeyValues[index]);
- maxMacKey = Double.valueOf(macKeyValues[index + 1]);
- minIAQI = Double.valueOf(IAQIValues[index]);
- maxIAQI = Double.valueOf(IAQIValues[index + 1]);
- Double result = CalculateUtils.calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg);
- IAQIs.add(result);
- }
}
- }
- IAQIs.remove(null);
- if (isEmpty(IAQIs)) {
- resultMap.put("AQI", "N/V");
- } else {
- Double AQI = Collections.max(IAQIs);
- if (AQI == Double.MAX_VALUE) {
- resultMap.put("AQI", IAQIValues[IAQIValues.length - 1]);
+ String monthStr = month < 10 ? ("0" + month) : month + "";
+ String yearAndMonth = year + monthStr;
+ // ������00:00:00
+ parameters.put("start", time.minusDays(1));
+
+ // ������00:00:00
+ parameters.put("end", time);
+ parameters.put("yearAndMonth", yearAndMonth);
+ parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
+ Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
+ return getAQIByDataMap(average);
+ }
+
+ @Override
+ public Map<String, Object> getHourAQIByDevice(Map<String, Object> parameters) {
+ //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
+ LocalDate localDate = LocalDate.now();
+ // ������00:00:00
+ //parameters.put("start", localDate.minusDays(1));
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(new Date());
+ calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1);
+ int hour = calendar.get(Calendar.HOUR) - 1;
+
+ // ������00:00:00
+ parameters.put("end", localDate);
+ parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
+ Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
+ return getAQIByDataMap(average);
+ }
+
+ private Map<String, Object> getAQIByDataMap(Map<String, Double> average) {
+ Map<String, Object> resultMap = new HashMap<String, Object>();
+ if (isEmpty(average)) {
+ resultMap.put("AQI", "N/V");
} else {
- resultMap.put("AQI", String.format("%.0f", AQI));
- }
- }
- }
- return resultMap;
- }
-
- @Override
- public Map<String, List> getCompareReport(Map<String, Object> parameters) throws Exception {
- Map<String, List> resultMap = new HashMap<String, List>();
- List<Map<String, Object>> list = JSON.parseObject((String) parameters.remove("items"), new TypeReference<List<Map<String, Object>>>() {
- });
-
- String type = (String) parameters.get("type");
- // parameters.putAll(getElementByType(type));
- ParameterUtils.getElementByType(parameters);
- Integer timeLength = Integer.valueOf(parameters.remove("timeLength").toString());
- if ("month".equals(type)) {
- for (Map<String, Object> map : list) {
- String[] formatTime = map.get("formatTime").toString().split("-");
- LocalDate localDate = LocalDate.of(Integer.valueOf(formatTime[0]), Integer.valueOf(formatTime[1]), 1);
- int lengthOfMonth = localDate.lengthOfMonth();
- if (lengthOfMonth > timeLength) {
- timeLength = lengthOfMonth;
- }
- }
- }
-
- List<Object> timeList = new ArrayList<Object>();
- for (int i = 0; i < timeLength; i++) {
- timeList.add(String.format("%02d", "day".equals(type) || "hour".equals(type) ? i : i + 1));
- }
- parameters.put("timeList", timeList);
-
- ExecutorService threadPool = Executors.newCachedThreadPool();
- CompletionService<Map<String, Object>> cs = new ExecutorCompletionService<Map<String, Object>>(threadPool);
- for (int i = 0; i < list.size(); i++) {
- Map<String, Object> map = list.get(i);
- map.put("part", i);
- if (ObjectUtils.isEmpty(map.get("mac"))) {
- map.remove("mac");
- }
- map.put("time", map.remove("formatTime"));
- map.putAll(parameters);
- cs.submit(new Callable<Map<String, Object>>() {
- @Override
- public Map<String, Object> call() throws Exception {
- return getMonitorPointOrDeviceAvgData4Compare(map);
- }
- });
- }
-
- List<Object> dataList = new ArrayList<Object>();
- for (Map<String, Object> map : list) {
- dataList.add(cs.take().get());
- }
- Object[] datas = new Object[list.size()];
- Object[] deviceCounts = new Object[list.size()];
- Object[] alarmDatas = new Object[list.size()];
- Set<String> sensors = new TreeSet<String>(new Comparator<String>() {
- @Override
- public int compare(String o1, String o2) {
- return o1.split("-")[0].compareTo(o2.split("-")[0]);
- //return Integer.compare(Integer.valueOf(o1.split("-")[0].replace("e", "")), Integer.valueOf(o2.split("-")[0].replace("e", "")));
- }
- });
- Map<String, Double> sortMap = new HashMap<String, Double>();
- for (Object object : dataList) {
- Map<String, Object> map = (Map<String, Object>) object;
- for (String key : map.keySet()) {
- int index = Integer.valueOf(key.substring(key.length() - 1));
- String actual = key.substring(0, key.length() - 1);
- Object obj = map.get(key);
- switch (actual) {
- case "data":
- datas[index] = obj;
- break;
- case "deviceCount":
- deviceCounts[index] = obj;
- break;
- case "alarmData":
- alarmDatas[index] = obj;
- if (!ObjectUtils.isEmpty(obj)) {
- Map<String, BigDecimal> mapData = (Map<String, BigDecimal>) obj;
- BigDecimal sum = mapData.remove("sum");
- for (Entry<String, BigDecimal> entry : mapData.entrySet()) {
- if (!"name".equals(entry.getKey())) {
- sortMap.put(entry.getKey() + "-" + index, new BigDecimal(100).multiply(entry.getValue())
- .divide(sum, 2, BigDecimal.ROUND_HALF_UP).doubleValue());
-
+ String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
+ Set<Double> IAQIs = new HashSet<Double>();
+ for (Map.Entry<String, Double> entry : average.entrySet()) {
+ double minMacKey = 0, maxMacKey = 0, minIAQI = 0, maxIAQI = 0;
+ String[] macKeyValues = ResourceUtil.getArrValue(entry.getKey());
+ Double avg = entry.getValue();
+ if (isEmpty(avg)) {
+ IAQIs.add(null);
+ } else {
+ int index = -1;
+ for (int i = 0; i < macKeyValues.length; i++) {
+ if (avg <= Double.valueOf(macKeyValues[i])) {
+ if (i == 0) {
+ index = i;
+ } else {
+ index = i - 1;
+ }
+ break;
+ }
+ }
+ if (index == -1) {
+ IAQIs.add(Double.MAX_VALUE);
+ } else {
+ minMacKey = Double.valueOf(macKeyValues[index]);
+ maxMacKey = Double.valueOf(macKeyValues[index + 1]);
+ minIAQI = Double.valueOf(IAQIValues[index]);
+ maxIAQI = Double.valueOf(IAQIValues[index + 1]);
+ Double result = CalculateUtils.calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg);
+ IAQIs.add(result);
+ }
}
- }
}
- break;
- case "sensors":
- sensors.addAll((List<String>) obj);
- break;
+ IAQIs.remove(null);
+ if (isEmpty(IAQIs)) {
+ resultMap.put("AQI", "N/V");
+ } else {
+ Double AQI = Collections.max(IAQIs);
+ if (AQI == Double.MAX_VALUE) {
+ resultMap.put("AQI", IAQIValues[IAQIValues.length - 1]);
+ } else {
+ resultMap.put("AQI", String.format("%.0f", AQI));
+ }
+ }
}
- }
+ return resultMap;
}
- List<Map.Entry<String, Double>> sortList = new ArrayList<Map.Entry<String, Double>>(sortMap.entrySet());
- Collections.sort(sortList, new Comparator<Map.Entry<String, Double>>() {
- @Override
- public int compare(Entry<String, Double> o1, Entry<String, Double> o2) {
- if (o2.getValue().compareTo(o1.getValue()) == 0) {
- String[] key1 = o1.getKey().split("-");
- String[] key2 = o2.getKey().split("-");
+
+ @Override
+ public Map<String, List> getCompareReport(Map<String, Object> parameters) throws Exception {
+ Map<String, List> resultMap = new HashMap<String, List>();
+ List<Map<String, Object>> list = JSON.parseObject((String) parameters.remove("items"), new TypeReference<List<Map<String, Object>>>() {
+ });
+
+ String type = (String) parameters.get("type");
+ // parameters.putAll(getElementByType(type));
+ ParameterUtils.getElementByType(parameters);
+ Integer timeLength = Integer.valueOf(parameters.remove("timeLength").toString());
+ if ("month".equals(type)) {
+ for (Map<String, Object> map : list) {
+ String[] formatTime = map.get("formatTime").toString().split("-");
+ LocalDate localDate = LocalDate.of(Integer.valueOf(formatTime[0]), Integer.valueOf(formatTime[1]), 1);
+ int lengthOfMonth = localDate.lengthOfMonth();
+ if (lengthOfMonth > timeLength) {
+ timeLength = lengthOfMonth;
+ }
+ }
+ }
+
+ List<Object> timeList = new ArrayList<Object>();
+ for (int i = 0; i < timeLength; i++) {
+ timeList.add(String.format("%02d", "day".equals(type) || "hour".equals(type) ? i : i + 1));
+ }
+ parameters.put("timeList", timeList);
+
+ ExecutorService threadPool = Executors.newCachedThreadPool();
+ CompletionService<Map<String, Object>> cs = new ExecutorCompletionService<Map<String, Object>>(threadPool);
+ for (int i = 0; i < list.size(); i++) {
+ Map<String, Object> map = list.get(i);
+ map.put("part", i);
+ if (ObjectUtils.isEmpty(map.get("mac"))) {
+ map.remove("mac");
+ }
+ map.put("time", map.remove("formatTime"));
+ map.putAll(parameters);
+ cs.submit(new Callable<Map<String, Object>>() {
+ @Override
+ public Map<String, Object> call() throws Exception {
+ return getMonitorPointOrDeviceAvgData4Compare(map);
+ }
+ });
+ }
+
+ List<Object> dataList = new ArrayList<Object>();
+ for (Map<String, Object> map : list) {
+ dataList.add(cs.take().get());
+ }
+ Object[] datas = new Object[list.size()];
+ Object[] deviceCounts = new Object[list.size()];
+ Object[] alarmDatas = new Object[list.size()];
+ Set<String> sensors = new TreeSet<String>(new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ return o1.split("-")[0].compareTo(o2.split("-")[0]);
+ //return Integer.compare(Integer.valueOf(o1.split("-")[0].replace("e", "")), Integer.valueOf(o2.split("-")[0].replace("e", "")));
+ }
+ });
+ Map<String, Double> sortMap = new HashMap<String, Double>();
+ for (Object object : dataList) {
+ Map<String, Object> map = (Map<String, Object>) object;
+ for (String key : map.keySet()) {
+ int index = Integer.valueOf(key.substring(key.length() - 1));
+ String actual = key.substring(0, key.length() - 1);
+ Object obj = map.get(key);
+ switch (actual) {
+ case "data":
+ datas[index] = obj;
+ break;
+ case "deviceCount":
+ deviceCounts[index] = obj;
+ break;
+ case "alarmData":
+ alarmDatas[index] = obj;
+ if (!ObjectUtils.isEmpty(obj)) {
+ Map<String, BigDecimal> mapData = (Map<String, BigDecimal>) obj;
+ BigDecimal sum = mapData.remove("sum");
+ for (Entry<String, BigDecimal> entry : mapData.entrySet()) {
+ if (!"name".equals(entry.getKey())) {
+ sortMap.put(entry.getKey() + "-" + index, new BigDecimal(100).multiply(entry.getValue())
+ .divide(sum, 2, BigDecimal.ROUND_HALF_UP).doubleValue());
+
+ }
+ }
+ }
+ break;
+ case "sensors":
+ sensors.addAll((List<String>) obj);
+ break;
+ }
+ }
+ }
+ List<Map.Entry<String, Double>> sortList = new ArrayList<Map.Entry<String, Double>>(sortMap.entrySet());
+ Collections.sort(sortList, new Comparator<Map.Entry<String, Double>>() {
+ @Override
+ public int compare(Entry<String, Double> o1, Entry<String, Double> o2) {
+ if (o2.getValue().compareTo(o1.getValue()) == 0) {
+ String[] key1 = o1.getKey().split("-");
+ String[] key2 = o2.getKey().split("-");
// String sensor1 = key1[0].replace("e", "");
// String sensor2 = key2[0].replace("e", "");
// if (Integer.valueOf(sensor1).compareTo(Integer.valueOf(sensor2)) == 0) {
// return Integer.compare(Integer.valueOf(key1[1]), Integer.valueOf(key2[1]));
// }
// return Integer.valueOf(sensor1).compareTo(Integer.valueOf(sensor2));
- if (key1[0].compareTo(key2[0]) == 0) {
- return Integer.compare(Integer.valueOf(key1[1]), Integer.valueOf(key2[1]));
- } else {
- return key1[0].compareTo(key2[0]);
- }
- } else {
- return o2.getValue().compareTo(o1.getValue());
- }
- }
+ if (key1[0].compareTo(key2[0]) == 0) {
+ return Integer.compare(Integer.valueOf(key1[1]), Integer.valueOf(key2[1]));
+ } else {
+ return key1[0].compareTo(key2[0]);
+ }
+ } else {
+ return o2.getValue().compareTo(o1.getValue());
+ }
+ }
- });
- resultMap.put("times", timeList);
- resultMap.put("datas", Arrays.asList(datas));
- resultMap.put("deviceCounts", Arrays.asList(deviceCounts));
- resultMap.put("alarmDatas", Arrays.asList(alarmDatas));
- resultMap.put("sensors", new ArrayList<Object>(sensors));
- resultMap.put("sortList", sortList);
- return resultMap;
- }
-
-
- public Map<String, Object> getMonitorPointOrDeviceAvgData4Compare(Map<String, Object> parameters) throws Exception {
- Map<String, Object> resultMap = new HashMap<String, Object>();
- List<Map<String, Object>> resultList = getMonitorPointOrDeviceAvgData(parameters);
- List<Object> timeList = (List<Object>) parameters.get("timeList");
- List<String> sensors = (List<String>) parameters.get("sensors");
- String part = parameters.get("part").toString();
- Map<String, Double[]> doubleMap = new LinkedHashMap<String, Double[]>();
- for (Map<String, Object> map : resultList) {
- String time = map.get("time").toString();
- time = time.substring(time.length() - 2);
- int index = timeList.indexOf(time);
- for (String sensor : sensors) {
- String[] split = sensor.split("-");
- String sensorKey = split[0];
- if (map.containsKey(sensorKey)) {
- Double[] doubles;
- if (doubleMap.containsKey(sensor)) {
- doubles = doubleMap.get(sensor);
- } else {
- doubles = new Double[timeList.size()];
- }
- doubles[index] = (Double) map.get(sensorKey);
- doubleMap.put(sensor, doubles);
- }
- }
- }
-
- Object deviceCount;
- if (parameters.containsKey("deviceCount")) {
- deviceCount = parameters.remove("deviceCount");
- } else {
- deviceCount = deviceMapper.getDeviceCountByRegion(parameters);
- }
-
- resultMap.put("deviceCount" + part, deviceCount);
- resultMap.put("data" + part, doubleMap);
- resultMap.put("sensors" + part, sensors);
- Object type = parameters.get("type");
- if ("year".equals(type) || "month".equals(type)) {
- parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
- List<Map<String, Object>> alarmData = alarmDailyMapper.getAlarmData(parameters);
- if (!ObjectUtils.isEmpty(alarmData)) {
- resultMap.put("alarmData" + part, alarmDailyMapper.getAlarmData(parameters).get(0));
- }
- }
- return resultMap;
- }
-
- @Override
- public List<Map<String, Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters) throws Exception {
- convertQueryParam(parameters);
- if (!ObjectUtils.isEmpty(parameters.get("compensate"))) {
- parameters.put("timeUnits", "10min");
- }
- return historyMinutelyMapper.getMonitorPointOrDeviceAvgData(parameters);
- }
-
- @Override
- public List<Map<String, Object>> getAreaAvgDataByAreaCode(Map<String, Object> parameters) throws Exception {
- convertQueryParam(parameters);
- if (!ObjectUtils.isEmpty(parameters.get("compensate"))) {
- parameters.put("timeUnits", "10min");
- }
- return historyMinutelyMapper.getAreaAvgDataByAreaCode(parameters);
-
- }
-
- @Override
- public void convertQueryParam(Map<String, Object> parameters) throws ParseException {
- if (!parameters.containsKey("field")) {
- // String type = (String) parameters.get("type");
- // parameters.putAll(getElementByType(type));
- ParameterUtils.getElementByType(parameters);
- }
- String time = (String) parameters.get("time");
- String format = (String) parameters.get("format");
- Integer field = Integer.valueOf(parameters.get("field").toString());
- Date start = DateUtils.parseDate(time, format), end = null;
- if (parameters.containsKey("timeb")) {
- end = DateUtils.parseDate((String) parameters.get("timeb"), format);
- } else {
- Calendar instance = Calendar.getInstance();
- instance.setTime(start);
- instance.add(field, 1);
- end = instance.getTime();
- }
- parameters.put("start", start);
- parameters.put("end", end);
-
- List<String> sensorKeys = new ArrayList<String>();
- List<String> sensors = new ArrayList<String>();
- if (parameters.containsKey("sensors")) {
- try {
- sensors = JSON.parseObject((String) parameters.get("sensors"), new TypeReference<List<String>>() {
});
- for (String sensor : sensors) {
- sensorKeys.add(sensor.split("-")[0]);
- }
- } catch (Exception e) {
- sensorKeys = sensors = (List<String>) parameters.remove("sensors");
- }
- } else {
- List<Sensor> sensorList = sensorMapper.getSensorsByCriteria(parameters);
- for (Sensor sensor : sensorList) {
- sensorKeys.add(sensor.getSensorKey());
- String string = sensor.getSensorKey() + "-" + sensor.getName() + "-" + sensor.getUnit();
- if (parameters.containsKey("description")) {
- string += "-" + sensor.getDescription();
- }
- sensors.add(string);
- }
+ resultMap.put("times", timeList);
+ resultMap.put("datas", Arrays.asList(datas));
+ resultMap.put("deviceCounts", Arrays.asList(deviceCounts));
+ resultMap.put("alarmDatas", Arrays.asList(alarmDatas));
+ resultMap.put("sensors", new ArrayList<Object>(sensors));
+ resultMap.put("sortList", sortList);
+ return resultMap;
}
- parameters.put("sensorKeys", sensorKeys);
- parameters.put("sensors", sensors);
- }
- @Override
- public Map<String, Object> getMonthAverageBySensor(Map<String, Object> parameters) {
- //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
- Object sensorKey = parameters.remove("macKey");
- ValidateUtil.notNull(sensorKey, "param.is.null");
- Map<String, Object> result = new HashMap<String, Object>();
- LocalDate end = LocalDate.now(), start;
- // ���������������������������������������
- if (1 == end.getDayOfMonth()) {
- // ���������1���00:00:00
- start = end.plusDays(-1).with(TemporalAdjusters.firstDayOfMonth());
- } else {
- // ���������1���00:00:00
- start = end.with(TemporalAdjusters.firstDayOfMonth());
- }
- parameters.put("start", start);
- parameters.put("end", end);
- parameters.put("sensorKeys", Arrays.asList(sensorKey));
- Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
- if (isEmpty(average)) {
- result.put("average", NULL_VALUE);
- } else {
- result.put("average", String.format("%.2f", average.get(sensorKey)));
+ public Map<String, Object> getMonitorPointOrDeviceAvgData4Compare(Map<String, Object> parameters) throws Exception {
+ Map<String, Object> resultMap = new HashMap<String, Object>();
+ List<Map<String, Object>> resultList = getMonitorPointOrDeviceAvgData(parameters);
+ List<Object> timeList = (List<Object>) parameters.get("timeList");
+ List<String> sensors = (List<String>) parameters.get("sensors");
+ String part = parameters.get("part").toString();
+ Map<String, Double[]> doubleMap = new LinkedHashMap<String, Double[]>();
+ for (Map<String, Object> map : resultList) {
+ String time = map.get("time").toString();
+ time = time.substring(time.length() - 2);
+ int index = timeList.indexOf(time);
+ for (String sensor : sensors) {
+ String[] split = sensor.split("-");
+ String sensorKey = split[0];
+ if (map.containsKey(sensorKey)) {
+ Double[] doubles;
+ if (doubleMap.containsKey(sensor)) {
+ doubles = doubleMap.get(sensor);
+ } else {
+ doubles = new Double[timeList.size()];
+ }
+ doubles[index] = (Double) map.get(sensorKey);
+ doubleMap.put(sensor, doubles);
+ }
+ }
+ }
+
+ Object deviceCount;
+ if (parameters.containsKey("deviceCount")) {
+ deviceCount = parameters.remove("deviceCount");
+ } else {
+ deviceCount = deviceMapper.getDeviceCountByRegion(parameters);
+ }
+
+ resultMap.put("deviceCount" + part, deviceCount);
+ resultMap.put("data" + part, doubleMap);
+ resultMap.put("sensors" + part, sensors);
+ Object type = parameters.get("type");
+ if ("year".equals(type) || "month".equals(type)) {
+ parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
+ List<Map<String, Object>> alarmData = alarmDailyMapper.getAlarmData(parameters);
+ if (!ObjectUtils.isEmpty(alarmData)) {
+ resultMap.put("alarmData" + part, alarmDailyMapper.getAlarmData(parameters).get(0));
+ }
+ }
+ return resultMap;
}
- return result;
- }
+
+ @Override
+ public List<Map<String, Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters) throws Exception {
+ convertQueryParam(parameters);
+ if (!ObjectUtils.isEmpty(parameters.get("compensate"))) {
+ parameters.put("timeUnits", "10min");
+ }
+ return historyMinutelyMapper.getMonitorPointOrDeviceAvgData(parameters);
+ }
+
+ @Override
+ public List<Map<String, Object>> getAreaAvgDataByAreaCode(Map<String, Object> parameters) throws Exception {
+ convertQueryParam(parameters);
+ if (!ObjectUtils.isEmpty(parameters.get("compensate"))) {
+ parameters.put("timeUnits", "10min");
+ }
+ return historyMinutelyMapper.getAreaAvgDataByAreaCode(parameters);
+
+ }
+
+ @Override
+ public void convertQueryParam(Map<String, Object> parameters) throws ParseException {
+ if (!parameters.containsKey("field")) {
+ // String type = (String) parameters.get("type");
+ // parameters.putAll(getElementByType(type));
+ ParameterUtils.getElementByType(parameters);
+ }
+ String time = (String) parameters.get("time");
+ String format = (String) parameters.get("format");
+ Integer field = Integer.valueOf(parameters.get("field").toString());
+ Date start = DateUtils.parseDate(time, format), end = null;
+ if (parameters.containsKey("timeb")) {
+ end = DateUtils.parseDate((String) parameters.get("timeb"), format);
+ } else {
+ Calendar instance = Calendar.getInstance();
+ instance.setTime(start);
+ instance.add(field, 1);
+ end = instance.getTime();
+ }
+ parameters.put("start", start);
+ parameters.put("end", end);
+
+ List<String> sensorKeys = new ArrayList<String>();
+ List<String> sensors = new ArrayList<String>();
+ if (parameters.containsKey("sensors")) {
+ try {
+ sensors = JSON.parseObject((String) parameters.get("sensors"), new TypeReference<List<String>>() {
+ });
+ for (String sensor : sensors) {
+ sensorKeys.add(sensor.split("-")[0]);
+ }
+ } catch (Exception e) {
+ sensorKeys = sensors = (List<String>) parameters.remove("sensors");
+ }
+ } else {
+ List<Sensor> sensorList = sensorMapper.getSensorsByCriteria(parameters);
+ for (Sensor sensor : sensorList) {
+ sensorKeys.add(sensor.getSensorKey());
+ String string = sensor.getSensorKey() + "-" + sensor.getName() + "-" + sensor.getUnit();
+ if (parameters.containsKey("description")) {
+ string += "-" + sensor.getDescription();
+ }
+ sensors.add(string);
+ }
+ }
+ parameters.put("sensorKeys", sensorKeys);
+ parameters.put("sensors", sensors);
+ }
+
+ @Override
+ public Map<String, Object> getMonthAverageBySensor(Map<String, Object> parameters) {
+ //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
+ Object sensorKey = parameters.remove("macKey");
+ ValidateUtil.notNull(sensorKey, "param.is.null");
+ Map<String, Object> result = new HashMap<String, Object>();
+ LocalDate end = LocalDate.now(), start;
+ // ���������������������������������������
+ if (1 == end.getDayOfMonth()) {
+ // ���������1���00:00:00
+ start = end.plusDays(-1).with(TemporalAdjusters.firstDayOfMonth());
+ } else {
+ // ���������1���00:00:00
+ start = end.with(TemporalAdjusters.firstDayOfMonth());
+ }
+ parameters.put("start", start);
+ parameters.put("end", end);
+ parameters.put("sensorKeys", Arrays.asList(sensorKey));
+
+ Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
+ if (isEmpty(average)) {
+ result.put("average", NULL_VALUE);
+ } else {
+ result.put("average", String.format("%.2f", average.get(sensorKey)));
+ }
+ return result;
+ }
@Override
public Map<String, Object> getAverageBySensor(Map<String, Object> parameters) {
@@ -472,244 +472,244 @@
return result;
}
- /**
- * ������������������������������������������������������������������
- *
- * @param lineChartCriteria
- * @return
- */
- @Override
- public Map<String, List<List<Double>>> queryLineChartDateByCrieria(LineChartCriteria lineChartCriteria) {
- Map<String, List<List<Double>>> listMap = new HashMap<>();
- List<String> sensorKeys = lineChartCriteria.getSensorKeys();
- List<DataCondition> dataConditionList = lineChartCriteria.getDataConditions();
- TimePeriod timePeriod = lineChartCriteria.getTimePeriod();
- sensorKeys.forEach(sensorKey -> {
- listMap.put(sensorKey, new ArrayList<List<Double>>(dataConditionList.size()));
- });
- dataConditionList.forEach(dataCondition -> {
- Map<String, List<Double>> dataMap = queryOneLineChartDateByCrieria(sensorKeys, timePeriod, dataCondition);
- // ������������
- listMap.forEach((sensorKey, list) -> {
- List<Double> rowData = dataMap.get(sensorKey);
- list.add(rowData);
- });
- });
- return listMap;
- }
-
- /**
- * ������������������������������������������������������������������,������ ������������������
- *
- * @param sensorKeys
- * @param timePeriod
- * @param dataCondition
- * @return
- */
- public Map<String, List<Double>> queryOneLineChartDateByCrieria(List<String> sensorKeys, TimePeriod timePeriod, DataCondition dataCondition) {
- List<String> timeList = ReportTimeFormat.makeTimeList(timePeriod);
- List<Map<String, Object>> lineChartDatas = historyMinutelyMapper.selectLineChartDateByCrieria(sensorKeys, timePeriod, dataCondition);
- Map<String, List<Double>> lineChartDatasWithEmpty = new HashMap<>();
- // lineChartDatasWithEmpty ���������
- sensorKeys.forEach(sensorKey -> {
- lineChartDatasWithEmpty.put(sensorKey, timeList.stream().map(time -> {
- Double data = null;
- return data;
- }).collect(Collectors.toList()));
- });
- // m ���������data���index������������������m������
- int m = 0;
- int dataLength = lineChartDatas.size() - 1;
- m = dataLength > -1 ? 0 : -1;
- if (m > -1) {
- for (int n = 0; n < timeList.size(); n++) {
- if (m > -1) {
- String time = timeList.get(n);
- Map<String, Object> rowData = lineChartDatas.get(m);
- String keyTime = rowData.get("format_time").toString();
- if (time.equals(keyTime)) {
- // list to map
- int finalN = n;
- sensorKeys.forEach(sensorKey -> {
- Object value = rowData.get(sensorKey);
- List<Double> lineChartDatasWithEmptyTemp = lineChartDatasWithEmpty.get(sensorKey);
- if (finalN < lineChartDatasWithEmptyTemp.size()) {
- Double sensorValue = value != null ? new Double(value.toString()) : null;
- lineChartDatasWithEmptyTemp.set(finalN, sensorValue);
- }
+ /**
+ * ������������������������������������������������������������������
+ *
+ * @param lineChartCriteria
+ * @return
+ */
+ @Override
+ public Map<String, List<List<Double>>> queryLineChartDateByCrieria(LineChartCriteria lineChartCriteria) {
+ Map<String, List<List<Double>>> listMap = new HashMap<>();
+ List<String> sensorKeys = lineChartCriteria.getSensorKeys();
+ List<DataCondition> dataConditionList = lineChartCriteria.getDataConditions();
+ TimePeriod timePeriod = lineChartCriteria.getTimePeriod();
+ sensorKeys.forEach(sensorKey -> {
+ listMap.put(sensorKey, new ArrayList<List<Double>>(dataConditionList.size()));
+ });
+ dataConditionList.forEach(dataCondition -> {
+ Map<String, List<Double>> dataMap = queryOneLineChartDateByCrieria(sensorKeys, timePeriod, dataCondition);
+ // ������������
+ listMap.forEach((sensorKey, list) -> {
+ List<Double> rowData = dataMap.get(sensorKey);
+ list.add(rowData);
});
- // ������ -1���������������
- m = m < dataLength ? m + 1 : -1;
- }
- }
- }
+ });
+ return listMap;
}
- return lineChartDatasWithEmpty;
- }
- private Map<String, Object> getElementByType(Object type) {
- Map<String, Object> resultMap = new HashMap<String, Object>();
- switch (type.toString()) {
- case "year":
- resultMap.put("format", "yyyy");
- resultMap.put("typeFormat", "%Y-%m");
- resultMap.put("timeLength", 12);
- resultMap.put("field", Calendar.YEAR);
- break;
- case "month":
- resultMap.put("format", "yyyy-MM");
- resultMap.put("typeFormat", "%Y-%m-%d");
- resultMap.put("timeLength", 28);
- resultMap.put("field", Calendar.MONTH);
- break;
- case "day":
- resultMap.put("format", "yyyy-MM-dd");
- resultMap.put("typeFormat", "%Y-%m-%d %H");
- resultMap.put("timeLength", 24);
- resultMap.put("field", Calendar.DATE);
- break;
- case "hour":
- resultMap.put("format", "yyyy-MM-dd HH");
- resultMap.put("typeFormat", "%Y-%m-%d %H:%i");
- resultMap.put("timeLength", 60);
- resultMap.put("field", Calendar.HOUR);
- break;
- }
- return resultMap;
- }
-
- /*
- * @description ���������������������������������sensor���
- * @author ZhuDongming
- * @date 2019-07-25 09:21:45
- * @param parameters
- * @return
- */
- @Override
- public List<List<Map<String, Object>>> getSensorData(Map<String, Object> parameters) {
- String startTime = parameters.get("startTime").toString();
- DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
- int year = startTimeLocalDateTime.getYear();
- int month = startTimeLocalDateTime.getMonthValue();
- String monthStr = month < 10 ? ("0" + month) : month + "";
- String yearAndMonth = year + monthStr;
- List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters);
- List<String> sensorKeys = new ArrayList<>();
- for (Sensor sensor : sensors) {
- sensorKeys.add(sensor.getSensorKey());
- }
- parameters.put("sensorKeys", sensorKeys);
- List<Map<String, Object>> listMap = null;
- if (year <= 2019) {
- listMap = historyMinutelyMapper.getSensorData(parameters);
- } else {
- parameters.put("yearAndMonth", yearAndMonth);
- listMap = historyMinutelyMapper.getSensorData2020(parameters);
- }
- List<List<Map<String, Object>>> listMaps = new ArrayList<>();
- List<Map<String, Object>> listMapAvg = new ArrayList<>();
- List<Map<String, Object>> listMapMin = new ArrayList<>();
- List<Map<String, Object>> listMapMax = new ArrayList<>();
- if (CollectionUtils.isNotEmpty(listMap)) {
- for (Map<String, Object> map : listMap) {
- Map<String, Object> mapAvg = new LinkedHashMap<>();
- Map<String, Object> mapMin = new LinkedHashMap<>();
- Map<String, Object> mapMax = new LinkedHashMap<>();
- mapAvg.put("time", map.get("time"));
- mapMin.put("time", map.get("time"));
- mapMax.put("time", map.get("time"));
- for (Entry<String, Object> entry : map.entrySet()) {
- for (Sensor sensor : sensors) {
- if (sensor.getSensorKey().equals(entry.getKey())) {
- mapAvg.put(entry.getKey(), new BigDecimal(entry.getValue().toString()).stripTrailingZeros().toPlainString() + sensor.getUnit());
- } else if (("min" + sensor.getSensorKey()).equals(entry.getKey())) {
- mapMin.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
- } else if (("max" + sensor.getSensorKey()).equals(entry.getKey())) {
- mapMax.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
+ /**
+ * ������������������������������������������������������������������,������ ������������������
+ *
+ * @param sensorKeys
+ * @param timePeriod
+ * @param dataCondition
+ * @return
+ */
+ public Map<String, List<Double>> queryOneLineChartDateByCrieria(List<String> sensorKeys, TimePeriod timePeriod, DataCondition dataCondition) {
+ List<String> timeList = ReportTimeFormat.makeTimeList(timePeriod);
+ List<Map<String, Object>> lineChartDatas = historyMinutelyMapper.selectLineChartDateByCrieria(sensorKeys, timePeriod, dataCondition);
+ Map<String, List<Double>> lineChartDatasWithEmpty = new HashMap<>();
+ // lineChartDatasWithEmpty ���������
+ sensorKeys.forEach(sensorKey -> {
+ lineChartDatasWithEmpty.put(sensorKey, timeList.stream().map(time -> {
+ Double data = null;
+ return data;
+ }).collect(Collectors.toList()));
+ });
+ // m ���������data���index������������������m������
+ int m = 0;
+ int dataLength = lineChartDatas.size() - 1;
+ m = dataLength > -1 ? 0 : -1;
+ if (m > -1) {
+ for (int n = 0; n < timeList.size(); n++) {
+ if (m > -1) {
+ String time = timeList.get(n);
+ Map<String, Object> rowData = lineChartDatas.get(m);
+ String keyTime = rowData.get("format_time").toString();
+ if (time.equals(keyTime)) {
+ // list to map
+ int finalN = n;
+ sensorKeys.forEach(sensorKey -> {
+ Object value = rowData.get(sensorKey);
+ List<Double> lineChartDatasWithEmptyTemp = lineChartDatasWithEmpty.get(sensorKey);
+ if (finalN < lineChartDatasWithEmptyTemp.size()) {
+ Double sensorValue = value != null ? new Double(value.toString()) : null;
+ lineChartDatasWithEmptyTemp.set(finalN, sensorValue);
+ }
+ });
+ // ������ -1���������������
+ m = m < dataLength ? m + 1 : -1;
+ }
+ }
}
- }
}
- if ("0��".equals(mapAvg.get("e76")) || "0".equals(mapMin.get("e76")) || "0".equals(mapMax.get("e76")) || "0��".equals(mapAvg.get("e77")) || "0".equals(mapMin.get("e77")) || "0".equals(mapMax.get("e77"))) {
- continue;
+ return lineChartDatasWithEmpty;
+ }
+
+ private Map<String, Object> getElementByType(Object type) {
+ Map<String, Object> resultMap = new HashMap<String, Object>();
+ switch (type.toString()) {
+ case "year":
+ resultMap.put("format", "yyyy");
+ resultMap.put("typeFormat", "%Y-%m");
+ resultMap.put("timeLength", 12);
+ resultMap.put("field", Calendar.YEAR);
+ break;
+ case "month":
+ resultMap.put("format", "yyyy-MM");
+ resultMap.put("typeFormat", "%Y-%m-%d");
+ resultMap.put("timeLength", 28);
+ resultMap.put("field", Calendar.MONTH);
+ break;
+ case "day":
+ resultMap.put("format", "yyyy-MM-dd");
+ resultMap.put("typeFormat", "%Y-%m-%d %H");
+ resultMap.put("timeLength", 24);
+ resultMap.put("field", Calendar.DATE);
+ break;
+ case "hour":
+ resultMap.put("format", "yyyy-MM-dd HH");
+ resultMap.put("typeFormat", "%Y-%m-%d %H:%i");
+ resultMap.put("timeLength", 60);
+ resultMap.put("field", Calendar.HOUR);
+ break;
}
- listMapAvg.add(mapAvg);
- listMapMin.add(mapMin);
- listMapMax.add(mapMax);
- }
- listMaps.add(listMapAvg);
- listMaps.add(listMapMin);
- listMaps.add(listMapMax);
+ return resultMap;
}
- return listMaps;
- }
- @Override
- public List<Map<String, Object>> getDevicesAvgDataToExcel(Map<String, Object> parameters) throws Exception {
- if ("month".equals(parameters.get("type"))) {
- parameters.put("timeUnits", "daily");
- parameters.put("typeFormat", "%Y-%m-%d");
- String time = parameters.get("time") + "-01T00:00:00";
- LocalDateTime value = LocalDateTime.parse(time);
- LocalDateTime start = value.with(TemporalAdjusters.firstDayOfMonth());
- LocalDateTime end = value.with(TemporalAdjusters.lastDayOfMonth());
- parameters.put("start", start);
- parameters.put("end", end);
- int day = end.getDayOfMonth();
- List<String> timeList = new ArrayList<>();
- for (int i = 0; i <= day - 1; i++) {
- timeList.add(start.plusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
- }
- parameters.put("timeList", timeList);
- } else if ("day".equals(parameters.get("type"))) {
- String time = parameters.get("time") + "T00:00:00";
- LocalDateTime value = LocalDateTime.parse(time);
- LocalDateTime end = value.plusHours(23);
- parameters.put("timeUnits", "hourly");
- parameters.put("typeFormat", "%Y-%m-%d %H:%i");
- parameters.put("start", time);
- parameters.put("end", end);
- List<String> timeList = new ArrayList<>();
- for (int i = 0; i <= 23; i++) {
- timeList.add(value.plusHours(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
- }
- parameters.put("timeList", timeList);
+ /*
+ * @description ���������������������������������sensor���
+ * @author ZhuDongming
+ * @date 2019-07-25 09:21:45
+ * @param parameters
+ * @return
+ */
+ @Override
+ public List<List<Map<String, Object>>> getSensorData(Map<String, Object> parameters) {
+ String startTime = parameters.get("startTime").toString();
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
+ int year = startTimeLocalDateTime.getYear();
+ int month = startTimeLocalDateTime.getMonthValue();
+ String monthStr = month < 10 ? ("0" + month) : month + "";
+ String yearAndMonth = year + monthStr;
+ List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters);
+ List<String> sensorKeys = new ArrayList<>();
+ for (Sensor sensor : sensors) {
+ sensorKeys.add(sensor.getSensorKey());
+ }
+ parameters.put("sensorKeys", sensorKeys);
+ List<Map<String, Object>> listMap = null;
+ if (year <= 2019) {
+ listMap = historyMinutelyMapper.getSensorData(parameters);
+ } else {
+ parameters.put("yearAndMonth", yearAndMonth);
+ listMap = historyMinutelyMapper.getSensorData2020(parameters);
+ }
+ List<List<Map<String, Object>>> listMaps = new ArrayList<>();
+ List<Map<String, Object>> listMapAvg = new ArrayList<>();
+ List<Map<String, Object>> listMapMin = new ArrayList<>();
+ List<Map<String, Object>> listMapMax = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(listMap)) {
+ for (Map<String, Object> map : listMap) {
+ Map<String, Object> mapAvg = new LinkedHashMap<>();
+ Map<String, Object> mapMin = new LinkedHashMap<>();
+ Map<String, Object> mapMax = new LinkedHashMap<>();
+ mapAvg.put("time", map.get("time"));
+ mapMin.put("time", map.get("time"));
+ mapMax.put("time", map.get("time"));
+ for (Entry<String, Object> entry : map.entrySet()) {
+ for (Sensor sensor : sensors) {
+ if (sensor.getSensorKey().equals(entry.getKey())) {
+ mapAvg.put(entry.getKey(), new BigDecimal(entry.getValue().toString()).stripTrailingZeros().toPlainString() + sensor.getUnit());
+ } else if (("min" + sensor.getSensorKey()).equals(entry.getKey())) {
+ mapMin.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
+ } else if (("max" + sensor.getSensorKey()).equals(entry.getKey())) {
+ mapMax.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
+ }
+ }
+ }
+ if ("0��".equals(mapAvg.get("e76")) || "0".equals(mapMin.get("e76")) || "0".equals(mapMax.get("e76")) || "0��".equals(mapAvg.get("e77")) || "0".equals(mapMin.get("e77")) || "0".equals(mapMax.get("e77"))) {
+ continue;
+ }
+ listMapAvg.add(mapAvg);
+ listMapMin.add(mapMin);
+ listMapMax.add(mapMax);
+ }
+ listMaps.add(listMapAvg);
+ listMaps.add(listMapMin);
+ listMaps.add(listMapMax);
+ }
+ return listMaps;
}
- return historyMinutelyMapper.getDevicesAvgDataToExcel(parameters);
- }
- @Override
- public List<Map<String, Object>> getDevicesSensorsAvgDataToExcel(Map<String, Object> parameters) throws Exception {
- if ("month".equals(parameters.get("type"))) {
- parameters.put("timeUnits", "daily");
- parameters.put("typeFormat", "%Y-%m-%d");
- String time = parameters.get("time") + "-01T00:00:00";
- LocalDateTime value = LocalDateTime.parse(time);
- LocalDateTime start = value.with(TemporalAdjusters.firstDayOfMonth());
- LocalDateTime end = value.with(TemporalAdjusters.lastDayOfMonth());
- parameters.put("start", start);
- parameters.put("end", end);
- int day = end.getDayOfMonth();
- List<String> timeList = new ArrayList<>();
- for (int i = 0; i <= day - 1; i++) {
- timeList.add(start.plusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
- }
- parameters.put("timeList", timeList);
- } else if ("day".equals(parameters.get("type"))) {
- String time = parameters.get("time") + "T00:00:00";
- LocalDateTime value = LocalDateTime.parse(time);
- LocalDateTime end = value.plusHours(23);
- parameters.put("timeUnits", "hourly");
- parameters.put("typeFormat", "%Y-%m-%d %H:%i");
- parameters.put("start", time);
- parameters.put("end", end);
- List<String> timeList = new ArrayList<>();
- for (int i = 0; i <= 23; i++) {
- timeList.add(value.plusHours(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
- }
- parameters.put("timeList", timeList);
+ @Override
+ public List<Map<String, Object>> getDevicesAvgDataToExcel(Map<String, Object> parameters) throws Exception {
+ if ("month".equals(parameters.get("type"))) {
+ parameters.put("timeUnits", "daily");
+ parameters.put("typeFormat", "%Y-%m-%d");
+ String time = parameters.get("time") + "-01T00:00:00";
+ LocalDateTime value = LocalDateTime.parse(time);
+ LocalDateTime start = value.with(TemporalAdjusters.firstDayOfMonth());
+ LocalDateTime end = value.with(TemporalAdjusters.lastDayOfMonth());
+ parameters.put("start", start);
+ parameters.put("end", end);
+ int day = end.getDayOfMonth();
+ List<String> timeList = new ArrayList<>();
+ for (int i = 0; i <= day - 1; i++) {
+ timeList.add(start.plusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ }
+ parameters.put("timeList", timeList);
+ } else if ("day".equals(parameters.get("type"))) {
+ String time = parameters.get("time") + "T00:00:00";
+ LocalDateTime value = LocalDateTime.parse(time);
+ LocalDateTime end = value.plusHours(23);
+ parameters.put("timeUnits", "hourly");
+ parameters.put("typeFormat", "%Y-%m-%d %H:%i");
+ parameters.put("start", time);
+ parameters.put("end", end);
+ List<String> timeList = new ArrayList<>();
+ for (int i = 0; i <= 23; i++) {
+ timeList.add(value.plusHours(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
+ }
+ parameters.put("timeList", timeList);
+ }
+ return historyMinutelyMapper.getDevicesAvgDataToExcel(parameters);
}
- return historyMinutelyMapper.getDevicesSensorsAvgDataToExcel(parameters);
- }
+
+ @Override
+ public List<Map<String, Object>> getDevicesSensorsAvgDataToExcel(Map<String, Object> parameters) throws Exception {
+ if ("month".equals(parameters.get("type"))) {
+ parameters.put("timeUnits", "daily");
+ parameters.put("typeFormat", "%Y-%m-%d");
+ String time = parameters.get("time") + "-01T00:00:00";
+ LocalDateTime value = LocalDateTime.parse(time);
+ LocalDateTime start = value.with(TemporalAdjusters.firstDayOfMonth());
+ LocalDateTime end = value.with(TemporalAdjusters.lastDayOfMonth());
+ parameters.put("start", start);
+ parameters.put("end", end);
+ int day = end.getDayOfMonth();
+ List<String> timeList = new ArrayList<>();
+ for (int i = 0; i <= day - 1; i++) {
+ timeList.add(start.plusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ }
+ parameters.put("timeList", timeList);
+ } else if ("day".equals(parameters.get("type"))) {
+ String time = parameters.get("time") + "T00:00:00";
+ LocalDateTime value = LocalDateTime.parse(time);
+ LocalDateTime end = value.plusHours(23);
+ parameters.put("timeUnits", "hourly");
+ parameters.put("typeFormat", "%Y-%m-%d %H:%i");
+ parameters.put("start", time);
+ parameters.put("end", end);
+ List<String> timeList = new ArrayList<>();
+ for (int i = 0; i <= 23; i++) {
+ timeList.add(value.plusHours(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
+ }
+ parameters.put("timeList", timeList);
+ }
+ return historyMinutelyMapper.getDevicesSensorsAvgDataToExcel(parameters);
+ }
}
--
Gitblit v1.8.0