Browse Source

将报警条件放入redis

xujiaheng 3 years ago
parent
commit
bbf611653c

+ 12 - 2
AlarmEngineStarter/src/main/java/com/persagy/apm/energyalarmstarter/alarmengine/jms/AlarmEngineMsgHandler.java

@@ -1,5 +1,6 @@
 package com.persagy.apm.energyalarmstarter.alarmengine.jms;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.apm.energyalarmstarter.alarmdata.mq.model.DmpMessage;
@@ -9,6 +10,9 @@ import io.netty.channel.ChannelHandler;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import javax.annotation.Resource;
 import org.springframework.util.CollectionUtils;
 
 import java.util.Map;
@@ -26,6 +30,9 @@ public class AlarmEngineMsgHandler {
     @Autowired
     private AlarmRecordMsgHandler alarmRecordMsgHandler;
 
+    @Resource(name = "alarmRedisTemplate")
+    private RedisTemplate<String, String> alarmRedisTemplate;
+
     @SneakyThrows
     public String getAlarmCategory(DmpMessage dmpMessage) {
         JSONObject data = dmpMessage.getExts();
@@ -91,6 +98,7 @@ public class AlarmEngineMsgHandler {
     public void syncNewCondition(DmpMessage msg) {
         AlarmCondition alarmCondition = JSONObject.parseObject(msg.getStr1(), AlarmCondition.class);
         // TODO: 2021/11/16  更新redis
+        alarmRedisTemplate.opsForHash().put("ALARM_CONDITION", alarmCondition.getId(), JSON.toJSONString(alarmCondition));
     }
 
     /**
@@ -103,6 +111,8 @@ public class AlarmEngineMsgHandler {
     public void syncUpdatedCondition(DmpMessage msg) {
         AlarmCondition alarmCondition = JSONObject.parseObject(msg.getStr1(), AlarmCondition.class);
         // TODO: 2021/11/16  更新redis
+        alarmRedisTemplate.opsForHash().delete("ALARM_CONDITION",alarmCondition.getId());
+        alarmRedisTemplate.opsForHash().put("ALARM_CONDITION", alarmCondition.getId(), JSON.toJSONString(alarmCondition));
     }
 
     /**
@@ -113,9 +123,9 @@ public class AlarmEngineMsgHandler {
      * @version V1.0 2021/10/26 7:51 下午
      */
     public void syncDeletedCondition(DmpMessage msg) {
-        AlarmCondition alarmCondition = new AlarmCondition();
-        alarmCondition.setId(msg.getStr1());
         // TODO: 2021/11/16 更新redis
+        alarmRedisTemplate.opsForHash().delete("ALARM_CONDITION",msg.getStr1());
+
     }
 
     /**