Browse Source

#推送通讯中断mqtt消息

zhongwei
yang_shj 7 months ago
parent
commit
b3af6b43e8
  1. 2
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/constants/InterruptionConstants.java
  2. 7
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java
  3. 44
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java
  4. 2
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java
  5. 7
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java

2
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/interruption/constants/InterruptionConstants.java

@ -8,6 +8,8 @@ import java.util.List;
*/
public interface InterruptionConstants {
String HZ3000_TOPIC_PREFIX = "iot/sync/hz3000soe/";
List<String> INTERRUPTION_TYPE = Arrays.asList("13","14");
/**通讯恢复*/

7
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java

@ -2,6 +2,7 @@ package com.hnac.hzims.alarm.monitor.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.hnac.hzims.alarm.config.constants.AlarmConstants;
import com.hnac.hzims.alarm.config.service.AlarmConfigService;
import com.hnac.hzims.alarm.config.entity.AlarmEntity;
import com.hnac.hzims.alarm.monitor.service.AlarmSaveService;
@ -60,13 +61,17 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
if(CollectionUtil.isEmpty(stations)){
return;
}
//根据最近5分钟的数据,做去重
// 根据最近5分钟的数据,做去重
for (String key : keys) {
String value = stringRedisTemplate.opsForValue().get(key);
if (value.equals(stations.get(0).getName()+alarm.getAlarmContext())){
return;
}
}
// fpd告警拼接
if(AlarmConstants.EARLY_WARNING.equals(alarm.getAlarmSource())){
alarm.setAlarmContext(stations.get(0).getName() + "." + alarm.getAlarmContext());
}
// 步骤3.站点参数设置
alarm.setCreateDept(stations.get(0).getCreateDept());
alarm.setStationName(stations.get(0).getName());

44
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.alarm.config.constants.AlarmConstants;
import com.hnac.hzims.alarm.config.entity.AlarmDefaultConfigEntity;
import com.hnac.hzims.alarm.config.entity.AlarmEntity;
import com.hnac.hzims.alarm.config.vo.SystemAlarmVo;
import com.hnac.hzims.business.interruption.constants.InterruptionConstants;
import com.hnac.hzims.business.interruption.entity.InterruptionEntity;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
@ -21,10 +22,12 @@ import com.hnac.hzinfo.sdk.core.response.HzPage;
import com.hnac.hzinfo.sdk.core.response.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.mqtt.producer.IMqttSender;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@ -52,6 +55,8 @@ public class AlarmServiceImpl implements AlarmService {
private final RedisTemplate redisTemplate;
private final IMqttSender mqttSender;
private final static String start_stop_cache_final = "hzims:operation:start:stop:key";
private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key";
@ -151,12 +156,12 @@ public class AlarmServiceImpl implements AlarmService {
alarm.setDeviceCode(real.getDeviceCode());
alarm.setDeviceName(real.getDeviceName());
alarm.setAlarmId(station.getCode() + "_" + Func.randomUUID());
alarm.setAlarmContext(station.getName() + "_" + real.getDeviceName() + "_关机");
alarm.setAlarmContext(station.getName() + "." + real.getDeviceName() + "_关机");
alarm.setAlarmSource(AlarmConstants.START_STOP_WARNING);
alarm.setAlarmType(AlarmConstants.STOP);
if(state == 1){
alarm.setAlarmType(AlarmConstants.START);
alarm.setAlarmContext(station.getName() + "_" + real.getDeviceName() + "_开机");
alarm.setAlarmContext(station.getName() + "." + real.getDeviceName() + "_开机");
}
alarm.setStatus(0);
alarm.setAlarmTime(new Date());
@ -221,8 +226,7 @@ public class AlarmServiceImpl implements AlarmService {
List<SoeData> soes = result.getData().getRecords();
// 查询当天数据中断告警记录
List<InterruptionEntity> saves = this.saveInterruptions(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()));
// 批量保存中断告警数据
this.interruptionAlarmService.saveBatch(soes.stream().filter(o-> CollectionUtil.isEmpty(saves) || !saves.stream().map(InterruptionEntity::getAlarmId).collect(Collectors.toList()).contains(o.getId())).map(soe->{
List<InterruptionEntity> entities = soes.stream().filter(o-> CollectionUtil.isEmpty(saves) || !saves.stream().map(InterruptionEntity::getAlarmId).collect(Collectors.toList()).contains(o.getId())).map(soe->{
InterruptionEntity entity = new InterruptionEntity();
List<StationEntity> soeStations = stations.stream().filter(o->o.getCode().equals(soe.getStation())).collect(Collectors.toList());
if(!CollectionUtil.isEmpty(soeStations)){
@ -243,7 +247,37 @@ public class AlarmServiceImpl implements AlarmService {
entity.setStatus(1);
}
return entity;
}).collect(Collectors.toList()));
}).collect(Collectors.toList());
if(CollectionUtil.isEmpty(entities)){
return;
}
// 批量保存中断告警数据
this.interruptionAlarmService.saveBatch(entities);
// FIXME 发送HZ3000中通讯告警
this.sendInterruptionMsg(entities);
}
/**
* 发送HZ3000中通讯告警
* @param entities
*/
private void sendInterruptionMsg(List<InterruptionEntity> entities) {
entities.forEach(entity->{
SystemAlarmVo alarm = new SystemAlarmVo();
if(ObjectUtil.isEmpty(entity.getId())){
alarm.setId(DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME_MINI));
}else{
alarm.setId(String.valueOf(entity.getId()));
}
alarm.setTs(entity.getAlarmTime().getTime());
alarm.setType(Integer.parseInt(entity.getType()));
alarm.setStation(entity.getStationId());
alarm.setRealId(entity.getRealId());
alarm.setContext(entity.getSoeExplain());
alarm.setState(entity.getStatus());
log.error("send_interruption_msg : {}",JsonUtil.toJson(alarm));
mqttSender.sendToMqtt(InterruptionConstants.HZ3000_TOPIC_PREFIX + entity.getStationId(), JsonUtil.toJson(alarm));
});
}

2
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java

@ -720,7 +720,7 @@ public class MonitorServiceImpl implements MonitorService {
if(!CollectionUtil.isEmpty(powers)){
for(RealAttributeVo attr : powers){
if(!"-".equals(attr.getValue())){
if(Double.parseDouble(attr.getValue()) > 0){
if(attr.getQuality() == 0 && Double.parseDouble(attr.getValue()) > 0){
station.setStatus(0);
return;
}

7
hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java

@ -281,7 +281,12 @@ public class HzimsDataServiceImpl implements HzimsDataService {
ActivePowerVo activePower = new ActivePowerVo();
activePower.setHour(entry.getKey());
activePower.setStrHour(entry.getValue().get(0).getStrHour());
activePower.setActivePower(String.valueOf(entry.getValue().stream().mapToDouble(o->Double.parseDouble(o.getActivePower())).sum()));
List<ActivePowerVo> powers = entry.getValue().stream().filter(o->StringUtil.isNotBlank(o.getActivePower())).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(powers)){
activePower.setActivePower(String.valueOf(powers.stream().mapToDouble(o->Double.parseDouble(o.getActivePower())).sum()));
}else {
activePower.setActivePower(null);
}
return activePower;
}).sorted(Comparator.comparing(ActivePowerVo::getStrHour)).collect(Collectors.toList());
}

Loading…
Cancel
Save