From 3bf0369d26548d5a0275c8b7f09499afb79c34cb Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 11 Jan 2024 17:03:59 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=91=8A=E8=AD=A6=E4=BB=A3=E7=A0=81=E7=A7=BB?= =?UTF-8?q?=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/alarm/constants/AlarmHandleConstant.java | 64 +++ .../alarm/entity/AlarmHandleDetailEntity.java | 38 ++ .../hnac/hzims/alarm/entity/AlarmHandleEntity.java | 45 ++ .../com/hnac/hzims/alarm/vo/AlarmHandleVo.java | 55 ++ .../alert/constants/AbnormalAlarmConstant.java | 64 --- .../alert/entity/AlarmHandleDetailEntity.java | 38 -- .../alert/entity/AlarmHandleEntity.java | 45 -- .../hzims/operational/alert/vo/AlarmHandleVo.java | 55 -- .../alarm/handle/mapper/AlarmHistoryMapper.java | 12 - .../alarm/handle/mapper/AlarmHistoryMapper.xml | 5 - .../alarm/handle/service/AlarmHistoryService.java | 11 - .../alarm/handle/service/DroolsAlarmService.java | 16 - .../alarm/handle/service/FdpAlarmService.java | 16 - .../alarm/handle/service/LevelAlarmService.java | 16 - .../hzims/alarm/handle/service/MessageService.java | 15 - .../alarm/handle/service/SystemAlarmService.java | 16 - .../alarm/handle/service/VideoAlarmService.java | 16 - .../service/impl/AlarmHistoryServiceImpl.java | 19 - .../service/impl/DroolsAlarmServiceImpl.java | 93 --- .../handle/service/impl/FdpAlarmServiceImpl.java | 103 ---- .../handle/service/impl/LevelAlarmServiceImpl.java | 110 ---- .../handle/service/impl/MessageServiceImpl.java | 163 ------ .../service/impl/SystemAlarmServiceImpl.java | 105 ---- .../handle/service/impl/VideoAlarmServiceImpl.java | 121 ---- .../alarm/monitor/listener/AlarmListener.java | 2 +- .../hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java | 2 +- .../com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java | 2 +- .../hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java | 2 +- .../hnac/hzims/alarm/mqtt/VideoMqttConsumer.java | 2 +- .../show/controller/AlarmHandleController.java | 74 +++ .../alarm/show/controller/ShowAlarmController.java | 2 +- .../alarm/show/mapper/AlarmHandleDetailMapper.java | 13 + .../alarm/show/mapper/AlarmHandleDetailMapper.xml | 6 + .../hzims/alarm/show/mapper/AlarmHandleMapper.java | 24 + .../hzims/alarm/show/mapper/AlarmHandleMapper.xml | 51 ++ .../show/service/AlarmHandleDetailService.java | 14 + .../alarm/show/service/AlarmHandleService.java | 27 + .../service/impl/AlarmHandleDetailServiceImpl.java | 21 + .../show/service/impl/AlarmHandleServiceImpl.java | 151 +++++ .../alarm/show/service/impl/AlarmServiceImpl.java | 31 +- .../hzims/alarm/show/wrapper/HandleWrapper.java | 28 + .../alarm/source/mapper/AlarmHistoryMapper.java | 12 + .../alarm/source/mapper/AlarmHistoryMapper.xml | 5 + .../alarm/source/service/AlarmHistoryService.java | 11 + .../alarm/source/service/DroolsAlarmService.java | 16 + .../alarm/source/service/FdpAlarmService.java | 16 + .../alarm/source/service/LevelAlarmService.java | 16 + .../hzims/alarm/source/service/MessageService.java | 15 + .../alarm/source/service/SystemAlarmService.java | 16 + .../alarm/source/service/VideoAlarmService.java | 16 + .../service/impl/AlarmHistoryServiceImpl.java | 19 + .../service/impl/DroolsAlarmServiceImpl.java | 93 +++ .../source/service/impl/FdpAlarmServiceImpl.java | 103 ++++ .../source/service/impl/LevelAlarmServiceImpl.java | 110 ++++ .../source/service/impl/MessageServiceImpl.java | 163 ++++++ .../service/impl/SystemAlarmServiceImpl.java | 105 ++++ .../source/service/impl/VideoAlarmServiceImpl.java | 121 ++++ .../hnac/hzims/alarm/task/VideoScheduledTask.java | 2 +- .../hzims/alarm/ws/level/LevelAlarmRegular.java | 2 +- .../hzims/alarm/ws/level/LevelAlarmWebSocket.java | 2 +- .../operational/alert/AlertWebSocketClient.java | 182 ------ .../operational/alert/WebSocketClientManager.java | 44 -- .../alert/controller/AbnormalAlarmController.java | 157 ----- .../alert/controller/AlarmHandleController.java | 74 --- .../alert/controller/LevelAlarmController.java | 67 --- .../alert/mapper/AbnormalAlarmMapper.java | 17 - .../alert/mapper/AbnormalAlarmMapper.xml | 17 - .../alert/mapper/AlarmHandleDetailMapper.java | 13 - .../alert/mapper/AlarmHandleDetailMapper.xml | 6 - .../alert/mapper/AlarmHandleMapper.java | 24 - .../operational/alert/mapper/AlarmHandleMapper.xml | 57 -- .../alert/mapper/AlertDefectConfigMapper.java | 13 - .../alert/mapper/AlertDefectConfigMapper.xml | 8 - .../alert/mapper/HistoryAbnormalAlarmMapper.java | 26 - .../alert/mapper/HistoryAbnormalAlarmMapper.xml | 49 -- .../alert/mapper/HistoryLevelAlarmMapper.java | 11 - .../alert/mapper/HistoryLevelAlarmMapper.xml | 6 - .../alert/service/AbnormalAlarmService.java | 17 - .../alert/service/AlarmHandleDetailService.java | 13 - .../alert/service/AlarmHandleService.java | 27 - .../alert/service/AlarmMergeService.java | 15 - .../alert/service/AlertDefectService.java | 13 - .../alert/service/HistoryAbnormalAlarmService.java | 40 -- .../alert/service/HistoryLevelAlarmService.java | 21 - .../alert/service/LevelAlarmService.java | 12 - .../service/impl/AbnormalAlarmServiceImpl.java | 268 --------- .../service/impl/AlarmHandleDetailServiceImpl.java | 21 - .../alert/service/impl/AlarmHandleServiceImpl.java | 163 ------ .../alert/service/impl/AlertDefectServiceImpl.java | 133 ----- .../alert/service/impl/AlertMerageServiceImpl.java | 125 ---- .../impl/HistoryAbnormalAlarmServiceImpl.java | 433 -------------- .../service/impl/HistoryLevelAlarmServiceImpl.java | 122 ---- .../alert/service/impl/LevelAlarmServiceImpl.java | 237 -------- .../operational/alert/wrapper/HandleWrapper.java | 28 - .../operational/config/config/WebSocketConfig.java | 8 - .../controller/CentralMonitorController.java | 9 - .../controller/HistoryAbnormalAlarmController.java | 38 -- .../config/controller/StAlamRecordController.java | 9 - .../config/scheduled/StAlamRecordTask.java | 110 ---- .../config/service/StAlamRecordService.java | 8 - .../service/impl/StAlamRecordServiceImpl.java | 46 +- .../hzims/operational/config/ws/AlarmHandler.java | 79 --- .../operational/config/ws/AlarmSessionManager.java | 58 -- .../operational/config/ws/LevelAlarmRegular.java | 51 -- .../operational/config/ws/LevelAlarmWebSocket.java | 125 ---- .../hzims/operational/config/ws/SocketPool.java | 2 - .../duty/mapper/ImsDutyGroupPMapper.xml | 2 +- .../station/service/IRealMonitorService.java | 16 - .../service/impl/RealMonitorServiceImpl.java | 630 --------------------- 109 files changed, 1484 insertions(+), 4702 deletions(-) create mode 100644 hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmHandleConstant.java create mode 100644 hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleDetailEntity.java create mode 100644 hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleEntity.java create mode 100644 hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleVo.java delete mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java delete mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleDetailEntity.java delete mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleEntity.java delete mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmHandleVo.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.xml delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/AlarmHistoryService.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/DroolsAlarmService.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/FdpAlarmService.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/LevelAlarmService.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/SystemAlarmService.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/VideoAlarmService.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/AlarmHistoryServiceImpl.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/DroolsAlarmServiceImpl.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/FdpAlarmServiceImpl.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/LevelAlarmServiceImpl.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/SystemAlarmServiceImpl.java delete mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/VideoAlarmServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.xml create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleDetailService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleDetailServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/wrapper/HandleWrapper.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.xml create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/AlarmHistoryService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/FdpAlarmService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/LevelAlarmService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/VideoAlarmService.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/AlarmHistoryServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/VideoAlarmServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/AlertWebSocketClient.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/WebSocketClientManager.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AlarmHandleController.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/LevelAlarmController.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.xml delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.xml delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.xml delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.xml delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.xml delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AbnormalAlarmService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleDetailService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlertDefectService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryLevelAlarmService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleDetailServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryLevelAlarmServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/wrapper/HandleWrapper.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/HistoryAbnormalAlarmController.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/scheduled/StAlamRecordTask.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmWebSocket.java diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmHandleConstant.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmHandleConstant.java new file mode 100644 index 0000000..8804bc0 --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmHandleConstant.java @@ -0,0 +1,64 @@ +package com.hnac.hzims.alarm.constants; + +import java.util.Arrays; +import java.util.List; + +/** + * @author YSJ + */ +public interface AlarmHandleConstant { + + List INTERRUPT_LIST = Arrays.asList("13","14"); + + List TYPE_LIST = Arrays.asList("3","2","5","10","13","14"); + + List LONG_TYPE_LIST = Arrays.asList(3L,2L,5L,10L,13L,14L); + + List SEND_MESSSAGE_TYPE_LIST = Arrays.asList("3","13","14"); + + String LEVEL_TYPE_LIST = "3,2,5,10,13,14"; + String SYSTEM_TYPE_LIST = "3,2,5,13,14"; + + /**通讯恢复*/ + String ABNORMAL_STATUS = "1"; + + /**故障**/ + String FAULT = "3"; + + /**预警**/ + Long EARLY_WARNING = 20L; + + String WEBSOCKET_FAULT = "3"; + + String[] TYPE_NAMES = {"默认", "系统", "告警" + , "故障", "用户操作", "遥测越限", "遥信变位", "注册信息", "信息提示", "设备巡检", "遥控操作", "遥测越限恢复","未定义","通讯中断","数据异常"}; + + /**误报 、延后、缺陷 、检修、处理*/ + List HANDLE_WAY = Arrays.asList(1L,2L,3L,4L,5L); + + List HANDLE = Arrays.asList(3L,4L,5L); + + /** + * 2-告警,3-故障,5-遥测越限,13-通讯异常,14-数据异常 + */ + List SOE_TYPE_LIST = Arrays.asList(2,3,5,13,14); + + /** + * 告警等级: 0 - 1级告警 1-二级告警 + */ + List LEVEL_LIST = Arrays.asList("0","1"); + + /** + * 告警类型: HZ3000告警 + */ + Integer SYSTEM_ALARM = 0; + + /** + * 告警类型: 智能告警 + */ + Integer INTELLIGENCE_ALARM = 1; + /** + * 告警类型: 视频告警 + */ + Integer VIDEO_ALARM = 4; +} diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleDetailEntity.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleDetailEntity.java new file mode 100644 index 0000000..5f68cad --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleDetailEntity.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.alarm.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import java.util.Date; + +@Data +@TableName("hzims_alarm_handle_detail") +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "告警处理详情对象") +public class AlarmHandleDetailEntity extends BaseEntity { + + @ApiModelProperty("通知处理人") + private Long handleUser; + + @ApiModelProperty("现象ID") + private Long phenomenonId; + + @ApiModelProperty("检修ID") + private Long accessId; + + @ApiModelProperty("延后时间") + private Date delayTime; + + @ApiModelProperty("延后原因") + private String delayCause; + + @ApiModelProperty("误报描述") + private String falseAlarmDesc; + + @ApiModelProperty("附件路径") + private String filePath; +} diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleEntity.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleEntity.java new file mode 100644 index 0000000..23e6a46 --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleEntity.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.alarm.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.models.auth.In; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import java.util.Date; + +/** + * @author ysj + */ +@Data +@TableName("hzims_alarm_handle") +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "告警处理对象") +public class AlarmHandleEntity extends BaseEntity { + + @ApiModelProperty("告警Id") + private String alarmId; + + @ApiModelProperty("站点编码") + private String stationCode; + + @ApiModelProperty("告警类型") + private Long alarmType; + + @ApiModelProperty("告警所属类型:0-系统告警 1-智能告警") + private Integer type; + + @ApiModelProperty("告警时间") + private Date alarmTime; + + @ApiModelProperty("告警内容") + private String alarmContent; + + @ApiModelProperty("处理方式") + private Long handleWay; + + @ApiModelProperty("处理详情ID") + private Long detailId; +} diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleVo.java new file mode 100644 index 0000000..85f2e35 --- /dev/null +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleVo.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.alarm.vo; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import com.hnac.hzims.alarm.entity.AlarmHandleEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @author ysj + * @date 2023/03/17 10:02:33 + * @version 4.0.0 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class AlarmHandleVo extends AlarmHandleEntity { + + @ApiModelProperty("站点名称") + private String stationName; + + @ApiModelProperty("延后处理时间") + private Date delayTime; + + @ApiModelProperty("延后处理时间") + private String delayCause; + + @ApiModelProperty("误报描述") + private String falseAlarmDesc; + + @ApiModelProperty("附件路径") + private String filePath; + + @ApiModelProperty("通知处理人") + private Long handleUser; + + @ApiModelProperty("现象Id") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long phenomenonId; + + @ApiModelProperty("现象流程Id") + private String checkProcessInstanceId; + + @ApiModelProperty("检修ID") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long accessId; + + @ApiModelProperty("检修流程Id") + private String processInstanceId; + + @ApiModelProperty("用户名称") + private String userName; +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java deleted file mode 100644 index 3bf7e4f..0000000 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.hnac.hzims.operational.alert.constants; - -import java.util.Arrays; -import java.util.List; - -/** - * @author YSJ - */ -public interface AbnormalAlarmConstant { - - List INTERRUPT_LIST = Arrays.asList("13","14"); - - List TYPE_LIST = Arrays.asList("3","2","5","10","13","14"); - - List LONG_TYPE_LIST = Arrays.asList(3L,2L,5L,10L,13L,14L); - - List SEND_MESSSAGE_TYPE_LIST = Arrays.asList("3","13","14"); - - String LEVEL_TYPE_LIST = "3,2,5,10,13,14"; - String SYSTEM_TYPE_LIST = "3,2,5,13,14"; - - /**通讯恢复*/ - String ABNORMAL_STATUS = "1"; - - /**故障**/ - String FAULT = "3"; - - /**预警**/ - Long EARLY_WARNING = 20L; - - String WEBSOCKET_FAULT = "3"; - - String[] TYPE_NAMES = {"默认", "系统", "告警" - , "故障", "用户操作", "遥测越限", "遥信变位", "注册信息", "信息提示", "设备巡检", "遥控操作", "遥测越限恢复","未定义","通讯中断","数据异常"}; - - /**误报 、延后、缺陷 、检修、处理*/ - List HANDLE_WAY = Arrays.asList(1L,2L,3L,4L,5L); - - List HANDLE = Arrays.asList(3L,4L,5L); - - /** - * 2-告警,3-故障,5-遥测越限,13-通讯异常,14-数据异常 - */ - List SOE_TYPE_LIST = Arrays.asList(2,3,5,13,14); - - /** - * 告警等级: 0 - 1级告警 1-二级告警 - */ - List LEVEL_LIST = Arrays.asList("0","1"); - - /** - * 告警类型: HZ3000告警 - */ - Integer SYSTEM_ALARM = 0; - - /** - * 告警类型: 智能告警 - */ - Integer INTELLIGENCE_ALARM = 1; - /** - * 告警类型: 视频告警 - */ - Integer VIDEO_ALARM = 4; -} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleDetailEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleDetailEntity.java deleted file mode 100644 index 0307998..0000000 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleDetailEntity.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.hnac.hzims.operational.alert.entity; - -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.springblade.core.mp.base.BaseEntity; - -import java.util.Date; - -@Data -@TableName("hzims_alarm_handle_detail") -@EqualsAndHashCode(callSuper = true) -@ApiModel(value = "告警处理详情对象") -public class AlarmHandleDetailEntity extends BaseEntity { - - @ApiModelProperty("通知处理人") - private Long handleUser; - - @ApiModelProperty("现象ID") - private Long phenomenonId; - - @ApiModelProperty("检修ID") - private Long accessId; - - @ApiModelProperty("延后时间") - private Date delayTime; - - @ApiModelProperty("延后原因") - private String delayCause; - - @ApiModelProperty("误报描述") - private String falseAlarmDesc; - - @ApiModelProperty("附件路径") - private String filePath; -} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleEntity.java deleted file mode 100644 index 1fc22fc..0000000 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleEntity.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.hnac.hzims.operational.alert.entity; - -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import io.swagger.models.auth.In; -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.springblade.core.mp.base.BaseEntity; - -import java.util.Date; - -/** - * @author ysj - */ -@Data -@TableName("hzims_alarm_handle") -@EqualsAndHashCode(callSuper = true) -@ApiModel(value = "告警处理对象") -public class AlarmHandleEntity extends BaseEntity { - - @ApiModelProperty("告警Id") - private String alarmId; - - @ApiModelProperty("站点编码") - private String stationCode; - - @ApiModelProperty("告警类型") - private Long alarmType; - - @ApiModelProperty("告警所属类型:0-系统告警 1-智能告警") - private Integer type; - - @ApiModelProperty("告警时间") - private Date alarmTime; - - @ApiModelProperty("告警内容") - private String alarmContent; - - @ApiModelProperty("处理方式") - private Long handleWay; - - @ApiModelProperty("处理详情ID") - private Long detailId; -} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmHandleVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmHandleVo.java deleted file mode 100644 index b0e5fa4..0000000 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmHandleVo.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.hnac.hzims.operational.alert.vo; - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.NullSerializer; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.Date; - -/** - * @author ysj - * @date 2023/03/17 10:02:33 - * @version 4.0.0 - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class AlarmHandleVo extends AlarmHandleEntity { - - @ApiModelProperty("站点名称") - private String stationName; - - @ApiModelProperty("延后处理时间") - private Date delayTime; - - @ApiModelProperty("延后处理时间") - private String delayCause; - - @ApiModelProperty("误报描述") - private String falseAlarmDesc; - - @ApiModelProperty("附件路径") - private String filePath; - - @ApiModelProperty("通知处理人") - private Long handleUser; - - @ApiModelProperty("现象Id") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Long phenomenonId; - - @ApiModelProperty("现象流程Id") - private String checkProcessInstanceId; - - @ApiModelProperty("检修ID") - @JsonSerialize(nullsUsing = NullSerializer.class) - private Long accessId; - - @ApiModelProperty("检修流程Id") - private String processInstanceId; - - @ApiModelProperty("用户名称") - private String userName; -} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.java deleted file mode 100644 index 4b2d713..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.alarm.handle.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.hnac.hzims.alarm.entity.AlarmHistoryEntity; - -/** - * @author ysj - */ -public interface AlarmHistoryMapper extends BaseMapper { - - -} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.xml b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.xml deleted file mode 100644 index f6dd5d6..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/AlarmHistoryService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/AlarmHistoryService.java deleted file mode 100644 index 3805436..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/AlarmHistoryService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hnac.hzims.alarm.handle.service; - -import com.hnac.hzims.alarm.entity.AlarmHistoryEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface AlarmHistoryService extends BaseService { - -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/DroolsAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/DroolsAlarmService.java deleted file mode 100644 index 186609a..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/DroolsAlarmService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hnac.hzims.alarm.handle.service; - -import com.hnac.hzims.alarm.entity.AlarmEntity; - -import java.util.List; - -/** - * 等级处理接口 - * @author ysj - */ -public interface DroolsAlarmService { - - String message(); - - List receiveMessage(String message); -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/FdpAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/FdpAlarmService.java deleted file mode 100644 index bbb248d..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/FdpAlarmService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hnac.hzims.alarm.handle.service; - -import com.hnac.hzims.alarm.entity.AlarmEntity; - -import java.util.List; - -/** - * 告警处理接口 - * @author ysj - */ -public interface FdpAlarmService { - - String sendMessage(); - - List receiveMessage(String message); -} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/LevelAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/LevelAlarmService.java deleted file mode 100644 index 4d3a695..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/LevelAlarmService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hnac.hzims.alarm.handle.service; - -import com.hnac.hzims.alarm.entity.AlarmEntity; - -import java.util.List; - -/** - * 等级处理接口 - * @author ysj - */ -public interface LevelAlarmService { - - String message(); - - List receiveMessage(String message); -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java deleted file mode 100644 index 230150e..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hnac.hzims.alarm.handle.service; - -import com.hnac.hzims.alarm.entity.AlarmEntity; - -/** - * @author ysj - */ -public interface MessageService { - - void shortMessage(AlarmEntity entity); - - void webAppMessage(AlarmEntity entity); - - void weChatMessage(AlarmEntity entity); -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/SystemAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/SystemAlarmService.java deleted file mode 100644 index 42f44d8..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/SystemAlarmService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hnac.hzims.alarm.handle.service; - -import com.hnac.hzims.alarm.entity.AlarmEntity; - -import java.util.List; - -/** - * 告警处理接口 - * @author ysj - */ -public interface SystemAlarmService { - - String sendMessage(); - - List receiveMessage(String message); -} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/VideoAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/VideoAlarmService.java deleted file mode 100644 index 2751346..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/VideoAlarmService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hnac.hzims.alarm.handle.service; - -import com.hnac.hzims.alarm.entity.AlarmEntity; - -import java.util.List; - -/** - * 告警处理接口 - * @author ysj - */ -public interface VideoAlarmService { - - List sendMessage(); - - List receiveMessage(String message); -} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/AlarmHistoryServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/AlarmHistoryServiceImpl.java deleted file mode 100644 index 2de5d10..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/AlarmHistoryServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hnac.hzims.alarm.handle.service.impl; - -import com.hnac.hzims.alarm.entity.AlarmHistoryEntity; -import com.hnac.hzims.alarm.handle.mapper.AlarmHistoryMapper; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseService; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author ysj - */ -@AllArgsConstructor -@Service -@Slf4j -public class AlarmHistoryServiceImpl extends BaseServiceImpl implements BaseService { - -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/DroolsAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/DroolsAlarmServiceImpl.java deleted file mode 100644 index 501b131..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/DroolsAlarmServiceImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.hnac.hzims.alarm.handle.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.DroolsAlarmService; -import com.hnac.hzims.alarm.handle.service.MessageService; -import com.hnac.hzims.alarm.show.service.AlarmService; -import com.hnac.hzims.alarm.vo.ConditionAlarmVo; -import com.hnac.hzims.equipment.feign.IEmInfoClient; -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.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import static com.hnac.hzims.alarm.constants.AlarmConstants.CONDITION; -import static com.hnac.hzims.alarm.constants.AlarmConstants.CONDITION_ALARM; - -/** - * 等级告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class DroolsAlarmServiceImpl implements DroolsAlarmService { - - private final AlarmService alarmService; - - private final MessageService messageService; - - private final RedisTemplate redisTemplate; - - private final IEmInfoClient deviceClient; - - private final IStationClient stationClient; - - public final static String device_cache_cofig_final = "hzims:equipment:emInfo:deviceCode.emInfoList"; - - /** - * 发送websocket消息 - * @return - */ - @Override - public String message() { - return ""; - } - - - /** - * 转换接收服务推送消息 - * @param message - */ - @Override - public List receiveMessage(String message) { - // 对象转换 - List alarms = JSONObject.parseArray(message, ConditionAlarmVo.class); - if (CollectionUtil.isEmpty(alarms)) { - return new ArrayList<>(); - } - List res = alarms.stream().map(s -> { - AlarmEntity entity = getAlarmEntity(s); - return entity; - }).collect(Collectors.toList()); - return res; - } - - private AlarmEntity getAlarmEntity(ConditionAlarmVo item) { - AlarmEntity entity = new AlarmEntity(); - entity.setAlarmId(item.getFaultId()); - entity.setAlarmTime(item.getCreateTime()); - entity.setAlarmContext(item.getFinfo()); - entity.setAlarmType(CONDITION); - entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus()))); - entity.setStationId(item.getStation()); - entity.setAlarmSource(CONDITION_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; - } -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/FdpAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/FdpAlarmServiceImpl.java deleted file mode 100644 index f801958..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/FdpAlarmServiceImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.hnac.hzims.alarm.handle.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.FdpAlarmService; -import com.hnac.hzims.alarm.handle.service.MessageService; -import com.hnac.hzims.alarm.show.service.AlarmService; -import com.hnac.hzims.alarm.vo.FdpAlarmVo; -import com.hnac.hzims.message.fegin.IMessageClient; -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.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -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.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -import static com.hnac.hzims.alarm.constants.AlarmConstants.EARLY; -import static com.hnac.hzims.alarm.constants.AlarmConstants.EARLY_WARNING; - -/** - * 等级告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class FdpAlarmServiceImpl implements FdpAlarmService { - - - private final MessageService messageService; - private final IUserClient userClient; - private final ISysClient sysClient; - - private final IMessageClient messageClient; - private final AlarmService alarmService; - private final IStationClient stationClient; - /** - * 定时发送消息内容 - * @return String - */ - @Override - public String sendMessage() { - R> listAll = stationClient.getListAll(); - if (!listAll.isSuccess()||CollectionUtil.isEmpty(listAll.getData())){ - throw new ServiceException("FdpAlarm send message is null"); - } - List stations = listAll.getData(); - Map map = new ConcurrentHashMap<>(); - map.put("stations",stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); - return JSONObject.toJSONString(map); - } - - /** - * 转换接收服务推送消息 - * @param message - */ - @Override - public List receiveMessage(String message) { - // 对象转换 - FdpAlarmVo alarms = JSONObject.parseObject(message, FdpAlarmVo.class); - if (ObjectUtils.isEmpty(alarms)) { - 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); - } - - private AlarmEntity getAlarmEntity(FdpAlarmVo item) { - AlarmEntity entity = new AlarmEntity(); - entity.setAlarmId(item.getFaultId()); - entity.setAlarmTime(item.getCreateTime()); - entity.setAlarmContext(item.getFinfo()); - entity.setAlarmType(EARLY); - entity.setDeviceName(item.getDeviceName()); - entity.setAlarmStatus(Integer.valueOf(item.getStatus())); - entity.setStationId(item.getStation()); - 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/handle/service/impl/LevelAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/LevelAlarmServiceImpl.java deleted file mode 100644 index 3f3c926..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/LevelAlarmServiceImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.hnac.hzims.alarm.handle.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.hnac.hzims.alarm.constants.AlarmConstants; -import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.LevelAlarmService; -import com.hnac.hzims.alarm.handle.service.MessageService; -import com.hnac.hzims.alarm.show.service.AlarmService; -import com.hnac.hzims.alarm.vo.LevelMessageVo; -import com.hnac.hzims.alarm.vo.LevelVo; -import com.hnac.hzims.equipment.feign.IEmInfoClient; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -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.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * 等级告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class LevelAlarmServiceImpl implements LevelAlarmService { - - private final AlarmService alarmService; - - private final MessageService messageService; - - private final RedisTemplate redisTemplate; - - private final IEmInfoClient deviceClient; - - private final IStationClient stationClient; - - public final static String device_cache_cofig_final = "hzims:equipment:emInfo:deviceCode.emInfoList"; - - /** - * 发送websocket消息 - * @return - */ - @Override - public String message() { - StationEntity station = new StationEntity(); - station.setDataOrigin("0"); - // 站点 - R> result = stationClient.list(station); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - log.error("level alarm send message station is null"); - return ""; - } - LevelMessageVo message = new LevelMessageVo(); - message.setProjectIds(result.getData().stream().map(StationEntity::getCode).collect(Collectors.joining(","))); - message.setType(AlarmConstants.HZ3000_ALARAM_LIST.stream().map(String::valueOf).collect(Collectors.joining(","))); - message.setStartTime(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"); - return JSONObject.toJSONString(message); - } - - /** - * 转换接收服务推送消息 - * @param message - */ - @Override - public List receiveMessage(String message) { - // 对象转换 - List alarms = JSONObject.parseArray(message, LevelVo.class); - if (CollectionUtil.isEmpty(alarms)) { - return new ArrayList<>(); - } - List res = alarms.stream().map(s -> { - AlarmEntity entity = getAlarmEntity(s); - return entity; - }).collect(Collectors.toList()); - return res; - } - - private AlarmEntity getAlarmEntity(LevelVo level) { - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(),new TypeReference>() {}); - AlarmEntity entity = new AlarmEntity(); - entity.setAlarmSource(AlarmConstants.LEVEL_ALARM); - entity.setAlarmId(level.getId()); - entity.setAlarmTime(DateUtil.parse(level.getTs(), "yyyy-MM-dd HH:mm:ss.s")); - entity.setAlarmType(level.getType()); - entity.setRealId(level.getSignage()); - entity.setAlarmContext(level.getName()); - entity.setDeviceCode(level.getDevicecode()); - entity.setDeviceName(level.getDevicename()); - entity.setAlarmLevel(level.getLevel()); - List ems = devices.stream().filter(o->level.getDevicecode().equals(o.getEmCode())).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(ems)){ - entity.setStationId(ems.get(0).getStationCode()); - entity.setDeviceName(ems.get(0).getStationName()); - } - return entity; - } - - -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java deleted file mode 100644 index 1e691a6..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.hnac.hzims.alarm.handle.service.impl; - -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.hnac.hzims.alarm.config.service.AlarmConfigService; -import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.MessageService; -import com.hnac.hzims.message.MessageConstants; -import com.hnac.hzims.message.dto.BusinessMessageDTO; -import com.hnac.hzims.message.dto.SmsPushDto; -import com.hnac.hzims.message.dto.WxMessageDTO; -import com.hnac.hzims.message.fegin.IMessageClient; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springblade.system.cache.DictCache; -import org.springblade.system.feign.ISysClient; -import org.springblade.system.user.entity.User; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.stereotype.Service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MANAGER; - -/** - * 消息推送实现类 - * @author ysj - */ -@Slf4j -@Service -@AllArgsConstructor -public class MessageServiceImpl implements MessageService { - private final ISysClient sysClient; - private final IStationClient stationClient; - private final IUserClient userClient; - private final IMessageClient messageClient; - private final AlarmConfigService alarmConfigService; - /** - * 短信推送 - * @param entity : 告警对象 - */ - @Override - public void shortMessage(AlarmEntity entity) { - R station = stationClient.getStationByCode(entity.getStationId()); - if (!station.isSuccess() && ObjectUtils.isEmpty(station.getData())) { - log.error("消息发送失败:站点code获取失败 : {}",entity); - return; - } - //通知站点项目经理这个角色 - List users = userClient.relationUserListByRoleAlias("200000", station.getData().getRefDept(), PROJECT_MANAGER).getData(); - if(CollectionUtil.isEmpty(users)){ - return; - } - List phones = users.stream().map(User::getPhone).filter(phone -> !StringUtil.isEmpty(phone)).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(phones)){ - return; - } - SmsPushDto sms = new SmsPushDto(); - sms.setPhones(phones); - Map params = new HashMap<>(); - params.put("projectName",entity.getStationName()); - params.put("deviceName",entity.getDeviceCode()); - params.put("ruleDefName",entity.getAlarmContext()); - params.put("ts", DateUtil.format(entity.getAlarmTime(),DateUtil.PATTERN_DATETIME)); - sms.setParams(params); - messageClient.sendSmsMessage(sms); - } - - /** - * web/app消息推送 - * @param entity : 告警对象 - */ - @Override - public void webAppMessage(AlarmEntity entity) { - R stationByCode = stationClient.getStationByCode(entity.getStationId()); - if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { - log.error("消息发送失败:站点code获取失败 : {}",entity); - return; - } - Long dept = stationByCode.getData().getCreateDept(); - // 获取站点用户 - R> result = userClient.userListByDeptId(dept); - if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { - log.error("消息发送失败:用户获取失败 : {}",entity); - return; - } - BusinessMessageDTO message = new BusinessMessageDTO(); - message.setBusinessClassify("warning"); - message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); - message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); - message.setTaskId(Long.valueOf(entity.getAlarmId())); - message.setTenantId("200000"); - message.setContent(entity.getAlarmContext()); - message.setDeptId(dept); - R deptName = sysClient.getDeptName(dept); - if (deptName.isSuccess()) { - message.setDeptName(deptName.getData()); - } - message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); - message.setCreateUser(result.getData().get(0).getId()); - messageClient.sendAppAndWsMsgByUsers(message); - } - - /** - * 微信公众号消息推送 - * @param entity - */ - @Override - public void weChatMessage(AlarmEntity entity) { - R stationByCode = stationClient.getStationByCode(entity.getStationId()); - if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { - log.error("消息发送失败:站点code获取失败 : {}",entity); - return; - } - Long dept = stationByCode.getData().getCreateDept(); - // 获取站点用户 - R> result = userClient.userListByDeptId(dept); - if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { - log.error("消息发送失败:用户获取失败 : {}",entity); - return; - } - WxMessageDTO message = new WxMessageDTO(); - // 模板Id - message.setTemplateId("hIgINCsjpG-gyCKh8wzwBWjR-hkbjkNLFTXQEsnR_Z8"); - // 微信消息跳转地址 - message.setSkipUrl("http://baidu.com"); - // 机构Id - message.setDeptId(result.getData().get(0).getId()); - // 业务关键字 - message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); - // 业务分类关键字 - message.setBusinessClassify(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); - // 任务Id - message.setTaskId(Long.valueOf(entity.getAlarmId())); - // 微信参数键值对 - HashMap map = new HashMap<>(); - map.put("thing18",entity.getStationName()); - map.put("thing5",entity.getDeviceCode()); - map.put("thing11",entity.getAlarmContext()); - map.put("thing14", DictCache.getValue("alarm_source", entity.getAlarmType())); - map.put("time2",entity.getAlarmTime()); - message.setMap(map); - // 消息内容 - message.setContent(entity.getAlarmContext()); - // 消息主题 - message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); - // 推送用户 - message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); - // 创建用户 - message.setCreateUser(result.getData().get(0).getId()); - // 租户Id - message.setTenantId("200000"); - messageClient.sendWxMessage(message); - } -} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/SystemAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/SystemAlarmServiceImpl.java deleted file mode 100644 index e73da1a..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/SystemAlarmServiceImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.hnac.hzims.alarm.handle.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.hnac.hzims.alarm.constants.AlarmConstants; -import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.MessageService; -import com.hnac.hzims.alarm.handle.service.SystemAlarmService; -import com.hnac.hzims.alarm.show.service.AlarmService; -import com.hnac.hzims.alarm.vo.SystemAlarmVo; -import com.hnac.hzims.message.fegin.IMessageClient; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -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.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -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.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -/** - * 华自3000告警实现类 - * - * @author ty - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class SystemAlarmServiceImpl implements SystemAlarmService { - - private final MessageService messageService; - private final IUserClient userClient; - - private final ISysClient sysClient; - - private final IMessageClient messageClient; - private final AlarmService alarmService; - private final IStationClient stationClient; - - /** - * 定时发送消息内容 - * - * @return String - */ - @Override - public String sendMessage() { - R> listAll = stationClient.getListAll(); - if (!listAll.isSuccess() || CollectionUtil.isEmpty(listAll.getData())) { - throw new ServiceException("systemAlarm send message is null"); - } - List stations = listAll.getData(); - Map map = new ConcurrentHashMap<>(); - map.put("stations", stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); - map.put("soe_type", AbnormalAlarmConstant.SYSTEM_TYPE_LIST); - return JSONObject.toJSONString(map); - } - - - /** - * 转换接收服务推送消息 - * @param message - */ - @Override - public List receiveMessage(String message) { - // 对象转换 - List alarms = JSONObject.parseArray(message, SystemAlarmVo.class); - if (CollectionUtil.isEmpty(alarms)) { - return new ArrayList<>(); - } - List res = alarms.stream().map(s -> { - AlarmEntity entity = getAlarmEntity(s); - return entity; - }).collect(Collectors.toList()); - return res; - } - - 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()); - entity.setStationId(item.getStation()); - 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; - } -} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/VideoAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/VideoAlarmServiceImpl.java deleted file mode 100644 index 0c0447d..0000000 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/VideoAlarmServiceImpl.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.hnac.hzims.alarm.handle.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.hnac.hzims.alarm.constants.AlarmConstants; -import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.VideoAlarmService; -import com.hnac.hzims.alarm.show.service.AlarmService; -import com.hnac.hzims.equipment.entity.EmInfoEntity; -import com.hnac.hzims.equipment.feign.IEmInfoClient; -import com.hnac.hzims.message.fegin.IMessageClient; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzinfo.datasearch.soe.ISoeClient; -import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; -import com.hnac.hzinfo.sdk.core.response.HzPage; -import com.hnac.hzinfo.sdk.core.response.Result; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * 华自3000告警实现类 - * - * @author ty - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class VideoAlarmServiceImpl implements VideoAlarmService { - private final IMessageClient messageClient; - private final AlarmService alarmService; - private final ISoeClient iSoeClient; - private final IStationClient stationClient; - private final IEmInfoClient emInfoClient; - - /** - * 定时查询告警信息 - * - * @return String - */ - @Override - public List sendMessage() { - String startTime = DateUtil.format(new Date(), "yyyy-MM-dd 00:00:00"); - String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); -// 根据海康摄像头的字段查询所有设备 - EmInfoEntity emInfoEntity = new EmInfoEntity(); -// 字典配的deviceType,4是海康视频 - emInfoEntity.setEmType("4"); - List infoEntityList = emInfoClient.getVideoDeviceByEmCode(emInfoEntity); - // 拿到所有设备后,掉平台预警信息的接口 - List> collect = infoEntityList.stream() - .map(s -> { - List records = new ArrayList<>(); - Result> deviceCodeByTaosSoe = iSoeClient.getDeviceCodeByTaosSoe(startTime, endTime, s.getNumber(), 1, "999"); - if (deviceCodeByTaosSoe.isSuccess() && ObjectUtils.isNotEmpty(deviceCodeByTaosSoe.getData())) { - HzPage data = deviceCodeByTaosSoe.getData(); - records = data.getRecords(); - return records; - } - return records; - }).filter(s -> CollectionUtil.isNotEmpty(s)).collect(Collectors.toList()); - List res =new ArrayList<>(); - if (CollectionUtil.isNotEmpty(collect)) { - res= collect.stream().flatMap(List::stream).collect(Collectors.toList()); - } -// 转换平台视频预警信息 - List alarmEntities =new ArrayList<>(); - if (CollectionUtil.isNotEmpty(res)) { - alarmEntities= res.stream().filter(s->ObjectUtils.isNotEmpty(s)).map(s -> getAlarmEntity(s)).collect(Collectors.toList()); - } - return alarmEntities; - } - - - /** - * 转换接收服务推送消息 - * @param message - */ - @Override - public List receiveMessage(String message) { - // 对象转换 - List alarms = JSONObject.parseArray(message, DeviceSoeVO.class); - if (CollectionUtil.isEmpty(alarms)) { - return new ArrayList<>(); - } - List res = alarms.stream().map(s -> { - AlarmEntity entity = getAlarmEntity(s); - return entity; - }).collect(Collectors.toList()); - return res; - } - - private AlarmEntity getAlarmEntity(DeviceSoeVO 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(AbnormalAlarmConstant.VIDEO_ALARM); - entity.setAlarmStatus(Integer.valueOf(item.getSoeStatus())); - entity.setRealId(item.getRealId()); - entity.setStationId(item.getStation()); - entity.setAlarmSource(AlarmConstants.VIDEO_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/monitor/listener/AlarmListener.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java index ce4f618..3441281 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java @@ -2,7 +2,7 @@ package com.hnac.hzims.alarm.monitor.listener; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.MessageService; +import com.hnac.hzims.alarm.source.service.MessageService; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.StringUtil; import org.springblade.queue.annotation.RedisQueue; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java index 33a9697..e320b37 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java @@ -2,7 +2,7 @@ package com.hnac.hzims.alarm.mqtt; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.DroolsAlarmService; +import com.hnac.hzims.alarm.source.service.DroolsAlarmService; import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; import com.hnac.hzinfo.subscribe.SubscribeCallBack; import lombok.extern.slf4j.Slf4j; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java index 90fd7a6..e37e57c 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java @@ -2,7 +2,7 @@ package com.hnac.hzims.alarm.mqtt; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.FdpAlarmService; +import com.hnac.hzims.alarm.source.service.FdpAlarmService; import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; import com.hnac.hzinfo.subscribe.SubscribeCallBack; import org.springblade.core.log.exception.ServiceException; 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 6060a59..b624c23 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 @@ -2,7 +2,7 @@ package com.hnac.hzims.alarm.mqtt; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.SystemAlarmService; +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; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java index e42bfa3..bc285e1 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java @@ -2,7 +2,7 @@ package com.hnac.hzims.alarm.mqtt; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.VideoAlarmService; +import com.hnac.hzims.alarm.source.service.VideoAlarmService; import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; import com.hnac.hzinfo.subscribe.SubscribeCallBack; import lombok.extern.slf4j.Slf4j; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java new file mode 100644 index 0000000..9f638cb --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java @@ -0,0 +1,74 @@ +package com.hnac.hzims.alarm.show.controller; + + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.alarm.show.service.AlarmHandleService; +import com.hnac.hzims.alarm.vo.AlarmHandleVo; +import com.hnac.hzims.common.logs.annotation.OperationAnnotation; +import com.hnac.hzims.common.logs.enums.BusinessType; +import com.hnac.hzims.common.logs.enums.OperatorType; +import com.hnac.hzims.operational.alert.vo.HandleQueryVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.log.annotation.ApiLog; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.system.user.entity.User; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +@Api(tags = {"告警处理"}) +@RestController +@AllArgsConstructor +@RequestMapping("/handle") +public class AlarmHandleController extends BladeController { + + private final AlarmHandleService service; + + + /** + * 告警处理:处理、延后、误报 + */ + @PostMapping("/execute") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "告警处理", notes = "传入AlarmHandleEntity") + public R execute(@RequestBody AlarmHandleVo param) { + return R.status(service.execute(param)); + } + + /** + * 分页 + */ + @ApiLog + @GetMapping("/list") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "分页", notes = "传入AlarmHandleEntity") + @OperationAnnotation(moduleName = "分页查询告警处理记录", title = "查询告警处理记录", operatorType = OperatorType.MOBILE, businessType = + BusinessType.GENCODE, + action = "分页") + public R> list(HandleQueryVo param, Query query) { + IPage pages = service.pageCondition(query, param); + return R.data(pages); + } + + /** + * 告警处理用户查询 + */ + @ApiLog + @GetMapping("/handleUser") + @ApiOperationSupport(order = 3) + @ApiOperation(value = "告警通知人", notes = "告警通知人") + public R> handleUser() { + return R.data(service.handleUser()); + } + +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java index 5410138..178fba2 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java @@ -3,7 +3,7 @@ package com.hnac.hzims.alarm.show.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.SystemAlarmService; +import com.hnac.hzims.alarm.source.service.SystemAlarmService; import com.hnac.hzims.alarm.show.service.AlarmService; import com.hnac.hzims.alarm.vo.AlarmCountVo; import io.swagger.annotations.Api; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.java new file mode 100644 index 0000000..d7e5cec --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.alarm.show.mapper; + +import com.hnac.hzims.alarm.entity.AlarmHandleDetailEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +public interface AlarmHandleDetailMapper extends UserDataScopeBaseMapper { + +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.xml b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.xml new file mode 100644 index 0000000..fe0ad87 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java new file mode 100644 index 0000000..8a25d64 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.alarm.show.mapper; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.alarm.entity.AlarmHandleEntity; +import com.hnac.hzims.alarm.vo.AlarmHandleVo; +import com.hnac.hzims.operational.alert.vo.HandleQueryVo; +import org.apache.ibatis.annotations.Param; +import org.springblade.core.datascope.annotation.UserDataAuth; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +public interface AlarmHandleMapper extends UserDataScopeBaseMapper { + + @UserDataAuth + IPage selectHandlePage(IPage page, @Param("param") HandleQueryVo param); + + List handles(@Param("start") String start,@Param("end") String end); +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml new file mode 100644 index 0000000..78b9f15 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleDetailService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleDetailService.java new file mode 100644 index 0000000..3e7f4ba --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleDetailService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.alarm.show.service; + + +import com.hnac.hzims.alarm.entity.AlarmHandleDetailEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +public interface AlarmHandleDetailService extends BaseService { + +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java new file mode 100644 index 0000000..99ef712 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.alarm.show.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.alarm.entity.AlarmHandleEntity; +import com.hnac.hzims.alarm.vo.AlarmHandleVo; +import com.hnac.hzims.operational.alert.vo.HandleQueryVo; +import org.springblade.core.mp.base.BaseService; +import org.springblade.core.mp.support.Query; +import org.springblade.system.user.entity.User; + +import java.util.List; + +/** + * @author ysj + * @date 2023/03/09 09:19:13 + * @version 4.0.0 + */ +public interface AlarmHandleService extends BaseService { + + boolean execute(AlarmHandleVo param); + + IPage pageCondition(Query query, HandleQueryVo param); + + List handleUser(); + + List handles(); +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleDetailServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleDetailServiceImpl.java new file mode 100644 index 0000000..a0d5703 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleDetailServiceImpl.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.alarm.show.service.impl; + +import com.hnac.hzims.alarm.entity.AlarmHandleDetailEntity; +import com.hnac.hzims.alarm.show.mapper.AlarmHandleDetailMapper; +import com.hnac.hzims.alarm.show.service.AlarmHandleDetailService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + * @date 2023/03/09 09:29:34 + * @version 4.0.0 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AlarmHandleDetailServiceImpl extends BaseServiceImpl implements AlarmHandleDetailService { + +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java new file mode 100644 index 0000000..5363fb1 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java @@ -0,0 +1,151 @@ +package com.hnac.hzims.alarm.show.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.alarm.entity.AlarmHandleDetailEntity; +import com.hnac.hzims.alarm.entity.AlarmHandleEntity; +import com.hnac.hzims.alarm.show.mapper.AlarmHandleMapper; +import com.hnac.hzims.alarm.show.service.AlarmHandleDetailService; +import com.hnac.hzims.alarm.show.service.AlarmHandleService; +import com.hnac.hzims.alarm.show.wrapper.HandleWrapper; +import com.hnac.hzims.alarm.vo.AlarmHandleVo; +import com.hnac.hzims.fdp.feign.IFdpMonitorClient; +import com.hnac.hzims.fdp.vo.UpdateFaultStateVo; +import com.hnac.hzims.alarm.constants.AlarmHandleConstant; +import com.hnac.hzims.operational.alert.vo.HandleQueryVo; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.system.entity.Dept; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.entity.User; +import org.springblade.system.user.feign.IUserClient; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + * @version 4.0.0 + * @date 2023/03/09 09:29:34 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AlarmHandleServiceImpl extends BaseServiceImpl implements AlarmHandleService { + + private final AlarmHandleDetailService detailService; + + private final ISysClient sysClient; + + private final IUserClient userClient; + + private final IFdpMonitorClient fdpMonitorClient; + + /** + * 告警处理 + * + * @param param + * @return + */ + @Override + public boolean execute(AlarmHandleVo param) { + Long way = param.getHandleWay(); + if (!AlarmHandleConstant.HANDLE_WAY.contains(way)) { + throw new ServiceException("无效处理!"); + } + // 预警 + if(AlarmHandleConstant.EARLY_WARNING.equals(param.getAlarmType())){ + this.updateFalultState(param); + } + // 详情 + AlarmHandleDetailEntity detail = new AlarmHandleDetailEntity(); + detail.setAccessId(param.getAccessId()); + detail.setPhenomenonId(param.getPhenomenonId()); + detail.setHandleUser(param.getHandleUser()); + detail.setDelayTime(param.getDelayTime()); + detail.setDelayCause(param.getDelayCause()); + detail.setFalseAlarmDesc(param.getFalseAlarmDesc()); + detail.setFilePath(param.getFilePath()); + detailService.save(detail); + // 处理记录 + AlarmHandleEntity entity = new AlarmHandleEntity(); + entity.setAlarmId(param.getAlarmId()); + entity.setType(param.getType()); + entity.setDetailId(detail.getId()); + entity.setAlarmTime(param.getAlarmTime()); + entity.setAlarmContent(param.getAlarmContent()); + entity.setHandleWay(param.getHandleWay()); + entity.setStationCode(param.getStationCode()); + entity.setAlarmType(param.getAlarmType()); + return this.save(entity); + } + + /** + * 预警处理推送智能诊断服务 + * @param param + */ + private void updateFalultState(AlarmHandleVo param) { + try{ + UpdateFaultStateVo state = new UpdateFaultStateVo(); + state.setStationId(param.getStationCode()); + state.setFaultId(param.getAlarmId()); + if(AlarmHandleConstant.HANDLE.contains(param.getHandleWay())){ + state.setConfidence(1f); + }else{ + state.setConfidence(0f); + } + state.setCreateTime(DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME)); + state.setCreateUser(String.valueOf(AuthUtil.getUserId())); + state.setLifeTime(1); + state.setPriority(1); + state.setInfo(param.getFalseAlarmDesc()); + String result = fdpMonitorClient.updateFaultState(state); + }catch (Exception exception){ + log.error("update_falult_state: {}",exception.getMessage()); + } + } + + /** + * 分页 + * @param query + * @param param + * @return + */ + @Override + public IPage pageCondition(Query query, HandleQueryVo param) { + IPage pages = this.baseMapper.selectHandlePage(Condition.getPage(query), param); + List list = HandleWrapper.build().listVO(pages.getRecords()); + return pages.setRecords(list); + } + + /** + * 告警处理人 + * @return + */ + @Override + public List handleUser() { + List users = userClient.userListByDeptAndChildrenWithAuth(Long.valueOf(AuthUtil.getUser().getDeptId())).getData(); + return users.stream().distinct().collect(Collectors.toList()); + } + + /** + * 查询处理告警记录 + * @return + */ + @Override + public List handles() { + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + return this.baseMapper.handles(start,end); + } +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java index 4efb20a..22c5ad2 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java @@ -3,13 +3,13 @@ package com.hnac.hzims.alarm.show.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.alarm.config.service.AlarmConfigService; import com.hnac.hzims.alarm.constants.AlarmConstants; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.MessageService; import com.hnac.hzims.alarm.show.mapper.AlarmMapper; +import com.hnac.hzims.alarm.show.service.AlarmHandleService; import com.hnac.hzims.alarm.show.service.AlarmService; +import com.hnac.hzims.alarm.source.service.MessageService; import com.hnac.hzims.alarm.vo.AlarmCountVo; import com.hnac.hzims.alarm.vo.ChildAlarmCountVo; import com.hnac.hzims.message.dto.MailMessageDTO; @@ -42,6 +42,8 @@ public class AlarmServiceImpl extends BaseServiceImpl private final AlarmConfigService configService; + private final AlarmHandleService alarmHandleService; + private final IUserClient userClient; private final IStationClient stationClient; @@ -77,6 +79,12 @@ public class AlarmServiceImpl extends BaseServiceImpl wrapper.eq("ALARM_TYPE",alarm.getAlarmType()); } + // 处理告警过滤 :当天处理告警 + List handles = alarmHandleService.handles(); + if(!CollectionUtil.isEmpty(handles)){ + wrapper.notIn("ALARM_ID",handles); + } + // 查询数据 return this.page(page,wrapper); } @@ -184,13 +192,18 @@ public class AlarmServiceImpl extends BaseServiceImpl if(CollectionUtil.isEmpty(effectives)){ return null; } - List alarms = this.list(Wrappers.lambdaQuery() - .in(AlarmEntity::getStationId,effectives) - .in(AlarmEntity::getAlarmType, Arrays.asList(AlarmConstants.FAULT,AlarmConstants.EARLY)) - .eq(AlarmEntity::getIsShowAlert,0) - .eq(AlarmEntity::getStatus,0) - //.ge(AlarmEntity::getAlarmType, DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00") - ); + // 条件过滤 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().in(AlarmEntity::getStationId,effectives); + queryWrapper.lambda().in(AlarmEntity::getAlarmType, Arrays.asList(AlarmConstants.FAULT,AlarmConstants.EARLY)); + queryWrapper.lambda().eq(AlarmEntity::getIsShowAlert,0); + queryWrapper.lambda().eq(AlarmEntity::getStatus,0); + // 处理告警过滤 :当天处理告警 + List handles = alarmHandleService.handles(); + if(!CollectionUtil.isEmpty(handles)){ + queryWrapper.lambda().notIn(AlarmEntity::getAlarmId,handles); + } + List alarms = this.list(queryWrapper); if(CollectionUtil.isEmpty(alarms)){ return null; } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/wrapper/HandleWrapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/wrapper/HandleWrapper.java new file mode 100644 index 0000000..9fb55e9 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/wrapper/HandleWrapper.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.alarm.show.wrapper; + +import com.hnac.hzims.alarm.vo.AlarmHandleVo; +import org.springblade.core.mp.support.BaseEntityWrapper; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; + +import java.util.Optional; + + +public class HandleWrapper extends BaseEntityWrapper { + + public static HandleWrapper build() { + return new HandleWrapper(); + } + + @Override + public AlarmHandleVo entityVO(AlarmHandleVo entity) { + User createUser = UserCache.getUser(entity.getCreateUser()); + if(ObjectUtil.isEmpty(createUser)){ + return entity; + } + assert entity != null; + entity.setUserName(Optional.ofNullable(createUser.getName()).orElse(null)); + return entity; + } +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.java new file mode 100644 index 0000000..25d3aed --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.alarm.source.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.alarm.entity.AlarmHistoryEntity; + +/** + * @author ysj + */ +public interface AlarmHistoryMapper extends BaseMapper { + + +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.xml b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.xml new file mode 100644 index 0000000..fa2e261 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/AlarmHistoryService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/AlarmHistoryService.java new file mode 100644 index 0000000..d7ef128 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/AlarmHistoryService.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.alarm.source.service; + +import com.hnac.hzims.alarm.entity.AlarmHistoryEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface AlarmHistoryService extends BaseService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java new file mode 100644 index 0000000..4d2b0da --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.alarm.source.service; + +import com.hnac.hzims.alarm.entity.AlarmEntity; + +import java.util.List; + +/** + * 等级处理接口 + * @author ysj + */ +public interface DroolsAlarmService { + + String message(); + + List receiveMessage(String message); +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/FdpAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/FdpAlarmService.java new file mode 100644 index 0000000..e50da70 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/FdpAlarmService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.alarm.source.service; + +import com.hnac.hzims.alarm.entity.AlarmEntity; + +import java.util.List; + +/** + * 告警处理接口 + * @author ysj + */ +public interface FdpAlarmService { + + String sendMessage(); + + List receiveMessage(String message); +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/LevelAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/LevelAlarmService.java new file mode 100644 index 0000000..903b81e --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/LevelAlarmService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.alarm.source.service; + +import com.hnac.hzims.alarm.entity.AlarmEntity; + +import java.util.List; + +/** + * 等级处理接口 + * @author ysj + */ +public interface LevelAlarmService { + + String message(); + + List receiveMessage(String message); +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java new file mode 100644 index 0000000..8496031 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.alarm.source.service; + +import com.hnac.hzims.alarm.entity.AlarmEntity; + +/** + * @author ysj + */ +public interface MessageService { + + void shortMessage(AlarmEntity entity); + + void webAppMessage(AlarmEntity entity); + + void weChatMessage(AlarmEntity entity); +} \ No newline at end of file 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 new file mode 100644 index 0000000..3adf860 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.alarm.source.service; + +import com.hnac.hzims.alarm.entity.AlarmEntity; + +import java.util.List; + +/** + * 告警处理接口 + * @author ysj + */ +public interface SystemAlarmService { + + String sendMessage(); + + List receiveMessage(String message); +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/VideoAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/VideoAlarmService.java new file mode 100644 index 0000000..4d7432b --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/VideoAlarmService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.alarm.source.service; + +import com.hnac.hzims.alarm.entity.AlarmEntity; + +import java.util.List; + +/** + * 告警处理接口 + * @author ysj + */ +public interface VideoAlarmService { + + List sendMessage(); + + List receiveMessage(String message); +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/AlarmHistoryServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/AlarmHistoryServiceImpl.java new file mode 100644 index 0000000..773d266 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/AlarmHistoryServiceImpl.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.alarm.source.service.impl; + +import com.hnac.hzims.alarm.entity.AlarmHistoryEntity; +import com.hnac.hzims.alarm.source.mapper.AlarmHistoryMapper; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseService; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@AllArgsConstructor +@Service +@Slf4j +public class AlarmHistoryServiceImpl extends BaseServiceImpl implements BaseService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java new file mode 100644 index 0000000..1584d15 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java @@ -0,0 +1,93 @@ +package com.hnac.hzims.alarm.source.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.source.service.DroolsAlarmService; +import com.hnac.hzims.alarm.source.service.MessageService; +import com.hnac.hzims.alarm.show.service.AlarmService; +import com.hnac.hzims.alarm.vo.ConditionAlarmVo; +import com.hnac.hzims.equipment.feign.IEmInfoClient; +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.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static com.hnac.hzims.alarm.constants.AlarmConstants.CONDITION; +import static com.hnac.hzims.alarm.constants.AlarmConstants.CONDITION_ALARM; + +/** + * 等级告警实现类 + * @author ysj + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class DroolsAlarmServiceImpl implements DroolsAlarmService { + + private final AlarmService alarmService; + + private final MessageService messageService; + + private final RedisTemplate redisTemplate; + + private final IEmInfoClient deviceClient; + + private final IStationClient stationClient; + + public final static String device_cache_cofig_final = "hzims:equipment:emInfo:deviceCode.emInfoList"; + + /** + * 发送websocket消息 + * @return + */ + @Override + public String message() { + return ""; + } + + + /** + * 转换接收服务推送消息 + * @param message + */ + @Override + public List receiveMessage(String message) { + // 对象转换 + List alarms = JSONObject.parseArray(message, ConditionAlarmVo.class); + if (CollectionUtil.isEmpty(alarms)) { + return new ArrayList<>(); + } + List res = alarms.stream().map(s -> { + AlarmEntity entity = getAlarmEntity(s); + return entity; + }).collect(Collectors.toList()); + return res; + } + + private AlarmEntity getAlarmEntity(ConditionAlarmVo item) { + AlarmEntity entity = new AlarmEntity(); + entity.setAlarmId(item.getFaultId()); + entity.setAlarmTime(item.getCreateTime()); + entity.setAlarmContext(item.getFinfo()); + entity.setAlarmType(CONDITION); + entity.setAlarmStatus(Integer.valueOf(String.valueOf(item.getStatus()))); + entity.setStationId(item.getStation()); + entity.setAlarmSource(CONDITION_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; + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..48428a0 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java @@ -0,0 +1,103 @@ +package com.hnac.hzims.alarm.source.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.source.service.FdpAlarmService; +import com.hnac.hzims.alarm.source.service.MessageService; +import com.hnac.hzims.alarm.show.service.AlarmService; +import com.hnac.hzims.alarm.vo.FdpAlarmVo; +import com.hnac.hzims.message.fegin.IMessageClient; +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.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +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.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +import static com.hnac.hzims.alarm.constants.AlarmConstants.EARLY; +import static com.hnac.hzims.alarm.constants.AlarmConstants.EARLY_WARNING; + +/** + * 等级告警实现类 + * @author ysj + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class FdpAlarmServiceImpl implements FdpAlarmService { + + + private final MessageService messageService; + private final IUserClient userClient; + private final ISysClient sysClient; + + private final IMessageClient messageClient; + private final AlarmService alarmService; + private final IStationClient stationClient; + /** + * 定时发送消息内容 + * @return String + */ + @Override + public String sendMessage() { + R> listAll = stationClient.getListAll(); + if (!listAll.isSuccess()||CollectionUtil.isEmpty(listAll.getData())){ + throw new ServiceException("FdpAlarm send message is null"); + } + List stations = listAll.getData(); + Map map = new ConcurrentHashMap<>(); + map.put("stations",stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); + return JSONObject.toJSONString(map); + } + + /** + * 转换接收服务推送消息 + * @param message + */ + @Override + public List receiveMessage(String message) { + // 对象转换 + FdpAlarmVo alarms = JSONObject.parseObject(message, FdpAlarmVo.class); + if (ObjectUtils.isEmpty(alarms)) { + 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); + } + + private AlarmEntity getAlarmEntity(FdpAlarmVo item) { + AlarmEntity entity = new AlarmEntity(); + entity.setAlarmId(item.getFaultId()); + entity.setAlarmTime(item.getCreateTime()); + entity.setAlarmContext(item.getFinfo()); + entity.setAlarmType(EARLY); + entity.setDeviceName(item.getDeviceName()); + entity.setAlarmStatus(Integer.valueOf(item.getStatus())); + entity.setStationId(item.getStation()); + 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/LevelAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java new file mode 100644 index 0000000..c46e28b --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java @@ -0,0 +1,110 @@ +package com.hnac.hzims.alarm.source.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.hnac.hzims.alarm.constants.AlarmConstants; +import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.source.service.LevelAlarmService; +import com.hnac.hzims.alarm.source.service.MessageService; +import com.hnac.hzims.alarm.show.service.AlarmService; +import com.hnac.hzims.alarm.vo.LevelMessageVo; +import com.hnac.hzims.alarm.vo.LevelVo; +import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +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.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 等级告警实现类 + * @author ysj + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class LevelAlarmServiceImpl implements LevelAlarmService { + + private final AlarmService alarmService; + + private final MessageService messageService; + + private final RedisTemplate redisTemplate; + + private final IEmInfoClient deviceClient; + + private final IStationClient stationClient; + + public final static String device_cache_cofig_final = "hzims:equipment:emInfo:deviceCode.emInfoList"; + + /** + * 发送websocket消息 + * @return + */ + @Override + public String message() { + StationEntity station = new StationEntity(); + station.setDataOrigin("0"); + // 站点 + R> result = stationClient.list(station); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + log.error("level alarm send message station is null"); + return ""; + } + LevelMessageVo message = new LevelMessageVo(); + message.setProjectIds(result.getData().stream().map(StationEntity::getCode).collect(Collectors.joining(","))); + message.setType(AlarmConstants.HZ3000_ALARAM_LIST.stream().map(String::valueOf).collect(Collectors.joining(","))); + message.setStartTime(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"); + return JSONObject.toJSONString(message); + } + + /** + * 转换接收服务推送消息 + * @param message + */ + @Override + public List receiveMessage(String message) { + // 对象转换 + List alarms = JSONObject.parseArray(message, LevelVo.class); + if (CollectionUtil.isEmpty(alarms)) { + return new ArrayList<>(); + } + List res = alarms.stream().map(s -> { + AlarmEntity entity = getAlarmEntity(s); + return entity; + }).collect(Collectors.toList()); + return res; + } + + private AlarmEntity getAlarmEntity(LevelVo level) { + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(),new TypeReference>() {}); + AlarmEntity entity = new AlarmEntity(); + entity.setAlarmSource(AlarmConstants.LEVEL_ALARM); + entity.setAlarmId(level.getId()); + entity.setAlarmTime(DateUtil.parse(level.getTs(), "yyyy-MM-dd HH:mm:ss.s")); + entity.setAlarmType(level.getType()); + entity.setRealId(level.getSignage()); + entity.setAlarmContext(level.getName()); + entity.setDeviceCode(level.getDevicecode()); + entity.setDeviceName(level.getDevicename()); + entity.setAlarmLevel(level.getLevel()); + List ems = devices.stream().filter(o->level.getDevicecode().equals(o.getEmCode())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(ems)){ + entity.setStationId(ems.get(0).getStationCode()); + entity.setDeviceName(ems.get(0).getStationName()); + } + return entity; + } + + +} \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java new file mode 100644 index 0000000..2f4c9be --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java @@ -0,0 +1,163 @@ +package com.hnac.hzims.alarm.source.service.impl; + +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.alarm.config.service.AlarmConfigService; +import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.source.service.MessageService; +import com.hnac.hzims.message.MessageConstants; +import com.hnac.hzims.message.dto.BusinessMessageDTO; +import com.hnac.hzims.message.dto.SmsPushDto; +import com.hnac.hzims.message.dto.WxMessageDTO; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.cache.DictCache; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.entity.User; +import org.springblade.system.user.feign.IUserClient; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MANAGER; + +/** + * 消息推送实现类 + * @author ysj + */ +@Slf4j +@Service +@AllArgsConstructor +public class MessageServiceImpl implements MessageService { + private final ISysClient sysClient; + private final IStationClient stationClient; + private final IUserClient userClient; + private final IMessageClient messageClient; + private final AlarmConfigService alarmConfigService; + /** + * 短信推送 + * @param entity : 告警对象 + */ + @Override + public void shortMessage(AlarmEntity entity) { + R station = stationClient.getStationByCode(entity.getStationId()); + if (!station.isSuccess() && ObjectUtils.isEmpty(station.getData())) { + log.error("消息发送失败:站点code获取失败 : {}",entity); + return; + } + //通知站点项目经理这个角色 + List users = userClient.relationUserListByRoleAlias("200000", station.getData().getRefDept(), PROJECT_MANAGER).getData(); + if(CollectionUtil.isEmpty(users)){ + return; + } + List phones = users.stream().map(User::getPhone).filter(phone -> !StringUtil.isEmpty(phone)).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(phones)){ + return; + } + SmsPushDto sms = new SmsPushDto(); + sms.setPhones(phones); + Map params = new HashMap<>(); + params.put("projectName",entity.getStationName()); + params.put("deviceName",entity.getDeviceCode()); + params.put("ruleDefName",entity.getAlarmContext()); + params.put("ts", DateUtil.format(entity.getAlarmTime(),DateUtil.PATTERN_DATETIME)); + sms.setParams(params); + messageClient.sendSmsMessage(sms); + } + + /** + * web/app消息推送 + * @param entity : 告警对象 + */ + @Override + public void webAppMessage(AlarmEntity entity) { + R stationByCode = stationClient.getStationByCode(entity.getStationId()); + if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { + log.error("消息发送失败:站点code获取失败 : {}",entity); + return; + } + Long dept = stationByCode.getData().getCreateDept(); + // 获取站点用户 + R> result = userClient.userListByDeptId(dept); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + log.error("消息发送失败:用户获取失败 : {}",entity); + return; + } + BusinessMessageDTO message = new BusinessMessageDTO(); + message.setBusinessClassify("warning"); + message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); + message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); + message.setTaskId(Long.valueOf(entity.getAlarmId())); + message.setTenantId("200000"); + message.setContent(entity.getAlarmContext()); + message.setDeptId(dept); + R deptName = sysClient.getDeptName(dept); + if (deptName.isSuccess()) { + message.setDeptName(deptName.getData()); + } + message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); + message.setCreateUser(result.getData().get(0).getId()); + messageClient.sendAppAndWsMsgByUsers(message); + } + + /** + * 微信公众号消息推送 + * @param entity + */ + @Override + public void weChatMessage(AlarmEntity entity) { + R stationByCode = stationClient.getStationByCode(entity.getStationId()); + if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { + log.error("消息发送失败:站点code获取失败 : {}",entity); + return; + } + Long dept = stationByCode.getData().getCreateDept(); + // 获取站点用户 + R> result = userClient.userListByDeptId(dept); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + log.error("消息发送失败:用户获取失败 : {}",entity); + return; + } + WxMessageDTO message = new WxMessageDTO(); + // 模板Id + message.setTemplateId("hIgINCsjpG-gyCKh8wzwBWjR-hkbjkNLFTXQEsnR_Z8"); + // 微信消息跳转地址 + message.setSkipUrl("http://baidu.com"); + // 机构Id + message.setDeptId(result.getData().get(0).getId()); + // 业务关键字 + message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); + // 业务分类关键字 + message.setBusinessClassify(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); + // 任务Id + message.setTaskId(Long.valueOf(entity.getAlarmId())); + // 微信参数键值对 + HashMap map = new HashMap<>(); + map.put("thing18",entity.getStationName()); + map.put("thing5",entity.getDeviceCode()); + map.put("thing11",entity.getAlarmContext()); + map.put("thing14", DictCache.getValue("alarm_source", entity.getAlarmType())); + map.put("time2",entity.getAlarmTime()); + message.setMap(map); + // 消息内容 + message.setContent(entity.getAlarmContext()); + // 消息主题 + message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); + // 推送用户 + message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); + // 创建用户 + message.setCreateUser(result.getData().get(0).getId()); + // 租户Id + message.setTenantId("200000"); + messageClient.sendWxMessage(message); + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..6c09aae --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java @@ -0,0 +1,105 @@ +package com.hnac.hzims.alarm.source.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.alarm.constants.AlarmConstants; +import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.source.service.MessageService; +import com.hnac.hzims.alarm.source.service.SystemAlarmService; +import com.hnac.hzims.alarm.show.service.AlarmService; +import com.hnac.hzims.alarm.vo.SystemAlarmVo; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.alarm.constants.AlarmHandleConstant; +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.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +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.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +/** + * 华自3000告警实现类 + * + * @author ty + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class SystemAlarmServiceImpl implements SystemAlarmService { + + private final MessageService messageService; + private final IUserClient userClient; + + private final ISysClient sysClient; + + private final IMessageClient messageClient; + private final AlarmService alarmService; + private final IStationClient stationClient; + + /** + * 定时发送消息内容 + * + * @return String + */ + @Override + public String sendMessage() { + R> listAll = stationClient.getListAll(); + if (!listAll.isSuccess() || CollectionUtil.isEmpty(listAll.getData())) { + throw new ServiceException("systemAlarm send message is null"); + } + List stations = listAll.getData(); + Map map = new ConcurrentHashMap<>(); + map.put("stations", stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); + map.put("soe_type", AlarmHandleConstant.SYSTEM_TYPE_LIST); + return JSONObject.toJSONString(map); + } + + + /** + * 转换接收服务推送消息 + * @param message + */ + @Override + public List receiveMessage(String message) { + // 对象转换 + List alarms = JSONObject.parseArray(message, SystemAlarmVo.class); + if (CollectionUtil.isEmpty(alarms)) { + return new ArrayList<>(); + } + List res = alarms.stream().map(s -> { + AlarmEntity entity = getAlarmEntity(s); + return entity; + }).collect(Collectors.toList()); + return res; + } + + 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()); + entity.setStationId(item.getStation()); + 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; + } +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/VideoAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/VideoAlarmServiceImpl.java new file mode 100644 index 0000000..10ac876 --- /dev/null +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/VideoAlarmServiceImpl.java @@ -0,0 +1,121 @@ +package com.hnac.hzims.alarm.source.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.alarm.constants.AlarmConstants; +import com.hnac.hzims.alarm.entity.AlarmEntity; +import com.hnac.hzims.alarm.source.service.VideoAlarmService; +import com.hnac.hzims.alarm.show.service.AlarmService; +import com.hnac.hzims.equipment.entity.EmInfoEntity; +import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.alarm.constants.AlarmHandleConstant; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import com.hnac.hzinfo.datasearch.soe.ISoeClient; +import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import com.hnac.hzinfo.sdk.core.response.Result; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 华自3000告警实现类 + * + * @author ty + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class VideoAlarmServiceImpl implements VideoAlarmService { + private final IMessageClient messageClient; + private final AlarmService alarmService; + private final ISoeClient iSoeClient; + private final IStationClient stationClient; + private final IEmInfoClient emInfoClient; + + /** + * 定时查询告警信息 + * + * @return String + */ + @Override + public List sendMessage() { + String startTime = DateUtil.format(new Date(), "yyyy-MM-dd 00:00:00"); + String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); +// 根据海康摄像头的字段查询所有设备 + EmInfoEntity emInfoEntity = new EmInfoEntity(); +// 字典配的deviceType,4是海康视频 + emInfoEntity.setEmType("4"); + List infoEntityList = emInfoClient.getVideoDeviceByEmCode(emInfoEntity); + // 拿到所有设备后,掉平台预警信息的接口 + List> collect = infoEntityList.stream() + .map(s -> { + List records = new ArrayList<>(); + Result> deviceCodeByTaosSoe = iSoeClient.getDeviceCodeByTaosSoe(startTime, endTime, s.getNumber(), 1, "999"); + if (deviceCodeByTaosSoe.isSuccess() && ObjectUtils.isNotEmpty(deviceCodeByTaosSoe.getData())) { + HzPage data = deviceCodeByTaosSoe.getData(); + records = data.getRecords(); + return records; + } + return records; + }).filter(s -> CollectionUtil.isNotEmpty(s)).collect(Collectors.toList()); + List res =new ArrayList<>(); + if (CollectionUtil.isNotEmpty(collect)) { + res= collect.stream().flatMap(List::stream).collect(Collectors.toList()); + } +// 转换平台视频预警信息 + List alarmEntities =new ArrayList<>(); + if (CollectionUtil.isNotEmpty(res)) { + alarmEntities= res.stream().filter(s->ObjectUtils.isNotEmpty(s)).map(s -> getAlarmEntity(s)).collect(Collectors.toList()); + } + return alarmEntities; + } + + + /** + * 转换接收服务推送消息 + * @param message + */ + @Override + public List receiveMessage(String message) { + // 对象转换 + List alarms = JSONObject.parseArray(message, DeviceSoeVO.class); + if (CollectionUtil.isEmpty(alarms)) { + return new ArrayList<>(); + } + List res = alarms.stream().map(s -> { + AlarmEntity entity = getAlarmEntity(s); + return entity; + }).collect(Collectors.toList()); + return res; + } + + private AlarmEntity getAlarmEntity(DeviceSoeVO 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(AlarmHandleConstant.VIDEO_ALARM); + entity.setAlarmStatus(Integer.valueOf(item.getSoeStatus())); + entity.setRealId(item.getRealId()); + entity.setStationId(item.getStation()); + entity.setAlarmSource(AlarmConstants.VIDEO_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/task/VideoScheduledTask.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/task/VideoScheduledTask.java index 6b5daf0..169d8ca 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/task/VideoScheduledTask.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/task/VideoScheduledTask.java @@ -1,7 +1,7 @@ package com.hnac.hzims.alarm.task; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.VideoAlarmService; +import com.hnac.hzims.alarm.source.service.VideoAlarmService; import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; import com.xxl.job.core.biz.model.ReturnT; import lombok.extern.slf4j.Slf4j; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmRegular.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmRegular.java index d2726b8..1727c10 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmRegular.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmRegular.java @@ -1,6 +1,6 @@ package com.hnac.hzims.alarm.ws.level; -import com.hnac.hzims.alarm.handle.service.LevelAlarmService; +import com.hnac.hzims.alarm.source.service.LevelAlarmService; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java index 601071c..cdbb5a4 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java @@ -1,7 +1,7 @@ package com.hnac.hzims.alarm.ws.level; import com.hnac.hzims.alarm.entity.AlarmEntity; -import com.hnac.hzims.alarm.handle.service.LevelAlarmService; +import com.hnac.hzims.alarm.source.service.LevelAlarmService; import com.hnac.hzims.alarm.monitor.service.AlarmSaveService; import lombok.extern.slf4j.Slf4j; import org.java_websocket.client.WebSocketClient; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/AlertWebSocketClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/AlertWebSocketClient.java deleted file mode 100644 index abb1dac..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/AlertWebSocketClient.java +++ /dev/null @@ -1,182 +0,0 @@ -package com.hnac.hzims.operational.alert; - -import com.alibaba.fastjson.JSONObject; -import com.hnac.hzims.monitor.feign.IMonitorClient; -import com.hnac.hzims.operational.alert.service.AlertDefectService; -import com.hnac.hzims.operational.alert.vo.AlertVo; -import com.hnac.hzims.operational.station.service.IStationService; -import com.hnac.hzinfo.core.push.enums.PushAudienceType; -import com.hnac.hzinfo.core.push.model.PushAudience; -import com.hnac.hzinfo.core.push.model.PushInfo; -import com.hnac.hzinfo.core.push.model.PushPlatform; -import lombok.extern.slf4j.Slf4j; -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.handshake.ServerHandshake; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.SpringUtil; -import org.springblade.resource.feign.IPushClient; -import org.springblade.resource.vo.PushInfoVO; -import org.springblade.system.user.entity.User; -import org.springframework.beans.factory.annotation.Value; - -import javax.net.ssl.*; -import java.net.URI; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 该socket服务只能启一个微服务,启动多个微服务的话同一个信息会重复发。 - * 如果operation服务需要部署多个微服务,这个alert需要分离出来作为单独的微服务部署,且只能部署一个。 - * @Author: py - */ -@Slf4j -public class AlertWebSocketClient extends WebSocketClient { - - @Value("${hzims.operation.task.jgPushCode}") - String jgPushCode; - - IStationService stationService; - IPushClient pushClient; - IMonitorClient monitorClient; - - AlertDefectService alertDefectService; - - public AlertWebSocketClient(URI serverUri) { - super(serverUri); - stationService = SpringUtil.getBean(IStationService.class); - pushClient = SpringUtil.getBean(IPushClient.class); - monitorClient = SpringUtil.getBean(IMonitorClient.class); - alertDefectService = SpringUtil.getBean(AlertDefectService.class); - if(serverUri.toString().contains("wss://")){ - trustAllHosts(this); - } - } - - @Override - public void onOpen(ServerHandshake handshakedata) { - log.info("[websocket] 连接成功"); - } - - - @Override - public void onMessage(String message) { - log.info("[websocket] 收到消息={}",message); - try{ - // 处理信息 - handleMsg(message); - // 告警缺陷处理现象 - handleAlertDefect(message); - } - catch (Exception e){ - log.error(e.getMessage()); - } - /**自动诊断**/ - this.diagnosisByMsg(message); - } - - - @Override - public void onClose(int code, String reason, boolean remote) { - log.info("[websocket] 退出连接={}-{}, 是否远程主动中断 = ", code , reason, remote); - } - - - @Override - public void onError(Exception ex) { - log.error("[websocket] onError = {}",ex.getMessage()); - } - - - void trustAllHosts(AlertWebSocketClient appClient) { - log.info("[websocket] wss 连接 ----- "); - try { - // wss需添加 - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(null, new TrustManager[] { new X509TrustManager() { - - @Override - public void checkClientTrusted(X509Certificate[] chain, - String authType) { - - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, - String authType) { - - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - } }, new SecureRandom()); - SSLSocketFactory factory = sslContext.getSocketFactory(); - appClient.setSocket(factory.createSocket()); - } catch (Exception e) { - log.error("[websocket] trustAllHosts 错误 - " + e.toString()); - } - } - - - /** - * 推送信息到移动端 - * @param message - */ - private void handleMsg(String message){ - JSONObject msg = JSONObject.parseObject(message); - if(Func.isEmpty(msg.getString("soe_explain")) || Func.isEmpty(msg.getString("station"))){ - return; - } - List users = stationService.getUsersByStationId(msg.getString("station")); - if(Func.isEmpty(users)){ - return; - } - // 移动端消息推送 : 使用 用户id做TAG,前端注册用户id为TAG - PushInfoVO pushInfoVO = new PushInfoVO(); - pushInfoVO.setTenantId(users.get(0).getTenantId()); - PushPlatform platform = PushPlatform.all(); - Map> audienceMap = new HashMap<>(); - audienceMap.put(PushAudienceType.TAG, users.stream().map(user -> user.getId().toString()).collect(Collectors.toList())); - PushAudience audience = new PushAudience(false, audienceMap); - PushInfo pushInfo = new PushInfo(jgPushCode - , "实时告警" - , msg.getString("soe_explain") - , "" - , null - , platform - , audience); - pushInfoVO.setPushInfo(pushInfo); - // FIXME:极光推送暂时关闭 推送消息给移动端 - //pushClient.tenantPush(pushInfoVO); - log.info("[websocket] handleMsg finish ----- " + pushInfo.toString()); - } - - /** - * 告警缺陷处理 - * @param message - */ - private void handleAlertDefect(String message) { - List list = Collections.singletonList(JSONObject.parseObject(message, AlertVo.class)); - alertDefectService.saveAlertDefect(list); - } - - /*** - * 根据返回信息自动诊断 - * @param message - */ - private void diagnosisByMsg(String message){ - JSONObject msg = JSONObject.parseObject(message); - if(Func.isEmpty(msg.getString("station")) || Func.isEmpty(msg.getString("realid"))){ - return; - } - /**根据station/realid进行诊断**/ - monitorClient.alertAutoDiagnosis(msg.getString("realid"),msg.getString("station")); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/WebSocketClientManager.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/WebSocketClientManager.java deleted file mode 100644 index 460cf4c..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/WebSocketClientManager.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.hnac.hzims.operational.alert; - -import lombok.extern.slf4j.Slf4j; -import org.java_websocket.client.WebSocketClient; -import org.springblade.core.tool.utils.Func; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.net.URI; - -/** - * @Author: py - */ -@Slf4j -@EnableScheduling -@Component -public class WebSocketClientManager { - @Value("${hzims.alert.ws-url}") - String wsUrl; - - WebSocketClient webSocketClient; - - /** - * 保活,每30秒发送一次信息 - */ - @Scheduled(cron="0 */1 * * * ? ") - private void keepAlive(){ - if(Func.isNotEmpty(webSocketClient) && webSocketClient.isOpen()){ - webSocketClient.send("{\"type\":\"soe\"}"); - log.info("[WebSocketClient] 发送保活信息"); - } else { - try { - webSocketClient = new AlertWebSocketClient(new URI(wsUrl)); - if(webSocketClient.connectBlocking()){ - webSocketClient.send("{\"type\":\"soe\"}"); - } - } catch (Exception e) { - log.error("[WebSocketClient] connectBlocking 错误={}",e.toString()); - } - } - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java deleted file mode 100644 index cd4979d..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.hnac.hzims.operational.alert.controller; - - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.common.logs.annotation.OperationAnnotation; -import com.hnac.hzims.common.logs.enums.BusinessType; -import com.hnac.hzims.common.logs.enums.OperatorType; -import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; -import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; -import com.hnac.hzims.operational.alert.vo.AlarmParamVo; -import com.hnac.hzims.operational.alert.vo.AlarmReustVo; -import com.hnac.hzims.operational.alert.vo.HistoryAlarmVo; -import com.hnac.hzims.operational.config.vo.AlarmDataPageVo; -import com.hnac.hzims.operational.config.vo.AlarmVo; -import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; -import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import lombok.AllArgsConstructor; -import org.springblade.core.boot.ctrl.BladeController; -import org.springblade.core.log.annotation.ApiLog; -import org.springblade.core.mp.support.Condition; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.Func; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; - -/** - * @author ysj - */ -@Api(tags = {"通讯中断、数据异常"}) -@RestController -@AllArgsConstructor -@RequestMapping("/abnormal/alarm") -public class AbnormalAlarmController extends BladeController { - - - private final HistoryAbnormalAlarmService service; - /** - * 统计通讯中断时间 - */ - @ApiLog - @RequestMapping(value = "/statisticsTime", method = {RequestMethod.GET, RequestMethod.POST}) - @ApiOperationSupport(order = 1) - @ApiOperation(value = "统计通讯中断时间", notes = "传入imsDutyMainEntity") - @OperationAnnotation(moduleName = "通讯告警统计",title = "通讯告警统计", operatorType = OperatorType.MOBILE, - businessType = BusinessType.GENCODE,action = "查询通讯告警统计数据") - public R> statisticsTime(HistoryAlarmVo entity, Query query) { - IPage pages = service.getAlarmTime(query,entity); - return R.data(pages); - } - - /** - * 统计通讯中断二级目录查询 - */ - @ApiLog - @RequestMapping(value = "/queryByEntity", method = {RequestMethod.GET, RequestMethod.POST}) - @ApiOperationSupport(order = 1) - @ApiOperation(value = "统计通讯中断二级目录查询", notes = "传入imsDutyMainEntity") - public R> queryByEntity(HistoryAlarmVo entity, Query query) { - IPage pages = service.queryByEntity(entity,query); - return R.data(pages); - } - - @ApiLog - @GetMapping("/queryStationName") - @ApiOperationSupport(order = 2) - @ApiOperation(value = "查询站点") - public R> queryStationName() { - List res = service.queryStationName(); - return R.data(res); - } - /** - * 详情 - */ - @ApiLog - @RequestMapping(value = "/detail", method = {RequestMethod.GET, RequestMethod.POST}) - @ApiOperationSupport(order = 3) - @ApiOperation(value = "详情", notes = "传入HistoryAbnormalAlarmEntity") - public R detail(HistoryAbnormalAlarmEntity entity) { - HistoryAbnormalAlarmEntity detail = service.getOne(Condition.getQueryWrapper(entity)); - return R.data(detail); - } - - /** - * 分页 - */ - @ApiLog - @GetMapping("/list") - @ApiOperationSupport(order = 4) - @ApiOperation(value = "分页", notes = "传入HistoryAbnormalAlarmEntity") - public R> list(HistoryAbnormalAlarmEntity entity, Query query) { - IPage pages = service.page(Condition.getPage(query), Condition.getQueryWrapper(entity)); - return R.data(pages); - } - - /** - * 新增或修改 - */ - @PostMapping("/submit") - @ApiOperationSupport(order = 5) - @ApiOperation(value = "新增或修改", notes = "传入HistoryAbnormalAlarmEntity") - public R submit(@Valid @RequestBody HistoryAbnormalAlarmEntity entity) { - return R.status(service.saveOrUpdate(entity)); - } - - - /** - * 删除 - */ - @PostMapping("/remove") - @ApiOperationSupport(order = 6) - @ApiOperation(value = "逻辑删除", notes = "传入ids") - public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { - return R.status(service.deleteLogic(Func.toLongList(ids))); - } - - /** - * - */ - @ApiLog - @ApiOperation(value = "原始告警接口") - @ApiOperationSupport(order = 7) - @RequestMapping(value = "/alarms", method = {RequestMethod.GET, RequestMethod.POST}) - public R alarms(AlarmParamVo param){ - return R.data(service.alarms(param)); - } - - /** - * 智能告警数量: 时间范围当天 - */ - @ApiLog - @ApiOperation(value = "智能告警数量") - @ApiOperationSupport(order = 8) - @RequestMapping(value = "/count", method = {RequestMethod.GET, RequestMethod.POST}) - public R> count(){ - return R.data(service.alarmCount()); - } - - - /** - * 智能告警数据: 时间范围当天 - */ - @ApiLog - @ApiOperation(value = "智能告警数据") - @ApiOperationSupport(order = 9) - @RequestMapping(value = "/data", method = RequestMethod.GET) - public R> data(AlarmDataPageVo page,Query query) { - return R.data(service.alarmData(page,query)); - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AlarmHandleController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AlarmHandleController.java deleted file mode 100644 index 0a9cd85..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AlarmHandleController.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.hnac.hzims.operational.alert.controller; - - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.common.logs.annotation.OperationAnnotation; -import com.hnac.hzims.common.logs.enums.BusinessType; -import com.hnac.hzims.common.logs.enums.OperatorType; -import com.hnac.hzims.operational.alert.service.AlarmHandleService; -import com.hnac.hzims.operational.alert.vo.AlarmHandleVo; -import com.hnac.hzims.operational.alert.vo.HandleQueryVo; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.boot.ctrl.BladeController; -import org.springblade.core.log.annotation.ApiLog; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.system.user.entity.User; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * @author ysj - * @date 2023/03/09 09:19:13 - * @version 4.0.0 - */ -@Api(tags = {"告警处理"}) -@RestController -@AllArgsConstructor -@RequestMapping("/alarm/handle") -public class AlarmHandleController extends BladeController { - - private final AlarmHandleService service; - - - /** - * 告警处理:处理、延后、误报 - */ - @PostMapping("/execute") - @ApiOperationSupport(order = 1) - @ApiOperation(value = "告警处理", notes = "传入AlarmHandleEntity") - public R execute(@RequestBody AlarmHandleVo param) { - return R.status(service.execute(param)); - } - - /** - * 分页 - */ - @ApiLog - @GetMapping("/list") - @ApiOperationSupport(order = 2) - @ApiOperation(value = "分页", notes = "传入AlarmHandleEntity") - @OperationAnnotation(moduleName = "告警配置", title = "告警配置记录", operatorType = OperatorType.MOBILE, businessType = - BusinessType.GENCODE, - action = "分页") - public R> list(HandleQueryVo param, Query query) { - IPage pages = service.pageCondition(query, param); - return R.data(pages); - } - - /** - * 告警处理用户查询 - */ - @ApiLog - @GetMapping("/handleUser") - @ApiOperationSupport(order = 3) - @ApiOperation(value = "告警通知人", notes = "告警通知人") - public R> handleUser() { - return R.data(service.handleUser()); - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/LevelAlarmController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/LevelAlarmController.java deleted file mode 100644 index 2adf429..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/LevelAlarmController.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.hnac.hzims.operational.alert.controller; - - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; -import com.hnac.hzims.operational.alert.service.HistoryLevelAlarmService; -import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import lombok.AllArgsConstructor; -import org.springblade.core.boot.ctrl.BladeController; -import org.springblade.core.log.annotation.ApiLog; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.Func; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * @author ysj - */ -@Api(tags = {"等级告警"}) -@RestController -@AllArgsConstructor -@RequestMapping("/level/alarm") -public class LevelAlarmController extends BladeController { - - private HistoryLevelAlarmService service; - - /** - * 分页 - */ - @ApiLog - @GetMapping("/list") - @ApiOperationSupport(order = 1) - @ApiOperation(value = "分页", notes = "传入HistoryAbnormalAlarmEntity") - public R> list(HistoryLevelAlarmEntity entity, Query query) { - IPage pages = service.pageCondition(query, entity); - return R.data(pages); - } - - - /** - * 删除 - */ - @PostMapping("/remove") - @ApiOperationSupport(order = 2) - @ApiOperation(value = "逻辑删除", notes = "传入ids") - public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { - return R.status(service.deleteLogic(Func.toLongList(ids))); - } - - /** - * 智能告警数量: 时间范围当天 - */ - @ApiLog - @ApiOperation(value = "智能告警数量") - @ApiOperationSupport(order = 3) - @RequestMapping(value = "/count", method = {RequestMethod.GET, RequestMethod.POST}) - public R> count(){ - return R.data(service.alarmCount()); - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.java deleted file mode 100644 index 34f6317..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hnac.hzims.operational.alert.mapper; - -import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; -import org.apache.ibatis.annotations.Param; -import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; - -import java.util.List; - -/** - * @author YSJ - */ -public interface AbnormalAlarmMapper extends UserDataScopeBaseMapper { - - AbnormalAlarmEntity getAbnormalAlarm(@Param("stationId") String stationId,@Param("type") String type); - - List getAbnormalAlarmList(); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.xml deleted file mode 100644 index 034ec61..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.java deleted file mode 100644 index b87f290..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.operational.alert.mapper; - -import com.hnac.hzims.operational.alert.entity.AlarmHandleDetailEntity; -import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; - -/** - * @author ysj - * @date 2023/03/09 09:19:13 - * @version 4.0.0 - */ -public interface AlarmHandleDetailMapper extends UserDataScopeBaseMapper { - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.xml deleted file mode 100644 index c4664e9..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.java deleted file mode 100644 index c989ecc..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.hnac.hzims.operational.alert.mapper; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import com.hnac.hzims.operational.alert.vo.AlarmHandleVo; -import com.hnac.hzims.operational.alert.vo.HandleQueryVo; -import org.apache.ibatis.annotations.Param; -import org.springblade.core.datascope.annotation.UserDataAuth; -import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; - -import java.util.List; - -/** - * @author ysj - * @date 2023/03/09 09:19:13 - * @version 4.0.0 - */ -public interface AlarmHandleMapper extends UserDataScopeBaseMapper { - - @UserDataAuth - IPage selectHandlePage(IPage page,@Param("param") HandleQueryVo param); - - List handles(@Param("types") List types,@Param("start") String start,@Param("end") String end); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.xml deleted file mode 100644 index 18304a2..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.java deleted file mode 100644 index b78d7ed..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.operational.alert.mapper; - -import com.hnac.hzims.operational.alert.entity.AlertDefectConfigEntity; - -import java.util.List; - -/** - * @author YSJ - */ -public interface AlertDefectConfigMapper { - - List getConfigAll(); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.xml deleted file mode 100644 index 3b1071a..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java deleted file mode 100644 index fc81187..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hnac.hzims.operational.alert.mapper; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; -import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; -import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; -import com.hnac.hzims.spare.vo.SpReceiveVO; -import org.apache.ibatis.annotations.Param; -import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; - -import java.util.Date; -import java.util.List; - -/** - * @author YSJ - */ -public interface HistoryAbnormalAlarmMapper extends UserDataScopeBaseMapper { - - List getHistoryAbnormalAlarm(@Param("stationId") String stationId,@Param("type") String type); - - List selectPageList(IPage page, String type, List stations); - - List getAlarmEntity(@Param("type") String type,@Param("stationName") List stationName,@Param("startTime") Date startTime,@Param("endTime") Date endTime); - - List getStationName(); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml deleted file mode 100644 index 366645a..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.java deleted file mode 100644 index 9eb6c3b..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hnac.hzims.operational.alert.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; - -/** - * @author YSJ - */ -public interface HistoryLevelAlarmMapper extends BaseMapper { - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.xml deleted file mode 100644 index 40e7037..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AbnormalAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AbnormalAlarmService.java deleted file mode 100644 index b75d835..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AbnormalAlarmService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * 告警处理接口 - * @author ysj - */ -public interface AbnormalAlarmService extends BaseService { - - void alarmDataHandle(String param); - - List getAbnormalAlarmList(); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleDetailService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleDetailService.java deleted file mode 100644 index d14dcf0..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleDetailService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -import com.hnac.hzims.operational.alert.entity.AlarmHandleDetailEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - * @date 2023/03/09 09:19:13 - * @version 4.0.0 - */ -public interface AlarmHandleDetailService extends BaseService { - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleService.java deleted file mode 100644 index ce66494..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import com.hnac.hzims.operational.alert.vo.AlarmHandleVo; -import com.hnac.hzims.operational.alert.vo.HandleQueryVo; -import org.springblade.core.mp.base.BaseService; -import org.springblade.core.mp.support.Query; -import org.springblade.system.user.entity.User; - -import java.util.List; - -/** - * @author ysj - * @date 2023/03/09 09:19:13 - * @version 4.0.0 - */ -public interface AlarmHandleService extends BaseService { - - boolean execute(AlarmHandleVo param); - - IPage pageCondition(Query query, HandleQueryVo param); - - List handleUser(); - - List handles(List types,Integer alarmType); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java deleted file mode 100644 index 4cb0260..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -import com.hnac.hzims.operational.config.vo.MessageParamVo; -import org.springframework.web.socket.TextMessage; - -/** - * @author ysj - * @date 2023/03/09 09:19:13 - * @version 4.0.0 - */ -public interface AlarmMergeService { - - // 获取发送消息 - TextMessage getSendMessage(MessageParamVo param); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlertDefectService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlertDefectService.java deleted file mode 100644 index ae3c966..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlertDefectService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -import com.hnac.hzims.operational.alert.vo.AlertVo; - -import java.util.List; - -/** - * 告警缺陷处理接口 - */ -public interface AlertDefectService { - - void saveAlertDefect(List list); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java deleted file mode 100644 index ca936c6..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; -import com.hnac.hzims.operational.alert.vo.AlarmParamVo; -import com.hnac.hzims.operational.alert.vo.AlarmReustVo; -import com.hnac.hzims.operational.alert.vo.HistoryAlarmVo; -import com.hnac.hzims.operational.config.vo.AlarmDataPageVo; -import com.hnac.hzims.operational.config.vo.AlarmVo; -import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; -import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; -import org.springblade.core.mp.base.BaseService; -import org.springblade.core.mp.support.Query; - -import java.util.List; - -/** - * 告警处理接口 - * @author ysj - */ -public interface HistoryAbnormalAlarmService extends BaseService { - - HistoryAbnormalAlarmEntity getAbnormalAlarm(String station, String soeType); - - IPage list(IPage page, String type); - - IPage getAlarmTime(Query query, HistoryAlarmVo entity); - - IPage queryByEntity(HistoryAlarmVo entity,Query query); - - AlarmReustVo alarms(AlarmParamVo param); - - // 智能告警数量: 时间范围当天 - List alarmCount(); - - // 告警数据:时间范围-当天 - IPage alarmData(AlarmDataPageVo page,Query query); - - List queryStationName(); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryLevelAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryLevelAlarmService.java deleted file mode 100644 index c0cffea..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryLevelAlarmService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; -import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; -import org.springblade.core.mp.base.BaseService; -import org.springblade.core.mp.support.Query; - -import java.util.List; - -/** - * 等级告警数据查询 - * @author ysj - */ -public interface HistoryLevelAlarmService extends BaseService { - - - IPage pageCondition(Query query, HistoryLevelAlarmEntity entity); - - List alarmCount(); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java deleted file mode 100644 index 885ab64..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.operational.alert.service; - -/** - * 告警处理接口 - * @author ysj - */ -public interface LevelAlarmService { - - String sendMessage(); - - void receiveMessage(String message); -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java deleted file mode 100644 index c4067ea..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.message.MessageConstants; -import com.hnac.hzims.message.dto.BusinessMessageDTO; -import com.hnac.hzims.message.fegin.IMessageClient; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; -import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; -import com.hnac.hzims.operational.alert.mapper.AbnormalAlarmMapper; -import com.hnac.hzims.operational.alert.service.AbnormalAlarmService; -import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.service.IStationService; -import com.hnac.hzinfo.datasearch.soe.ISoeClient; -import com.hnac.hzinfo.datasearch.soe.domian.SoeData; -import com.hnac.hzinfo.datasearch.soe.domian.SoeQueryConditionByStation; -import com.hnac.hzinfo.sdk.core.response.HzPage; -import com.hnac.hzinfo.sdk.core.response.Result; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springblade.system.entity.Dept; -import org.springblade.system.feign.ISysClient; -import org.springblade.system.user.entity.User; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.stereotype.Service; - -import java.time.LocalDateTime; -import java.util.*; -import java.util.stream.Collectors; - -/** - * 告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class AbnormalAlarmServiceImpl extends BaseServiceImpl implements AbnormalAlarmService { - - private final IStationService stationService; - - private final HistoryAbnormalAlarmService historyAbnormalAlarmService; - - private final ISysClient sysClient; - - private final ISoeClient soeClient; - - private final IUserClient userClient; - - private final IMessageClient messageClient; - - /** - * 故障、中断,异常告警数据处理 - * @param param - */ - @Override - public void alarmDataHandle(String param) { - // 查询站点站点 - List stations = stationService.list(); - if(CollectionUtil.isEmpty(stations)){ - return; - } - // 查询告警数据: 间隔3分钟 - SoeQueryConditionByStation query = new SoeQueryConditionByStation(); - query.setTypes(AbnormalAlarmConstant.SEND_MESSSAGE_TYPE_LIST); - query.setStationIds(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - Calendar calendar = Calendar.getInstance(); - query.setEndTime(LocalDateTime.parse(DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER)); - calendar.add(Calendar.MINUTE,-10); - query.setBeginTime(LocalDateTime.parse(DateUtil.format(calendar.getTime() , DateUtil.PATTERN_DATETIME),DateUtil.DATETIME_FORMATTER)); - query.setNeedPage(false); - query.setPage(1); - query.setLimit(100000); - Result> result = soeClient.getByStationsAndTime(query); - // 未查询到告警信息 - if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())) { - return; - } - List soes = result.getData().getRecords(); - // 过滤已经当天存储得告警数据 - List history = historyAbnormalAlarmService.list(Wrappers.lambdaQuery() - .in(HistoryAbnormalAlarmEntity::getAlarmId,soes.stream().map(SoeData::getId).collect(Collectors.toList())) - .ge(HistoryAbnormalAlarmEntity::getStartTime,DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00") - ); - if(CollectionUtil.isNotEmpty(history)){ - soes = result.getData().getRecords().stream().filter(soe-> !history.stream().map(HistoryAbnormalAlarmEntity::getAlarmId).collect(Collectors.toList()).contains(soe.getId())).collect(Collectors.toList()); - } - if(CollectionUtil.isEmpty(soes)){ - return; - } - - // 遍历告警信息 - soes.forEach(item -> { - if(!AbnormalAlarmConstant.INTERRUPT_LIST.contains(item.getSoeType())){ - return; - } - this.interrupt(stations,item); - }); - - // 历史数据处理 - this.saveHistoryAlarm(stations,soes); - } - - - /** - * 中断、异常数据处理 - * @param stations - * @param item - */ - private void interrupt(List stations,SoeData item) { - // 查询中断数据 - AbnormalAlarmEntity queryEntity = this.baseMapper.getAbnormalAlarm(item.getStation(),item.getSoeType()); - // 是否为中断恢复 - boolean flag = AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType()); - // 站点名称 - String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); - // 不存在记录进行保存 - if(ObjectUtil.isEmpty(queryEntity)){ - AbnormalAlarmEntity entity = new AbnormalAlarmEntity(); - entity.setStationId(item.getStation()); - entity.setStationName(stationName); - entity.setRealId(item.getRealId()); - entity.setSoeExplain(item.getSoeExplain()); - entity.setType(item.getSoeType()); - entity.setStartTime(item.getTs()); - entity.setEndTime(null); - entity.setStatus(0); - if(flag){ - entity.setStartTime(null); - entity.setEndTime(item.getTs()); - entity.setStatus(1); - } - // 保存告警信息 - this.save(entity); - // 存在记录进行修改 - }else{ - queryEntity.setSoeExplain(item.getSoeExplain()); - queryEntity.setStartTime(queryEntity.getStartTime()); - queryEntity.setUpdateTime(new Date()); - queryEntity.setEndTime(null); - queryEntity.setStatus(0); - if(flag){ - queryEntity.setEndTime(item.getTs()); - queryEntity.setStatus(1); - } - this.updateById(queryEntity); - } - } - - /** - * 历史数据处理 - * - * @param stations - * @param list - */ - private void saveHistoryAlarm(List stations, List list) { - List historys = historyAbnormalAlarmService.list(Wrappers.lambdaQuery() - .in(HistoryAbnormalAlarmEntity::getAlarmId,list.stream().map(SoeData::getId).collect(Collectors.toList())) - ); - List explains = new ArrayList<>(); - for(SoeData item: list){ - if(CollectionUtil.isNotEmpty(historys) && historys.stream().map(HistoryAbnormalAlarmEntity::getAlarmId).collect(Collectors.toList()).contains(item.getId())){ - return; - } - HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity(); - String stationName = Optional.ofNullable(stations.stream().filter(o-> o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); - entity.setAlarmId(item.getId()); - entity.setStationId(item.getStation()); - entity.setStationName(stationName); - entity.setRealId(item.getRealId()); - entity.setType(item.getSoeType()); - entity.setStartTime(item.getTs()); - entity.setSoeExplain(item.getSoeExplain()); - if(AbnormalAlarmConstant.ABNORMAL_STATUS.equals(item.getSoeAlarmType())){ - entity.setStatus(1); - }else{ - entity.setStatus(0); - } - this.historyAbnormalAlarmService.save(entity); - if(explains.contains(entity.getSoeExplain())){ - continue; - }else{ - // 相同告警只允许添加一次,发送一次消息 - explains.add(item.getSoeExplain()); - } - // 发送消息 - this.sendAlarmMessage(entity,stations,stationName); - // 推送短信: 只推送拥有项目经理角色用户 - }; - } - - /** - * 告警消息推送 - * @param entity - */ - private void sendAlarmMessage(HistoryAbnormalAlarmEntity entity,List stations,String stationName) { - if(StringUtil.isEmpty(entity.getStationId())){ - return; - } - List depts = stations.stream().filter(station -> station.getCode().equals(entity.getStationId())).map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(depts)){ - return; - } - List users = this.parentAuthUser(depts.get(0)); - if(CollectionUtil.isEmpty(users)){ - log.error("alarmmessagestation {} user is null",entity.getStationId()); - return; - } - BusinessMessageDTO message = new BusinessMessageDTO(); - message.setDeptId(depts.get(0)); - message.setBusinessClassify("warning"); - message.setUserIds(users.stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); - message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); - message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription() + "-[" + stationName + "]"); - message.setTaskId(entity.getId()); - message.setTenantId("200000"); - message.setContent(entity.getSoeExplain()); - R deptName = sysClient.getDeptName(depts.get(0)); - if (deptName.isSuccess()) { - message.setDeptName(deptName.getData()); - } - User admin = userClient.userByAccount("200000", "admin").getData(); - message.setCreateUser(admin.getId()); - messageClient.sendAppAndWsMsgByUsers(message); - } - - /** - * 获取本级机构或者上级机构用户 - * @param deptId - * @return - */ - private List parentAuthUser(Long deptId) { - List users = new ArrayList<>(); - R> selfs = userClient.userListByDeptId(deptId); - if(selfs.isSuccess() && CollectionUtil.isNotEmpty(selfs.getData())){ - users.addAll(selfs.getData()); - } - R dept = sysClient.getDept(deptId); - if(dept.isSuccess() && ObjectUtil.isNotEmpty(dept.getData())){ - R> parents = userClient.userByDeptId("200000",dept.getData().getParentId()); - if(parents.isSuccess() && CollectionUtil.isNotEmpty(parents.getData())){ - users.addAll(parents.getData()); - } - } - return users; - } - - /** - * 查询实时告警数据 - * @return - */ - @Override - public List getAbnormalAlarmList() { - List alarmList = this.baseMapper.getAbnormalAlarmList(); - if(CollectionUtil.isEmpty(alarmList)){ - return new ArrayList<>(); - } - return alarmList; - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleDetailServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleDetailServiceImpl.java deleted file mode 100644 index d40abac..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleDetailServiceImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.hnac.hzims.operational.alert.entity.AlarmHandleDetailEntity; -import com.hnac.hzims.operational.alert.mapper.AlarmHandleDetailMapper; -import com.hnac.hzims.operational.alert.service.AlarmHandleDetailService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author ysj - * @date 2023/03/09 09:29:34 - * @version 4.0.0 - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class AlarmHandleDetailServiceImpl extends BaseServiceImpl implements AlarmHandleDetailService { - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleServiceImpl.java deleted file mode 100644 index 9daebb3..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleServiceImpl.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.fdp.feign.IFdpMonitorClient; -import com.hnac.hzims.fdp.vo.UpdateFaultStateVo; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -import com.hnac.hzims.operational.alert.entity.AlarmHandleDetailEntity; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import com.hnac.hzims.operational.alert.mapper.AlarmHandleMapper; -import com.hnac.hzims.operational.alert.service.AlarmHandleDetailService; -import com.hnac.hzims.operational.alert.service.AlarmHandleService; -import com.hnac.hzims.operational.alert.vo.AlarmHandleVo; -import com.hnac.hzims.operational.alert.vo.HandleQueryVo; -import com.hnac.hzims.operational.alert.wrapper.HandleWrapper; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.mp.support.Condition; -import org.springblade.core.mp.support.Query; -import org.springblade.core.secure.utils.AuthUtil; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.system.entity.Dept; -import org.springblade.system.feign.ISysClient; -import org.springblade.system.user.entity.User; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - * @version 4.0.0 - * @date 2023/03/09 09:29:34 - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class AlarmHandleServiceImpl extends BaseServiceImpl implements AlarmHandleService { - - private final AlarmHandleDetailService detailService; - - private final ISysClient sysClient; - - private final IUserClient userClient; - - private final IFdpMonitorClient fdpMonitorClient; - - /** - * 告警处理 - * - * @param param - * @return - */ - @Override - public boolean execute(AlarmHandleVo param) { - Long way = param.getHandleWay(); - if (!AbnormalAlarmConstant.HANDLE_WAY.contains(way)) { - throw new ServiceException("无效处理!"); - } - // 预警 - if(AbnormalAlarmConstant.EARLY_WARNING.equals(param.getAlarmType())){ - this.updateFalultState(param); - } - // 详情 - AlarmHandleDetailEntity detail = new AlarmHandleDetailEntity(); - detail.setAccessId(param.getAccessId()); - detail.setPhenomenonId(param.getPhenomenonId()); - detail.setHandleUser(param.getHandleUser()); - detail.setDelayTime(param.getDelayTime()); - detail.setDelayCause(param.getDelayCause()); - detail.setFalseAlarmDesc(param.getFalseAlarmDesc()); - detail.setFilePath(param.getFilePath()); - detailService.save(detail); - // 处理记录 - AlarmHandleEntity entity = new AlarmHandleEntity(); - entity.setAlarmId(param.getAlarmId()); - entity.setType(param.getType()); - entity.setDetailId(detail.getId()); - entity.setAlarmTime(param.getAlarmTime()); - entity.setAlarmContent(param.getAlarmContent()); - entity.setHandleWay(param.getHandleWay()); - entity.setStationCode(param.getStationCode()); - entity.setAlarmType(param.getAlarmType()); - return this.save(entity); - } - - /** - * 预警处理推送智能诊断服务 - * @param param - */ - private void updateFalultState(AlarmHandleVo param) { - try{ - UpdateFaultStateVo state = new UpdateFaultStateVo(); - state.setStationId(param.getStationCode()); - state.setFaultId(param.getAlarmId()); - if(AbnormalAlarmConstant.HANDLE.contains(param.getHandleWay())){ - state.setConfidence(1f); - }else{ - state.setConfidence(0f); - } - state.setCreateTime(DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME)); - state.setCreateUser(String.valueOf(AuthUtil.getUserId())); - state.setLifeTime(1); - state.setPriority(1); - state.setInfo(param.getFalseAlarmDesc()); - String result = fdpMonitorClient.updateFaultState(state); - }catch (Exception exception){ - log.error("update_falult_state: {}",exception.getMessage()); - } - } - - /** - * 分页 - * @param query - * @param param - * @return - */ - @Override - public IPage pageCondition(Query query, HandleQueryVo param) { - IPage pages = this.baseMapper.selectHandlePage(Condition.getPage(query), param); - List list = HandleWrapper.build().listVO(pages.getRecords()); - return pages.setRecords(list); - } - - /** - * 告警处理人 - * @return - */ - @Override - public List handleUser() { - R> result = sysClient.getDeptByCurrentUser(); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - throw new ServiceException("查询告警处理人失败!"); - } - List users = new ArrayList<>(); - result.getData().forEach(dept->{ - users.addAll(userClient.userListByDeptAndChildrenWithAuth(dept.getId()).getData()); - }); - return users.stream().distinct().collect(Collectors.toList()); - } - - /** - * 查询处理告警记录 - * @param types 告警类型 - * @return - */ - @Override - public List handles(List types,Integer isEarly) { - if(AbnormalAlarmConstant.INTELLIGENCE_ALARM.equals(isEarly)){ - String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); - return this.baseMapper.handles(types,null,end); - } - String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; - String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); - return this.baseMapper.handles(types,start,end); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java deleted file mode 100644 index bff16bb..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.operational.alert.constants.AlertDefectConfigConstant; -import com.hnac.hzims.operational.alert.entity.AlertDefectConfigEntity; -import com.hnac.hzims.operational.alert.mapper.AlertDefectConfigMapper; -import com.hnac.hzims.operational.alert.service.AlertDefectService; -import com.hnac.hzims.operational.alert.vo.AlertVo; -import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; -import com.hnac.hzims.operational.defect.service.IDefectCheckService; -import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; -import com.hnac.hzims.operational.station.service.IStationService; -import com.hnac.hzims.operational.station.vo.StationVO; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.springblade.core.tool.utils.*; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 告警缺陷处理实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class AlertDefectServiceImpl implements AlertDefectService { - - private final AlertDefectConfigMapper defectConfigMapper; - - private final IDefectCheckService defectCheckService; - - private final IStationService stationService; - - private final IMainSystemMonitoringService mainSystemMonitoringService; - - - @Value("${hzims.operation.alert.saveDefectIsOpen}") - public Boolean isOpen; - - /** - * 保存告警缺陷 - * @param list - */ - @Override - public void saveAlertDefect(List list) { - if(!isOpen){ - return; - } - // 查询保存告警类型配置 - List configAll = this.defectConfigMapper.getConfigAll(); - if(CollectionUtil.isEmpty(configAll)){ - return; - } - List saveAlertType = configAll.stream().filter(o->o.getIsOpen().equals(1)).map(AlertDefectConfigEntity::getAlertType).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(saveAlertType)){ - return; - } - // 所有设备信息 - List devices = mainSystemMonitoringService.getEmInfoList(); - DateTimeFormatter format = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME_MINI); - list.forEach(alert->{ - // 不在配置告警保存类型内 - if(!saveAlertType.contains(Integer.valueOf(alert.getSoeType()))){ - return; - } - // TODO 近约大概时长不进行重复记录现象 - //this.defectCheckService.get - - // 组装现象对象 - OperPhenomenonEntity phenomenon = new OperPhenomenonEntity(); - phenomenon.setSourceCode(AlertDefectConfigConstant.ALERT_SOURCE_CODE); - phenomenon.setDefectCode(AlertDefectConfigConstant.ALERT_SOURCE_CODE + format.format(LocalDateTime.now()) + Func.random(3)); - phenomenon.setFaultName(alert.getRealid() + alert.getSoeAlarmType()); - phenomenon.setFindTime(new Date()); - phenomenon.setDescripiton(alert.getSoeExplain()); - phenomenon.setCreateTime(new Date()); - phenomenon.setInitResult("系统捕捉告警,分析因现场设备某个指标不在可控阀值内或设备出现故障"); - phenomenon.setFinder(1575044163023556610L); - phenomenon.setCreateDept(20000001L); - phenomenon.setCreateUser(1575044163023556610L); - phenomenon.setUpdateUser(1575044163023556610L); - phenomenon.setTypeCode("0"); - phenomenon.setDiscriminateStatus("0"); - phenomenon.setTenantId("200000"); - EminfoAndEmParamVo device = this.findDeviceByRealId(devices,alert.getRealid()); - if(ObjectUtil.isEmpty(device)){ - StationVO station = stationService.getStationByCode(alert.getStation()); - if(ObjectUtil.isEmpty(station)){ - phenomenon.setName(alert.getStation() + "-未知设备"); - }else{ - phenomenon.setName(station.getName() + "-站点设备"); - } - }else { - phenomenon.setEmCode(device.getEmCode()); - phenomenon.setName(device.getName()); - } - // 现象保存,缺陷流程开启 - defectCheckService.startCheck(phenomenon); - }); - } - - /** - * 根据realId查找设备 - * @param devices - * @param realid - * @return - */ - private EminfoAndEmParamVo findDeviceByRealId(List devices, String realid) { - if(CollectionUtil.isEmpty(devices) || StringUtil.isBlank(realid)){ - return null; - } - // 遍历设备监测点 - for(EminfoAndEmParamVo device : devices){ - Map map = device.getPoint(); - if(MapUtils.isEmpty(map)){ - continue; - } - if(map.containsKey(realid)){ - return device; - } - } - return null; - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java deleted file mode 100644 index ad687cb..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; -import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; -import com.hnac.hzims.operational.alert.service.*; -import com.hnac.hzims.operational.alert.vo.AlarmMergeVo; -import com.hnac.hzims.operational.config.vo.MessageParamVo; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.service.IStationService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springframework.stereotype.Service; -import org.springframework.web.socket.TextMessage; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * 告警合并处理实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class AlertMerageServiceImpl implements AlarmMergeService { - - private final IStationService stationService; - - private final AlarmHandleService alarmHandleService; - - private final HistoryAbnormalAlarmService faultAlarmService; - - private final HistoryLevelAlarmService levelAlarmService; - - /** - * 根据用户获取hz3000事故告警、平台一级告警、二级告警 - * @param param - * @return - */ - @Override - public TextMessage getSendMessage(MessageParamVo param) { - // 查询用户 - if(ObjectUtil.isEmpty(param)){ - return null; - } - List depts = param.getDeptIds(); - if(CollectionUtil.isEmpty(depts)){ - return null; - } - // 查询站点 - List stations = stationService.list(Wrappers.lambdaQuery() - .in(StationEntity::getRefDept,depts) - .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) - ); - if(CollectionUtil.isEmpty(stations)){ - return null; - } - String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; - String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 23:59:59"; - - // hz3000事故告警 - List faults = faultAlarmService.list(Wrappers.lambdaQuery() - .in(HistoryAbnormalAlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())) - .eq(HistoryAbnormalAlarmEntity::getType, AbnormalAlarmConstant.FAULT) - .between(HistoryAbnormalAlarmEntity::getStartTime,start,end) - ); - // 处理告警记录 - List handles = alarmHandleService.handles(AbnormalAlarmConstant.LONG_TYPE_LIST,null); - - List alarms = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(faults)){ - alarms.addAll(faults.stream().filter(o -> CollectionUtil.isEmpty(handles) - || !handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList()).contains(o.getAlarmId().toString())). - map(fault->{ - AlarmMergeVo alarm = new AlarmMergeVo(); - alarm.setStationCode(fault.getStationId()); - alarm.setStationName(fault.getStationName()); - alarm.setContent(fault.getSoeExplain()); - alarm.setDate(fault.getStartTime()); - alarm.setRealId(fault.getRealId()); - alarm.setAlarmCode(String.valueOf(fault.getAlarmId())); - alarm.setType(fault.getType()); - alarm.setAlarmType(AbnormalAlarmConstant.SYSTEM_ALARM); - return alarm; - }).collect(Collectors.toList())); - } - // 等级告警 - List levels = levelAlarmService.list(Wrappers.lambdaQuery() - .in(HistoryLevelAlarmEntity::getAlarmLevel,AbnormalAlarmConstant.LEVEL_LIST) - .in(HistoryLevelAlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())) - .in(HistoryLevelAlarmEntity::getType, AbnormalAlarmConstant.TYPE_LIST) - .between(HistoryLevelAlarmEntity::getCreateTime,start,end) - ); - if(CollectionUtil.isNotEmpty(levels)){ - alarms.addAll(levels.stream().filter(l -> CollectionUtil.isEmpty(handles) - || !handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList()).contains(l.getAlarmId())). - map(level->{ - AlarmMergeVo alarm = new AlarmMergeVo(); - alarm.setStationCode(level.getStationId()); - alarm.setStationName(level.getStationName()); - alarm.setContent(level.getSoeExplain()); - alarm.setDate(level.getAlarmTime()); - alarm.setRealId(level.getRealId()); - alarm.setLevel(level.getAlarmLevel()); - alarm.setAlarmCode(level.getAlarmId()); - alarm.setType(level.getType()); - alarm.setAlarmType(AbnormalAlarmConstant.INTELLIGENCE_ALARM); - return alarm; - }).collect(Collectors.toList())); - } - - return new TextMessage(JSONObject.toJSONString(alarms.stream().sorted(Comparator.comparing(AlarmMergeVo::getDate)).collect(Collectors.toList()))); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java deleted file mode 100644 index e02cfe7..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ /dev/null @@ -1,433 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; -import com.hnac.hzims.operational.alert.mapper.HistoryAbnormalAlarmMapper; -import com.hnac.hzims.operational.alert.service.AlarmHandleService; -import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; -import com.hnac.hzims.operational.alert.vo.*; -import com.hnac.hzims.operational.config.vo.AlarmDataPageVo; -import com.hnac.hzims.operational.config.vo.AlarmVo; -import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.service.IStationService; -import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; -import com.hnac.hzinfo.datasearch.soe.ISoeClient; -import com.hnac.hzinfo.datasearch.soe.domian.SoeData; -import com.hnac.hzinfo.datasearch.soe.domian.SoeQueryConditionByStation; -import com.hnac.hzinfo.sdk.core.response.HzPage; -import com.hnac.hzinfo.sdk.core.response.Result; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import net.logstash.logback.encoder.org.apache.commons.lang3.ObjectUtils; -import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.mp.support.Condition; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.system.entity.Dept; -import org.springblade.system.feign.ISysClient; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.lang.reflect.Field; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -/** - * 历史告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl implements HistoryAbnormalAlarmService { - - private final IStationService stationService; - - private final AlarmHandleService handleService; - - private final ISysClient sysClient; - - private final ISoeClient alarmClient; - - @Value("${hzims.operation.alarm.types}") - private String types; - - /** - * 查询单条历史告警 - * - * @param station - * @param soeType - * @return - */ - @Override - public HistoryAbnormalAlarmEntity getAbnormalAlarm(String station, String soeType) { - List alarms = this.baseMapper.getHistoryAbnormalAlarm(station, soeType); - if(CollectionUtil.isEmpty(alarms)){ - return null; - } - return alarms.stream().sorted(Comparator.comparing(HistoryAbnormalAlarmEntity::getStartTime)).collect(Collectors.toList()).get(0); - } - - /** - * 查询告警列表 - * @param page - * @param type - * @return - */ - @Override - public IPage list(IPage page, String type) { - List stations = stationService.getStationByType(HomePageConstant.HYDROPOWER, HomePageConstant.HYDROPOWER_SERVETYPE); - if (CollectionUtil.isEmpty(stations)) { - return null; - } - List result = this.baseMapper.selectPageList(page, type, stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - page.setRecords(result); - return page; - } - - /** - * 统计告警时长 - * @param query - * @param entity - * @return - */ - @Override - public IPage getAlarmTime(Query query, HistoryAlarmVo entity) { - QueryWrapper alarmEntityQueryWrapper = getAlarmEntityQueryWrapper(entity); - List historyAbnormalAlarmEntity = this.baseMapper.selectList(alarmEntityQueryWrapper); - if (historyAbnormalAlarmEntity == null) { - return null; - } - List historyAbnormalAlarmVos = BeanUtil.copy(historyAbnormalAlarmEntity, HistoryAbnormalAlarmVo.class); - //赋值空的endTime - if (ObjectUtils.isNotEmpty(entity.getEndTime())) { - historyAbnormalAlarmVos.stream().filter(s -> s.getEndTime() == null).forEach(s -> s.setEndTime(entity.getEndTime())); - } else { - historyAbnormalAlarmVos.stream().filter(s -> s.getEndTime() == null).forEach(s -> s.setEndTime(new Date())); - } - List voList = historyAbnormalAlarmVos.parallelStream().peek(s -> s.setTimes((s.getEndTime().getTime() - s.getStartTime().getTime()))).collect(Collectors.toList()); - //次数统计 - Map timesList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName, - Collectors.counting())); - //时间统计 - Map durationList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName, - Collectors.summingLong(HistoryAbnormalAlarmVo::getTimes))); - List res = new ArrayList<>(); - for (Map.Entry entry : durationList.entrySet()) { - //累计时长 - double v = BigDecimal.valueOf(entry.getValue() / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - HistoryAbnormalAlarmVo historyAbnormalAlarmVo = new HistoryAbnormalAlarmVo(); - historyAbnormalAlarmVo.setDuration(v); - String key = entry.getKey(); - historyAbnormalAlarmVo.setStationName(key); - historyAbnormalAlarmVo.setTimes(timesList.get(key)); - if (CollectionUtil.isNotEmpty(entity.getType())) { - //只有告警类型唯一,前端才根据这个字段进行渲染 - if (entity.getType().size()==1) { - historyAbnormalAlarmVo.setType(entity.getType().get(0)); - } - } - res.add(historyAbnormalAlarmVo); - } - //根据电站名字排序 - res = res.stream(). - sorted(Comparator.comparing(HistoryAbnormalAlarmVo::getStationName)) - .collect(Collectors.toList()); - IPage page = Condition.getPage(query); - page.setTotal(res.size()); - if (entityIsNull(query)) { - page.setRecords(res); - } else { - if (res.size() > query.getCurrent() * query.getSize()) { - page.setRecords(res.subList((query.getCurrent() - 1) * query.getSize(), query.getCurrent() * query.getSize())); - } else { - page.setRecords(res.subList((query.getCurrent() - 1) * query.getSize(), res.size())); - } - } - return page; - } - - - private QueryWrapper getAlarmEntityQueryWrapper(HistoryAlarmVo entity) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - if (entity.getStationName() != null) { - String[] list = entity.getStationName().split(","); - queryWrapper.lambda().in(HistoryAbnormalAlarmEntity::getStationName, Arrays.stream(list).collect(Collectors.toList())); - } - if (entity.getType() != null) { - queryWrapper.lambda().in(HistoryAbnormalAlarmEntity::getType, entity.getType()); - } - if (entity.getStartTime() != null) { - queryWrapper.lambda().ge(HistoryAbnormalAlarmEntity::getStartTime, entity.getStartTime()); - } - if (entity.getEndTime() != null) { - queryWrapper.lambda().le(HistoryAbnormalAlarmEntity::getStartTime, entity.getEndTime()); - } - return queryWrapper; - } - - @Override - public IPage queryByEntity(HistoryAlarmVo entity, Query query) { - QueryWrapper alarmEntityQueryWrapper = getAlarmEntityQueryWrapper(entity); - IPage historyAbnormalAlarmEntityIPage = this.baseMapper.selectPage(Condition.getPage(query), alarmEntityQueryWrapper); - List records = historyAbnormalAlarmEntityIPage.getRecords(); - List voList =new ArrayList<>(); - if (records.size()>0) { - List historyAbnormalAlarmVos = BeanUtil.copy(records, HistoryAbnormalAlarmVo.class); - //赋值空的endTime - if (ObjectUtils.isNotEmpty(entity.getEndTime())) { - historyAbnormalAlarmVos.stream().filter(s -> s.getEndTime() == null).forEach(s -> s.setEndTime(entity.getEndTime())); - } else { - historyAbnormalAlarmVos.stream().filter(s -> s.getEndTime() == null).forEach(s -> s.setEndTime(new Date())); - } - voList= historyAbnormalAlarmVos.parallelStream().peek(s -> { - long duration = s.getEndTime().getTime() - s.getStartTime().getTime(); - double v = BigDecimal.valueOf(duration / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - s.setDuration(v); - }).collect(Collectors.toList()); - } - IPage page = Condition.getPage(query); - page.setTotal(historyAbnormalAlarmEntityIPage.getTotal()); - page.setRecords(voList); - return page; - } - - /** - * 告警优化 - * @param param - * @return - */ - @Override - public AlarmReustVo alarms(AlarmParamVo param) { - // 查询用户权限机构 - R> result = sysClient.getDeptByCurrentUser(); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return new AlarmReustVo(); - } - // 查询站点 - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); - wrapper.in(StationEntity::getRefDept,result.getData().stream().map(Dept::getId).collect(Collectors.toList())); - - List stations = stationService.list(wrapper); - if(CollectionUtil.isEmpty(stations)){ - return new AlarmReustVo(); - } - // 查询告警数据 - SoeQueryConditionByStation condition = new SoeQueryConditionByStation(); - condition.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00", DateUtil.DATETIME_FORMATTER)); - condition.setEndTime(LocalDateTime.now()); - condition.setNeedPage(true); - condition.setPage(param.getCurrent()); - condition.setLimit(param.getSize()); - condition.setStationIds(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - List types = Arrays.asList(param.getType().split(",")); - condition.setTypes(types); - Result> soe = alarmClient.getByStationsAndTime(condition); - if(!soe.isSuccess() || ObjectUtil.isEmpty(soe.getData()) || CollectionUtil.isEmpty(soe.getData().getRecords())){ - return new AlarmReustVo(); - } - - // 查询当天类型处理告警 - List handles = handleService.handles(types.stream().map(Long::parseLong).collect(Collectors.toList()),AbnormalAlarmConstant.SYSTEM_ALARM); - - // 返回数据 - AlarmReustVo response = new AlarmReustVo(); - List datas = soe.getData().getRecords().stream().map(alarm -> { - AlarmDataVo record = new AlarmDataVo(); - // 继承类属性拷贝 - BeanUtil.copyProperties(alarm, record); - if(CollectionUtil.isEmpty(handles)){ - record.setIsHandle(false); - }else{ - record.setIsHandle(handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList()).contains(String.valueOf(alarm.getId()))); - } - record.setStationCode(alarm.getStation()); - record.setContent(alarm.getSoeExplain()); - record.setType(alarm.getSoeType()); - record.setSoeType(AbnormalAlarmConstant.TYPE_NAMES[Integer.parseInt(alarm.getSoeType())]); - List filter = stations.stream().filter(station -> station.getCode().equals(alarm.getStation())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(filter)) { - return record; - } - record.setStationName(filter.get(0).getName()); - record.setServeType(filter.get(0).getServeType()); - record.setAlarmType(AbnormalAlarmConstant.SYSTEM_ALARM); - return record; - }).sorted(Comparator.comparing(AlarmDataVo::getIsHandle) - .thenComparing(AlarmDataVo::getTs, Comparator.reverseOrder())).collect(Collectors.toList()); - - response.setCount((int) (soe.getData().getTotal() - handles.size())); - response.setSoeList(datas); - response.setTotal(soe.getData().getTotal()); - return response; - } - - - - /** - * 获取处理数据ID集合 - * @return - */ - private List getAlarmHandleIds() { - List handles = handleService.list(); - if(CollectionUtil.isEmpty(handles)){ - return null; - } - return handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList()); - } - - /** - * 告警数量:时间范围-当天 - * @return - */ - @Override - public List alarmCount() { - // 查询用户权限机构 - R> result = sysClient.getDeptByCurrentUser(); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return new ArrayList<>(); - } - // 步骤1.查询用户权限站点 - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); - wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); - wrapper.in(StationEntity::getRefDept,result.getData().stream().map(Dept::getId).collect(Collectors.toList())); - - List stations = stationService.list(wrapper); - if(CollectionUtil.isEmpty(stations)){ - return new ArrayList<>(); - } - // 步骤2.查询告警数据 - SoeQueryConditionByStation condition = new SoeQueryConditionByStation(); - condition.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00", DateUtil.DATETIME_FORMATTER)); - condition.setEndTime(LocalDateTime.now()); - condition.setNeedPage(false); - condition.setStationIds(stations.stream().map(StationEntity::getCode).filter(StringUtils::isNotEmpty).collect(Collectors.toList())); - // nacos中配置告警类型:"0-默认", "1-系统", "2-告警", "3-故障", "4-用户操作", "5-遥测越限", "6-遥信变位", "7-注册信息", - // "8-信息提示", "9-设备巡检", "10-遥控操作", "11-遥测越限恢复","12-未定义","13-通讯中断","14-数据异常" - condition.setTypes(Arrays.asList(types.split(","))); - Result> soe = alarmClient.getByStationsAndTime(condition); - - // 步骤3. TODO 过滤已处理告警 - - // 步骤4.遍历获取 - return Arrays.stream(types.split(",")).map(type->{ - IntelligentAlarmCountVo count = new IntelligentAlarmCountVo(); - count.setType(type); - count.setName(AbnormalAlarmConstant.TYPE_NAMES[Integer.parseInt(type)]); - if(soe.isSuccess() && !ObjectUtil.isEmpty(soe.getData())){ - count.setCount(soe.getData().getRecords().stream().filter(record->type.equals(record.getSoeType())).count()); - }else { - count.setCount(0L); - } - return count; - }).collect(Collectors.toList()); - } - - /** - * 告警数据:时间范围-当天 - * @param param - * @param query - * @return - */ - @Override - public IPage alarmData(AlarmDataPageVo param,Query query) { - // 步骤1.查询用户权限站点 - LambdaQueryWrapper wappers = Wrappers.lambdaQuery(); - if(StringUtils.isNotEmpty(param.getCode())){ - wappers.eq(StationEntity::getCode,param.getCode()); - } - List stations = stationService.list(wappers); - - // 步骤2.查询告警数据 - List type_list; - if(Optional.ofNullable(param.getType()).isPresent()){ - type_list = Collections.singletonList(param.getType()); - }else { - type_list = Collections.singletonList(Arrays.asList(types.split(",")).get(0)); - } - SoeQueryConditionByStation condition = new SoeQueryConditionByStation(); - DateTimeFormatter format = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); - condition.setBeginTime(LocalDateTime.parse(/*DateUtil.format(new Date(), DateUtil.PATTERN_DATE) +*/ "2022-12-01 00:00:00", format)); - condition.setEndTime(LocalDateTime.parse(/*DateUtil.format(new Date(), DateUtil.PATTERN_DATE) +*/ "2022-12-28 00:00:00", format)); - condition.setNeedPage(false); - condition.setStationIds(stations.stream().map(StationEntity::getCode).filter(StringUtils::isNotEmpty).collect(Collectors.toList())); - // nacos中配置告警类型:"0-默认", "1-系统", "2-告警", "3-故障", "4-用户操作", "5-遥测越限", "6-遥信变位", "7-注册信息", - // "8-信息提示", "9-设备巡检", "10-遥控操作", "11-遥测越限恢复","12-未定义","13-通讯中断","14-数据异常" - condition.setTypes(type_list); - Result> result = alarmClient.getByStationsAndTime(condition); - IPage page = Condition.getPage(query); - if(result.isSuccess() && ObjectUtil.isNotEmpty(result)){ - // 步骤3.过滤完成告警处理数据 - List alarms = result.getData().getRecords().stream().map(record ->{ - AlarmVo alarm = new AlarmVo(); - alarm.setId(record.getId()); - alarm.setContent(record.getSoeExplain()); - alarm.setRealId(record.getRealId()); - alarm.setTs(record.getTs()); - alarm.setSoeStatus(record.getSoeStatus()); - alarm.setSoeType(AbnormalAlarmConstant.TYPE_NAMES[Integer.parseInt(record.getSoeType())]); - alarm.setOptionvals(record.getOptionvals()); - alarm.setSoeStatus(record.getSoeStatus()); - alarm.setStation(record.getStation()); - List names = stations.stream().filter(station -> station.getCode().equals(record.getStation())).map(StationEntity::getName).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(names)){ - alarm.setStationName(names.get(0)); - } - return alarm; - }).collect(Collectors.toList()); - - // 步骤4.分页 - page.setTotal(alarms.size()); - page.setRecords(alarms.stream().sorted(Comparator.comparing(AlarmVo::getTs,Comparator.reverseOrder())) - .skip(page.getSize() * (page.getCurrent() - 1)).limit(page.getSize()) - .collect(Collectors.toList())); - page.setPages((alarms.size() -1) / page.getSize() + 1); - }else{ - page.setTotal(0); - page.setPages(0); - } - return page; - } - - @Override - public List queryStationName() { - return this.baseMapper.getStationName(); - } - - - - private Boolean entityIsNull(Object object) { - if (null == object) { - return true; - } - try { - for (Field f : object.getClass().getDeclaredFields()) { - f.setAccessible(true); - if (f.get(object) != null && StringUtils.isNotBlank(f.get(object).toString())) { - return false; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return true; - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryLevelAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryLevelAlarmServiceImpl.java deleted file mode 100644 index 324b205..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryLevelAlarmServiceImpl.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; -import com.hnac.hzims.operational.alert.mapper.HistoryLevelAlarmMapper; -import com.hnac.hzims.operational.alert.service.AlarmHandleService; -import com.hnac.hzims.operational.alert.service.HistoryLevelAlarmService; -import com.hnac.hzims.operational.config.vo.IntelligentAlarmCountVo; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.service.IStationService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.mp.support.Condition; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springframework.stereotype.Service; - -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * 等级告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class HistoryLevelAlarmServiceImpl extends BaseServiceImpl implements HistoryLevelAlarmService { - - - private final IStationService stationService; - - private final AlarmHandleService handleService; - - /** - * 列表查询 - * @param query - * @param entity - * @return - */ - @Override - public IPage pageCondition(Query query, HistoryLevelAlarmEntity entity) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); - wrapper.between(HistoryLevelAlarmEntity::getAlarmTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00", - DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); - if(ObjectUtil.isNotEmpty(entity.getType())){ - wrapper.eq(HistoryLevelAlarmEntity::getType, entity.getType()); - } - if(ObjectUtil.isNotEmpty(entity.getStationId())){ - wrapper.eq(HistoryLevelAlarmEntity::getStationId, entity.getStationId()); - }else{ - List stations = stationService.list(); - if(CollectionUtil.isNotEmpty(stations)){ - wrapper.in(HistoryLevelAlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - } - } - IPage page = super.page(Condition.getPage(query), wrapper); - List records = page.getRecords(); - // 步骤2. 过滤已处理等級告警 - List handles = handleService.handles(ObjectUtil.isEmpty(entity.getType()) ? AbnormalAlarmConstant.LONG_TYPE_LIST : Collections.singletonList(Long.parseLong(entity.getType())),AbnormalAlarmConstant.INTELLIGENCE_ALARM); - - page.setRecords(records.stream().peek(record-> { - record.setIsHandle(CollectionUtil.isNotEmpty(handles) && handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList()).contains(record.getAlarmId())); - record.setAlarmType(AbnormalAlarmConstant.INTELLIGENCE_ALARM); - }).collect(Collectors.toList())); - return page; - } - - /** - * 告警数量:时间范围-当天 - * @return - */ - @Override - public List alarmCount() { - // 步骤1.查询用户权限站点 - List stations = stationService.list(); - if(CollectionUtil.isEmpty(stations)){ - return null; - } - - // 步骤2. 过滤已处理等級告警 - LambdaQueryWrapper handleWarpper = new LambdaQueryWrapper(); - handleWarpper.between(AlarmHandleEntity::getCreateTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00", - DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); - handleWarpper.in(AlarmHandleEntity::getStationCode, stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - List handles = handleService.list(); - - // 步骤2.查询告警数据 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); - wrapper.between(HistoryLevelAlarmEntity::getAlarmTime, DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00", - DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME)); - wrapper.in(HistoryLevelAlarmEntity::getStationId, stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - wrapper.in(HistoryLevelAlarmEntity::getType,AbnormalAlarmConstant.TYPE_LIST); - if(CollectionUtil.isNotEmpty(handles)){ - wrapper.notIn(HistoryLevelAlarmEntity::getAlarmId,handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList())); - } - List levels = this.list(wrapper); - - // 步骤4.遍历获取 - return AbnormalAlarmConstant.TYPE_LIST.stream().map(type->{ - IntelligentAlarmCountVo count = new IntelligentAlarmCountVo(); - count.setType(type); - count.setName(AbnormalAlarmConstant.TYPE_NAMES[Integer.parseInt(type)]); - if(CollectionUtil.isEmpty(levels)){ - count.setCount(0L); - }else{ - count.setCount(levels.stream().filter(level->level.getType().equals(type)).count()); - } - return count; - }).collect(Collectors.toList()); - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java deleted file mode 100644 index 24bc744..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.hnac.hzims.operational.alert.service.impl; - -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.equipment.entity.EmInfoEntity; -import com.hnac.hzims.equipment.feign.IEmInfoClient; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.message.MessageConstants; -import com.hnac.hzims.message.dto.MessagePushRecordDto; -import com.hnac.hzims.message.fegin.IMessageClient; -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.config.vo.LevelAlarmVo; -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.service.IStationService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springblade.system.feign.ISysClient; -import org.springblade.system.user.entity.User; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.stereotype.Service; - -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -/** - * 等级告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class LevelAlarmServiceImpl implements LevelAlarmService { - - private final IStationService stationService; - - private final IEmInfoClient deviceClient; - - private final HistoryLevelAlarmService historyLevelAlarmService; - - private final IUserClient userClient; - - private final ISysClient sysClient; - - private final IMessageClient messageClient; - - /** - * 定时发送消息内容 - * @return String - */ - @Override - public String sendMessage() { - // 站点 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE)); - if(CollectionUtil.isEmpty(stations)){ - throw new ServiceException("level send message is null"); - } - Map map = new ConcurrentHashMap<>(); - map.put("projectIds",stations.stream().map(StationEntity::getCode).collect(Collectors.joining(","))); - map.put("type", AbnormalAlarmConstant.LEVEL_TYPE_LIST); - map.put("startTime", DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"); - return JSONObject.toJSONString(map); - } - - - /** - * 接收服务推送消息 - * @param message - */ - @Override - public void receiveMessage(String message) { - // 对象转换 - List alarms = JSONObject.parseArray(message,LevelAlarmVo.class); - if(CollectionUtil.isEmpty(alarms)){ - return; - } - - // 站点 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE)); - if(CollectionUtil.isEmpty(stations)){ - throw new ServiceException("level send message is null"); - } - - // 设备 - List devices = deviceClient.list(); - - // 查询当天已经记录的告警 - List historys = historyLevelAlarmService.list(Wrappers.lambdaQuery() - .ge(HistoryLevelAlarmEntity::getCreateTime,DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00") - ); - - // 数据过滤 - List entitys = alarms.stream().filter(alarm -> CollectionUtil.isNotEmpty(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 alarmDevices = devices.stream().filter(device->device.getNumber().equals(item.getDevicecode())).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(alarmDevices)){ - // 找到站点 - List 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); - - // 消息推送 - CompletableFuture.runAsync(()->this.sendAlarmMessage(entitys,stations.stream().filter(station -> entitys.stream().filter(stationId -> !StringUtil.isEmpty(stationId)).map(HistoryLevelAlarmEntity::getStationId).collect(Collectors.toList()).contains(station.getCode())).collect(Collectors.toList()))); - } - - /** - * 告警消息推送 - * @param entitys - */ - private void sendAlarmMessage(List entitys,List stations) { - if(CollectionUtil.isEmpty(entitys)){ - return; - } - // 告警等级 :一级、二级告警发送通知 - List alarms = entitys.stream().filter(entity -> AbnormalAlarmConstant.LEVEL_LIST.contains(entity.getAlarmLevel())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(alarms)){ - return; - } - // 查询站点用户 - entitys.forEach(entity->{ - if(StringUtil.isEmpty(entity.getStationId())){ - return; - } - List depts = stations.stream().filter(station -> station.getCode().equals(entity.getStationId())).map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(depts)){ - return; - } - // app,web消息推送 - this.sendMessageByWebApp(depts.get(0),entity); - // 短信推送 - //this.message(depts.get(0),entity); - }); - } - - private void sendMessageByWebApp(Long dept,HistoryLevelAlarmEntity entity) { - // 获取站点用户 - R> result = userClient.userListByDeptId(dept); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return; - } - MessagePushRecordDto message = new MessagePushRecordDto(); - message.setBusinessClassify("warning"); - message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); - message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); - message.setTaskId(entity.getId()); - message.setTenantId("200000"); - message.setContent(entity.getSoeExplain()); - message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); - message.setPushType(MessageConstants.IMMEDIATELY); - message.setDeptId(dept); - message.setCreateDept(dept); - R deptName = sysClient.getDeptName(dept); - if (deptName.isSuccess()) { - message.setDeptName(deptName.getData()); - } - message.setCreateDept(dept); - result.getData().forEach(user->{ - message.setPusher(String.valueOf(user.getId())); - message.setPusherName(user.getName()); - message.setAccount(String.valueOf(user.getId())); - message.setCreateUser(user.getId()); - messageClient.sendMessage(message); - }); - } - - /** - * 发送短信 - * @param dept - * @param entity - */ - private void message(Long dept,HistoryLevelAlarmEntity entity) { - // 获取站点用户 - R> result = userClient.relationUserListByRoleAlias("200000",dept,"projectManager"); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return; - } - MessagePushRecordDto message = new MessagePushRecordDto(); - message.setBusinessClassify("warning"); - message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); - message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); - message.setTaskId(entity.getId()); - message.setTenantId("200000"); - message.setContent(entity.getSoeExplain()); - message.setTypes(Collections.singletonList(MessageConstants.SMS_PUSH)); - message.setPushType(MessageConstants.IMMEDIATELY); - message.setDeptId(dept); - R deptName = sysClient.getDeptName(dept); - if (deptName.isSuccess()) { - message.setDeptName(deptName.getData()); - } - User admin = userClient.userByAccount("200000", "admin").getData(); - message.setCreateDept(admin.getCreateDept()); - message.setCreateUser(admin.getId()); - result.getData().forEach(user->{ - message.setPusher(String.valueOf(user.getId())); - message.setPusherName(user.getName()); - message.setAccount(String.valueOf(user.getId())); - messageClient.sendMessage(message); - }); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/wrapper/HandleWrapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/wrapper/HandleWrapper.java deleted file mode 100644 index 0902031..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/wrapper/HandleWrapper.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.hnac.hzims.operational.alert.wrapper; - -import com.hnac.hzims.operational.alert.vo.AlarmHandleVo; -import org.springblade.core.mp.support.BaseEntityWrapper; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.system.user.cache.UserCache; -import org.springblade.system.user.entity.User; - -import java.util.Optional; - - -public class HandleWrapper extends BaseEntityWrapper { - - public static HandleWrapper build() { - return new HandleWrapper(); - } - - @Override - public AlarmHandleVo entityVO(AlarmHandleVo entity) { - User createUser = UserCache.getUser(entity.getCreateUser()); - if(ObjectUtil.isEmpty(createUser)){ - return entity; - } - assert entity != null; - entity.setUserName(Optional.ofNullable(createUser.getName()).orElse(null)); - return entity; - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java index eab3f8d..2ccc50e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java @@ -1,7 +1,6 @@ package com.hnac.hzims.operational.config.config; -import com.hnac.hzims.operational.config.ws.AlarmHandler; import com.hnac.hzims.operational.config.ws.MessageHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -21,8 +20,6 @@ public class WebSocketConfig implements WebSocketConfigurer{ public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { // 集中监控处理器 registry.addHandler(monitorHandler(), "/comprehensiveD/{uid}").setAllowedOrigins("*"); - // 告警处理器 - registry.addHandler(alarmHandler(), "/alarmHandler/{uid}").setAllowedOrigins("*"); } @Bean @@ -31,11 +28,6 @@ public class WebSocketConfig implements WebSocketConfigurer{ } @Bean - public WebSocketHandler alarmHandler() { - return new AlarmHandler(); - } - - @Bean public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java index 4f64964..afea65f 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java @@ -40,15 +40,6 @@ public class CentralMonitorController extends BladeController { } - @GetMapping("/getRealTimeData") - @ApiOperation("获取站点实时缓存数据") - @ApiOperationSupport(order = 1) - public R getRealTimeData() { - realMonitorService.realTimeData(""); - return R.success("true"); - } - - /** * 查询通讯告警的最后一小时的运行数据 * @param page diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/HistoryAbnormalAlarmController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/HistoryAbnormalAlarmController.java deleted file mode 100644 index ba7d161..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/HistoryAbnormalAlarmController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.hnac.hzims.operational.config.controller; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; -import com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.boot.ctrl.BladeController; -import org.springblade.core.mp.support.Condition; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - - -/** - * @author ysj - */ -@RestController -@AllArgsConstructor -@Api(value = "集中监控智能告警",tags = "集中监控智能告警") -@RequestMapping("/abnormalAlarm") -public class HistoryAbnormalAlarmController extends BladeController { - - private final HistoryAbnormalAlarmService historyAbnormalAlarmService; - - @PostMapping("/list") - @ApiOperation("智能告警数据异常列表查询") - @ApiOperationSupport(order = 1) - public R> getStationMonitor(@RequestParam(value = "type",required = false) String type, Query query) { - return R.data(historyAbnormalAlarmService.list(Condition.getPage(query), type)); - } - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/StAlamRecordController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/StAlamRecordController.java index e0ba376..545f561 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/StAlamRecordController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/StAlamRecordController.java @@ -1,7 +1,6 @@ package com.hnac.hzims.operational.config.controller; -import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; @@ -9,7 +8,6 @@ import com.hnac.hzims.common.logs.enums.BusinessType; import com.hnac.hzims.common.logs.enums.OperatorType; import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; import com.hnac.hzims.operational.config.service.StAlamRecordService; -import com.hnac.hzims.operational.config.vo.FaultVo; import com.hnac.hzims.operational.config.vo.SoeBodyVo; import com.hnac.hzims.operational.config.vo.StAlarmRecordVo; import io.swagger.annotations.Api; @@ -24,7 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Date; -import java.util.List; @Api(tags = "告警记录") @RestController @@ -64,12 +61,6 @@ public class StAlamRecordController { return stAlamRecordService.getDaySoeList(AuthUtil.getUser(), date, type,current,size,code); } - @ApiOperation("获取故障列表数据") - @RequestMapping(value = "/getFaultList", method = {RequestMethod.GET, RequestMethod.POST}) - public R> getFaultList(@ApiParam(value = "站点编码") @RequestParam(required = false) String code) { - return R.data(stAlamRecordService.getFaultList(code)); - } - /** * 分页 获取告警记录列表 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/scheduled/StAlamRecordTask.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/scheduled/StAlamRecordTask.java deleted file mode 100644 index 1355aa1..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/scheduled/StAlamRecordTask.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.hnac.hzims.operational.config.scheduled; - -import com.hnac.hzims.operational.alert.service.AbnormalAlarmService; -import com.hnac.hzims.operational.config.service.StFocusPropertiesService; -import com.hnac.hzims.operational.station.service.IRealMonitorService; -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.annotation.XxlJob; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.util.Date; - -import static com.hnac.hzims.operational.main.constant.MainConstants.*; - -/** - * 集中监控 - */ -@Slf4j -@Component -public class StAlamRecordTask { - - @Value("${hzims.operation.comprehensiveD}") - public String path; - - @Autowired - private IRealMonitorService monitorService; - - @Autowired - private AbnormalAlarmService abnormalAlarmService; - - @Autowired - private StFocusPropertiesService stFocusPropertiesService; - /** - * 站点数据统计 - * @return ReturnT - */ - @XxlJob(STATION_DATA_COUNT) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT stationDataCount(String param) throws Exception { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - monitorService.stationDataCount(param); - return new ReturnT<>("SUCCESS"); - } - - /** - * realId获取 - * @return ReturnT - */ - @XxlJob(REAL_ID_DATA) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT realIdData(String param) throws Exception { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - stFocusPropertiesService.getStationRealIds(param); - return new ReturnT<>("SUCCESS"); - } - - /** - * 站点实时数据 - * @return ReturnT - */ - @XxlJob(REAL_TIME_DATA) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT realTimeData(String param) throws Exception { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - monitorService.realTimeData(param); - return new ReturnT<>("SUCCESS"); - } - - /** - * 集中监控数据处理 - * @return ReturnT - */ - @XxlJob(CENTRALIZED_MONITORING) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT centralizedMonitoring(String param) throws Exception { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - monitorService.centralizedMonitoring(param); - return new ReturnT<>("SUCCESS"); - } - - - /** - * 数据中断告警 - * @return ReturnT - */ - @XxlJob(ALARM_DATA_HANDLE) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT alarmDataHandle(String param) throws Exception { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - abnormalAlarmService.alarmDataHandle(param); - return new ReturnT<>("SUCCESS"); - } - - -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/StAlamRecordService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/StAlamRecordService.java index 185b123..fca0f07 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/StAlamRecordService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/StAlamRecordService.java @@ -3,7 +3,6 @@ package com.hnac.hzims.operational.config.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; -import com.hnac.hzims.operational.config.vo.FaultVo; import com.hnac.hzims.operational.config.vo.SoeBodyVo; import com.hnac.hzims.operational.config.vo.StAlarmRecordVo; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; @@ -49,11 +48,4 @@ public interface StAlamRecordService extends BaseService { Long insertAlert(String stationId,String realId); List getJointRelayInfo(); - - /** - * 获取故障列表 - * - * @return - */ - List getFaultList(String code); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java index 97411f8..66b4041 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java @@ -3,19 +3,14 @@ package com.hnac.hzims.operational.config.service.impl; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.hutool.core.map.MapUtil; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.fdp.feign.IFdpMonitorClient; import com.hnac.hzims.fdp.vo.FdpFaultStatusVo; -import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; -import com.hnac.hzims.operational.alert.entity.AlarmHandleEntity; -import com.hnac.hzims.operational.alert.service.AlarmHandleService; import com.hnac.hzims.operational.config.entity.DataSet; import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; import com.hnac.hzims.operational.config.entity.StFocusPropertiesEntity; @@ -23,9 +18,11 @@ import com.hnac.hzims.operational.config.enume.ConfigStatus; import com.hnac.hzims.operational.config.mapper.StAlarmRecordMapper; import com.hnac.hzims.operational.config.service.StAlamRecordService; import com.hnac.hzims.operational.config.service.StFocusPropertiesService; -import com.hnac.hzims.operational.config.vo.*; +import com.hnac.hzims.operational.config.vo.SoeBodyVo; +import com.hnac.hzims.operational.config.vo.StAlarmRecordExcelVo; +import com.hnac.hzims.operational.config.vo.StAlarmRecordVo; +import com.hnac.hzims.operational.config.vo.TimeDataVo; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; -import com.hnac.hzims.operational.main.vo.RealDeviceVo; import com.hnac.hzims.operational.main.vo.SoeDataVo; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; @@ -72,8 +69,6 @@ public class StAlamRecordServiceImpl extends BaseServiceImpl getFaultList(String code) { - List stations = this.getStationByUserAuth(code);; - if(CollectionUtil.isEmpty(stations)){ - return null; - } - String result = fdpMonitorClient.getFaultList(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - if(StringUtil.isEmpty(result)){ - return null; - } - List list = JSONArray.parseArray(result,FaultVo.class); - if(CollectionUtil.isEmpty(list)){ - return null; - } - // 过滤已处理预警信息 - List handles = handleService.handles(Collections.singletonList(AbnormalAlarmConstant.EARLY_WARNING),AbnormalAlarmConstant.INTELLIGENCE_ALARM); - Map map = stations.stream().collect(Collectors.toMap(StationEntity::getCode,StationEntity::getName)); - return list.stream().filter(fault -> map.containsKey(fault.getStation())).peek(record -> { - record.setStationName(map.get(record.getStation())); - if(CollectionUtil.isEmpty(handles)){ - record.setIsHandle(false); - }else{ - record.setIsHandle(handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList()).contains(String.valueOf(record.getFaultId()))); - } - }).sorted(Comparator.comparing((FaultVo::getIsHandle)).reversed().thenComparing(FaultVo::getCreateTime).reversed()).collect(Collectors.toList()); - } - - - /** * map添加redis原有数据 * @param map * @return diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java deleted file mode 100644 index 7bcb706..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.hnac.hzims.operational.config.ws; - -import com.alibaba.fastjson.JSONObject; -import com.hnac.hzims.operational.alert.service.AlarmMergeService; -import com.hnac.hzims.operational.config.vo.MessageParamVo; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -import java.io.IOException; - -/** - * @author ysj - */ -@Slf4j -public class AlarmHandler extends TextWebSocketHandler { - - private final Long defaultRealDataRefreshTime = 20000L; - - @Autowired - private AlarmMergeService alarmMergeService; - - - //WebSocket连接建立成功之后调用 - @Override - public void afterConnectionEstablished(WebSocketSession session) { - String[] split = session.getUri().toString().split("/"); - String uid = split[split.length - 1]; - // session 参数设置用户进行标识 - session.getAttributes().put("userId", uid); - AlarmSessionManager.add(uid, session); - SocketPool.alarm_pool.put(session.getId(), this); - } - - // 连接关闭时调用 - @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { - // 移除会话 - AlarmSessionManager.removeAndClose(session.getId()); - // map移除用户 - SocketPool.alarm_pool.remove(session.getId()); - } - - // 消息传输错误触发 - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) { - // 移除会话 - AlarmSessionManager.removeAndClose(session.getId()); - // map移除用户 - SocketPool.alarm_pool.remove(session.getId()); - } - - - // 接收消息触发 - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) throws IOException { - // 获取会话用户编号 - String userId = (String) session.getAttributes().get("userId"); - String message = textMessage.getPayload(); - if(StringUtil.isBlank(message)){ - return; - } - MessageParamVo param = JSONObject.parseObject(message, MessageParamVo.class); - if(ObjectUtil.isEmpty(param) || CollectionUtil.isEmpty(param.getDeptIds())){ - return; - } - TextMessage sendMessage = alarmMergeService.getSendMessage(param); - if(ObjectUtil.isEmpty(sendMessage)){ - return; - } - session.sendMessage(sendMessage); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java deleted file mode 100644 index 707c0cf..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.hnac.hzims.operational.config.ws; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.socket.WebSocketSession; - -import java.io.IOException; -import java.util.concurrent.ConcurrentHashMap; - - -/** - * @author ysj - */ -@Slf4j -public class AlarmSessionManager { - - public static ConcurrentHashMap SESSION_POOL = new ConcurrentHashMap<>(); - - /** - * 添加会话 - * @param uid 用户 - * @param session 会话对象 - */ - public static void add(String uid, WebSocketSession session) { - if (SESSION_POOL.containsKey(uid)) { - AlarmSessionManager.removeAndClose(uid); - } - SESSION_POOL.put(uid, session); - log.info("添加 WebSocketSession 会话成功,uid=" + uid); - } - - - /** - * 获取会话 - * @param uid 用户 - * @return - */ - public static WebSocketSession get(String uid) { - return SESSION_POOL.get(uid); - } - - /** - * 移除会话并关闭会话 - * @param uid 用户 - */ - public static void removeAndClose(String uid) { - WebSocketSession session = SESSION_POOL.get(uid); - if (session != null) { - try { - //关闭连接 - session.close(); - } catch (IOException ex) { - throw new RuntimeException("关闭ws会话失败!", ex); - } - } - - SESSION_POOL.remove(uid); - } -} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java deleted file mode 100644 index 25a9bcc..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.hnac.hzims.operational.config.ws; - -import com.hnac.hzims.operational.alert.service.LevelAlarmService; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.net.URI; - -/** - * 等级告警获取数据长链接 - * @author ysj - */ -@Slf4j -@Component -@EnableScheduling -public class LevelAlarmRegular{ - - @Value("${hzims.level.ws-url}") - private String level_wss_url; - - private LevelAlarmWebSocket client; - - @Autowired - private LevelAlarmService levelAlarmService; - - // 定时发送消息 - @Scheduled(cron = "0 0/30 * * * ?") - private void regular(){ - // 检查链接存活状态 - if(ObjectUtil.isNotEmpty(client) && client.isOpen()){ - client.send(levelAlarmService.sendMessage()); - }else { - this.createClient(); - } - } - - // 创建websocket链接 - private void createClient() { - try{ - client = new LevelAlarmWebSocket(new URI(level_wss_url)); - client.connectBlocking(); - }catch (Exception e){ - log.error("level create error : {}",e.getMessage()); - } - } -} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmWebSocket.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmWebSocket.java deleted file mode 100644 index ed224dd..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmWebSocket.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.hnac.hzims.operational.config.ws; - -import com.hnac.hzims.operational.alert.service.LevelAlarmService; -import lombok.extern.slf4j.Slf4j; -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.handshake.ServerHandshake; -import org.springblade.core.tool.utils.SpringUtil; -import org.springblade.core.tool.utils.StringUtil; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import java.net.Socket; -import java.net.URI; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.Optional; - -/** - * 等级告警获取数据长链接 - * @author ysj - */ -@Slf4j -public class LevelAlarmWebSocket extends WebSocketClient { - - private final LevelAlarmService levelAlarmService; - - /** - * 构造等级告警websocket - * @param uri - */ - public LevelAlarmWebSocket(URI uri) { - super(uri); - levelAlarmService = SpringUtil.getBean(LevelAlarmService.class); - connection(this); - } - - // 链接到服务器回调接口 - @Override - public void onOpen(ServerHandshake handshakedata) { - log.error("levl websocket open"); - } - - // 接收到服务器消息回调接口 - @Override - public void onMessage(String message) { - if(StringUtil.isEmpty(message)){ - log.error("levl on message is null"); - }else{ - // 等级告警数据处理 - levelAlarmService.receiveMessage(message); - } - } - - // 与服务器链接中断回调接口 - @Override - public void onClose(int code, String reason, boolean remote) { - log.error("levl websocket close"); - } - - // 与服务器通讯异常触发 - @Override - public void onError(Exception e) { - log.error("levl websocket error : {}",e.getMessage()); - } - - /** - * 建立链接 - * @param webSocket - */ - private void connection(LevelAlarmWebSocket webSocket) { - SSLContext context = init(); - if(Optional.ofNullable(context).isPresent()){ - Socket socket = create(context); - if(Optional.ofNullable(socket).isPresent()){ - webSocket.setSocket(socket); - } - } - } - - /** - * 创建Socket - * @param context - * @return - */ - private Socket create(SSLContext context) { - Socket socket = null; - try{ - socket = context.getSocketFactory().createSocket(); - }catch (Exception e){ - log.error("leve socket create error : {}",e.getMessage()); - } - return socket; - } - - /** - * 协议初始化 - * @return SSLContext - */ - private SSLContext init() { - SSLContext SSL = null; - try{ - SSL = SSLContext.getInstance("TLS"); - SSL.init(null, new TrustManager[]{new X509TrustManager() { - @Override - public void checkClientTrusted(X509Certificate[] chain, - String authType) { - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) { - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - }}, new SecureRandom()); - }catch (Exception e){ - log.error("leve SSL init error : {}",e.getMessage()); - } - return SSL; - } - -} \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java index a38b27c..a48c9ae 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java @@ -10,6 +10,4 @@ public class SocketPool { public static Map pool = new ConcurrentHashMap<>(); - public static Map alarm_pool = new ConcurrentHashMap<>(); - } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyGroupPMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyGroupPMapper.xml index 0698d1a..358a702 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyGroupPMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyGroupPMapper.xml @@ -160,7 +160,7 @@ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IRealMonitorService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IRealMonitorService.java index af3d89f..3b5cf12 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IRealMonitorService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IRealMonitorService.java @@ -9,23 +9,7 @@ import org.springframework.web.socket.TextMessage; */ public interface IRealMonitorService { - /** - * 站点实时数据 - * @param param - */ - void realTimeData(String param); - /** - * 获取站点数量 - * @param param - */ - void stationDataCount(String param); - - /** - * 集中监控数据处理 - * @param param - */ - void centralizedMonitoring(String param); /** * 获取发送前端文本消息 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index cd7b49f..7da8cc2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -1,26 +1,18 @@ package com.hnac.hzims.operational.station.service.impl; import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.fdp.vo.FdpFaultStatusVo; import com.hnac.hzims.hzimsweather.response.weather.Daily; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse; import com.hnac.hzims.hzimsweather.response.weather.Now; -import com.hnac.hzims.operational.alert.service.AbnormalAlarmService; -import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; -import com.hnac.hzims.operational.config.enume.ConfigStatus; import com.hnac.hzims.operational.config.service.StAlamRecordService; import com.hnac.hzims.operational.config.service.StFocusPropertiesService; import com.hnac.hzims.operational.config.vo.MessageParamVo; -import com.hnac.hzims.operational.config.vo.StationRealVo; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.main.service.IWeatherService; import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.station.entity.StationAttributeEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IRealMonitorService; import com.hnac.hzims.operational.station.service.IStationAttrConfigService; @@ -31,7 +23,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; @@ -47,9 +38,7 @@ import javax.validation.constraints.NotNull; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; -import java.util.concurrent.*; import java.util.stream.Collectors; -import java.util.stream.Stream; /** @@ -80,9 +69,6 @@ public class RealMonitorServiceImpl implements IRealMonitorService { private final IMainSystemMonitoringService systemMonitoringService; - @NotNull - private final AbnormalAlarmService abnormalAlarmService; - private final RedisClient redisClient; @NotNull @@ -128,86 +114,6 @@ public class RealMonitorServiceImpl implements IRealMonitorService { private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; - - @Override - public void realTimeData(String param) { - Long beginTime = System.currentTimeMillis(); - // 获取设备 - List devices = systemMonitoringService.getEmInfoList(); - // 设备开关机集合监测点 - List switchOnOff = devices.stream().map(o->{ - Map points = o.getPoint(); - if(CollectionUtil.isEmpty(points)){ - return ""; - } - String jointRelay = points.get(HomePageConstant.JOINT_RELAY); - if(!StringUtil.isEmpty(jointRelay)){ - return jointRelay; - } - String onOff = points.get(HomePageConstant.SWITCH_ON_OFF); - if(!StringUtil.isEmpty(onOff)){ - return onOff; - } - return ""; - }).collect(Collectors.toList()); - // 获取站点缓存数据 - List stationRealVos = (List) redisTemplate.opsForValue().get(moniter_realId_key); - if(CollectionUtil.isEmpty(stationRealVos)){ - return; - } - // 数据切割 - int limit = countStep(stationRealVos.size()); - List> list = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stationRealVos.stream().skip((long) a * MAX_SEND).limit(MAX_SEND).parallel().collect(Collectors.toList())).collect(Collectors.toList()); - ExecutorService pool = Executors.newFixedThreadPool(limit); - // - Map valueMap = new ConcurrentHashMap<>(); - // > - Map> keyMap = new ConcurrentHashMap<>(); - CountDownLatch countDownLatch = new CountDownLatch(limit); - pool.execute(()-> list.forEach(stations -> { - stations.forEach(stationReal -> { - String[] realIdArr = stationReal.getRealId(); - List realIds = Stream.of(realIdArr).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(realIds)){ - return; - } - log.error("real_time_data: {},{}",stationReal.getStation(),realIds); - List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); - for(int i = 0; i < realIds.size() ;i++){ - if(ObjectUtil.isEmpty(objects.get(i))){ - log.error(realIds.get(i) + "is null"); - }else{ - Map attribute = (Map) JSONObject.parse(objects.get(i)); - attribute.put("realId",attribute.get("k")); - attribute.put("value",attribute.get("v")); - attribute.put("time",attribute.get("t")); - attribute.remove("v"); - attribute.remove("k"); - attribute.remove("t"); - this.getCheckMap(attribute,switchOnOff); - valueMap.put(realIdArr[i],attribute.get("value")); - keyMap.put(realIdArr[i],attribute); - } - } - }); - countDownLatch.countDown(); - })); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - pool.shutdown(); - // redis 存储 - redisTemplate.opsForValue().set(real_id_key_path,JSONObject.toJSONString(valueMap)); - redisTemplate.opsForValue().set(real_id_key_gather_path,JSONObject.toJSONString(keyMap)); - Long endTime = System.currentTimeMillis(); - Long time = endTime - beginTime; - log.error("处理redis实时数据 耗时 : {}",time); - } - /** * 监测点过期数据检查 * @param value @@ -241,53 +147,6 @@ public class RealMonitorServiceImpl implements IRealMonitorService { */ private final static String SIGNAGE = "active_power"; - /** - * 站点数据统计 - * @param param - */ - @Override - public void stationDataCount(String param) { - // realId实时数据 - Object json = redisTemplate.opsForValue().get(real_id_key_path); - if(ObjectUtil.isEmpty(json)){ - return; - } - Map map = JSONObject.parseObject(json.toString(), new TypeReference>() { - }); - if(MapUtils.isEmpty(map)){ - return; - } - // 站点实时功率 key - stationCode,value - sumPower - Map realPowerMap = this.getPowerConversionMap(map); - if(MapUtils.isNotEmpty(realPowerMap)){ - redisTemplate.opsForValue().set(active_power_key, realPowerMap); - } - // 站点开关机状态 - List devices = systemMonitoringService.getEmInfoList(); - if(CollectionUtil.isEmpty(devices)){ - return; - } - // key->机构编号 value -> 设备集合 - Map> deviceMap = devices.stream().collect(Collectors.groupingBy(EminfoAndEmParamVo::getCreateDept)); - Map data = new HashMap<>(); - deviceMap.forEach((key, value) -> { - JointRelayVo jointRelay = new JointRelayVo(); - List relays = value.stream().filter(o -> MapUtils.isNotEmpty(o.getPoint()) && !StringUtil.isEmpty(o.getPoint().get(HomePageConstant.JOINT_RELAY))).map(relay -> map.get(relay.getPoint().get(HomePageConstant.JOINT_RELAY))).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(relays)) { - jointRelay.setUnitSum(0); - jointRelay.setShutdownCount(0); - jointRelay.setStartingUpCount(0); - } else { - jointRelay.setUnitSum(relays.size()); - Optional> off = Optional.ofNullable(relays.stream().filter("0"::equals).collect(Collectors.toList())); - jointRelay.setShutdownCount(off.map(List::size).orElse(0)); - Optional> on = Optional.ofNullable(relays.stream().filter("1"::equals).collect(Collectors.toList())); - jointRelay.setStartingUpCount(on.map(List::size).orElse(0)); - } - data.put(key, jointRelay); - }); - redisTemplate.opsForValue().set(joint_relay_key, data); - } /** * 获取所有有功功率的realId及其他信息 @@ -349,495 +208,6 @@ public class RealMonitorServiceImpl implements IRealMonitorService { return result; } - - /** - * 集中监控数据处理 - * @param param - */ - @Override - public void centralizedMonitoring(String param) { - long beginTime = System.currentTimeMillis(); - Thread thread = Thread.currentThread(); - Object json = redisTemplate.opsForValue().get(real_id_key_gather_path); - if (ObjectUtil.isEmpty(json)) { - return; - } - Map> map = JSONObject.parseObject(json.toString(), new TypeReference>>() { - }); - if (MapUtils.isEmpty(map)) { - return; - } - log.info(thread.getName() + "步骤1获取检测点数据耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 获取所有设备重点属性 - List list = attbtService.list(new LambdaQueryWrapper() {{ - isNotNull(StationAttributeEntity::getStationId); - eq(StationAttributeEntity::getIsDeleted, "0"); - orderByAsc(StationAttributeEntity::getSort); - }}); - if (CollectionUtil.isEmpty(list)) { - return; - } - log.info(thread.getName() + "步骤2获取监控配置监测点 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 获取所有告警记录 - List alertList = alertService.list(new LambdaQueryWrapper() {{ - orderByDesc(StAlarmRecordEntity::getCreateTime); - }}); - log.info(thread.getName() + "步骤3获取告警记录 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - List alarmList = abnormalAlarmService.getAbnormalAlarmList(); - log.info(thread.getName() + "步骤4获取数据中断告警记录 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 获取所有故障记录 - List faultList = this.getFdpFaultAll(); - log.info(thread.getName() + "步骤5获取故障记录 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 所有设备分类 - Map> deviceClassifyMap = (Map>) redisTemplate.opsForValue().get(device_classify_key); - log.info(thread.getName() + "步骤6获取设备分类 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 所有设备 - List emList = maintenanceTaskService.getEmInfoList(); - log.info(thread.getName() + "步骤7获取设备信息 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 根据站点分组 - Map> stationAttbtMap = list.stream().collect(Collectors.groupingBy(StationAttributeEntity::getStationId)); - // 获取站点列表 - List stationEntityList = stationService.getStationByInCode(new ArrayList<>(stationAttbtMap.keySet())); - log.info(thread.getName() + "步骤8站点列表 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 隐藏设备列表 - List hideList = stationAttrConfigService.getHideList(); - // 分割,每个map限制10个长度 - List>> handleList = this.mapChunk(stationAttbtMap); - log.info(thread.getName() + "步骤9监测点数据切割 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 创建线程池 - ExecutorService pool = Executors.newFixedThreadPool(handleList.size()); - CountDownLatch countDownLatch = new CountDownLatch(handleList.size()); - log.info(thread.getName() +"步骤10创建线程 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 所有机构 - R> deptAll = sysClient. getDeptList(); - // 存储数据节点 - List stationList = new CopyOnWriteArrayList<>(); - pool.execute(()->{ - // 线程处理数据 - for(Map> item : handleList){ - item.forEach((key,value)->{ - RealStationVo station = new RealStationVo(); - // 站点编码 - station.setStationCode(key); - // 名称、限制水位、服务类型、机构、排序 - this.stationParam(stationEntityList,station,deptAll.getData()); - // 根据设备名称分组 - Map> deviceAttbtMap = value.stream().filter(o -> !hideList.contains(o.getEmName())).collect(Collectors.groupingBy(StationAttributeEntity::getEmName)); - List deviceList = new ArrayList<>(); - // device - 设备,arrbt - 设备重点属性 - deviceAttbtMap.forEach((device, attbt) -> { - RealDeviceVo deviceVo = new RealDeviceVo(); - // 设备名称 - deviceVo.setDeviceName(device); - deviceVo.setDeviceCode(attbt.get(0).getEmCode()); - // 设备处理 - this.handleDevice(attbt, map, deviceVo, alertList, faultList); - deviceList.add(deviceVo); - }); - // 设备状态 - this.getDeviceParam(emList, deviceClassifyMap, deviceList); - // 运行设备状态设置 - this.deviceState(deviceList); - // 设置站点状态 - this.setStationStatus(alarmList,station,key,deviceList); - station.setDeviceList(deviceList.stream().sorted(Comparator.comparing((RealDeviceVo::getDeviceName))).collect(Collectors.toList())); - stationList.add(station); - }); - countDownLatch.countDown(); - } - }); - log.info(thread.getName() + "步骤11线程数据处理 耗时 : {}",System.currentTimeMillis() - beginTime); - beginTime = System.currentTimeMillis(); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - pool.shutdown(); - log.info(thread.getName() + "步骤12所有线程完成 耗时 : {}",System.currentTimeMillis() - beginTime); - redisTemplate.opsForValue().set(moniter_station_key, stationList); - } - - /** - * 设备状态 - * @param deviceList - */ - private void deviceState(List deviceList) { - deviceList.forEach(device->{ - // 设备属性列表 - List attbts = device.getAttbtList(); - if(CollectionUtil.isEmpty(attbts)){ - return; - } - // 功率属性记录 - List powers = attbts.stream().filter(att-> HomePageConstant.powerList.contains(att.getName())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(powers)){ - return; - } - if("0.000000".equals(powers.get(0).getValue()) || "-".equals(powers.get(0).getValue()) || HomePageConstant.ON.equals(powers.get(0).getValue())){ - return; - } - device.setState(1); - }); - } - - /** - * 设置站点状态 - * @param alarmList - * @param station - * @param key - */ - private void setStationStatus(List alarmList, RealStationVo station, String key,List deviceList) { - station.setStatus(0); - // 站点功率大于0为正常上送数据 - double powerSum = deviceList.stream().mapToDouble(o->{ - List attbts = o.getAttbtList(); - if(CollectionUtil.isEmpty(attbts)){ - return 0; - } - // 功率属性记录 - List powers = attbts.stream().filter(att-> HomePageConstant.powerList.contains(att.getName())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(powers)){ - return 0; - } - return powers.stream().filter(power-> !"0.000000".equals(power.getValue()) && !"-".equals(power.getValue()) && !HomePageConstant.ON.equals(power.getValue())).mapToDouble(value->Double.parseDouble(value.getValue())).sum(); - }).sum(); - if(powerSum > 0){ - return; - } - if(alarmList.contains(key)){ - station.setStatus(1); - } - } - - /** - * map分割 - * - * @param - * @param - * @param chunkMap - * @return - */ - private List> mapChunk(Map chunkMap) { - if (chunkMap == null || RealMonitorServiceImpl.MAX_SEND <= 0) { - List> list = new ArrayList<>(); - list.add(chunkMap); - return list; - } - Set keySet = chunkMap.keySet(); - Iterator iterator = keySet.iterator(); - int i = 1; - List> total = new ArrayList<>(); - Map tem = new HashMap<>(); - while (iterator.hasNext()) { - k next = iterator.next(); - tem.put(next, chunkMap.get(next)); - if (i == RealMonitorServiceImpl.MAX_SEND) { - total.add(tem); - tem = new HashMap<>(); - i = 0; - } - i++; - } - if (!CollectionUtil.isEmpty(tem)) { - total.add(tem); - } - return total; - } - - /** - * 获取所有告警记录 - * - * @return - */ - private List getFdpFaultAll() { - Object json = redisTemplate.opsForValue().get(fdp_fault_data_key); - if (ObjectUtil.isEmpty(json)) { - return new ArrayList<>(); - } - return (List) json; - } - - /** - * 设备处理 - * - * @param list - * @param map - * @param device - */ - private void handleDevice(List list, Map> map, - RealDeviceVo device, List alertList, - List faultList) { - if (CollectionUtil.isEmpty(list) || MapUtils.isEmpty(map)) { - return; - } - List attbtList = new ArrayList<>(); - list.forEach(item -> { - RealAttributeVo realAttributeVo = new RealAttributeVo(); - // 设备重点属性处理 : 单条-item - Map real = map.get(item.getMonitorId()); - if(MapUtils.isEmpty(real)){ - realAttributeVo.setName(item.getAttributes()); - realAttributeVo.setType(item.getAttributeType()); - realAttributeVo.setRealId(item.getMonitorId()); - realAttributeVo.setQuality(-1); - realAttributeVo.setStatus(0); - realAttributeVo.setValue("0"); - realAttributeVo.setUnit(item.getUnit()); - attbtList.add(realAttributeVo); - return; - } - realAttributeVo = handleAttbt(item, real, alertList, faultList); - if (ObjectUtil.isEmpty(realAttributeVo)) { - return; - } - attbtList.add(realAttributeVo); - }); - device.setAttbtList(attbtList); - } - - /** - * 设备参数设置 - * - * @param emList - * @param deviceClassifyMap - * @param deviceList - */ - private void getDeviceParam(List emList, Map> deviceClassifyMap, List deviceList) { - if (CollectionUtil.isEmpty(emList) || CollectionUtil.isEmpty(deviceList) || MapUtils.isEmpty(deviceClassifyMap)) { - return; - } - List faultList = deviceClassifyMap.get(HomePageConstant.FAULT); - List maintaintList = deviceClassifyMap.get(HomePageConstant.MAINTAIN); - List overhaultList = deviceClassifyMap.get(HomePageConstant.OVERHAUL); - List runtList = deviceClassifyMap.get(HomePageConstant.RUN); - List sparetList = deviceClassifyMap.get(HomePageConstant.SPARE); - deviceList.forEach(device -> { - if (StringUtil.isBlank(device.getDeviceCode())) { - device.setState(-1); - return; - } - List list = emList.stream().filter(o -> null != o.getId() && o.getId().toString().equals(device.getDeviceCode())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(list)) { - device.setState(-1); - return; - } - String deviceCode = list.get(0).getEmCode(); - if (StringUtil.isBlank(deviceCode)) { - device.setState(-1); - return; - } - // 故障 - if (CollectionUtil.isNotEmpty(faultList) && faultList.contains(deviceCode)) { - device.setState(4); - // 保养 - } else if (CollectionUtil.isNotEmpty(maintaintList) && maintaintList.contains(deviceCode)) { - device.setState(3); - // 备用 - } else if (CollectionUtil.isNotEmpty(sparetList) && sparetList.contains(deviceCode)) { - device.setState(2); - // 运行 - } else if (CollectionUtil.isNotEmpty(runtList) && runtList.contains(deviceCode)) { - device.setState(1); - // 检修 - } else if (CollectionUtil.isNotEmpty(overhaultList) && overhaultList.contains(deviceCode)) { - device.setState(0); - // 未知 - } else { - device.setState(-1); - } - }); - } - - /** - * 设备单条重点属性处理 - * - * @param item - * @param real - * @return - */ - private RealAttributeVo handleAttbt(StationAttributeEntity item, Map real, - List alertList, List faultList) { - RealAttributeVo attest = new RealAttributeVo(); - this.setAttbtParam(attest, real); - attest.setRealId(item.getMonitorId()); - attest.setName(item.getAttributes()); - attest.setUnit(item.getUnit()); - attest.setType(item.getAttributeType()); - String value = Optional.ofNullable(attest.getValue()).orElse("-"); - // 正常状态 - attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); - int quality = Optional.ofNullable(attest.getQuality()).orElse(-1); - String time = Optional.ofNullable(attest.getTime()).orElse(""); - // 延时状态 :质量为空 && 时间为空 - if (-1 == quality && StringUtil.isEmpty(time)) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.GRAY.getStatus()); - } - int type = item.getAttributeType(); - switch (type) { - case 1://遥测 - // 预警状态 :value值为"1" && quality值为0 - if ("1".equals(value) && 0 == quality) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.RED.getStatus()); - } - break; - case 2://遥信 - signalyRemote(item, attest, quality, value, alertList); - //处理 - break; - default: - throw new IllegalStateException("Unexpected type: " + type); - } - // 故障信息设置 - accidentDetails(attest, faultList, value); - return attest; - } - - /** - * 设置重点属性参数 - * - * @param attest - * @param real - */ - private void setAttbtParam(RealAttributeVo attest, Map real) { - if (CollectionUtil.isEmpty(real)) { - return; - } - real.forEach((key, value) -> { - if (StringUtil.isBlank(value)) { - return; - } - switch (key) { - case "q": - attest.setQuality(Integer.parseInt(value)); - break; - case "realId": - attest.setRealId(value); - break; - case "value": - attest.setValue(Optional.ofNullable(value).orElse("-")); - break; - case "time": - attest.setTime(value); - break; - } - }); - } - - /** - * 重点属性类型-遥信 :数据逻辑处理 - * - * @param attest - */ - private void signalyRemote(StationAttributeEntity item, RealAttributeVo attest, int quality, String strValue, List alertList) { - //需要所有值的数据不为null,并且满足条件才会进去添加数据返回id - if (null == item.getUpUpLimit() || null == item.getDownDownLimit() || null == item.getUpLimit() || null == item.getDownLimit()) { - return; - } - if (-1 == quality) { - return; - } - if (quality != 0) { - return; - } - if ("-".equals(strValue)) { - return; - } - double upup = item.getUpUpLimit(); - double lwlw = item.getDownDownLimit(); - double up = item.getUpLimit(); - double lw = item.getDownLimit(); - //查询出来已处理告警记录 - List handleList = alertList.stream().filter(o -> o.getStationId().equals(item.getStationId()) && o.getRealId().equals(attest.getRealId()) && o.getStatus() == 1).collect(Collectors.toList()); - //查询出来未处理告警记录 - List recordList = alertList.stream().filter(o -> o.getStationId().equals(item.getStationId()) && o.getRealId().equals(attest.getRealId()) && o.getStatus() == 0).collect(Collectors.toList()); - long past = 0L; - double value = Double.parseDouble(strValue); - if (value > upup || value < lwlw) { - if (CollectionUtil.isNotEmpty(handleList)) { - // 现在时间 - 处理时间 - past = System.currentTimeMillis() - handleList.get(0).getProcessTime().getTime(); - } - boolean isOverrun = ((CollectionUtil.isEmpty(handleList) && CollectionUtil.isEmpty(recordList)) || (past / 1000 / 60 > 30 && CollectionUtil.isEmpty(recordList))); - if (isOverrun) { - Long alertId = alertService.insertAlert(item.getStationId(), item.getMonitorId()); - attest.setId(alertId); - attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); - } else if (CollectionUtil.isNotEmpty(recordList)) { - StAlarmRecordEntity record = recordList.get(0); - attest.setId(record.getId()); - // 告警处理完成 - if (record.getProcessTime() != null && record.getStatus() == (byte) 1) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); - // 告警未处理 - } else if (record.getProcessTime() == null && record.getStatus() == (byte) 0) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.HAND_DELAY_STATUS.getStatus()); - } - } - } else if (value > up && value < upup || value < lw && value > lwlw) { - if (CollectionUtil.isNotEmpty(handleList)) { - // 现在时间 - 处理时间 - past = System.currentTimeMillis() - handleList.get(0).getProcessTime().getTime(); - } - boolean exist = ((CollectionUtil.isEmpty(handleList) && CollectionUtil.isEmpty(recordList)) || (past / 1000 / 60 > 30 && CollectionUtil.isEmpty(recordList))); - if (exist){ - Long alertId = alertService.insertAlert(item.getStationId(), item.getMonitorId()); - attest.setId(alertId); - attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); - // 存在告警记录 - } else if (CollectionUtil.isNotEmpty(recordList)) { - StAlarmRecordEntity record = recordList.get(0); - if (recordList.get(0).getStatus() == (byte) 0 && recordList.get(0).getCreateTime() != null) { - attest.setId(record.getId()); - attest.setStatus(ConfigStatus.ConfigStatusEnum.RED.getStatus()); - } else { - attest.setId(recordList.get(0).getId()); - attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); - } - } - } - } - - /** - * 故障信息设置 - * - * @param attest - * @param faultList - * @param value - */ - private void accidentDetails(RealAttributeVo attest, List faultList, String value) { - if (CollectionUtil.isEmpty(faultList) || "-".equals(value)) { - return; - } - List fault = faultList.stream().filter(o -> o.getRealId().equals(attest.getRealId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(fault)) { - return; - } - FdpFaultStatusVo fdpFaultStatusVo = fault.get(0); - // 黄色 - if (fdpFaultStatusVo.getValue() > greater_than && fdpFaultStatusVo.getValue() < less_than) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); - // 橙色 - } else if (fdpFaultStatusVo.getValue() >= be_equal_or_greater_than) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.ORANGE.getStatus()); - } - attest.setFdpRate(fdpFaultStatusVo.getValue()); - attest.setFdpFaultId(fdpFaultStatusVo.getFaultId()); - attest.setFdpMonitorId(fdpFaultStatusVo.getMonitorId()); - } - /** * 根据websocket传入的用户信息,返回对应站点数据 * @param message