|
@@ -1,10 +1,13 @@
|
|
|
package com.bz.rmcp.alarm.service.impl;
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
+
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.bz.rmcp.alarm.common.Constants;
|
|
@@ -22,11 +25,10 @@ import com.zcxk.rmcp.core.dao.AlarmTypeMapper;
|
|
|
import com.zcxk.rmcp.core.dao.DeviceAlarmMapper;
|
|
|
import com.zcxk.rmcp.core.dao.DeviceAlarmRuleMapper;
|
|
|
import com.zcxk.rmcp.core.dao.DeviceMapper;
|
|
|
-import com.zcxk.rmcp.core.entity.AlarmType;
|
|
|
+
|
|
|
import com.zcxk.rmcp.core.entity.Device;
|
|
|
import com.zcxk.rmcp.core.entity.DeviceAlarm;
|
|
|
-import com.zcxk.rmcp.core.entity.DeviceAlarmRule;
|
|
|
-import com.zcxk.rmcp.core.mongo.DeviceData;
|
|
|
+
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -77,10 +79,10 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
updateDevice(device,isAlarm);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
* @description 判断设备告警
|
|
|
* @param device
|
|
|
- * @param measuringMap
|
|
|
+ * @param measureDataDto
|
|
|
* @return
|
|
|
* @author linqingwei
|
|
|
**/
|
|
@@ -102,7 +104,9 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
AlarmRulePageDto rulePageDto = new AlarmRulePageDto();
|
|
|
rulePageDto.setAlarmTypeId(alarmType.getId());
|
|
|
List<AlarmRuleDto> ruleList = deviceAlarmRuleMapper.selectList(rulePageDto);
|
|
|
- if(ruleList.isEmpty())break;
|
|
|
+ if(ruleList.isEmpty()){
|
|
|
+ break;
|
|
|
+ }
|
|
|
for (AlarmRuleDto rule : ruleList) {
|
|
|
String measuringCode = rule.getMeasuringCode();
|
|
|
|
|
@@ -129,7 +133,7 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
deviceAlarm.setLastAlarmTime(DateUtil.asLocalDateTime(measureDataDto.getReceiveDate()));
|
|
|
deviceAlarm.setAlarmCount(1);
|
|
|
deviceAlarm.setHandleStatus(0);
|
|
|
- deviceAlarm.setMeasuringData(StrUtil.sub(measuringData.toString(), 0, -1));
|
|
|
+ deviceAlarm.setMeasuringData(CharSequenceUtil.sub(measuringData.toString(), 0, -1));
|
|
|
deviceAlarm.setStatus(StatusEnum.OK.getCode());
|
|
|
deviceAlarm.setCreateBy(Constants.SYS_FLAG);
|
|
|
deviceAlarm.setUpdateBy(Constants.SYS_FLAG);
|
|
@@ -143,7 +147,7 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
return deviceAlarmList;
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
* @description 更新设备
|
|
|
* @param device
|
|
|
* @param isAlarm
|
|
@@ -159,7 +163,7 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
deviceMapper.updateByAlarm(update);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
* @description 查看最后一次上报的告警信息
|
|
|
* @param device
|
|
|
* @return
|
|
@@ -168,8 +172,57 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
protected List<DeviceAlarm> getDeviceLastErrorList(Device device) {
|
|
|
return deviceAlarmMapper.getLastDeviceErrorList(device.getId());
|
|
|
}
|
|
|
+ /**无最新告警记录,将告警记录直接入库
|
|
|
+ * @param rtnList
|
|
|
+ * @description
|
|
|
+ * @author hym
|
|
|
+ * @updateTime 2021/8/20 17:45
|
|
|
+ * @return void
|
|
|
+ * @throws
|
|
|
+ */
|
|
|
+ private boolean generateAlarmRecordsDirectly(List<DeviceAlarm> rtnList,List<DeviceAlarm> lastErrorList,
|
|
|
+ List<DeviceAlarm> deviceAlarmList,Device device){
|
|
|
+ //不能直接生成告警记录标识
|
|
|
+ boolean flag=true;
|
|
|
+ if(CollUtil.isEmpty(lastErrorList)) {
|
|
|
+ flag=false;
|
|
|
+ // 无最新告警记录,将告警记录直接入库
|
|
|
+ for(DeviceAlarm de :deviceAlarmList ) {
|
|
|
+ rtnList.add(saveNewDeviceAlarm(device,de));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+ private void generateAlarmRecordsAfterComparison(List<DeviceAlarm> rtnList,List<DeviceAlarm> lastErrorList,
|
|
|
+ List<DeviceAlarm> deviceAlarmList,Device device){
|
|
|
+ for(DeviceAlarm de : deviceAlarmList) {
|
|
|
+ boolean isSame = false ;
|
|
|
+ DeviceAlarm originalError = null ;
|
|
|
+ for( DeviceAlarm lde : lastErrorList) {
|
|
|
+ if(lde.getAlarmTypeId().equals(de.getAlarmTypeId())) {
|
|
|
+ isSame = true ;
|
|
|
+ originalError = lde;
|
|
|
+ break ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isSame) {
|
|
|
+ // 告警类型与上次告警类型不同,则直接新增记录
|
|
|
+ rtnList.add(saveNewDeviceAlarm(device,de));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 告警类型与上次告警类型相同
|
|
|
+ if(device.getLastAlarmDate()!=null){
|
|
|
+ //上次有告警则更新
|
|
|
+ rtnList.add(updateExistDeviceAlarm(de, originalError));
|
|
|
+ }else {
|
|
|
+ //上次无告警则新增
|
|
|
+ rtnList.add(saveNewDeviceAlarm(device,de));
|
|
|
+ }
|
|
|
|
|
|
- /*
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
* @description 处理告警
|
|
|
* @param device
|
|
|
* @param deviceAlarmList
|
|
@@ -181,49 +234,19 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
List<DeviceAlarm> rtnList = new ArrayList<>();
|
|
|
// 1,查询最新告警记录
|
|
|
List<DeviceAlarm> lastErrorList = getDeviceLastErrorList(device);
|
|
|
- if(deviceAlarmList !=null && !deviceAlarmList.isEmpty() ) {
|
|
|
- if(lastErrorList== null || lastErrorList.isEmpty()) {
|
|
|
- // 无最新告警记录,将告警记录直接入库
|
|
|
- for(DeviceAlarm de :deviceAlarmList ) {
|
|
|
- rtnList.add(saveNewDeviceAlarm(device,de));
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(deviceAlarmList)&&
|
|
|
+ generateAlarmRecordsDirectly(rtnList,lastErrorList,deviceAlarmList,device)) {
|
|
|
// 2,有最新告警记录,对比最新告警的告警类型是否同新生成告警记录的告警类型
|
|
|
- for(DeviceAlarm de : deviceAlarmList) {
|
|
|
- boolean isSame = false ;
|
|
|
- DeviceAlarm originalError = null ;
|
|
|
- for( DeviceAlarm lde : lastErrorList) {
|
|
|
- if(lde.getAlarmTypeId().equals(de.getAlarmTypeId())) {
|
|
|
- isSame = true ;
|
|
|
- originalError = lde;
|
|
|
- break ;
|
|
|
- }
|
|
|
- }
|
|
|
- if(!isSame) {
|
|
|
- // 告警类型与上次告警类型不同,则直接新增记录
|
|
|
- rtnList.add(saveNewDeviceAlarm(device,de));
|
|
|
- }
|
|
|
- else {
|
|
|
- // 告警类型与上次告警类型相同
|
|
|
- if(device.getLastAlarmDate()!=null){
|
|
|
- //上次有告警则更新
|
|
|
- rtnList.add(updateExistDeviceAlarm(de, originalError));
|
|
|
- }else {
|
|
|
- //上次无告警则新增
|
|
|
- rtnList.add(saveNewDeviceAlarm(device,de));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ generateAlarmRecordsAfterComparison(rtnList,lastErrorList,deviceAlarmList,device);
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
log.info("end handleDeviceAlarm deviceAlarmList : {}",JSON.toJSONString(deviceAlarmList));
|
|
|
return !rtnList.isEmpty();
|
|
|
}
|
|
|
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
* @description 更新告警
|
|
|
* @param newDeviceAlarm
|
|
|
* @param oldDeviceAlarm
|
|
@@ -269,7 +292,7 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
return deviceAlarm;
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
* @description 判断是否告警
|
|
|
* @param rule
|
|
|
* @param measuringValue
|
|
@@ -287,7 +310,7 @@ public class DeviceAlarmServiceImpl implements DeviceAlarmService {
|
|
|
return parser.parseExpression(rule.getExpression()).getValue(context, Boolean.class);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
* @description 获取测点数据
|
|
|
* @param value
|
|
|
* @param code
|