|
|
@ -2,9 +2,14 @@ package com.hnac.hzims.operational.alert.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
|
|
|
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; |
|
|
|
import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; |
|
|
|
import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.alert.service.HistoryLevelAlarmService; |
|
|
|
import com.hnac.hzims.operational.alert.service.LevelAlarmService; |
|
|
|
import com.hnac.hzims.operational.alert.service.LevelAlarmService; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.config.vo.LevelAlarmVo; |
|
|
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
|
|
|
import com.hnac.hzims.operational.main.constant.HomePageConstant; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.service.IStationService; |
|
|
|
import com.hnac.hzims.operational.station.service.IStationService; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
@ -14,7 +19,9 @@ import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -29,6 +36,9 @@ public class LevelAlarmServiceImpl implements LevelAlarmService { |
|
|
|
|
|
|
|
|
|
|
|
private final IStationService stationService; |
|
|
|
private final IStationService stationService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final IMainSystemMonitoringService deviceService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final HistoryLevelAlarmService historyLevelAlarmService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 定时发送消息内容 |
|
|
|
* 定时发送消息内容 |
|
|
@ -45,10 +55,7 @@ public class LevelAlarmServiceImpl implements LevelAlarmService { |
|
|
|
Map<String,String> map = new ConcurrentHashMap<>(); |
|
|
|
Map<String,String> map = new ConcurrentHashMap<>(); |
|
|
|
map.put("projectIds",stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); |
|
|
|
map.put("projectIds",stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); |
|
|
|
map.put("type", AbnormalAlarmConstant.LEVEL_TYPE_LIST); |
|
|
|
map.put("type", AbnormalAlarmConstant.LEVEL_TYPE_LIST); |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
map.put("startTime", DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"); |
|
|
|
calendar.setTime(new Date()); |
|
|
|
|
|
|
|
calendar.add(Calendar.SECOND,-30); |
|
|
|
|
|
|
|
map.put("startTime", DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME)); |
|
|
|
|
|
|
|
return JSONObject.toJSONString(map); |
|
|
|
return JSONObject.toJSONString(map); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -60,10 +67,67 @@ public class LevelAlarmServiceImpl implements LevelAlarmService { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void receiveMessage(String message) { |
|
|
|
public void receiveMessage(String message) { |
|
|
|
// 对象转换
|
|
|
|
// 对象转换
|
|
|
|
|
|
|
|
List<LevelAlarmVo> alarms = JSONObject.parseArray(message,LevelAlarmVo.class); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(alarms)){ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 站点
|
|
|
|
|
|
|
|
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery() |
|
|
|
|
|
|
|
.eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE)); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(stations)){ |
|
|
|
|
|
|
|
throw new ServiceException("level send message is null"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询近10分钟记录告警
|
|
|
|
// 设备
|
|
|
|
|
|
|
|
List<EminfoAndEmParamVo> devices = deviceService.getEmInfoList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询当天已经记录的告警
|
|
|
|
|
|
|
|
List<HistoryLevelAlarmEntity> historys = historyLevelAlarmService.list(Wrappers.<HistoryLevelAlarmEntity>lambdaQuery() |
|
|
|
|
|
|
|
.ge(HistoryLevelAlarmEntity::getCreateTime,DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00") |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
// 数据过滤
|
|
|
|
|
|
|
|
List<HistoryLevelAlarmEntity> entitys = alarms.stream().filter(alarm -> CollectionUtil.isEmpty(historys) || !historys.stream().map(HistoryLevelAlarmEntity::getAlarmId).collect(Collectors.toList()).contains(alarm.getId())).map(item->{ |
|
|
|
|
|
|
|
HistoryLevelAlarmEntity entity = new HistoryLevelAlarmEntity(); |
|
|
|
|
|
|
|
entity.setAlarmId(item.getId()); |
|
|
|
|
|
|
|
entity.setAlarmTime(DateUtil.parse(item.getTs(), "yyyy-MM-dd HH:mm:ss.s")); |
|
|
|
|
|
|
|
entity.setType(String.valueOf(item.getType())); |
|
|
|
|
|
|
|
entity.setRealId(item.getSignage()); |
|
|
|
|
|
|
|
entity.setSoeExplain(item.getName()); |
|
|
|
|
|
|
|
entity.setDeviceCode(item.getDevicecode()); |
|
|
|
|
|
|
|
entity.setDeviceName(item.getDevicename()); |
|
|
|
|
|
|
|
entity.setAlarmLevel(String.valueOf(item.getLevel())); |
|
|
|
|
|
|
|
// 根据设备找站点
|
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(devices)){ |
|
|
|
|
|
|
|
// 找到设备
|
|
|
|
|
|
|
|
List<EminfoAndEmParamVo> alarmDevices = devices.stream().filter(device->device.getEmCode().equals(item.getDevicecode())).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(alarmDevices)){ |
|
|
|
|
|
|
|
// 找到站点
|
|
|
|
|
|
|
|
List<StationEntity> alarmStations = stations.stream().filter(station->station.getRefDept().equals(alarmDevices.get(0).getCreateDept())).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(alarmStations)){ |
|
|
|
|
|
|
|
entity.setStationId(alarmStations.get(0).getCode()); |
|
|
|
|
|
|
|
entity.setStationName(alarmStations.get(0).getName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return entity; |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(entitys)){ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 批量保存
|
|
|
|
|
|
|
|
historyLevelAlarmService.saveBatch(entitys); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 消息推送
|
|
|
|
|
|
|
|
this.sendAlarmMessage(entitys); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 告警消息推送 |
|
|
|
|
|
|
|
* @param entitys |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void sendAlarmMessage(List<HistoryLevelAlarmEntity> entitys) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|