|
|
@ -144,38 +144,60 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
* 采集设备告警定时任务
|
|
|
|
* 采集设备告警定时任务
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void collectDeviceAlarmsTask() {
|
|
|
|
public void collectDeviceAlarmsTask() {
|
|
|
|
|
|
|
|
// 定义分钟值
|
|
|
|
long minuteValue = 1000 * 60;
|
|
|
|
long minuteValue = 1000 * 60;
|
|
|
|
|
|
|
|
// 获取当前时间
|
|
|
|
Date date = new Date();
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
|
|
// 实例化EmsRecordAlarmRule
|
|
|
|
EmsRecordAlarmRule alarmRule = new EmsRecordAlarmRule();
|
|
|
|
EmsRecordAlarmRule alarmRule = new EmsRecordAlarmRule();
|
|
|
|
|
|
|
|
// 设置触发规则
|
|
|
|
alarmRule.setTriggerRule(1L);
|
|
|
|
alarmRule.setTriggerRule(1L);
|
|
|
|
|
|
|
|
// 查询告警规则
|
|
|
|
List<EmsRecordAlarmRule> alarmRules = emsRecordAlarmRuleMapper.selectEmsRecordAlarmRuleList(alarmRule);
|
|
|
|
List<EmsRecordAlarmRule> alarmRules = emsRecordAlarmRuleMapper.selectEmsRecordAlarmRuleList(alarmRule);
|
|
|
|
|
|
|
|
// 如果查询结果不为空
|
|
|
|
if (alarmRules.size() > 0) {
|
|
|
|
if (alarmRules.size() > 0) {
|
|
|
|
|
|
|
|
// 设置分钟值
|
|
|
|
minuteValue = alarmRules.get(0).getDeviceOfflineTime() * minuteValue;
|
|
|
|
minuteValue = alarmRules.get(0).getDeviceOfflineTime() * minuteValue;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果查询结果为空,直接返回
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 实例化EmsBaseCollectDeviceInfo
|
|
|
|
EmsBaseCollectDeviceInfo collectDeviceInfo = new EmsBaseCollectDeviceInfo();
|
|
|
|
EmsBaseCollectDeviceInfo collectDeviceInfo = new EmsBaseCollectDeviceInfo();
|
|
|
|
|
|
|
|
// 设置标志位
|
|
|
|
collectDeviceInfo.setIsFlag("1");
|
|
|
|
collectDeviceInfo.setIsFlag("1");
|
|
|
|
|
|
|
|
// 查询采集设备信息
|
|
|
|
List<EmsBaseCollectDeviceInfo> deviceInfoList = emsBaseCollectDeviceInfoMapper.selectEmsBaseCollectDeviceInfoList(collectDeviceInfo);
|
|
|
|
List<EmsBaseCollectDeviceInfo> deviceInfoList = emsBaseCollectDeviceInfoMapper.selectEmsBaseCollectDeviceInfoList(collectDeviceInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果查询结果不为空
|
|
|
|
if (deviceInfoList.size() > 0) {
|
|
|
|
if (deviceInfoList.size() > 0) {
|
|
|
|
|
|
|
|
// 实例化EmsRecordAlarmData
|
|
|
|
EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData();
|
|
|
|
EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData();
|
|
|
|
|
|
|
|
// 设置告警类型
|
|
|
|
recordAlarmData.setAlarmType(1L);
|
|
|
|
recordAlarmData.setAlarmType(1L);
|
|
|
|
|
|
|
|
// 设置告警状态
|
|
|
|
recordAlarmData.setAlarmStatus(1L);
|
|
|
|
recordAlarmData.setAlarmStatus(1L);
|
|
|
|
|
|
|
|
// 查询告警数据
|
|
|
|
List<EmsRecordAlarmData> alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData);
|
|
|
|
List<EmsRecordAlarmData> alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData);
|
|
|
|
|
|
|
|
// 获取告警数据的collectDeviceId
|
|
|
|
List<String> collectDeviceIdList = alarmDataList.stream().map(EmsRecordAlarmData::getCollectDeviceId).collect(Collectors.toList());
|
|
|
|
List<String> collectDeviceIdList = alarmDataList.stream().map(EmsRecordAlarmData::getCollectDeviceId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
// 遍历采集设备信息
|
|
|
|
for (EmsBaseCollectDeviceInfo deviceInfo : deviceInfoList) {
|
|
|
|
for (EmsBaseCollectDeviceInfo deviceInfo : deviceInfoList) {
|
|
|
|
|
|
|
|
// 如果告警数据中包含当前采集设备,跳过
|
|
|
|
if (collectDeviceIdList.contains(deviceInfo.getCollectDeviceId())) {
|
|
|
|
if (collectDeviceIdList.contains(deviceInfo.getCollectDeviceId())) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果采集设备离线超过设置的分钟值,插入告警数据
|
|
|
|
if ((deviceInfo.getUpdateTime().getTime() + minuteValue) < date.getTime()) {
|
|
|
|
if ((deviceInfo.getUpdateTime().getTime() + minuteValue) < date.getTime()) {
|
|
|
|
EmsRecordAlarmData alarmData = new EmsRecordAlarmData();
|
|
|
|
EmsRecordAlarmData alarmData = new EmsRecordAlarmData();
|
|
|
|
alarmData.setCollectDeviceId(deviceInfo.getCollectDeviceId());
|
|
|
|
alarmData.setCollectDeviceId(deviceInfo.getCollectDeviceId());
|
|
|
|
alarmData.setCollectTime(new Date());
|
|
|
|
alarmData.setCollectTime(new Date());
|
|
|
|
alarmData.setAlarmType(1L);
|
|
|
|
alarmData.setAlarmType(1L);
|
|
|
|
alarmData.setAlarmStatus(1L);
|
|
|
|
alarmData.setAlarmStatus(1L);
|
|
|
|
|
|
|
|
// 设置告警数据
|
|
|
|
alarmData.setAlarmData("设备离线已超过" + alarmRules.get(0).getDeviceOfflineTime() + "分钟");
|
|
|
|
alarmData.setAlarmData("设备离线已超过" + alarmRules.get(0).getDeviceOfflineTime() + "分钟");
|
|
|
|
|
|
|
|
// 插入告警数据
|
|
|
|
this.insertEmsRecordAlarmData(alarmData);
|
|
|
|
this.insertEmsRecordAlarmData(alarmData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -186,19 +208,28 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
* 超过电阈值定时任务
|
|
|
|
* 超过电阈值定时任务
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void exceedDnbThresholdAlarmsTask() {
|
|
|
|
public void exceedDnbThresholdAlarmsTask() {
|
|
|
|
|
|
|
|
// 创建EmsBaseMonitorThreshold对象,设置监测类型为2
|
|
|
|
EmsBaseMonitorThreshold monitorThreshold = new EmsBaseMonitorThreshold();
|
|
|
|
EmsBaseMonitorThreshold monitorThreshold = new EmsBaseMonitorThreshold();
|
|
|
|
monitorThreshold.setMonitorType(2L);
|
|
|
|
monitorThreshold.setMonitorType(2L);
|
|
|
|
|
|
|
|
// 查询阈值列表
|
|
|
|
List<EmsBaseMonitorThreshold> thresholdList = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(monitorThreshold);
|
|
|
|
List<EmsBaseMonitorThreshold> thresholdList = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(monitorThreshold);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建EmsRecordDnbInstant对象
|
|
|
|
EmsRecordDnbInstant dnbInstant = new EmsRecordDnbInstant();
|
|
|
|
EmsRecordDnbInstant dnbInstant = new EmsRecordDnbInstant();
|
|
|
|
|
|
|
|
// 查询记录列表
|
|
|
|
List<EmsRecordDnbInstant> dnbInstantList = emsRecordDnbInstantMapper.selectEmsRecordDnbInstantList(dnbInstant);
|
|
|
|
List<EmsRecordDnbInstant> dnbInstantList = emsRecordDnbInstantMapper.selectEmsRecordDnbInstantList(dnbInstant);
|
|
|
|
|
|
|
|
// 比较阈值和记录,将超过阈值的记录存入map
|
|
|
|
Map<String, String> thresholdMap = compareThresholdAndRecord(thresholdList, dnbInstantList);
|
|
|
|
Map<String, String> thresholdMap = compareThresholdAndRecord(thresholdList, dnbInstantList);
|
|
|
|
//防止多次存入异常数据
|
|
|
|
//防止多次存入异常数据
|
|
|
|
|
|
|
|
// 创建EmsRecordAlarmData对象,设置异常类型为0,异常状态为1
|
|
|
|
EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData();
|
|
|
|
EmsRecordAlarmData recordAlarmData = new EmsRecordAlarmData();
|
|
|
|
recordAlarmData.setAlarmType(0L);
|
|
|
|
recordAlarmData.setAlarmType(0L);
|
|
|
|
recordAlarmData.setAlarmStatus(1L);
|
|
|
|
recordAlarmData.setAlarmStatus(1L);
|
|
|
|
|
|
|
|
// 查询异常数据列表
|
|
|
|
List<EmsRecordAlarmData> alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData);
|
|
|
|
List<EmsRecordAlarmData> alarmDataList = emsRecordAlarmDataMapper.selectEmsRecordAlarmDataList(recordAlarmData);
|
|
|
|
|
|
|
|
// 将异常数据monitorId存入list
|
|
|
|
List<String> monitorIdList = alarmDataList.stream().map(EmsRecordAlarmData::getMonitorId).collect(Collectors.toList());
|
|
|
|
List<String> monitorIdList = alarmDataList.stream().map(EmsRecordAlarmData::getMonitorId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
// 遍历超过阈值的记录,如果已经存入异常数据,则跳过,否则存入异常数据
|
|
|
|
for (String monitorId : thresholdMap.keySet()) {
|
|
|
|
for (String monitorId : thresholdMap.keySet()) {
|
|
|
|
if (monitorIdList.contains(monitorId)) {
|
|
|
|
if (monitorIdList.contains(monitorId)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -222,23 +253,33 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Map<String, String> compareThresholdAndRecord(List<EmsBaseMonitorThreshold> baseDnbThresholds, List<EmsRecordDnbInstant> recordDnbInstants) {
|
|
|
|
public Map<String, String> compareThresholdAndRecord(List<EmsBaseMonitorThreshold> baseDnbThresholds, List<EmsRecordDnbInstant> recordDnbInstants) {
|
|
|
|
|
|
|
|
// 创建一个Map,用于存放结果
|
|
|
|
Map<String, String> resultMap = new HashMap<>();
|
|
|
|
Map<String, String> resultMap = new HashMap<>();
|
|
|
|
|
|
|
|
// 遍历记录DnbInstants
|
|
|
|
for (EmsRecordDnbInstant recordDnbInstant : recordDnbInstants) {
|
|
|
|
for (EmsRecordDnbInstant recordDnbInstant : recordDnbInstants) {
|
|
|
|
|
|
|
|
// 获取监测码
|
|
|
|
String monitorCode = recordDnbInstant.getMonitorCode();
|
|
|
|
String monitorCode = recordDnbInstant.getMonitorCode();
|
|
|
|
|
|
|
|
// 定义一个baseDnbThreshold,用于存放阈值
|
|
|
|
EmsBaseMonitorThreshold baseDnbThreshold = null;
|
|
|
|
EmsBaseMonitorThreshold baseDnbThreshold = null;
|
|
|
|
|
|
|
|
// 遍历baseDnbThresholds,查找阈值
|
|
|
|
for (EmsBaseMonitorThreshold threshold : baseDnbThresholds) {
|
|
|
|
for (EmsBaseMonitorThreshold threshold : baseDnbThresholds) {
|
|
|
|
if (threshold.getMonitorCode().equals(monitorCode)) {
|
|
|
|
if (threshold.getMonitorCode().equals(monitorCode)) {
|
|
|
|
baseDnbThreshold = threshold;
|
|
|
|
baseDnbThreshold = threshold;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果baseDnbThreshold不为空
|
|
|
|
if (baseDnbThreshold != null) {
|
|
|
|
if (baseDnbThreshold != null) {
|
|
|
|
|
|
|
|
// 调用compare方法,比较记录和阈值
|
|
|
|
String reason = compare(recordDnbInstant, baseDnbThreshold);
|
|
|
|
String reason = compare(recordDnbInstant, baseDnbThreshold);
|
|
|
|
|
|
|
|
// 如果比较结果不为空
|
|
|
|
if (reason != null) {
|
|
|
|
if (reason != null) {
|
|
|
|
|
|
|
|
// 将结果存入Map
|
|
|
|
resultMap.put(monitorCode, reason);
|
|
|
|
resultMap.put(monitorCode, reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回结果
|
|
|
|
return resultMap;
|
|
|
|
return resultMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -294,16 +335,25 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
* 小时耗量告警定时任务
|
|
|
|
* 小时耗量告警定时任务
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void hourlyConsumptionAlarmsTask() {
|
|
|
|
public void hourlyConsumptionAlarmsTask() {
|
|
|
|
|
|
|
|
// 创建EmsBaseMonitorThreshold对象
|
|
|
|
EmsBaseMonitorThreshold monitorThreshold = new EmsBaseMonitorThreshold();
|
|
|
|
EmsBaseMonitorThreshold monitorThreshold = new EmsBaseMonitorThreshold();
|
|
|
|
|
|
|
|
// 设置监控类型为2
|
|
|
|
monitorThreshold.setMonitorType(2L);
|
|
|
|
monitorThreshold.setMonitorType(2L);
|
|
|
|
|
|
|
|
// 查询监控阈值列表
|
|
|
|
List<EmsBaseMonitorThreshold> thresholdList = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(monitorThreshold);
|
|
|
|
List<EmsBaseMonitorThreshold> thresholdList = emsBaseMonitorThresholdMapper.selectEmsBaseMonitorThresholdList(monitorThreshold);
|
|
|
|
|
|
|
|
// 遍历监控阈值列表
|
|
|
|
for (EmsBaseMonitorThreshold threshold : thresholdList) {
|
|
|
|
for (EmsBaseMonitorThreshold threshold : thresholdList) {
|
|
|
|
|
|
|
|
// 获取小时耗量
|
|
|
|
BigDecimal consumption = threshold.getHourConsumption();
|
|
|
|
BigDecimal consumption = threshold.getHourConsumption();
|
|
|
|
|
|
|
|
// 如果小时耗量为0,则跳过本次循环
|
|
|
|
if (consumption.equals(new BigDecimal(0))){
|
|
|
|
if (consumption.equals(new BigDecimal(0))){
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 创建EmsReportPointDnb对象
|
|
|
|
EmsReportPointDnb reportPointDnb = new EmsReportPointDnb();
|
|
|
|
EmsReportPointDnb reportPointDnb = new EmsReportPointDnb();
|
|
|
|
|
|
|
|
// 设置监控编码
|
|
|
|
reportPointDnb.setMonitorCode(threshold.getMonitorCode());
|
|
|
|
reportPointDnb.setMonitorCode(threshold.getMonitorCode());
|
|
|
|
|
|
|
|
// 查询报告点列表
|
|
|
|
List<EmsReportPointDnb> dnbList = emsReportPointDnbMapper.selectEmsReportPointDnbList(reportPointDnb);
|
|
|
|
List<EmsReportPointDnb> dnbList = emsReportPointDnbMapper.selectEmsReportPointDnbList(reportPointDnb);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|