From 2bfc4ed9012c5cae2a01bc67bdce68eeb59dc0b8 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Tue, 03 Sep 2019 13:38:19 +0800
Subject: [PATCH] 完善排名
---
src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java | 37 ++++++++++++++++++-------------------
1 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java
index ce67df4..20f9137 100644
--- a/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java
@@ -1,12 +1,10 @@
package com.moral.service.impl;
-import static com.moral.common.bean.Constants.NULL_VALUE;
-import static org.springframework.util.ObjectUtils.isEmpty;
-
import java.math.BigDecimal;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Arrays;
@@ -28,8 +26,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
-
-import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.time.DateUtils;
@@ -53,6 +49,10 @@
import com.moral.mapper.HistoryMinutelyMapper;
import com.moral.mapper.SensorMapper;
import com.moral.service.HistoryMinutelyService;
+import javax.annotation.Resource;
+
+import static com.moral.common.bean.Constants.NULL_VALUE;
+import static org.springframework.util.ObjectUtils.isEmpty;
@Service
@SuppressWarnings({"unchecked", "unused", "rawtypes"})
@@ -538,12 +538,11 @@
@Override
public List<List<Map<String, Object>>> getSensorData(Map<String, Object> parameters) {
String startTime = parameters.get("startTime").toString();
- Boolean flag = null;
- try {
- flag = DateUtils.isSameDay(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime), new Date());
- } catch (ParseException e) {
- e.printStackTrace();
- }
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+ LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
+ LocalDate today = LocalDate.now();
+ LocalDate startTimeLocalDate=startTimeLocalDateTime.toLocalDate();
+ Boolean flag=today.isEqual(startTimeLocalDate);
List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters);
List<String> sensorKeys = new ArrayList<>();
for (Sensor sensor : sensors) {
@@ -568,14 +567,14 @@
mapAvg.put("time", map.get("time"));
mapMin.put("time", map.get("time"));
mapMax.put("time", map.get("time"));
- for (String key : map.keySet()) {
+ for (Entry<String,Object> entry : map.entrySet()) {
for (Sensor sensor : sensors) {
- if (sensor.getSensorKey().equals(key)) {
- mapAvg.put(key, new BigDecimal(map.get(key).toString()).stripTrailingZeros().toPlainString() + sensor.getUnit());
- } else if (("min" + sensor.getSensorKey()).equals(key)) {
- mapMin.put(key.substring(3), new BigDecimal(map.get(key).toString().replace("\"", "")).stripTrailingZeros().toPlainString());
- } else if (("max" + sensor.getSensorKey()).equals(key)) {
- mapMax.put(key.substring(3), new BigDecimal(map.get(key).toString().replace("\"", "")).stripTrailingZeros().toPlainString());
+ 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());
}
}
}
--
Gitblit v1.8.0