From b96cdf306e9124f93e5ca33e006728a2f4552c4d Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Wed, 04 Sep 2019 14:06:02 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/service/impl/HistoryServiceImpl.java | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 113 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
index da7fdbd..6a32a37 100644
--- a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -1,5 +1,6 @@
package com.moral.service.impl;
+import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -33,11 +34,14 @@
import com.moral.entity.Sensor;
import com.moral.mapper.DeviceMapper;
import com.moral.mapper.HistoryMapper;
+import com.moral.mapper.MonitorPointMapper;
+import com.moral.mapper.OrganizationRelationMapper;
import com.moral.mapper.SensorMapper;
import com.moral.mapper.SensorUnitMapper;
import com.moral.service.AccountService;
import com.moral.service.HistoryService;
import com.moral.service.ProfessionService;
+import com.moral.util.AQICalculation;
@Service
public class HistoryServiceImpl implements HistoryService {
@@ -56,6 +60,12 @@
@Resource
private ProfessionService professionService;
+
+ @Resource
+ private OrganizationRelationMapper organizationRelationMapper;
+
+ @Resource
+ private MonitorPointMapper monitorPointMapper;
@Override
public Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters) throws Exception {
@@ -286,7 +296,7 @@
if (sensorUnits.containsKey(sensorKey)) {
Map<String, Object> sensorUnit = (Map<String, Object>) sensorUnits.get(sensorKey);
String rules = sensorUnit.get("rules").toString();
- rules = rules.replace("d", "").replace("{0}", "sensorKeyValue");
+ rules = rules.replace("d", "").replace("{0}", "value");
Expression expression = AviatorEvaluator.compile(rules);
Map<String, Object> env = new HashMap<String, Object>();
env.put("value", Double.valueOf(sensorKeyValue.toString()));
@@ -359,6 +369,107 @@
startTime = localDate+" "+startHour+":00:00";
}
Map<String, Object> map = historyMapper.getAVGValueByMacAndTimeslot(mac, startTime, endTime);
- return map;
+ System.out.println(map);
+ Map<String, Object> returnMap = new HashMap<>();
+ if (map.isEmpty()) {
+ returnMap.put("AQI", "N/V");
+ } else {
+ Map<String, Double> AQIMap = new HashMap<>();
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ String key = entry.getKey();
+ Double value = Double.parseDouble(entry.getValue().toString());
+ AQIMap.put(key, value);
+ }
+ returnMap = AQICalculation.hourlyAQI(AQIMap);
+ }
+
+ return returnMap;
+ }
+
+ @Override
+ public List<Map<String, Object>> getMointorPointRankByOrganizationId(Map<String, Object> parameters) {
+ //������������id
+ String organizationId = parameters.get("organization_id").toString();
+ //������������������������������������������������������id
+ List<Object> organizationIdList = new ArrayList<>();
+ organizationIdList.add(organizationId);
+ //���������������������������������id
+ List<Object> parentIdList = new ArrayList<>();
+ parentIdList.add(organizationId);
+
+ //������������
+ for(int i=0;i<10;i++) {
+ if(!parentIdList.isEmpty()) {
+ //������������������������������
+ List<Map<String, Object>> childIdList = organizationRelationMapper.getChildIdByParentId(parentIdList);
+ //���������������id������
+ parentIdList.clear();
+ //������������id������������������
+ for (Map<String, Object> map : childIdList) {
+ organizationIdList.add(map.get("child_id"));
+ parentIdList.add(map.get("child_id"));
+ }
+ }else {
+ break;
+ }
+ }
+
+ //������������id������������id
+ List<Map<String, Object>> monitorPointIdListMap = monitorPointMapper.getIdByOrganizationId(organizationIdList);
+ //���List<Map<String, Object>>���������List<Object>
+ List<Object> monitorPointIdList = new ArrayList<>();
+ for (Map<String, Object> map : monitorPointIdListMap) {
+ monitorPointIdList.add(map.get("id"));
+ }
+
+ //������������id���������������������������
+ //������������������������
+ Calendar rightNow = Calendar.getInstance();
+ //���������������������������
+ Calendar beforeTime = Calendar.getInstance();
+ beforeTime.add(Calendar.MINUTE, -5);// 5���������������������
+ Date beforeD = beforeTime.getTime();
+ Date end = rightNow.getTime();
+ String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(end);
+ String before5Time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(beforeD); // ������������������
+
+ String sensor = parameters.get("sensor").toString();
+ List<Map<String, Object>> result = historyMapper.getAVGSensorRankByMonitorPointIdList(sensor, monitorPointIdList, before5Time, endTime);
+ return result;
+ }
+
+ @Override
+ public Map<String, Object> gitHourlyAQIByMonitorPointIdAndTimeslot(Map<String, Object> parameters) {
+ String monitor_point_id = parameters.get("monitor_point_id").toString();
+ //������������
+ LocalDate localDate = LocalDate.now();
+ Calendar c = Calendar.getInstance();//������������������������������������
+ int endHour = c.get(Calendar.HOUR_OF_DAY);
+ String endTime = localDate+" "+endHour+":00:00";
+
+ String startTime;
+ if(endHour == 0) {
+ LocalDate startDate = localDate.minusDays(1);
+ startTime = startDate+" "+"23:00:00";
+ }else {
+ int startHour = endHour-1;
+ startTime = localDate+" "+startHour+":00:00";
+ }
+ Map<String, Object> map = historyMapper.getMonitorPointAVGValueByMonitorPointIdAndTimeslot(monitor_point_id, startTime, endTime);
+ System.out.println(map);
+ Map<String, Object> returnMap = new HashMap<>();
+ if (map.isEmpty()) {
+ returnMap.put("AQI", "N/V");
+ } else {
+ Map<String, Double> AQIMap = new HashMap<>();
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ String key = entry.getKey();
+ Double value = Double.parseDouble(entry.getValue().toString());
+ AQIMap.put(key, value);
+ }
+ returnMap = AQICalculation.hourlyAQI(AQIMap);
+ }
+
+ return returnMap;
}
}
--
Gitblit v1.8.0