From 9aab6c9bc995b26225614e07841776126ea2b49b Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 14 Mar 2024 13:59:11 +0800 Subject: [PATCH] =?UTF-8?q?#HZ3000=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/alarm/config/vo/SystemAlarmVo.java | 59 +++++++++++----------- .../monitor/service/impl/AlarmSaveServiceImpl.java | 18 +++++-- .../hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java | 9 ++-- .../java/com/hnac/hzims/alarm/mqtt/MqttConfig.java | 1 + .../alarm/source/service/SystemAlarmService.java | 1 + .../source/service/impl/FdpAlarmServiceImpl.java | 12 +---- .../service/impl/SystemAlarmServiceImpl.java | 37 ++++++-------- 7 files changed, 68 insertions(+), 69 deletions(-) diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/vo/SystemAlarmVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/vo/SystemAlarmVo.java index 833d0ef..ab422d0 100644 --- a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/vo/SystemAlarmVo.java +++ b/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; } \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java index a00ca41..90d5dc0 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/service/impl/AlarmSaveServiceImpl.java +++ b/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 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; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java index 313583d..67c4895 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java +++ b/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 data) { - System.out.println("监听到消息"+data.toString()); - String s = JSONObject.toJSONString(data); + log.error("HZ3000队列监听到消息 : {}",data); //消费代码 - List alarmEntities = systemAlarmService.receiveMessage(s); + List alarmEntities = systemAlarmService.receiveMessage(JSONObject.toJSONString(data)); //统一数据处理 try { alarmSaveService.save(alarmEntities); @@ -37,4 +38,4 @@ public class HZ300MqttConsumer implements SubscribeCallBack { log.error("HZ3000告警数据处理报错(HZ300Alarm):"+e); } } -} +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java index 01e2a01..9e8c483 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/MqttConfig.java +++ b/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}") diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java index fa6264c..87f5782 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java +++ b/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; /** * 告警处理接口 diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java index 2216534..930e4fa 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java +++ b/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 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 stationByCode = stationClient.getStationByCode(item.getStation()); - if (stationByCode.isSuccess()&& ObjectUtils.isNotEmpty(stationByCode.getData())){ - entity.setCreateDept(stationByCode.getData().getCreateDept()); - entity.setStationName(stationByCode.getData().getName()); - } return entity; } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java index a1f5c48..b8f14b2 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java +++ b/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 receiveMessage(String message) { // 对象转换 - List 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 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 stationByCode = stationClient.getStationByCode(item.getStation()); - if (stationByCode.isSuccess() && ObjectUtils.isNotEmpty(stationByCode.getData())) { - entity.setCreateDept(stationByCode.getData().getCreateDept()); - entity.setStationName(stationByCode.getData().getName()); - } return entity; } }