|
@@ -1,49 +1,36 @@
|
|
|
package com.persagy.service.impl;
|
|
|
|
|
|
-import static org.apache.commons.lang3.math.NumberUtils.INTEGER_ONE;
|
|
|
-
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.quartz.JobDataMap;
|
|
|
-import org.quartz.SchedulerException;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.googlecode.aviator.AviatorEvaluator;
|
|
|
import com.googlecode.aviator.Expression;
|
|
|
import com.persagy.cache.AlarmInfoCache;
|
|
|
import com.persagy.cache.CurrentDataCache;
|
|
|
import com.persagy.constant.CommonConst;
|
|
|
-import com.persagy.entity.AlarmDefine;
|
|
|
-import com.persagy.entity.AlarmRecord;
|
|
|
-import com.persagy.entity.AlarmState;
|
|
|
-import com.persagy.entity.Condition;
|
|
|
-import com.persagy.entity.ExpireAlarmMessage;
|
|
|
-import com.persagy.entity.NettyMessage;
|
|
|
-import com.persagy.entity.ZktAlarmRecordDO;
|
|
|
+import com.persagy.entity.*;
|
|
|
import com.persagy.job.ExpireAlarmQueue;
|
|
|
+import com.persagy.mapper.AlarmRecordMapper;
|
|
|
import com.persagy.netty.client.NettyClient;
|
|
|
-import com.persagy.repository.AlarmRecordRepository;
|
|
|
import com.persagy.service.AlarmHandleService;
|
|
|
import com.persagy.service.AlarmQuartzService;
|
|
|
import com.persagy.utils.DateUtils;
|
|
|
import com.persagy.utils.StringUtil;
|
|
|
-
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.quartz.JobDataMap;
|
|
|
+import org.quartz.SchedulerException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import static org.apache.commons.lang3.math.NumberUtils.INTEGER_ONE;
|
|
|
|
|
|
/**
|
|
|
* @description:报警处理实现类:包含报警产生和报警恢复
|
|
@@ -62,8 +49,7 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
@Autowired
|
|
|
AlarmQuartzService alarmQuartzService;
|
|
|
@Autowired
|
|
|
- AlarmRecordRepository alarmRecordRepository;
|
|
|
-
|
|
|
+ AlarmRecordMapper alarmRecordMapper;
|
|
|
|
|
|
/**
|
|
|
* @param msg:
|
|
@@ -77,11 +63,11 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void handleIOTData(String msg) throws SchedulerException, InterruptedException {
|
|
|
- JSONObject parseObject = JSONObject.parseObject(msg);
|
|
|
- msg = parseObject.getString("data");
|
|
|
- if (StrUtil.isBlank(msg)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ JSONObject parseObject = JSONObject.parseObject(msg);
|
|
|
+ msg = parseObject.getString("data");
|
|
|
+ if (StrUtil.isBlank(msg)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
String[] split = msg.split(";", -1);
|
|
|
if (split.length % 4 != 0) {
|
|
|
return;
|
|
@@ -94,11 +80,11 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
String funcId = split[i * 4 + 2];
|
|
|
String valueStr = split[i * 4 + 3];
|
|
|
if (StrUtil.isNotBlank(valueStr) || "null".equalsIgnoreCase(valueStr)) {
|
|
|
- double value = Double.parseDouble(valueStr);
|
|
|
+ double value = Double.parseDouble(valueStr);
|
|
|
if (AlarmInfoCache.hasKey(meterId, funcId)) {
|
|
|
validIotData(dateTime, meterId, funcId, value);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -137,7 +123,7 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
if (Objects.isNull(alarmState)) {
|
|
|
//默认正常报警状态
|
|
|
alarmState = new AlarmState(defineId);
|
|
|
- Optional<ZktAlarmRecordDO> recordOptional = alarmRecordRepository.findById(defineId);
|
|
|
+ Optional<ZktAlarmRecordDO> recordOptional = Optional.ofNullable(this.alarmRecordMapper.selectById(defineId));
|
|
|
if (recordOptional.isPresent()) {
|
|
|
ZktAlarmRecordDO alarmRecordDO = recordOptional.get();
|
|
|
//数据库报警状态:1-未处理
|
|
@@ -217,7 +203,10 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
if (DateUtils.betweenTwoTimeSecond(endTime, dateTime) >= uphold) {
|
|
|
log.info("产生一条报警恢复消息[{}]>[{}]", DateUtils.betweenTwoTimeSecond(endTime, dateTime), uphold);
|
|
|
NettyMessage<AlarmRecord> nettyMessage = new NettyMessage<>(6);
|
|
|
- ZktAlarmRecordDO alarmRecordDO = alarmRecordRepository.findById(AlarmInfoCache.getAlarmDefineId(alarmDefine)).orElse(new ZktAlarmRecordDO());
|
|
|
+ ZktAlarmRecordDO alarmRecordDO = this.alarmRecordMapper.selectById(defineId);
|
|
|
+ if (null == alarmRecordDO) {
|
|
|
+ alarmRecordDO = new ZktAlarmRecordDO();
|
|
|
+ }
|
|
|
alarmRecordDO.setDefinitionId(defineId);
|
|
|
alarmRecordDO.setObjId(alarmDefine.getObjId());
|
|
|
alarmRecordDO.setItemCode(alarmDefine.getItemCode());
|
|
@@ -226,7 +215,7 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
alarmRecordDO.setEndTime(DateUtils.parseDate(dateTime));
|
|
|
alarmRecordDO.setEndInfo(JSONObject.toJSONString(paramMap));
|
|
|
//更新报警状态
|
|
|
- alarmRecordRepository.save(alarmRecordDO);
|
|
|
+ this.alarmRecordMapper.replaceSave(alarmRecordDO);
|
|
|
String alarmId = alarmRecordDO.getAlarmId();
|
|
|
//报警恢复参数
|
|
|
AlarmRecord alarmResumeRecord = AlarmRecord.builder()
|
|
@@ -395,7 +384,11 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
nettyMessage.setContent(Arrays.asList(alarmRecord));
|
|
|
//推送一条报警记录给远端
|
|
|
nettyClient.sendMessage(nettyMessage);
|
|
|
- ZktAlarmRecordDO zktAlarmRecordDO = alarmRecordRepository.findById(defineId).orElse(new ZktAlarmRecordDO());
|
|
|
+// ZktAlarmRecordDO zktAlarmRecordDO = alarmRecordRepository.findById(defineId).orElse(new ZktAlarmRecordDO());
|
|
|
+ ZktAlarmRecordDO zktAlarmRecordDO = this.alarmRecordMapper.selectById(defineId);
|
|
|
+ if (null == zktAlarmRecordDO) {
|
|
|
+ zktAlarmRecordDO = new ZktAlarmRecordDO();
|
|
|
+ }
|
|
|
zktAlarmRecordDO.setDefinitionId(defineId);
|
|
|
zktAlarmRecordDO.setObjId(alarmDefine.getObjId());
|
|
|
zktAlarmRecordDO.setItemCode(alarmDefine.getItemCode());
|
|
@@ -403,13 +396,17 @@ public class AlarmHandleServiceImpl implements AlarmHandleService {
|
|
|
zktAlarmRecordDO.setState(AlarmState.State.NOT_DEAL.getType());
|
|
|
zktAlarmRecordDO.setAlarmTime(alarmState.getAlarmStartTime());
|
|
|
zktAlarmRecordDO.setProjectId(alarmDefine.getProjectId());
|
|
|
- alarmRecordRepository.save(zktAlarmRecordDO);
|
|
|
+ this.alarmRecordMapper.replaceSave(zktAlarmRecordDO);
|
|
|
alarmState.setState(AlarmState.State.NOT_DEAL.getType());
|
|
|
//有过期时间,生成报警过期消息
|
|
|
if (hasExpire && "period".equals(effectTime.getString("type"))) {
|
|
|
//过期时间
|
|
|
log.error("产生一条定时过期报警消息");
|
|
|
- String alarmId = alarmRecordRepository.findById(defineId).orElse(new ZktAlarmRecordDO()).getAlarmId();
|
|
|
+ ZktAlarmRecordDO data = this.alarmRecordMapper.selectById(defineId);
|
|
|
+ if (null == data) {
|
|
|
+ data = new ZktAlarmRecordDO();
|
|
|
+ }
|
|
|
+ String alarmId = data.getAlarmId();
|
|
|
ZktAlarmRecordDO alarmRecordDO = ZktAlarmRecordDO.builder()
|
|
|
.alarmTime(alarmState.getAlarmStartTime())
|
|
|
.effectEndTime(DateUtils.format(expireDateTime))
|