Browse Source

#HZ3000告警修改

zhongwei
yang_shj 9 months ago
parent
commit
9aab6c9bc9
  1. 59
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/vo/SystemAlarmVo.java
  2. 18
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java
  3. 9
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java
  4. 1
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java
  5. 1
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java
  6. 12
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java
  7. 37
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java

59
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/vo/SystemAlarmVo.java

@ -3,44 +3,45 @@ package com.hnac.hzims.alarm.config.vo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.io.Serializable;
/**
* @author ysj
*/
@Data
@ApiModel(value = "华自3000告警对象", description = "华自3000告警对象")
public class SystemAlarmVo {
public class SystemAlarmVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 告警时间
*/
private String ts;
/**
* 告警ID由平台生成具有唯一性
*/
private String id;
/**
* 告警内容
*/
private String soeExplain;
/**
* 告警类型对应数据字典 soe_alarm_type
*/
private Integer soeType;
private Integer soeStatus;
/**
* 告警动作对应HZ3000的告警 {"分", "合"}, {"复归", "动作"}
*/
private Integer soeAlarmType;
/**
* 动作值
*/
private String optionvals;
/**
* 站点id
*/
private Long ts;
private String station;
private String sid;
private String id;
private String realId;
private Integer type;
private String kind;
private String level;
private Integer state;
private String stateLabel;
private String context;
private String opvalue;
private String duration;
private Boolean trace;
private Integer traceCount;
}

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

@ -1,6 +1,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.service.AlarmConfigService;
import com.hnac.hzims.alarm.config.entity.AlarmEntity;
import com.hnac.hzims.alarm.monitor.service.AlarmSaveService;
@ -51,14 +52,23 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
// 步骤2.遍历保存告警数据
alarms.forEach(alarm->{
// 步骤3.根据站点查询配置标识
List<StationEntity> stations = result.getData().stream().filter(o->o.getCode().equals(alarm.getStationId())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(stations)){
return;
}
// 步骤3.站点参数设置
alarm.setCreateDept(stations.get(0).getCreateDept());
alarm.setStationName(stations.get(0).getName());
alarm.setTenantId(stations.get(0).getTenantId());
alarm.setStatus(0);
// 步骤4.根据站点查询配置标识
AlarmHandleMarkVo mark = alarmConfigService.mark(alarm.getStationId(),alarm.getAlarmSource(),alarm.getAlarmType());
if(ObjectUtil.isEmpty(mark)){
log.error("alarm obtain mark is null : {}",alarm.getAlarmId());
return;
}
// 步骤4.告警处理标识赋值
// 步骤5.告警处理标识赋值
alarm.setIsRightTabulation(mark.getIsRightTabulation());
alarm.setIsBroadcast(mark.getIsBroadcast());
alarm.setIsMask(mark.getIsMask());
@ -68,14 +78,14 @@ public class AlarmSaveServiceImpl implements AlarmSaveService {
alarm.setIsShortMessage(mark.getIsShortMessage());
alarm.setIsWxMessage(mark.getIsWxMessage());
// 步骤5.保存当日告警数据
// 步骤6.保存当日告警数据
boolean isSave = alarmService.save(alarm);
if(!isSave){
log.error("alarm save fail : {}",alarm.getAlarmId());
return;
}
// 步骤6.发生数据至redis告警队列
// 步骤7.发生数据至redis告警队列
stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm));
});
return true;

9
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java

@ -6,9 +6,11 @@ import com.hnac.hzims.alarm.source.service.SystemAlarmService;
import com.hnac.hzims.alarm.monitor.service.AlarmSaveService;
import com.hnac.hzinfo.subscribe.SubscribeCallBack;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -26,10 +28,9 @@ public class HZ300MqttConsumer implements SubscribeCallBack {
private AlarmSaveService alarmSaveService;
@Override
public void onMessage(Map<String, Object> data) {
System.out.println("监听到消息"+data.toString());
String s = JSONObject.toJSONString(data);
log.error("HZ3000队列监听到消息 : {}",data);
//消费代码
List<AlarmEntity> alarmEntities = systemAlarmService.receiveMessage(s);
List<AlarmEntity> alarmEntities = systemAlarmService.receiveMessage(JSONObject.toJSONString(data));
//统一数据处理
try {
alarmSaveService.save(alarmEntities);
@ -37,4 +38,4 @@ public class HZ300MqttConsumer implements SubscribeCallBack {
log.error("HZ3000告警数据处理报错(HZ300Alarm):"+e);
}
}
}
}

1
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java

@ -30,6 +30,7 @@ public class MqttConfig {
HZ300MqttConsumer hz300MqttConsumer;
@Autowired
VideoMqttConsumer videoMqttConsumer;
@Value("${hzims.mqtt.url}")
private String mqtt_fdp_url;
@Value("${hzims.mqtt.group}")

1
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java

@ -3,6 +3,7 @@ package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.config.entity.AlarmEntity;
import java.util.List;
import java.util.Map;
/**
* 告警处理接口

12
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java

@ -74,10 +74,6 @@ public class FdpAlarmServiceImpl implements FdpAlarmService {
return new ArrayList<>();
}
AlarmEntity entity = getAlarmEntity(alarms);
// List<AlarmEntity> res = alarms.stream().map(s -> {
// AlarmEntity entity = getAlarmEntity(s);
// return entity;
// }).collect(Collectors.toList());
return Collections.singletonList(entity);
}
@ -87,6 +83,7 @@ public class FdpAlarmServiceImpl implements FdpAlarmService {
entity.setRealId(item.getFaultId());
entity.setAlarmTime(item.getCreateTime());
entity.setAlarmContext(item.getFinfo());
entity.setAlarmSource(EARLY_WARNING);
entity.setAlarmType(EARLY);
entity.setDeviceCode(item.getDeviceId());
entity.setDeviceName(item.getDeviceName());
@ -95,13 +92,6 @@ public class FdpAlarmServiceImpl implements FdpAlarmService {
entity.setStationId(item.getStation());
entity.setDiagReason(item.getDiagReason());
entity.setDiagSolution(item.getDiagSolution());
entity.setAlarmSource(EARLY_WARNING);
entity.setTenantId("200000");
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation());
if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){
entity.setCreateDept(stationByCode.getData().getCreateDept());
entity.setStationName(stationByCode.getData().getName());
}
return entity;
}

37
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java

@ -1,6 +1,7 @@
package com.hnac.hzims.alarm.source.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.hnac.hzims.alarm.config.constants.AlarmConstants;
import com.hnac.hzims.alarm.config.entity.AlarmEntity;
@ -14,6 +15,7 @@ import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
@ -22,9 +24,7 @@ import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@ -73,33 +73,28 @@ public class SystemAlarmServiceImpl implements SystemAlarmService {
@Override
public List<AlarmEntity> receiveMessage(String message) {
// 对象转换
List<SystemAlarmVo> alarms = JSONObject.parseArray(message, SystemAlarmVo.class);
if (CollectionUtil.isEmpty(alarms)) {
SystemAlarmVo systemAlarm = JSONObject.parseObject(message, SystemAlarmVo.class);
log.error("HZ3000告警对象转换后:{}",systemAlarm);
if (ObjectUtils.isEmpty(systemAlarm)) {
return new ArrayList<>();
}
List<AlarmEntity> res = alarms.stream().map(s -> {
AlarmEntity entity = getAlarmEntity(s);
return entity;
}).collect(Collectors.toList());
return res;
return Collections.singletonList(this.getAlarmEntity(systemAlarm));
}
private AlarmEntity getAlarmEntity(SystemAlarmVo item) {
AlarmEntity entity = new AlarmEntity();
entity.setAlarmId(item.getId());
entity.setAlarmTime(DateUtil.parse(item.getTs(), "yyyy-MM-dd HH:mm:ss.s"));
entity.setAlarmContext(item.getSoeExplain());
entity.setAlarmType(item.getSoeAlarmType());
entity.setAlarmStatus(item.getSoeStatus());
entity.setAlarmValue(item.getOptionvals());
Date date = new Date();
date.setTime(item.getTs());
entity.setAlarmTime(DateUtil.parse(DateUtil.format(date,DateUtil.PATTERN_DATETIME),DateUtil.PATTERN_DATETIME));
entity.setAlarmContext(item.getContext());
entity.setAlarmType(item.getType());
entity.setAlarmStatus(item.getState());
entity.setAlarmValue(item.getOpvalue());
entity.setStationId(item.getStation());
entity.setAlarmCount(item.getTraceCount());
entity.setRealId(item.getRealId());
entity.setAlarmSource(AlarmConstants.HZ3000_ALARM);
entity.setTenantId("200000");
R<StationEntity> stationByCode = stationClient.getStationByCode(item.getStation());
if (stationByCode.isSuccess() && ObjectUtils.isNotEmpty(stationByCode.getData())) {
entity.setCreateDept(stationByCode.getData().getCreateDept());
entity.setStationName(stationByCode.getData().getName());
}
return entity;
}
}

Loading…
Cancel
Save