From bb77c5e3089fc3e9ccb520625b7798d81c99bfa2 Mon Sep 17 00:00:00 2001
From: 于紫祥_1901 <email@yuzixiang_1910>
Date: Fri, 06 Nov 2020 13:55:15 +0800
Subject: [PATCH] update
---
src/main/java/com/moral/service/impl/HistoryServiceImpl.java | 162 +++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 137 insertions(+), 25 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
index a9f03ea..343cdd3 100644
--- a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -1,6 +1,7 @@
package com.moral.service.impl;
import java.math.BigDecimal;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
@@ -10,22 +11,9 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import javax.annotation.Resource;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.springframework.stereotype.Service;
-import org.springframework.util.ObjectUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@@ -46,6 +34,11 @@
import com.moral.service.HistoryService;
import com.moral.service.ProfessionService;
import com.moral.util.AQICalculation;
+import com.moral.util.DatesUtil;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
@Service
public class HistoryServiceImpl implements HistoryService {
@@ -124,7 +117,9 @@
public String queryValueByMacAndTime(String mac, Date time) {
return historyMapper.selectValueByMacAndTime(mac, time);
}
-
+ public String getValueByMacAndTime(String mac, String time,String time1) {
+ return historyMapper.getValueByMacAndTime(mac, time,time1);
+ }
@Override
public List<Map<String, Object>> getRegionRankingData(Map<String, Object> parameters) {
ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null");
@@ -378,7 +373,6 @@
startTime = localDate + " " + startHour + ":00:00";
}
Map<String, Object> map = historyMapper.getAVGValueByMacAndTimeslot(mac, startTime, endTime);
- System.out.println(map);
Map<String, Object> returnMap = new HashMap<>();
if (map.isEmpty()) {
returnMap.put("AQI", "N/V");
@@ -391,7 +385,8 @@
}
returnMap = AQICalculation.hourlyAQI(AQIMap);
}
-
+ long aqi = Math.round(Double.valueOf(returnMap.get("AQI").toString()));
+ returnMap.put("AQI",aqi);
return returnMap;
}
@@ -465,7 +460,6 @@
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");
@@ -487,6 +481,8 @@
String startTime = parameters.get("startTime").toString();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
+ LocalDateTime today = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
+ LocalDateTime startTimeDay = startTimeLocalDateTime.truncatedTo(ChronoUnit.DAYS);
int year = startTimeLocalDateTime.getYear();
int month = startTimeLocalDateTime.getMonthValue();
String monthStr = month < 10 ? ("0" + month) : month + "";
@@ -498,13 +494,18 @@
}
parameters.put("sensorKeys", sensorKeys);
List<Map<String, Object>> listMap = null;
- listMap = historyMapper.getCarSensorData(parameters);
+ if (today.compareTo(startTimeDay) == 0) {
+ listMap = historyMapper.listGetSensorData(parameters);
+ }
if (CollectionUtils.isEmpty(listMap)) {
- if (year <= 2019) {
- listMap = historyMinutelyMapper.getSensorData(parameters);
- } else {
- parameters.put("yearAndMonth", yearAndMonth);
- listMap = historyMinutelyMapper.getSensorData2020(parameters);
+ listMap = historyMapper.getCarSensorData(parameters);
+ if (CollectionUtils.isEmpty(listMap)) {
+ if (year <= 2019) {
+ listMap = historyMinutelyMapper.getSensorData(parameters);
+ } else {
+ parameters.put("yearAndMonth", yearAndMonth);
+ listMap = historyMinutelyMapper.getSensorData2020(parameters);
+ }
}
}
List<List<Map<String, Object>>> listMaps = new ArrayList<>();
@@ -522,7 +523,9 @@
for (Map.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().replace("\"", "")).stripTrailingZeros().toPlainString() + sensor.getUnit());
+ if (entry.getValue() != null) {
+ mapAvg.put(entry.getKey(), new BigDecimal(entry.getValue().toString().replace("\"", "")).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())) {
@@ -543,4 +546,113 @@
}
return listMaps;
}
+
+ @Override
+ public List<Map<String, Object>> getUavSensorData(Map<String, Object> parameters) {
+ 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>> uavSensorData = historyMapper.getUavSensorData(parameters);
+ for (Map<String, Object> dataMap : uavSensorData) {
+ for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
+ for (Sensor sensor : sensors) {
+ if (sensor.getSensorKey().equals(entry.getKey())) {
+ if (entry.getValue() != null) {
+ dataMap.put(entry.getKey(), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString() + sensor.getUnit());
+ }
+ }
+ }
+ }
+ }
+ Map<String, Object> map = sensorMapper.getSensorBySensorKey(parameters.get("sensorKey").toString());
+ parameters.put("unit", map.get("unit"));
+ parameters.put("description", map.get("description"));
+ return uavSensorData;
+ }
+
+ @Override
+ public List<Map<String, Object>> getO3AVG(Map<String, Object> parameters) {
+ String mac = (String) parameters.get("mac");
+ String stime = (String) parameters.get("time");
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
+ Date time = null;
+ try {
+ time = format.parse(stime);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ List<String> stringListDate = DatesUtil.getAllTheDateOftheMonth(time);
+ List<Map<String, Object>> maxList = new ArrayList<Map<String, Object>>();
+ for (String date : stringListDate) {
+ Map<String, Object> parm = new HashMap<String, Object>();
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ LocalDateTime time1 = LocalDateTime.parse(date + " 00:00:00", df);
+ LocalDateTime time2 = time1.plusDays(1);
+ String time3 = time2.toString().substring(0, 10);
+ String nextDate = time3 + " 07:00:00";
+ parm.put("date", date);
+ parm.put("nextDate", nextDate);
+ parm.put("mac", mac);
+ List<Map<String, Object>> listMap = historyMapper.getO3AVG(parm);
+ List list = new ArrayList();
+ DatesUtil.getList(listMap, list);
+ List list1 = new ArrayList();
+ String maxO3 = "";
+ for (int i = 0; i < list.size(); i++) {
+ List elist = new ArrayList();
+ Double sum = 0.0;
+ Double avg = 0.0;
+ for (Object o : (List) list.get(i)) {
+ Iterator<Map.Entry> iterator = ((Map) o).entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = iterator.next();
+ if (entry.getKey().equals("e15")) {
+ elist.add(entry.getValue());
+ }
+ }
+ }
+ for (int j = 0; j < elist.size(); j++) {
+ sum += Double.parseDouble((String) elist.get(j));
+ if (listMap.size() <= 8 && listMap.size() > 0) {
+ avg = sum / listMap.size();
+ } else {
+ avg = sum / 8;
+ }
+ }
+ if (avg == 0.0) {
+ list1.add("");
+ } else {
+ BigDecimal b = new BigDecimal(avg);
+ double avg1 = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
+ list1.add(avg1);
+ }
+ }
+ String timef = date + " 00:00:00";
+ String timea = date + " 23:59:59";
+ int num = historyMapper.getNum(timef, timea);
+ if (num == 0) {
+ maxO3 = "";
+ } else {
+ if (list1.size() != 0) {
+ maxO3 = "" + Collections.max(list1);
+ } else {
+ maxO3 = "";
+ }
+ }
+ Map<String, Object> avgMap = new HashMap<String, Object>();
+ avgMap.put("time", date);
+ avgMap.put("e15", maxO3);
+ maxList.add(avgMap);
+ }
+ return maxList;
+ }
+
+ @Override
+ public String getJsonData(String mac, String time,String table) {
+ return historyMapper.getJsonData(mac,time,table);
+ }
+
}
--
Gitblit v1.8.0