Bladeren bron

修复报警过期消息bug

lixing 2 jaren geleden
bovenliggende
commit
97dd9b3285

+ 0 - 230
src/main/java/com/persagy/cache/AlarmInfoCache.java

@@ -25,79 +25,6 @@ import java.util.concurrent.ConcurrentHashMap;
 @Component
 @Slf4j
 public class AlarmInfoCache {
-
-    /**
-     * 报警对象id -> (条件Id,报警类型编码)列表,项目id
-     * objId -> {[{conditionId, itemCode}], projectId}
-     * 为线程安全,使用concurrentHashMap
-     */
-    private final ConcurrentHashMap<String, ObjConditionInfo> objConditionMap = new ConcurrentHashMap<>();
-
-    /**
-     * 报警条件id -> 报警条件
-     */
-    private final ConcurrentHashMap<String, AlarmCondition> alarmConditionMap = new ConcurrentHashMap<>();
-
-    /**
-     * (报警类型编码-报警对象id) -> 状态
-     * 报警类型和设备id可以确认唯一的报警条件
-     */
-    private final ConcurrentHashMap<String, AlarmConditionState> alarmConditionStateMap = new ConcurrentHashMap<>();
-
-    /**
-     * @param :
-     * @description:获取报警定义状态 <报警定义标识,报警时间状态>
-     * @exception:
-     * @author: LuoGuangyi
-     * @company: Persagy Technology Co.,Ltd
-     * @return: null
-     * @since: 2020/10/20 17:12
-     * @version: V1.0
-     */
-    public AlarmConditionState getAlarmDefineState(String definitionId) {
-        return alarmConditionStateMap.get(definitionId);
-    }
-
-    /**
-     * @param definitionId:        报警定义id
-     * @param alarmConditionState: 报警状态时间类
-     * @description:设置报警定义
-     * @exception:
-     * @author: LuoGuangyi
-     * @company: Persagy Technology Co.,Ltd
-     * @return: com.persagy.entity.AlarmState
-     * @since: 2020/10/20 17:15
-     * @version: V1.0
-     */
-    public AlarmConditionState setAlarmState(String definitionId, AlarmConditionState alarmConditionState) {
-        return alarmConditionStateMap.put(definitionId, alarmConditionState);
-    }
-
-    /**
-     * 根据报警对象id获取关联的报警条件
-     *
-     * @param objId 报警对象id
-     * @return 关联的报警条件信息
-     * @author lixing
-     * @version V1.0 2021/10/22 4:46 下午
-     */
-    public ObjConditionInfo getAlarmConditionsByObjId(String objId) {
-        return objConditionMap.get(objId);
-    }
-
-    /**
-     * 清空缓存
-     *
-     * @author lixing
-     * @version V1.0 2021/10/25 9:50 上午
-     */
-    public void clear() {
-        objConditionMap.clear();
-        alarmConditionMap.clear();
-        //清除编译表达式缓存
-        AviatorEvaluator.getInstance().clearExpressionCache();
-    }
-
     /**
      * @param alarmDefine:
      * @description:获取报警定义id, 中台报警定义ID没有实际意义,根据itemCode-objId拼接作为唯一标识
@@ -110,161 +37,4 @@ public class AlarmInfoCache {
     public static String getAlarmDefineId(AlarmDefine alarmDefine) {
         return alarmDefine.getItemCode() + "-" + alarmDefine.getObjId();
     }
-
-    /**
-     * 获取报警条件
-     *
-     * @param conditionId 报警条件id
-     * @return 报警条件
-     * @author lixing
-     * @version V1.0 2021/10/22 5:04 下午
-     */
-    public AlarmCondition getAlarmCondition(String conditionId) {
-        return alarmConditionMap.get(conditionId);
-    }
-
-    /**
-     * 缓存报警条件
-     *
-     * @param alarmCondition 报警条件
-     * @author lixing
-     * @version V1.0 2021/10/22 5:04 下午
-     */
-    public void cacheAlarmCondition(AlarmCondition alarmCondition) {
-        if (alarmCondition == null) {
-            return;
-        }
-        alarmConditionMap.put(alarmCondition.getId(), alarmCondition);
-    }
-
-    /**
-     * 移除缓存的报警条件
-     *
-     * @param alarmCondition 报警条件
-     * @author lixing
-     * @version V1.0 2021/10/22 5:04 下午
-     */
-    public void removeCachedAlarmCondition(AlarmCondition alarmCondition) {
-        if (alarmCondition == null) {
-            return;
-        }
-        alarmConditionMap.remove(alarmCondition.getId());
-    }
-
-    /**
-     * 缓存报警条件列表
-     *
-     * @param alarmConditions 报警条件列表
-     * @author lixing
-     * @version V1.0 2021/10/22 5:04 下午
-     */
-    public void cacheAlarmConditions(List<AlarmCondition> alarmConditions) {
-        if (CollectionUtils.isEmpty(alarmConditions)) {
-            return;
-        }
-        for (AlarmCondition alarmCondition : alarmConditions) {
-            cacheAlarmCondition(alarmCondition);
-        }
-    }
-
-
-    /**
-     * 缓存对象与条件的关联关系列表
-     *
-     * @param objConditionRelList 对象与条件的关联关系列表
-     * @author lixing
-     * @version V1.0 2021/10/25 10:36 上午
-     */
-    public void cacheObjConditionRelList(List<ObjConditionRel> objConditionRelList) {
-        if (CollectionUtils.isEmpty(objConditionRelList)) {
-            return;
-        }
-        for (ObjConditionRel objConditionRel : objConditionRelList) {
-            cacheObjConditionRel(objConditionRel);
-        }
-    }
-
-    /**
-     * 缓存对象与条件的关联关系
-     *
-     * @param objConditionRel 对象与条件的关联关系
-     * @author lixing
-     * @version V1.0 2021/10/25 10:36 上午
-     */
-    public void cacheObjConditionRel(ObjConditionRel objConditionRel) {
-        // 报警对象id
-        String objId = objConditionRel.getObjId();
-        // 报警对象和报警条件的关联信息
-        ObjConditionInfo objConditionInfo;
-        if (objConditionMap.containsKey(objId)) {
-            objConditionInfo = objConditionMap.get(objId);
-        } else {
-            objConditionInfo = new ObjConditionInfo(objConditionRel.getProjectId());
-            objConditionMap.put(objId, objConditionInfo);
-        }
-        ItemCodeCondition condition = new ItemCodeCondition();
-        condition.setConditionId(objConditionRel.getConditionId());
-        condition.setItemCode(objConditionRel.getItemCode());
-        // 对象内部自己做去重操作
-        objConditionInfo.addCondition(condition);
-    }
-
-    /**
-     * 移除缓存的对象与条件的关联关系
-     *
-     * @param objConditionRel 对象与条件的关联关系
-     * @author lixing
-     * @version V1.0 2021/10/25 10:36 上午
-     */
-    public void removeCachedObjConditionRel(ObjConditionRel objConditionRel) {
-        // 报警对象id
-        String objId = objConditionRel.getObjId();
-        if (!objConditionMap.containsKey(objId)) {
-            return;
-        }
-        // 报警对象和报警条件的关联信息
-        ObjConditionInfo objConditionInfo = objConditionMap.get(objId);
-        ItemCodeCondition condition = new ItemCodeCondition();
-        condition.setConditionId(objConditionRel.getConditionId());
-        condition.setItemCode(objConditionRel.getItemCode());
-        objConditionInfo.removeCondition(condition);
-        if (CollectionUtils.isEmpty(objConditionInfo.getConditions())) {
-            objConditionMap.remove(objId);
-        }
-    }
-
-    /**
-     * 获取缓存的报警条件数量
-     *
-     * @author lixing
-     * @version V1.0 2021/10/28 9:53 上午
-     */
-    public Integer getCachedConditionCount() {
-        return alarmConditionMap.size();
-    }
-
-    /**
-     * 获取缓存的设备数量
-     *
-     * @author lixing
-     * @version V1.0 2021/10/28 9:53 上午
-     */
-    public Integer getCachedObjCount() {
-        return objConditionMap.size();
-    }
-
-    /**
-     * 获取缓存的设备与报警条件关联关系数量
-     *
-     * @author lixing
-     * @version V1.0 2021/10/28 9:53 上午
-     */
-    public Integer getCachedObjConditionRelCount() {
-        int result = 0;
-        for (String objId : objConditionMap.keySet()) {
-            ObjConditionInfo objConditionInfo = objConditionMap.get(objId);
-            result += objConditionInfo.getConditions().size();
-        }
-        return result;
-    }
 }

+ 7 - 7
src/main/java/com/persagy/job/AlarmExpireJob.java

@@ -149,16 +149,16 @@ public class AlarmExpireJob extends QuartzJobBean {
                     message.setEndTime(DateUtils.parseDate(endTime));
                 }
 
-                DmpMessage dmpMessage = new DmpMessage();
-                dmpMessage.setDefaultValue();
-                dmpMessage.setMid(alarmId);
-                dmpMessage.setProjectId(zktAlarmRecordDO.getProjectId());
-                dmpMessage.setGroupCode(groupCode);
-                dmpMessage.setExts(JSONObject.parseObject(JSONObject.toJSONString(message)));
+//                DmpMessage dmpMessage = new DmpMessage();
+//                dmpMessage.setDefaultValue();
+//                dmpMessage.setMid(alarmId);
+//                dmpMessage.setProjectId(zktAlarmRecordDO.getProjectId());
+//                dmpMessage.setGroupCode(groupCode);
+//                dmpMessage.setExts(JSONObject.parseObject(JSONObject.toJSONString(message)));
                 //{"id","123", "state":1, "groupCode":"wd", "projectId":"Pj123"}
                 log.info("定时任务执行完成,向云端推送{}消息", jobType);
                 alarmHandleService.sendToMQ(
-                        JSONObject.parseObject(JSONObject.toJSONString(dmpMessage)),
+                        JSONObject.parseObject(JSONObject.toJSONString(message)),
                         alarmId,zktAlarmRecordDO.getProjectId(), AlarmRecordMsgEnum.UPDATE_ALARM_RECORD.getType());
                 // 删除缓存中报警id
                 //createdAlarmIdsCache.remove(alarmId);

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

@@ -60,8 +60,6 @@ import java.util.stream.Collectors;
 @Slf4j
 public class AlarmHandleServiceImpl {
     @Autowired
-    AlarmInfoCache alarmInfoCache;
-    @Autowired
     AlarmQuartzService alarmQuartzService;
     @Autowired
     AlarmRecordRepository alarmRecordRepository;
@@ -206,7 +204,6 @@ public class AlarmHandleServiceImpl {
         // 遍历这些条件,将采集值带入条件,判断是否产生报警
         for (ItemCodeCondition itemCodeCondition : itemCodeConditions) {
             String conditionId = itemCodeCondition.getConditionId();
-            //            AlarmCondition alarmCondition = alarmInfoCache.getAlarmCondition(conditionId);
             AlarmCondition alarmCondition = alarmRedisCache.getAlarmCondition(conditionId);
 
             if (alarmCondition == null) {