|
|
@@ -26,6 +26,7 @@ import java.math.BigDecimal;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
/**
|
|
|
@@ -95,6 +96,13 @@ public class WarnService {
|
|
|
warnConfigInfo.setDevBid(devBid);
|
|
|
|
|
|
Map<String, List<WarnConfigInfo>> configMap = iotWarnBussinessService.selectIotWarnConfigInfoMap(warnConfigInfo);
|
|
|
+ if (configMap == null || configMap.size() == 0) {
|
|
|
+ log.info("[设备告警] 该设备没有配置,devBid:{}", devBid);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, IotDevicefactor> factorMap = getDevicefactorMap(devBid);
|
|
|
+
|
|
|
//配置一个个检查
|
|
|
for(Map.Entry<String, List<WarnConfigInfo>> entry : configMap.entrySet()) {
|
|
|
List<WarnConfigInfo> configList = entry.getValue();
|
|
|
@@ -102,7 +110,7 @@ public class WarnService {
|
|
|
try{
|
|
|
switch (iotDeviceTypeLv1Enum) {
|
|
|
case QXZ: {
|
|
|
- warnResult = comparableQxzReportData(iotDevice, configList, data);
|
|
|
+ warnResult = comparableQxzReportData(iotDevice, configList, data, factorMap);
|
|
|
break;
|
|
|
}
|
|
|
// case SQZ: {
|
|
|
@@ -198,26 +206,43 @@ public class WarnService {
|
|
|
String wcStatus = config.getWcStatus();
|
|
|
String wiStatus = config.getWiStatus();
|
|
|
String key = wiAddress + wiCode;
|
|
|
+ String expression = config.getWiExpression();
|
|
|
|
|
|
+ // 如果上报数据中没有预警配置中的要素,直接返回null,不进行预警判断
|
|
|
if (!currentValueMap.containsKey(key)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ // 如果没有配置预警条件和值,直接返回null,不进行预警判断
|
|
|
+ if(StringUtils.isEmpty(expression) || StringUtils.isEmpty(targetValue)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
String wiName = config.getWiName();
|
|
|
if(factorMap.containsKey(key)){
|
|
|
IotDevicefactor iotDevicefactor = factorMap.get(key);
|
|
|
+ // 如果禁用,直接返回null,不进行预警判断
|
|
|
+ if(Objects.equals(iotDevicefactor.getDfDisable(), "1")){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
String displayname = iotDevicefactor.getDfDisplayname();
|
|
|
if(StringUtils.isNotEmpty(displayname)){
|
|
|
wiName = displayname;
|
|
|
}
|
|
|
}
|
|
|
- String wiUnit = config.getWiUnit();
|
|
|
|
|
|
+ String wiUnit = config.getWiUnit();
|
|
|
String currentValue = currentValueMap.get(key);
|
|
|
- String expression = config.getWiExpression();
|
|
|
+
|
|
|
EnumWarnRuleOp warnRuleOp = EnumWarnRuleOp.findEnumByCode(expression);
|
|
|
+ if(warnRuleOp == null){
|
|
|
+ log.error("[设备告警] 表达式不正确,devCode:{}, wiAddress:{}, config:{}", devCode, wiAddress, config);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
String ruleName = warnRuleOp.getName();
|
|
|
|
|
|
+ // 如果配置禁用,或者要素禁用,直接返回null,不进行预警判断
|
|
|
boolean status = "0".equals(wcStatus) && "0".equals(wiStatus);
|
|
|
if(!status){
|
|
|
return null;
|
|
|
@@ -225,7 +250,7 @@ public class WarnService {
|
|
|
boolean tempSuccess = CompareUtil.comp(currentValue, expression, targetValue);
|
|
|
|
|
|
String warnMessage = WarnMessageBuilderUtil.buildQxzWarningMessage(
|
|
|
- "气象站设备", devCode, wiName, currentValue, wiUnit, ruleName, targetValue);
|
|
|
+ "气象站", devCode, wiName, currentValue, wiUnit, ruleName, targetValue);
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("warnMessage", warnMessage);
|
|
|
@@ -240,7 +265,8 @@ public class WarnService {
|
|
|
* @param config 对应的配置
|
|
|
* @param jsonObject 上报的数据
|
|
|
*/
|
|
|
- private WarnResult comparableQxzReportData(IotDevice iotDevice, List<WarnConfigInfo> configList, JSONObject jsonObject) {
|
|
|
+ private WarnResult comparableQxzReportData(IotDevice iotDevice, List<WarnConfigInfo> configList,
|
|
|
+ JSONObject jsonObject, Map<String, IotDevicefactor> factorMap) {
|
|
|
String devCode = iotDevice.getDevCode();
|
|
|
String devBid = iotDevice.getDevBid();
|
|
|
WarnConfigInfo configInfo = configList.get(0);
|
|
|
@@ -263,7 +289,6 @@ public class WarnService {
|
|
|
warnResult.setConfig(iotWarnconfig);
|
|
|
warnResult.setTriggered(false);
|
|
|
|
|
|
- Map<String, IotDevicefactor> factorMap = getDevicefactorMap(devBid);
|
|
|
String message = null;
|
|
|
StringBuilder messageBuilder = new StringBuilder();
|
|
|
for (WarnConfigInfo config : configList) {
|