From 7cb615548209e3fa4c528b39012078c9031d2255 Mon Sep 17 00:00:00 2001
From: chen_xi <276999030@qq.com>
Date: Thu, 13 Oct 2022 16:18:41 +0800
Subject: [PATCH] 补偿接口bug修改
---
screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java | 90 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 73 insertions(+), 17 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 ecdfd80..f2b0a38 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
@@ -53,6 +53,9 @@
//������������������yyyy-MM-dd HH:mm
String format = DateUtils.yyyy_MM_dd_HH_mm_EN;
Date now = new Date();
+ now = DateUtils.getFiveMinuteDate(now);
+
+ //������������������������������
Map<String, Object> params = new HashMap<>();
//������������
Date start = DateUtils.dataToTimeStampTime(DateUtils.getDateOfMin(now, -5), format);
@@ -65,9 +68,9 @@
params.put("timeUnits", timeUnits);
//������
- QueryWrapper<Sensor> queryWrapper = new QueryWrapper<>();
- queryWrapper.select("code").eq("is_delete", Constants.NOT_DELETE);
- List<Object> sensorCodes = sensorService.listObjs(queryWrapper);
+ QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>();
+ sensorQueryWrapper.select("code", "lower", "upper").eq("is_delete", Constants.NOT_DELETE);
+ List<Sensor> sensors = sensorService.list(sensorQueryWrapper);
//���������������������5������������������
List<Map<String, Object>> fiveMinutelyData = historyMinutelyMapper.getHistoryMinutelyData(params);
@@ -85,44 +88,97 @@
data.forEach((key, value) -> {
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("mac", key);
- dataMap.put("time", end);
+ dataMap.put("time", start);
Map<String, Object> jsonMap = new HashMap<>();
+
+ Map<String, Object> map = new HashMap<>();
+ map.put("data", value);
+ map.put("type", "fiveMinutes");
+ for (Sensor sensor : sensors) {
+ String sensorCode = sensor.getCode();
+
+ //���������������
+ if (sensorCode.equals(Constants.SENSOR_CODE_WIND_DIR)) {
+ if (sensor.getUpper() != null) {
+ map.put("windDirUpper", sensor.getUpper());
+ }
+ if (sensor.getLower() != null) {
+ map.put("windDirLower", sensor.getLower());
+ }
+ }
+
+ //���������������
+ if (sensorCode.equals(Constants.SENSOR_CODE_WIND_SPEED)) {
+ if (sensor.getUpper() != null) {
+ map.put("windSpeedUpper", sensor.getUpper());
+ }
+ if (sensor.getLower() != null) {
+ map.put("windSpeedLower", sensor.getLower());
+ }
+ }
+ }
+
//���������������������������
- Object windDirAvg = AmendUtils.getWindDirAvg(value);
- if (windDirAvg != null) {
- jsonMap.put(Constants.SENSOR_CODE_WIND_DIR, windDirAvg);
+ Map<String, Object> windDirAvg = AmendUtils.getWindDirAvg(map);
+ if (!ObjectUtils.isEmpty(windDirAvg)) {
+ jsonMap.putAll(windDirAvg);
}
//������������������������������������
- sensorCodes.forEach(sensorCode -> {
- OptionalDouble optionalDouble = value.parallelStream()
+ sensors.forEach(sensor -> {
+ String sensorCode = sensor.getCode();
+ Double upper = sensor.getUpper();
+ Double lower = sensor.getLower();
+ DoubleStream optionalDouble = value.parallelStream()
.flatMapToDouble(v -> {
Map<String, Object> dataValue = JSONObject.parseObject((String) v.get("value"), Map.class);
- Object sensorValue = dataValue.get(sensorCode.toString());
+ Object sensorValue = dataValue.get(sensorCode);
+ //������������������������
+ Object flag = dataValue.get(sensorCode + "-" + Constants.MARKER_BIT_KEY);
+ if (!Constants.MARKER_BIT_TRUE.equals(flag)) {
+ return null;
+ }
+
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()) {
+ //������������������������������������
+ double aDouble = Double.parseDouble(sensorValue.toString());
+ if (!ObjectUtils.isEmpty(upper)) {
+ if (aDouble > upper) {
+ return null;
+ }
+ }
+ if (!ObjectUtils.isEmpty(lower)) {
+ if (aDouble < lower) {
+ return null;
+ }
+ }
+ return DoubleStream.of(aDouble);
+ });
+
+ OptionalDouble average = optionalDouble.average();
+ if (average.isPresent()) {
//���������������������
- double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 4);
- jsonMap.put(sensorCode.toString(), sciCal);
+ double sciCal = AmendUtils.sciCal(average.getAsDouble(), 4);
+ jsonMap.put(sensorCode, sciCal);
}
+
});
dataMap.put("value", JSONObject.toJSONString(jsonMap));
//������redis
+ jsonMap.put("dataTime", DateUtils.dateToDateString(start));
redisTemplate.opsForHash().put(RedisConstants.DATA_FIVE_MINUTES, key, jsonMap);
insertData.add(dataMap);
});
//5���������������
- String insertTimeUnits = DateUtils.dateToDateString(now, DateUtils.yyyyMM_EN);
+ String insertTimeUnits = DateUtils.dateToDateString(start, DateUtils.yyyyMM_EN);
//���������������
historyFiveMinutelyMapper.insertHistoryFiveMinutely(insertData, insertTimeUnits);
}
--
Gitblit v1.8.0