|
@@ -18,7 +18,6 @@ import com.persagy.entity.v2.AlarmCondition;
|
|
|
import com.persagy.entity.v2.DmpMessage;
|
|
|
import com.persagy.entity.v2.ItemCodeCondition;
|
|
|
import com.persagy.entity.v2.ObjConditionInfo;
|
|
|
-import com.persagy.enumeration.NettyMsgTypeEnum;
|
|
|
import com.persagy.job.ExpireAlarmQueue;
|
|
|
import com.persagy.mq.RabbitConfig;
|
|
|
import com.persagy.repository.AlarmRecordRepository;
|
|
@@ -579,54 +578,59 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
alarmLastTimeCache.setAlarmLastMsg(alarmId, projectId, objectNode);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param alarmDefine 报警定义
|
|
|
- * @param dataTime :IOT数据采集时间
|
|
|
- * @param paramMap 报警触发值
|
|
|
- * @description: 处理当前值报警的情况
|
|
|
- * @exception:
|
|
|
- * @author: LuoGuangyi
|
|
|
- * @company: Persagy Technology Co.,Ltd
|
|
|
- * @return: void
|
|
|
- * @since: 2020/10/20 22:31
|
|
|
- * @version: V1.0
|
|
|
- */
|
|
|
- private void handleAlarmTriggerData(AlarmDefine alarmDefine, String dataTime, HashMap<String, Object> paramMap)
|
|
|
- throws Exception {
|
|
|
- // 根据defineId获取报警定义状态
|
|
|
- String defineId = AlarmInfoCache.getAlarmDefineId(alarmDefine);
|
|
|
-// AlarmConditionState alarmConditionState = getAlarmDefineStateFromCacheOrDb(defineId);
|
|
|
-
|
|
|
- AlarmConditionState alarmConditionState = alarmRedisCache.getAlarmDefineState(defineId);
|
|
|
-
|
|
|
- Condition condition = alarmDefine.getCondition();
|
|
|
- // 判断报警是否在有效期内
|
|
|
- boolean inEffectTime = ConditionUtils.inEffectiveTime(condition, dataTime);
|
|
|
-
|
|
|
- if (inEffectTime) {
|
|
|
- // 已经产生报警
|
|
|
- if (AlarmConditionState.State.NOT_DEAL.getType().equals(alarmConditionState.getState())) {
|
|
|
- // 获取报警持续时间
|
|
|
- String alarmStartTime = alarmConditionState.getAlarmStartTime();
|
|
|
- long lastTime = DateUtils.betweenTwoTimeSecond(alarmStartTime, dataTime);
|
|
|
- String alarmId = alarmRecordRepository.findById(defineId).orElse(new ZktAlarmRecordDO()).getAlarmId();
|
|
|
- if (StringUtils.isNotBlank(alarmId)) {
|
|
|
- // TODO: 2021/11/17 移除alarmLastTimeCache,向mq发送报警持续消息
|
|
|
- alarmLastTimeCache.put(alarmId, Integer.valueOf(String.valueOf(lastTime)));
|
|
|
- log.debug("开始拼装报警持续消息");
|
|
|
- initAlarmContinueMsg(alarmId, lastTime, paramMap, alarmDefine.getProjectId());
|
|
|
- }
|
|
|
- }
|
|
|
- // 之前是是正常状态
|
|
|
- if (AlarmConditionState.State.NORMAL.getType().equals(alarmConditionState.getState())) {
|
|
|
- // 报警持续时间
|
|
|
- long alarmLastTime = 0;
|
|
|
- if (StringUtil.isNotEmpty(alarmConditionState.getAlarmStartTime())) {
|
|
|
- alarmLastTime = DateUtils.betweenTwoTimeSecond(alarmConditionState.getAlarmStartTime(), dataTime);
|
|
|
- } else {
|
|
|
- // 设置开始报警时间
|
|
|
- alarmConditionState.setAlarmStartTime(dataTime);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @param alarmDefine 报警定义
|
|
|
+ * @param dataTime :IOT数据采集时间
|
|
|
+ * @param paramMap 报警触发值
|
|
|
+ * @description: 处理当前值报警的情况
|
|
|
+ * @exception:
|
|
|
+ * @author: LuoGuangyi
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @return: void
|
|
|
+ * @since: 2020/10/20 22:31
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private void handleAlarmTriggerData(
|
|
|
+ AlarmDefine alarmDefine, String dataTime,
|
|
|
+ HashMap<String, Object> paramMap) throws Exception {
|
|
|
+ // 根据defineId获取报警定义状态
|
|
|
+ String defineId = AlarmInfoCache.getAlarmDefineId(alarmDefine);
|
|
|
+ AlarmConditionState alarmConditionState = alarmRedisCache.getAlarmDefineState(defineId);
|
|
|
+ Condition condition = alarmDefine.getCondition();
|
|
|
+ // 判断报警是否在有效期内
|
|
|
+ boolean inEffectTime = ConditionUtils.inEffectiveTime(condition, dataTime);
|
|
|
+
|
|
|
+ if (inEffectTime) {
|
|
|
+ // 已经产生报警
|
|
|
+ if (AlarmConditionState.State.NOT_DEAL.getType().equals(alarmConditionState.getState())) {
|
|
|
+ // 获取报警持续时间
|
|
|
+ String alarmStartTime = alarmConditionState.getAlarmStartTime();
|
|
|
+ long lastTime = DateUtils.betweenTwoTimeSecond(alarmStartTime, dataTime);
|
|
|
+ String alarmId = alarmRecordRepository.findById(defineId).orElse(new ZktAlarmRecordDO()).getAlarmId();
|
|
|
+ if (StringUtils.isNotBlank(alarmId)) {
|
|
|
+ // TODO: 2021/11/17 移除alarmLastTimeCache,向mq发送报警持续消息
|
|
|
+// alarmLastTimeCache.put(alarmId, Integer.valueOf(String.valueOf(lastTime)));
|
|
|
+// log.debug("开始拼装报警持续消息");
|
|
|
+// initAlarmContinueMsg(alarmId, lastTime, paramMap, alarmDefine.getProjectId());
|
|
|
+ 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);
|
|
|
+ rabbitTemplate.convertAndSend(RabbitConfig.exchange, RabbitConfig.alarmMsgRoutingKey, JSON.toJSONString(objectNode));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //之前是是正常状态
|
|
|
+ if (AlarmConditionState.State.NORMAL.getType().equals(alarmConditionState.getState())) {
|
|
|
+ // 报警持续时间
|
|
|
+ long alarmLastTime = 0;
|
|
|
+ if (StringUtil.isNotEmpty(alarmConditionState.getAlarmStartTime())) {
|
|
|
+ alarmLastTime = DateUtils.betweenTwoTimeSecond(alarmConditionState.getAlarmStartTime(), dataTime);
|
|
|
+ } else {
|
|
|
+ //设置开始报警时间
|
|
|
+ alarmConditionState.setAlarmStartTime(dataTime);
|
|
|
+ }
|
|
|
|
|
|
// 获取报警过期时间
|
|
|
LocalDateTime expireDateTime = getExpireLocalDateTime(dataTime, condition);
|
|
@@ -773,36 +777,52 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
return zktAlarmRecordDO;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @description: 发送创建报警记录消息
|
|
|
- * @param: alarmId 报警id
|
|
|
- * @param: alarmDefine 报警定义
|
|
|
- * @param: triggerTime 触发时间
|
|
|
- * @param: triggerInfo 触发值
|
|
|
- * @param: expireDate 过期时间
|
|
|
- * @return: void
|
|
|
- * @exception:
|
|
|
- * @author: lixing
|
|
|
- * @company: Persagy Technology Co.,Ltd
|
|
|
- * @since: 2021/1/8 下午5:38
|
|
|
- * @version: V1.0
|
|
|
- */
|
|
|
- private void sendCreateAlarmRecordMessage(String alarmId, AlarmDefine alarmDefine, String triggerTime,
|
|
|
- HashMap<String, Object> triggerInfo, Date expireDate) throws InterruptedException {
|
|
|
- Condition condition = alarmDefine.getCondition();
|
|
|
- AlarmRecord alarmRecord = AlarmRecord.builder().id(alarmId).category(alarmDefine.getCategory())
|
|
|
- .concern(alarmDefine.getConcern()).level(alarmDefine.getLevel()).projectId(alarmDefine.getProjectId())
|
|
|
- .state(1).triggerTime(DateUtils.parseDate(triggerTime)).remark(alarmDefine.getRemark())
|
|
|
- .triggerInfo(JSONObject.toJSONString(triggerInfo)).condition(condition.toString())
|
|
|
- .effectEndTime(expireDate).groupCode(groupCode).itemCode(alarmDefine.getItemCode())
|
|
|
- .objId(alarmDefine.getObjId()).classCode(alarmDefine.getClassCode()).createUser(systemId).treatState(1)
|
|
|
- .build();
|
|
|
- DmpMessage dmpMessage = new DmpMessage();
|
|
|
- dmpMessage.setDefaultValue();
|
|
|
- dmpMessage.setMid(alarmId);
|
|
|
- dmpMessage.setProjectId(alarmDefine.getProjectId());
|
|
|
- dmpMessage.setGroupCode(groupCode);
|
|
|
- dmpMessage.setExts(JSONObject.parseObject(JSONObject.toJSONString(alarmRecord)));
|
|
|
- // TODO: 2021/11/16 消息发送至mq
|
|
|
- }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 发送创建报警记录消息
|
|
|
+ * @param: alarmId 报警id
|
|
|
+ * @param: alarmDefine 报警定义
|
|
|
+ * @param: triggerTime 触发时间
|
|
|
+ * @param: triggerInfo 触发值
|
|
|
+ * @param: expireDate 过期时间
|
|
|
+ * @return: void
|
|
|
+ * @exception:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2021/1/8 下午5:38
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ private void sendCreateAlarmRecordMessage(
|
|
|
+ String alarmId,
|
|
|
+ AlarmDefine alarmDefine, String triggerTime,
|
|
|
+ HashMap<String, Object> triggerInfo, Date expireDate) throws InterruptedException {
|
|
|
+ Condition condition = alarmDefine.getCondition();
|
|
|
+ AlarmRecord alarmRecord = AlarmRecord.builder()
|
|
|
+ .id(alarmId)
|
|
|
+ .category(alarmDefine.getCategory())
|
|
|
+ .concern(alarmDefine.getConcern())
|
|
|
+ .level(alarmDefine.getLevel())
|
|
|
+ .projectId(alarmDefine.getProjectId())
|
|
|
+ .state(1)
|
|
|
+ .triggerTime(DateUtils.parseDate(triggerTime))
|
|
|
+ .remark(alarmDefine.getRemark())
|
|
|
+ .triggerInfo(JSONObject.toJSONString(triggerInfo))
|
|
|
+ .condition(condition.toString())
|
|
|
+ .effectEndTime(expireDate)
|
|
|
+ .groupCode(groupCode)
|
|
|
+ .itemCode(alarmDefine.getItemCode())
|
|
|
+ .objId(alarmDefine.getObjId())
|
|
|
+ .classCode(alarmDefine.getClassCode())
|
|
|
+ .createUser(systemId)
|
|
|
+ .treatState(1)
|
|
|
+ .build();
|
|
|
+ DmpMessage dmpMessage = new DmpMessage();
|
|
|
+ dmpMessage.setDefaultValue();
|
|
|
+ dmpMessage.setMid(alarmId);
|
|
|
+ dmpMessage.setProjectId(alarmDefine.getProjectId());
|
|
|
+ dmpMessage.setGroupCode(groupCode);
|
|
|
+ dmpMessage.setExts(JSONObject.parseObject(JSONObject.toJSONString(alarmRecord)));
|
|
|
+ // TODO: 2021/11/16 消息发送至mq
|
|
|
+ rabbitTemplate.convertAndSend(RabbitConfig.exchange, RabbitConfig.alarmMsgRoutingKey, JSON.toJSONString(dmpMessage));
|
|
|
+ }
|
|
|
}
|