Bladeren bron

捕捉同步报警定义的异常

lixing 2 jaren geleden
bovenliggende
commit
49c1ff6c90

+ 49 - 46
AlarmEngineStarter/src/main/java/com/persagy/apm/energyalarmstarter/alarmengine/jms/AlarmEngineMsgHandler.java

@@ -230,59 +230,62 @@ public class AlarmEngineMsgHandler {
      * @author lixing
      * @version V1.0 2021/11/20 3:08 下午
      */
-    @SneakyThrows
     public void incrementSyncAlarmConfig(DmpMessage dmpMessage) {
-        log.debug("增量同步报警定义");
-        Map<String, List<AlarmConfigItem>> changedAlarmConfigs = alarmRecordMsgHandler.queryChangedAlarmConfigs(dmpMessage);
-        List<AlarmConfigItem> createdConfigUniques = changedAlarmConfigs.get("createdConfigUniques");
-        List<AlarmConfigItem> deletedConfigUniques = changedAlarmConfigs.get("deletedConfigUniques");
-        if (!CollectionUtils.isEmpty(deletedConfigUniques)) {
-            for (AlarmConfigItem alarmConfigItem : deletedConfigUniques) {
-                //从redis拿到设备的报警条件信息
-                ObjConditionInfo objConditionInfo = redisUtil.get(RedisConstants.OBJ_CONDITION_REL, alarmConfigItem.getObjId(), ObjConditionInfo.class);
-                if (objConditionInfo == null) {
-                    continue;
-                }
-                LinkedList<ItemCodeCondition> conditions = objConditionInfo.getConditions();
-                if (CollectionUtils.isEmpty(conditions)) {
-                    continue;
-                }
-                LinkedList<ItemCodeCondition> conditionsRemain = new LinkedList<>();
-                for (ItemCodeCondition condition : conditions) {
-                    if (alarmConfigItem.getItemCode().equals(condition.getItemCode())) {
-                        //删除报警条件
-                        redisUtil.delete(RedisConstants.ALARM_CONDITIONS, condition.getConditionId());
+        try {
+            log.debug("增量同步报警定义");
+            Map<String, List<AlarmConfigItem>> changedAlarmConfigs = alarmRecordMsgHandler.queryChangedAlarmConfigs(dmpMessage);
+            List<AlarmConfigItem> createdConfigUniques = changedAlarmConfigs.get("createdConfigUniques");
+            List<AlarmConfigItem> deletedConfigUniques = changedAlarmConfigs.get("deletedConfigUniques");
+            if (!CollectionUtils.isEmpty(deletedConfigUniques)) {
+                for (AlarmConfigItem alarmConfigItem : deletedConfigUniques) {
+                    //从redis拿到设备的报警条件信息
+                    ObjConditionInfo objConditionInfo = redisUtil.get(RedisConstants.OBJ_CONDITION_REL, alarmConfigItem.getObjId(), ObjConditionInfo.class);
+                    if (objConditionInfo == null) {
+                        continue;
+                    }
+                    LinkedList<ItemCodeCondition> conditions = objConditionInfo.getConditions();
+                    if (CollectionUtils.isEmpty(conditions)) {
+                        continue;
+                    }
+                    LinkedList<ItemCodeCondition> conditionsRemain = new LinkedList<>();
+                    for (ItemCodeCondition condition : conditions) {
+                        if (alarmConfigItem.getItemCode().equals(condition.getItemCode())) {
+                            //删除报警条件
+                            redisUtil.delete(RedisConstants.ALARM_CONDITIONS, condition.getConditionId());
+                        } else {
+                            conditionsRemain.add(condition);
+                        }
+                    }
+                    if (CollectionUtil.isEmpty(conditionsRemain)) {
+                        redisUtil.delete(RedisConstants.OBJ_CONDITION_REL, alarmConfigItem.getObjId());
                     } else {
-                        conditionsRemain.add(condition);
+                        objConditionInfo.setConditions(conditionsRemain);
+                        redisUtil.put(RedisConstants.OBJ_CONDITION_REL, alarmConfigItem.getObjId(), objConditionInfo);
                     }
                 }
-                if (CollectionUtil.isEmpty(conditionsRemain)) {
-                    redisUtil.delete(RedisConstants.OBJ_CONDITION_REL, alarmConfigItem.getObjId());
-                } else {
-                    objConditionInfo.setConditions(conditionsRemain);
-                    redisUtil.put(RedisConstants.OBJ_CONDITION_REL, alarmConfigItem.getObjId(), objConditionInfo);
-                }
             }
-        }
-        if (!CollectionUtils.isEmpty(createdConfigUniques)) {
-            List<ObjConditionRel> createdRelList = new ArrayList<>();
-            for (AlarmConfigItem alarmConfigItem : createdConfigUniques) {
-                // 数据中台报警条件转化为业务中台报警条件和设备与条件的关联关系
-                AlarmCondition alarmCondition = avgAlarmDmpCondition(alarmConfigItem);
-                if (alarmCondition == null) {
-                    continue;
+            if (!CollectionUtils.isEmpty(createdConfigUniques)) {
+                List<ObjConditionRel> createdRelList = new ArrayList<>();
+                for (AlarmConfigItem alarmConfigItem : createdConfigUniques) {
+                    // 数据中台报警条件转化为业务中台报警条件和设备与条件的关联关系
+                    AlarmCondition alarmCondition = avgAlarmDmpCondition(alarmConfigItem);
+                    if (alarmCondition == null) {
+                        continue;
+                    }
+                    // 存储报警条件
+                    redisUtil.put(RedisConstants.ALARM_CONDITIONS, alarmCondition.getId(), alarmCondition);
+                    // 存储设备与条件的关联关系
+                    ObjConditionRel objConditionRel = new ObjConditionRel();
+                    objConditionRel.setConditionId(alarmCondition.getId());
+                    objConditionRel.setObjId(alarmConfigItem.getObjId());
+                    objConditionRel.setItemCode(alarmConfigItem.getItemCode());
+                    objConditionRel.setProjectId(alarmConfigItem.getProjectId());
+                    createdRelList.add(objConditionRel);
                 }
-                // 存储报警条件
-                redisUtil.put(RedisConstants.ALARM_CONDITIONS, alarmCondition.getId(), alarmCondition);
-                // 存储设备与条件的关联关系
-                ObjConditionRel objConditionRel = new ObjConditionRel();
-                objConditionRel.setConditionId(alarmCondition.getId());
-                objConditionRel.setObjId(alarmConfigItem.getObjId());
-                objConditionRel.setItemCode(alarmConfigItem.getItemCode());
-                objConditionRel.setProjectId(alarmConfigItem.getProjectId());
-                createdRelList.add(objConditionRel);
+                syncCreatedObjConditionRelList2Redis(createdRelList);
             }
-            syncCreatedObjConditionRelList2Redis(createdRelList);
+        } catch (Exception e) {
+            log.error("增量同步报警定义失败", e);
         }
     }