Sfoglia il codice sorgente

优化报警逻辑

lixing 3 anni fa
parent
commit
e86877e5f2

+ 6 - 0
src/main/java/com/persagy/entity/AlarmDefine.java

@@ -137,4 +137,10 @@ public class AlarmDefine {
         alarmDefine.setCondition(condition);
         return alarmDefine;
     }
+
+    public static void main(String[] args) {
+        String tmp = "{\\\"period\\\":{\\\"startTime\\\":\\\"000000\\\",\\\"endTime\\\":\\\"235958\\\"},\\\"type\\\":\\\"period\\\"}";
+        JSONObject jsonObject = JSON.parseObject(tmp);
+        System.out.println(jsonObject.getString("type"));
+    }
 }

+ 7 - 0
src/main/java/com/persagy/service/impl/AlarmHandleServiceImpl.java

@@ -25,6 +25,7 @@ import com.persagy.utils.StringUtil;
 import com.persagy.utils.ValidateUtils;
 import com.persagy.utils.condition.ConditionUtils;
 import com.rabbitmq.client.Channel;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.quartz.JobDataMap;
@@ -101,6 +102,7 @@ public class AlarmHandleServiceImpl {
      */
     @RabbitHandler
     @RabbitListener(queues = "alarm-data-queue")
+    @SneakyThrows
     public void handleIotMsg(Message message, Channel channel) {
         try {
             JSONArray msgJsonArray = JSON.parseArray(new String(message.getBody()));
@@ -164,6 +166,7 @@ public class AlarmHandleServiceImpl {
             channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
         } catch (Exception e) {
             log.error("mq 接收处理发数数据发生错误", e);
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
         }
 
     }
@@ -205,6 +208,10 @@ public class AlarmHandleServiceImpl {
             //            AlarmCondition alarmCondition = alarmInfoCache.getAlarmCondition(conditionId);
             AlarmCondition alarmCondition = alarmRedisCache.getAlarmCondition(conditionId);
 
+            if (alarmCondition == null) {
+                continue;
+            }
+
             // 解析触发和恢复条件
             String trigger = alarmCondition.getTriggerBackend();
             Expression triggerExp = AviatorEvaluator.compile(trigger, true);

+ 2 - 1
src/main/resources/application.yml

@@ -6,6 +6,7 @@ rabbitmq.host: 192.168.100.93
 rabbitmq.port: 9936
 rabbitmq.username: pbsage
 rabbitmq.password: pbsage123
+rabbitmq.virtual-host: /test
 # redis连接信息
 redis.host: 192.168.100.93
 redis.port: 9944
@@ -75,7 +76,7 @@ spring:
     port: ${rabbitmq.port}
     username: ${rabbitmq.username}
     password: ${rabbitmq.password}
-    virtual-host: /test
+    virtual-host: ${rabbitmq.virtual-host}
     connection-timeout: 2000ms
     listener:
       simple: