From 8dce9a3ac3d04150a8656219b32f0bdda445ab2c Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Mon, 14 Mar 2022 17:13:43 +0800
Subject: [PATCH] 环比数据接口修改
---
screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java | 89 +++++++++++++++++++++++++++++++++++++++++---
1 files changed, 83 insertions(+), 6 deletions(-)
diff --git a/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java b/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java
index 86f21fc..0064a49 100644
--- a/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java
+++ b/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java
@@ -9,6 +9,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import com.alibaba.fastjson.JSON;
import com.googlecode.aviator.AviatorEvaluator;
@@ -22,14 +24,28 @@
public class AdjustDataUtils {
/**
* @param deviceData ������������
- * @param adjustFormula ������������
- * @param aqiMap ���������������������������������aqi������
+ * @param adjustFormula ������������������������������������������������key���������code,value������������������������������������������List���
+ * @param aqiMap ������������������������������aqi������
* @return Map<String, Object> ���������������
*/
public Map<String, Object> adjust(Map<String, Object> deviceData, Map<String, Object> adjustFormula, Map<String, Object> aqiMap) {
try {
Date time = DateUtils.getDate((String) deviceData.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN);
long finalTime = DateUtils.dataToTimeStampTime(time, DateUtils.HH_mm_ss_EN).getTime();
+
+ //������������������������������������������������������
+ if (deviceData.get(Constants.SENSOR_CODE_CURRENT_SPEED) != null) {
+ deviceData = adjustFlueSpeedAndFlow(deviceData, adjustFormula);
+ }
+
+ //������������������������������������������������
+ Set<String> dateKey = deviceData.keySet();
+ for (String adjustKey : adjustFormula.keySet()) {
+ if (!dateKey.contains(adjustKey)) {
+ deviceData.put(adjustKey, "0");
+ }
+ }
+
for (String key : deviceData.keySet()) {
if (!key.contains("Flag")) {
//���������
@@ -40,11 +56,14 @@
deviceData.put(key, measuredValue);
continue;
}
-
//���������������������������������
- DeviceAdjustValue deviceAdjustValue = sensorFormulas.stream()
+ DeviceAdjustValue deviceAdjustValue = new DeviceAdjustValue();
+ Optional<DeviceAdjustValue> optional = sensorFormulas.stream()
.filter(o -> o.getStartTime().getTime() <= finalTime && o.getEndTime().getTime() > finalTime)
- .findFirst().get();
+ .findFirst();
+ if (optional.isPresent()) {
+ deviceAdjustValue = optional.get();
+ }
String formula = deviceAdjustValue.getValue();
if (StringUtils.isEmpty(formula)) {
deviceData.put(key, measuredValue);
@@ -78,7 +97,65 @@
}
} catch (Exception e) {
log.error("param[0] deviceData:" + JSON.toJSONString(deviceData));
- log.error(e.getMessage());
+ }
+ return deviceData;
+ }
+
+ /**
+ * ���������������������������������
+ *
+ * @param deviceData ���������������������������������������������������������������������������������������������������������
+ * @param adjustFormula ���������������������������������������������������key���������code
+ */
+ public Map<String, Object> adjustFlueSpeedAndFlow(Map<String, Object> deviceData, Map<String, Object> adjustFormula) {
+ Date time = DateUtils.getDate((String) deviceData.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN);
+ long finalTime = DateUtils.dataToTimeStampTime(time, DateUtils.HH_mm_ss_EN).getTime();
+ //���������������
+ Object measuredValue = deviceData.get(Constants.SENSOR_CODE_CURRENT_SPEED);
+
+
+ //������������
+ List<DeviceAdjustValue> speedFormulas = (List<DeviceAdjustValue>) adjustFormula.get(Constants.SENSOR_CODE_CURRENT_SPEED);
+ if (!ObjectUtils.isEmpty(speedFormulas)) {
+ //���������������������������������
+ DeviceAdjustValue deviceAdjustValue = new DeviceAdjustValue();
+ Optional<DeviceAdjustValue> optional = speedFormulas.stream()
+ .filter(o -> o.getStartTime().getTime() <= finalTime && o.getEndTime().getTime() > finalTime)
+ .findFirst();
+ if (optional.isPresent()) {
+ deviceAdjustValue = optional.get();
+ }
+
+ String formula = deviceAdjustValue.getValue();
+ if (!StringUtils.isEmpty(formula)) {
+
+ Expression expression = AviatorEvaluator.compile(formula);
+ Map<String, Object> env = new HashMap<>();
+ env.put("cel", Float.parseFloat((String) measuredValue));
+ //������
+ measuredValue = expression.execute(env);
+ deviceData.put(Constants.SENSOR_CODE_CURRENT_SPEED, Double.parseDouble(String.format("%.4f", measuredValue)));
+ }
+
+
+ //������������
+ List<DeviceAdjustValue> flowFormulas = (List<DeviceAdjustValue>) adjustFormula.get(Constants.SENSOR_CODE_CURRENT_FLOW);
+ //���������������������������������
+ optional = flowFormulas.stream()
+ .filter(o -> o.getStartTime().getTime() <= finalTime && o.getEndTime().getTime() > finalTime)
+ .findFirst();
+ if (optional.isPresent()) {
+ deviceAdjustValue = optional.get();
+ }
+
+ formula = deviceAdjustValue.getValue();
+ if (!StringUtils.isEmpty(formula)) {
+ Expression expression = AviatorEvaluator.compile(formula);
+ Map<String, Object> env = new HashMap<>();
+ String currentSpeed = deviceData.get(Constants.SENSOR_CODE_CURRENT_SPEED).toString();
+ env.put("currentSpeed", Float.parseFloat(currentSpeed));
+ deviceData.put(Constants.SENSOR_CODE_CURRENT_FLOW, Double.parseDouble(String.format("%.4f", expression.execute(env))));
+ }
}
return deviceData;
}
--
Gitblit v1.8.0