From dce0021131e955bac968cb2a7e24ce3673eb1a3b Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Mon, 02 Aug 2021 17:22:15 +0800
Subject: [PATCH] 监测因子趋势图
---
screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java | 43 ++++++++++++++++++++++++++++++++++++++-----
1 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java b/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
index ed9a04a..368cfb5 100644
--- a/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
+++ b/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -1,7 +1,9 @@
package com.moral.api.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
@@ -21,6 +23,8 @@
import com.moral.api.service.HistoryMinutelyService;
import com.moral.api.service.SensorService;
import com.moral.constant.Constants;
+import com.moral.constant.RedisConstants;
+import com.moral.util.AmendUtils;
import com.moral.util.DateUtils;
@Service
@@ -40,7 +44,11 @@
historyFiveMinutelyMapper.createTable(timeUnits);
}
+ @Autowired
+ private RedisTemplate redisTemplate;
+
@Override
+ @Transactional
public void insertHistoryFiveMinutely() {
//������������������yyyy-MM-dd HH:mm
String format = DateUtils.yyyy_MM_dd_HH_mm_EN;
@@ -63,6 +71,10 @@
//���������������������5������������
List<Map<String, Object>> fiveMinutelyData = historyMinutelyService.getHistoryFiveMinutelyData(params);
+ if (fiveMinutelyData.size() == 0) {
+ return;
+ }
+
//���mac������
Map<String, List<Map<String, Object>>> data = fiveMinutelyData.parallelStream()
.collect(Collectors.groupingBy(o -> (String) o.get("mac")));
@@ -72,9 +84,17 @@
data.forEach((key, value) -> {
Map<String, Object> dataMap = new HashMap<>();
- Map<String, Object> jsonMap = new HashMap<>();
dataMap.put("mac", key);
dataMap.put("time", end);
+ Map<String, Object> jsonMap = new HashMap<>();
+
+ //���������������������������
+ Object windDirAvg = AmendUtils.getWindDirAvg(value);
+ if (windDirAvg != null) {
+ jsonMap.put(Constants.SENSOR_CODE_WIND_DIR, windDirAvg);
+ }
+
+ //������������������������������������
sensorCodes.forEach(sensorCode -> {
OptionalDouble optionalDouble = value.parallelStream()
.flatMapToDouble(v -> {
@@ -83,23 +103,33 @@
if (ObjectUtils.isEmpty(sensorValue)) {
return null;
}
+ //������������������
+ if (Constants.SENSOR_CODE_WIND_DIR.equals(sensorCode)) {
+ return null;
+ }
return DoubleStream.of(Double.parseDouble(sensorValue.toString()));
}).average();
if (optionalDouble.isPresent()) {
- jsonMap.put(sensorCode.toString(), Double.parseDouble(String.format("%.4f", optionalDouble.getAsDouble())));
+ //���������������������
+ double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 4);
+ jsonMap.put(sensorCode.toString(), sciCal);
}
});
dataMap.put("value", JSONObject.toJSONString(jsonMap));
+ //������redis
+ redisTemplate.opsForHash().put(RedisConstants.DATA_FIVE_MINUTES, key, jsonMap);
insertData.add(dataMap);
});
//5���������������
- String insertTimeUnits = DateUtils.dateToDateString(new Date());
+ String insertTimeUnits = DateUtils.dateToDateString(now, DateUtils.yyyyMM_EN);
+ //���������������
historyFiveMinutelyMapper.insertHistoryFiveMinutely(insertData, insertTimeUnits);
}
+
public static void main(String[] args) {
- //������������
+ /* //������������
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> map1 = new HashMap<>();
map1.put("mac", "p5dnd1234567");
@@ -154,6 +184,9 @@
});
- System.out.println("666==" + insertData);
+ System.out.println("666==" + insertData);*/
+
+ double a = 5.5d;
+ System.out.println(Math.round(a));
}
}
--
Gitblit v1.8.0