|
@@ -11,7 +11,6 @@ import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
-import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
@@ -61,7 +60,6 @@ import com.persagy.utils.ValidateUtils;
|
|
|
import com.persagy.utils.condition.ConditionUtils;
|
|
|
import com.rabbitmq.client.Channel;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
/**
|
|
@@ -340,34 +338,6 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @description: 根据报警定义唯一标识从缓存或数据库中获取AlarmDefineState
|
|
|
- * @param: defineId 报警定义唯一标识
|
|
|
- * @exception:
|
|
|
- * @author: lixing
|
|
|
- * @company: Persagy Technology Co.,Ltd
|
|
|
- * @since: 2021/1/8 上午11:05
|
|
|
- * @version: V1.0
|
|
|
- */
|
|
|
- private AlarmConditionState getAlarmDefineStateFromCacheOrDb(String defineId) {
|
|
|
- AlarmConditionState alarmConditionState = alarmInfoCache.getAlarmDefineState(defineId);
|
|
|
- if (Objects.isNull(alarmConditionState)) {
|
|
|
- // 默认正常报警状态
|
|
|
- alarmConditionState = new AlarmConditionState(defineId);
|
|
|
- Optional<ZktAlarmRecordDO> recordOptional = alarmRecordRepository.findById(defineId);
|
|
|
- if (recordOptional.isPresent()) {
|
|
|
- ZktAlarmRecordDO alarmRecordDO = recordOptional.get();
|
|
|
- // 数据库报警状态:1-未处理
|
|
|
- if ("1".equals(alarmRecordDO.getState())) {
|
|
|
- alarmConditionState.setState(AlarmConditionState.State.NOT_DEAL.getType());
|
|
|
- alarmConditionState.setAlarmStartTime(alarmRecordDO.getAlarmTime());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.debug("alarmDefineState: [{}], ( 0-正常 1-报警)", alarmConditionState.getState());
|
|
|
- return alarmConditionState;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* @param alarmDefine :报警定义
|
|
|
* @param dataTime :IOT采集时间
|
|
|
* @param endResult :报警恢复监测结果
|
|
@@ -416,8 +386,6 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
alarmRedisCache.lock(alarmId, alarmId, 1000);
|
|
|
// 发送报警恢复消息
|
|
|
sendAlarmRecoverMessage(defineId, alarmSuspendStartTime, paramMap, alarmId);
|
|
|
- // 报警恢复后,从缓存中移除报警id
|
|
|
- createdAlarmIdsCache.remove(alarmId);
|
|
|
// 取消过期任务
|
|
|
cancelRelatedExpireJob(alarmId);
|
|
|
// 报警恢复,报警状态重置回默认
|
|
@@ -428,38 +396,6 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @description: 创建报警恢复定时任务
|
|
|
- * @param: recoverTime 恢复时间
|
|
|
- * @param: paramMap 采集值参数
|
|
|
- * @param: alarmRecordDO 报警定义对象
|
|
|
- * @return: void
|
|
|
- * @exception:
|
|
|
- * @author: lixing
|
|
|
- * @company: Persagy Technology Co.,Ltd
|
|
|
- * @since: 2021/2/7 10:10 上午
|
|
|
- * @version: V1.0
|
|
|
- */
|
|
|
- private void createAlarmRecoverTimingJob(String recoverTime, HashMap<String, Object> paramMap,
|
|
|
- ZktAlarmRecordDO alarmRecordDO) throws InterruptedException {
|
|
|
- JobDataMap jobDataMap = new JobDataMap();
|
|
|
- jobDataMap.put("alarmRecord", alarmRecordDO.toString());
|
|
|
- // 已重试次数
|
|
|
- jobDataMap.put("refire", "0");
|
|
|
- jobDataMap.put("endTime", recoverTime);
|
|
|
- jobDataMap.put("endInfo", JSONObject.toJSONString(paramMap));
|
|
|
- jobDataMap.put("defineId", alarmRecordDO.getDefinitionId());
|
|
|
- // 恢复
|
|
|
- jobDataMap.put("state", "2");
|
|
|
- ExpireAlarmMessage em = new ExpireAlarmMessage();
|
|
|
- em.setType("1");
|
|
|
- em.setStartTime(DateUtil.offsetMinute(new Date(), 3).toJdkDate());
|
|
|
- em.setJobDataMap(jobDataMap);
|
|
|
- em.setJobName(alarmRecordDO.getAlarmId());
|
|
|
- em.setJobGroupName("resume");
|
|
|
- ExpireAlarmQueue.getExpireAlarmMessageQueue().produce(em);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* @description: 发送报警恢复消息
|
|
|
* @param: projectId 项目id
|
|
|
* @param: recoverTime 恢复时间
|
|
@@ -507,20 +443,6 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
ExpireAlarmQueue.getExpireAlarmMessageQueue().produce(em);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @description: 当报警恢复时边缘端删除报警信息
|
|
|
- * @param: defineId 报警定义id
|
|
|
- * @exception:
|
|
|
- * @author: lixing
|
|
|
- * @company: Persagy Technology Co.,Ltd
|
|
|
- * @since: 2021/1/13 下午5:11
|
|
|
- * @version: V1.0
|
|
|
- */
|
|
|
- private void deleteZktAlarmRecordWhenAlarmSuspend(String defineId) {
|
|
|
- if (alarmRecordRepository.existsById(defineId)) {
|
|
|
- alarmRecordRepository.deleteById(defineId);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* @description: 当报警恢复时拼装边缘端报警信息
|
|
@@ -548,29 +470,6 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
return alarmRecordDO;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @description: 发送报警仍在继续的消息
|
|
|
- * @param: alarmId 报警记录id
|
|
|
- * @param: lastTime 报警持续时间(单位:s)
|
|
|
- * @param: paramMap 当前采集值
|
|
|
- * @param: projectId 项目id
|
|
|
- * @return: void
|
|
|
- * @exception:
|
|
|
- * @author: lixing
|
|
|
- * @company: Persagy Technology Co.,Ltd
|
|
|
- * @since: 2020/12/17 4:40 下午
|
|
|
- * @version: V1.0
|
|
|
- */
|
|
|
- private void initAlarmContinueMsg(String alarmId, long lastTime, HashMap<String, Object> paramMap, String projectId)
|
|
|
- throws Exception {
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- ObjectNode objectNode = objectMapper.createObjectNode();
|
|
|
- objectNode.put("id", alarmId);
|
|
|
- objectNode.put("lastTime", lastTime);
|
|
|
- objectNode.set("iotData", objectMapper.readTree(objectMapper.writeValueAsString(paramMap)));
|
|
|
- objectNode.put("groupCode", groupCode);
|
|
|
- alarmLastTimeCache.setAlarmLastMsg(alarmId, projectId, objectNode);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* @param alarmDefine 报警定义
|