Quellcode durchsuchen

修复 多参数请求生成sql语句失败的问题

zhaiyifei vor 9 Monaten
Ursprung
Commit
b792530cb2

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iots/core/http/ZjsfXycbHttpClient.java

@@ -191,7 +191,7 @@ public class ZjsfXycbHttpClient extends HttpClient {
 
         log.info("【中捷四方性诱HTTP】【开始请求:{}】参数:{}", sendUrl, sb);
         String rspBody = httpPost(sendUrl, sb.toString());
-        log.info("【中捷四方性诱HTTP】【结束请求:{}】参数:{} headers: {} 响应: {}", sendUrl, sb, headers, rspBody);
+        log.info("【中捷四方性诱HTTP】【结束请求:{}】参数:{}", sendUrl, sb);
         Map<String, Object> rspMap = JSONUtils.toMap(rspBody);
         String result = (String)rspMap.get("result");
         if(!Objects.equals(result, "success")){

+ 31 - 6
src/main/java/com/yunfeiyun/agmp/iots/warn/service/WarnService.java

@@ -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) {

+ 2 - 2
src/main/java/com/yunfeiyun/agmp/iots/warn/util/WarnMessageBuilderUtil.java

@@ -14,7 +14,7 @@ public class WarnMessageBuilderUtil {
      * @return 格式化后的告警信息。
      */
     public static String buildQxzWarningMessage(String devType, String devCode, String name, String value, String unit, String opt, String indicatorValue) {
-        return String.format("%s设备(%s),触发告警,告警原因(%s%s%s),%s设置的阀值%s",
+        return String.format("%s设备(%s),触发告警,告警原因(%s 上报值 %s%s),%s设置的阀值%s",
                 devType,
                 devCode,
                 name,
@@ -25,7 +25,7 @@ public class WarnMessageBuilderUtil {
     }
 
     public static void main(String[] args) {
-        String message = buildQxzWarningMessage("气象站设备", "87872877485", "温度", "42", "℃", "超过", "10-35℃");
+        String message = buildQxzWarningMessage("气象站", "87872877485", "温度", "42", "℃", "超过", "10-35℃");
         System.out.println(message);
     }
 }