From 1b693369a0855332084612ab5e2159e7cb9f681b Mon Sep 17 00:00:00 2001
From: chen_xi <276999030@qq.com>
Date: Wed, 19 Oct 2022 13:43:15 +0800
Subject: [PATCH] 根据mac查询报警信息加上特殊设备
---
screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java | 82 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 79 insertions(+), 3 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 d1d059b..3071566 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
@@ -5,11 +5,13 @@
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
+import java.math.BigDecimal;
import java.util.Date;
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;
@@ -23,7 +25,7 @@
public class AdjustDataUtils {
/**
* @param deviceData ������������
- * @param adjustFormula ������������
+ * @param adjustFormula ������������������������������������������������key���������code,value������������������������������������������List���
* @param aqiMap ������������������������������aqi������
* @return Map<String, Object> ���������������
*/
@@ -31,6 +33,20 @@
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")) {
//���������
@@ -62,14 +78,15 @@
if (aqiMap != null) {
aqiValue = aqiMap.get(key);
}
- env.put("aqi", ObjectUtils.isEmpty(aqiValue) ? 0F : Float.parseFloat((String) aqiValue));
+ env.put("aqi", ObjectUtils.isEmpty(aqiValue) ? 0F : new BigDecimal(String.valueOf(aqiValue)).floatValue());
}
if (formula.contains("vocs")) {
Object vocsValue = ObjectUtils.isEmpty(deviceData.get(Constants.SENSOR_CODE_VOCS)) ? 0F : deviceData.get(Constants.SENSOR_CODE_VOCS);
env.put("vocs", vocsValue);
}
if (formula.contains("cel")) {
- env.put("cel", Float.parseFloat((String) measuredValue));
+ //env.put("cel", Float.parseFloat((String) measuredValue));
+ env.put("cel", new BigDecimal(String.valueOf(measuredValue)).floatValue());
}
//������
measuredValue = expression.execute(env);
@@ -85,4 +102,63 @@
}
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