From 2759eea24b4d6cd5e0e8f8c88eae69a59b48d299 Mon Sep 17 00:00:00 2001
From: ZhuDongming <773644075@qq.com>
Date: Tue, 03 Sep 2019 13:43:57 +0800
Subject: [PATCH] update 污染传播接口
---
src/main/java/com/moral/service/impl/HistoryServiceImpl.java | 67 +++++++++++++++++++++++++++++++--
1 files changed, 63 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
index 2b23155..6238443 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,6 +34,7 @@
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;
@@ -61,6 +63,9 @@
@Resource
private OrganizationRelationMapper organizationRelationMapper;
+
+ @Resource
+ private MonitorPointMapper monitorPointMapper;
@Override
public Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters) throws Exception {
@@ -382,7 +387,7 @@
}
@Override
- public Map<String, Object> getMointorPointRankByOrganizationId(Map<String, Object> parameters) {
+ public List<Map<String, Object>> getMointorPointRankByOrganizationId(Map<String, Object> parameters) {
//������������id
String organizationId = parameters.get("organization_id").toString();
//������������������������������������������������������id
@@ -396,11 +401,9 @@
for(int i=0;i<10;i++) {
if(!parentIdList.isEmpty()) {
//������������������������������
- System.out.println("parentIdList:"+parentIdList);
List<Map<String, Object>> childIdList = organizationRelationMapper.getChildIdByParentId(parentIdList);
//���������������id������
parentIdList.clear();
- System.out.println("childIdList:"+childIdList);
//������������id������������������
for (Map<String, Object> map : childIdList) {
organizationIdList.add(map.get("child_id"));
@@ -412,6 +415,62 @@
}
System.out.println(organizationIdList);
- return null;
+ //������������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