Browse Source

#告警代码移植

zhongwei
yang_shj 11 months ago
parent
commit
3bf0369d26
  1. 4
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmHandleConstant.java
  2. 2
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleDetailEntity.java
  3. 2
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleEntity.java
  4. 4
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleVo.java
  5. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/monitor/listener/AlarmListener.java
  6. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/DroolsMqttConsumer.java
  7. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/FdpMqttConsumer.java
  8. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/HZ300MqttConsumer.java
  9. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/mqtt/VideoMqttConsumer.java
  10. 10
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java
  11. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/ShowAlarmController.java
  12. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.java
  13. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.xml
  14. 10
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java
  15. 51
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml
  16. 5
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleDetailService.java
  17. 8
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java
  18. 8
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleDetailServiceImpl.java
  19. 42
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java
  20. 31
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java
  21. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/wrapper/HandleWrapper.java
  22. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.java
  23. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.xml
  24. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/AlarmHistoryService.java
  25. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java
  26. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/FdpAlarmService.java
  27. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/LevelAlarmService.java
  28. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java
  29. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java
  30. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/VideoAlarmService.java
  31. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/AlarmHistoryServiceImpl.java
  32. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java
  33. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java
  34. 6
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java
  35. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java
  36. 10
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java
  37. 8
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/VideoAlarmServiceImpl.java
  38. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/task/VideoScheduledTask.java
  39. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmRegular.java
  40. 2
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/level/LevelAlarmWebSocket.java
  41. 182
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/AlertWebSocketClient.java
  42. 44
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/WebSocketClientManager.java
  43. 157
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java
  44. 67
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/LevelAlarmController.java
  45. 17
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.java
  46. 17
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.xml
  47. 57
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.xml
  48. 13
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.java
  49. 8
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.xml
  50. 26
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java
  51. 49
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml
  52. 11
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.java
  53. 6
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.xml
  54. 17
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AbnormalAlarmService.java
  55. 15
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java
  56. 13
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlertDefectService.java
  57. 40
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java
  58. 21
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryLevelAlarmService.java
  59. 12
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java
  60. 268
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java
  61. 133
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java
  62. 125
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java
  63. 433
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java
  64. 122
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryLevelAlarmServiceImpl.java
  65. 237
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java
  66. 8
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/config/WebSocketConfig.java
  67. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java
  68. 38
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/HistoryAbnormalAlarmController.java
  69. 9
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/StAlamRecordController.java
  70. 110
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/scheduled/StAlamRecordTask.java
  71. 8
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/StAlamRecordService.java
  72. 46
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/StAlamRecordServiceImpl.java
  73. 79
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java
  74. 58
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java
  75. 51
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java
  76. 125
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmWebSocket.java
  77. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java
  78. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyGroupPMapper.xml
  79. 16
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IRealMonitorService.java
  80. 630
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java

4
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java → hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/constants/AlarmHandleConstant.java

@ -1,4 +1,4 @@
package com.hnac.hzims.operational.alert.constants;
package com.hnac.hzims.alarm.constants;
import java.util.Arrays;
import java.util.List;
@ -6,7 +6,7 @@ import java.util.List;
/**
* @author YSJ
*/
public interface AbnormalAlarmConstant {
public interface AlarmHandleConstant {
List<String> INTERRUPT_LIST = Arrays.asList("13","14");

2
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleDetailEntity.java → hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleDetailEntity.java

@ -1,4 +1,4 @@
package com.hnac.hzims.operational.alert.entity;
package com.hnac.hzims.alarm.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;

2
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/entity/AlarmHandleEntity.java → hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/entity/AlarmHandleEntity.java

@ -1,4 +1,4 @@
package com.hnac.hzims.operational.alert.entity;
package com.hnac.hzims.alarm.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;

4
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/vo/AlarmHandleVo.java → hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/vo/AlarmHandleVo.java

@ -1,8 +1,8 @@
package com.hnac.hzims.operational.alert.vo;
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.operational.alert.entity.AlarmHandleEntity;
import com.hnac.hzims.alarm.entity.AlarmHandleEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

2
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;

2
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;

2
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;

2
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;

2
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;

10
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AlarmHandleController.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/controller/AlarmHandleController.java

@ -1,13 +1,13 @@
package com.hnac.hzims.operational.alert.controller;
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.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;
@ -29,7 +29,7 @@ import java.util.List;
@Api(tags = {"告警处理"})
@RestController
@AllArgsConstructor
@RequestMapping("/alarm/handle")
@RequestMapping("/handle")
public class AlarmHandleController extends BladeController {
private final AlarmHandleService service;
@ -52,7 +52,7 @@ public class AlarmHandleController extends BladeController {
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "分页", notes = "传入AlarmHandleEntity")
@OperationAnnotation(moduleName = "告警配置", title = "告警配置记录", operatorType = OperatorType.MOBILE, businessType =
@OperationAnnotation(moduleName = "分页查询告警处理记录", title = "查询告警处理记录", operatorType = OperatorType.MOBILE, businessType =
BusinessType.GENCODE,
action = "分页")
public R<IPage<AlarmHandleVo>> list(HandleQueryVo param, Query query) {

2
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;

4
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.java

@ -1,6 +1,6 @@
package com.hnac.hzims.operational.alert.mapper;
package com.hnac.hzims.alarm.show.mapper;
import com.hnac.hzims.operational.alert.entity.AlarmHandleDetailEntity;
import com.hnac.hzims.alarm.entity.AlarmHandleDetailEntity;
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper;
/**

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleDetailMapper.xml → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleDetailMapper.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.operational.alert.mapper.AlarmHandleDetailMapper">
<mapper namespace="com.hnac.hzims.alarm.show.mapper.AlarmHandleDetailMapper">
</mapper>

10
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.java

@ -1,8 +1,8 @@
package com.hnac.hzims.operational.alert.mapper;
package com.hnac.hzims.alarm.show.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.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;
@ -18,7 +18,7 @@ import java.util.List;
public interface AlarmHandleMapper extends UserDataScopeBaseMapper<AlarmHandleEntity> {
@UserDataAuth
IPage<AlarmHandleVo> selectHandlePage(IPage<Object> page,@Param("param") HandleQueryVo param);
IPage<AlarmHandleVo> selectHandlePage(IPage<Object> page, @Param("param") HandleQueryVo param);
List<AlarmHandleEntity> handles(@Param("types") List<Long> types,@Param("start") String start,@Param("end") String end);
List<String> handles(@Param("start") String start,@Param("end") String end);
}

51
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/mapper/AlarmHandleMapper.xml

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.alarm.show.mapper.AlarmHandleMapper">
<select id="selectHandlePage" resultType="com.hnac.hzims.alarm.vo.AlarmHandleVo">
SELECT H.*,HANDLE_USER,D.PHENOMENON_ID,D.ACCESS_ID,D.DELAY_TIME,D.DELAY_CAUSE,
D.FALSE_ALARM_DESC,D.FILE_PATH,S.NAME AS STATION_NAME,P.CHECK_PROCESS_INSTANCE_ID,A.PROCESS_INSTANCE_ID
FROM HZIMS_ALARM_HANDLE H
LEFT JOIN HZIMS_ALARM_HANDLE_DETAIL D
ON H.DETAIL_ID = D.ID
LEFT JOIN DEV_HZIMS_OPERATION.HZIMS_STATION S
ON H.STATION_CODE = S.CODE
LEFT JOIN DEV_HZIMS_OPERATION.HZIMS_OPER_PHENOMENON P
ON D.PHENOMENON_ID = P.ID
LEFT JOIN DEV_HZIMS_OPERATION.HZIMS_OPER_ACCESS_PLAN A
ON D.ACCESS_ID = A.ID
<where>
H.IS_DELETED = 0
<if test="param.stationCode != null">
AND H.STATION_CODE = #{param.stationCode}
</if>
<if test="param.handleUser != null">
AND H.CREATE_USER = #{param.handleUser}
</if>
<if test="param.startTime != null">
AND H.CREATE_TIME &gt;= #{param.startTime}
</if>
<if test="param.endTime != null">
AND H.CREATE_TIME &lt;= #{param.endTime}
</if>
<if test="param.handleWay != null">
AND H.HANDLE_WAY = #{param.handleWay}
</if>
</where>
order by create_time desc
</select>
<select id="handles" resultType="java.lang.String">
SELECT HANDLER.ALARM_ID
FROM HZIMS_ALARM_HANDLE HANDLER
LEFT JOIN HZIMS_ALARM_HANDLE_DETAIL DETAIL
ON HANDLER.DETAIL_ID = DETAIL.ID
<where>
HANDLER.IS_DELETED = 0
<if test="start != null and end != null">
AND HANDLER.CREATE_TIME BETWEEN #{start} AND #{end}
</if>
AND (DETAIL.DELAY_TIME &gt; #{end} OR DETAIL.DELAY_TIME IS NULL)
</where>
</select>
</mapper>

5
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleDetailService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleDetailService.java

@ -1,6 +1,7 @@
package com.hnac.hzims.operational.alert.service;
package com.hnac.hzims.alarm.show.service;
import com.hnac.hzims.operational.alert.entity.AlarmHandleDetailEntity;
import com.hnac.hzims.alarm.entity.AlarmHandleDetailEntity;
import org.springblade.core.mp.base.BaseService;
/**

8
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmHandleService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmHandleService.java

@ -1,8 +1,8 @@
package com.hnac.hzims.operational.alert.service;
package com.hnac.hzims.alarm.show.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.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;
@ -23,5 +23,5 @@ public interface AlarmHandleService extends BaseService<AlarmHandleEntity> {
List<User> handleUser();
List<AlarmHandleEntity> handles(List<Long> types,Integer alarmType);
List<String> handles();
}

8
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleDetailServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleDetailServiceImpl.java

@ -1,8 +1,8 @@
package com.hnac.hzims.operational.alert.service.impl;
package com.hnac.hzims.alarm.show.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 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;

42
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlarmHandleServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmHandleServiceImpl.java

@ -1,17 +1,17 @@
package com.hnac.hzims.operational.alert.service.impl;
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.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.alarm.constants.AlarmHandleConstant;
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;
@ -60,11 +60,11 @@ public class AlarmHandleServiceImpl extends BaseServiceImpl<AlarmHandleMapper, A
@Override
public boolean execute(AlarmHandleVo param) {
Long way = param.getHandleWay();
if (!AbnormalAlarmConstant.HANDLE_WAY.contains(way)) {
if (!AlarmHandleConstant.HANDLE_WAY.contains(way)) {
throw new ServiceException("无效处理!");
}
// 预警
if(AbnormalAlarmConstant.EARLY_WARNING.equals(param.getAlarmType())){
if(AlarmHandleConstant.EARLY_WARNING.equals(param.getAlarmType())){
this.updateFalultState(param);
}
// 详情
@ -99,7 +99,7 @@ public class AlarmHandleServiceImpl extends BaseServiceImpl<AlarmHandleMapper, A
UpdateFaultStateVo state = new UpdateFaultStateVo();
state.setStationId(param.getStationCode());
state.setFaultId(param.getAlarmId());
if(AbnormalAlarmConstant.HANDLE.contains(param.getHandleWay())){
if(AlarmHandleConstant.HANDLE.contains(param.getHandleWay())){
state.setConfidence(1f);
}else{
state.setConfidence(0f);
@ -134,30 +134,18 @@ public class AlarmHandleServiceImpl extends BaseServiceImpl<AlarmHandleMapper, A
*/
@Override
public List<User> handleUser() {
R<List<Dept>> result = sysClient.getDeptByCurrentUser();
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){
throw new ServiceException("查询告警处理人失败!");
}
List<User> users = new ArrayList<>();
result.getData().forEach(dept->{
users.addAll(userClient.userListByDeptAndChildrenWithAuth(dept.getId()).getData());
});
List<User> users = userClient.userListByDeptAndChildrenWithAuth(Long.valueOf(AuthUtil.getUser().getDeptId())).getData();
return users.stream().distinct().collect(Collectors.toList());
}
/**
* 查询处理告警记录
* @param types 告警类型
* @return
*/
@Override
public List<AlarmHandleEntity> handles(List<Long> 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);
}
public List<String> 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(types,start,end);
return this.baseMapper.handles(start,end);
}
}

31
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<AlarmMapper, AlarmEntity>
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<AlarmMapper, AlarmEntity>
wrapper.eq("ALARM_TYPE",alarm.getAlarmType());
}
// 处理告警过滤 :当天处理告警
List<String> 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<AlarmMapper, AlarmEntity>
if(CollectionUtil.isEmpty(effectives)){
return null;
}
List<AlarmEntity> alarms = this.list(Wrappers.<AlarmEntity>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<AlarmEntity> 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<String> handles = alarmHandleService.handles();
if(!CollectionUtil.isEmpty(handles)){
queryWrapper.lambda().notIn(AlarmEntity::getAlarmId,handles);
}
List<AlarmEntity> alarms = this.list(queryWrapper);
if(CollectionUtil.isEmpty(alarms)){
return null;
}

4
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/wrapper/HandleWrapper.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/wrapper/HandleWrapper.java

@ -1,6 +1,6 @@
package com.hnac.hzims.operational.alert.wrapper;
package com.hnac.hzims.alarm.show.wrapper;
import com.hnac.hzims.operational.alert.vo.AlarmHandleVo;
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;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.mapper;
package com.hnac.hzims.alarm.source.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnac.hzims.alarm.entity.AlarmHistoryEntity;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/mapper/AlarmHistoryMapper.xml → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/mapper/AlarmHistoryMapper.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.alarm.handle.mapper.AlarmHistoryMapper">
<mapper namespace="com.hnac.hzims.alarm.source.mapper.AlarmHistoryMapper">
</mapper>

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/AlarmHistoryService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/AlarmHistoryService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.service;
package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.entity.AlarmHistoryEntity;
import org.springblade.core.mp.base.BaseService;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/DroolsAlarmService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.service;
package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/FdpAlarmService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/FdpAlarmService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.service;
package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/LevelAlarmService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/LevelAlarmService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.service;
package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/MessageService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/MessageService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.service;
package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/SystemAlarmService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/SystemAlarmService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.service;
package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;

2
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/VideoAlarmService.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/VideoAlarmService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.alarm.handle.service;
package com.hnac.hzims.alarm.source.service;
import com.hnac.hzims.alarm.entity.AlarmEntity;

4
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/AlarmHistoryServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/AlarmHistoryServiceImpl.java

@ -1,7 +1,7 @@
package com.hnac.hzims.alarm.handle.service.impl;
package com.hnac.hzims.alarm.source.service.impl;
import com.hnac.hzims.alarm.entity.AlarmHistoryEntity;
import com.hnac.hzims.alarm.handle.mapper.AlarmHistoryMapper;
import com.hnac.hzims.alarm.source.mapper.AlarmHistoryMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseService;

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/DroolsAlarmServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java

@ -1,10 +1,10 @@
package com.hnac.hzims.alarm.handle.service.impl;
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.handle.service.DroolsAlarmService;
import com.hnac.hzims.alarm.handle.service.MessageService;
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;

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/FdpAlarmServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/FdpAlarmServiceImpl.java

@ -1,10 +1,10 @@
package com.hnac.hzims.alarm.handle.service.impl;
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.handle.service.FdpAlarmService;
import com.hnac.hzims.alarm.handle.service.MessageService;
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;

6
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/LevelAlarmServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/LevelAlarmServiceImpl.java

@ -1,11 +1,11 @@
package com.hnac.hzims.alarm.handle.service.impl;
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.handle.service.LevelAlarmService;
import com.hnac.hzims.alarm.handle.service.MessageService;
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;

4
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/MessageServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java

@ -1,9 +1,9 @@
package com.hnac.hzims.alarm.handle.service.impl;
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.handle.service.MessageService;
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;

10
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/SystemAlarmServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/SystemAlarmServiceImpl.java

@ -1,15 +1,15 @@
package com.hnac.hzims.alarm.handle.service.impl;
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.handle.service.MessageService;
import com.hnac.hzims.alarm.handle.service.SystemAlarmService;
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.operational.alert.constants.AbnormalAlarmConstant;
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;
@ -61,7 +61,7 @@ public class SystemAlarmServiceImpl implements SystemAlarmService {
List<StationEntity> stations = listAll.getData();
Map<String, String> map = new ConcurrentHashMap<>();
map.put("stations", stations.stream().map(StationEntity::getCode).collect(Collectors.joining(",")));
map.put("soe_type", AbnormalAlarmConstant.SYSTEM_TYPE_LIST);
map.put("soe_type", AlarmHandleConstant.SYSTEM_TYPE_LIST);
return JSONObject.toJSONString(map);
}

8
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/handle/service/impl/VideoAlarmServiceImpl.java → hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/VideoAlarmServiceImpl.java

@ -1,15 +1,15 @@
package com.hnac.hzims.alarm.handle.service.impl;
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.handle.service.VideoAlarmService;
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.operational.alert.constants.AbnormalAlarmConstant;
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;
@ -105,7 +105,7 @@ public class VideoAlarmServiceImpl implements VideoAlarmService {
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.setAlarmType(AlarmHandleConstant.VIDEO_ALARM);
entity.setAlarmStatus(Integer.valueOf(item.getSoeStatus()));
entity.setRealId(item.getRealId());
entity.setStationId(item.getStation());

2
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;

2
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;

2
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;

182
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/AlertWebSocketClient.java

@ -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<User> 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<PushAudienceType, List<String>> 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<AlertVo> 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"));
}
}

44
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/WebSocketClientManager.java

@ -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());
}
}
}
}

157
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/AbnormalAlarmController.java

@ -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<IPage<HistoryAbnormalAlarmVo>> statisticsTime(HistoryAlarmVo entity, Query query) {
IPage<HistoryAbnormalAlarmVo> 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<IPage<HistoryAbnormalAlarmVo>> queryByEntity(HistoryAlarmVo entity, Query query) {
IPage<HistoryAbnormalAlarmVo> pages = service.queryByEntity(entity,query);
return R.data(pages);
}
@ApiLog
@GetMapping("/queryStationName")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "查询站点")
public R<List<String>> queryStationName() {
List<String> 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<HistoryAbnormalAlarmEntity> 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<IPage<HistoryAbnormalAlarmEntity>> list(HistoryAbnormalAlarmEntity entity, Query query) {
IPage<HistoryAbnormalAlarmEntity> 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<AlarmReustVo> 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<List<IntelligentAlarmCountVo>> count(){
return R.data(service.alarmCount());
}
/**
* 智能告警数据: 时间范围当天
*/
@ApiLog
@ApiOperation(value = "智能告警数据")
@ApiOperationSupport(order = 9)
@RequestMapping(value = "/data", method = RequestMethod.GET)
public R<IPage<AlarmVo>> data(AlarmDataPageVo page,Query query) {
return R.data(service.alarmData(page,query));
}
}

67
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/controller/LevelAlarmController.java

@ -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<IPage<HistoryLevelAlarmEntity>> list(HistoryLevelAlarmEntity entity, Query query) {
IPage<HistoryLevelAlarmEntity> 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<List<IntelligentAlarmCountVo>> count(){
return R.data(service.alarmCount());
}
}

17
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.java

@ -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> {
AbnormalAlarmEntity getAbnormalAlarm(@Param("stationId") String stationId,@Param("type") String type);
List<String> getAbnormalAlarmList();
}

17
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AbnormalAlarmMapper.xml

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.operational.alert.mapper.AbnormalAlarmMapper">
<select id="getAbnormalAlarm" resultType="com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity">
select * from hzims_abnormal_alarm
where station_id = #{stationId}
and type = #{type}
and is_deleted = 0
</select>
<select id="getAbnormalAlarmList" resultType="java.lang.String">
select distinct station_id from hzims_abnormal_alarm
where is_deleted = 0
and type in (13,14)
and `STATUS` = 0
</select>
</mapper>

57
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlarmHandleMapper.xml

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.operational.alert.mapper.AlarmHandleMapper">
<select id="selectHandlePage" resultType="com.hnac.hzims.operational.alert.vo.AlarmHandleVo">
select h.*,handle_user,d.phenomenon_id,d.access_id,d.delay_time,d.delay_cause,
d.false_alarm_desc,d.file_path,s.name as station_name,p.check_process_instance_id,a.process_instance_id
from hzims_alarm_handle h
left join hzims_alarm_handle_detail d
on h.detail_id = d.id
left join hzims_station s
on h.station_code = s.code
left join hzims_oper_phenomenon p
on d.PHENOMENON_ID = p.id
left join hzims_oper_access_plan a
on d.access_id = a.id
<where>
h.is_deleted = 0
<if test="param.stationCode != null">
and h.station_code = #{param.stationCode}
</if>
<if test="param.handleUser != null">
and h.create_user = #{param.handleUser}
</if>
<if test="param.startTime != null">
and h.create_time &gt;= #{param.startTime}
</if>
<if test="param.endTime != null">
and h.create_time &lt;= #{param.endTime}
</if>
<if test="param.handleWay != null">
and h.handle_way = #{param.handleWay}
</if>
</where>
order by create_time desc
</select>
<select id="handles" resultType="com.hnac.hzims.operational.alert.entity.AlarmHandleEntity">
select handler.*
from hzims_alarm_handle handler
left join hzims_alarm_handle_detail detail
on handler.detail_id = detail.id
<where>
handler.is_deleted = 0
<if test="types != null and types.size > 0">
and alarm_type in
<foreach collection="types" item="type" index="index" open="(" close=")" separator=",">
#{type}
</foreach>
</if>
<if test="start != null and end != null">
and handler.create_time between #{start} and #{end}
</if>
and (detail.DELAY_TIME &gt; #{end} or detail.DELAY_TIME is null)
</where>
</select>
</mapper>

13
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.java

@ -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<AlertDefectConfigEntity> getConfigAll();
}

8
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/AlertDefectConfigMapper.xml

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.operational.alert.mapper.AlertDefectConfigMapper">
<select id="getConfigAll" resultType="com.hnac.hzims.operational.alert.entity.AlertDefectConfigEntity">
select * from hzims_alert_defect_config
</select>
</mapper>

26
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.java

@ -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<HistoryAbnormalAlarmEntity> {
List<HistoryAbnormalAlarmEntity> getHistoryAbnormalAlarm(@Param("stationId") String stationId,@Param("type") String type);
List<HistoryAbnormalAlarmVo> selectPageList(IPage<HistoryAbnormalAlarmVo> page, String type, List<String> stations);
List<HistoryAbnormalAlarmEntity> getAlarmEntity(@Param("type") String type,@Param("stationName") List<String> stationName,@Param("startTime") Date startTime,@Param("endTime") Date endTime);
List<String> getStationName();
}

49
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryAbnormalAlarmMapper.xml

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.operational.alert.mapper.HistoryAbnormalAlarmMapper">
<select id="getHistoryAbnormalAlarm" resultType="com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity">
select * from hzims_history_abnormal_alarm
where station_id = #{stationId}
and type = #{type}
and status = 0
</select>
<select id="selectPageList" resultType="com.hnac.hzims.operational.station.vo.HistoryAbnormalAlarmVo">
select * from hzims_history_abnormal_alarm
where status = 0
<if test="type != null and type != ''">
and type = #{type}
</if>
<if test="stations != null">
and station_id in
<foreach collection="stations" item="item" open="(" close=")" separator="," >
#{item}
</foreach>
</if>
</select>
<select id="getStationName" resultType="java.lang.String">
select distinct STATION_NAME from hzims_history_abnormal_alarm
</select>
<select id="getAlarmEntity" resultType="com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity">
select * from hzims_history_abnormal_alarm
where is_deleted = 0
<if test="type != null and type != ''">
and type = #{type}
</if>
<if test="stationName != null">
and station_name in
<foreach collection="stationName" item="item" open="(" close=")" separator="," >
#{item}
</foreach>
</if>
<if test="startTime != null">
and start_time &gt; #{startTime}
</if>
<if test="endTime != null">
and end_time &lt;= #{endTime}
</if>
</select>
</mapper>

11
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.java

@ -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<HistoryLevelAlarmEntity> {
}

6
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/mapper/HistoryLevelAlarmMapper.xml

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.operational.alert.mapper.HistoryLevelAlarmMapper">
</mapper>

17
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AbnormalAlarmService.java

@ -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<AbnormalAlarmEntity> {
void alarmDataHandle(String param);
List<String> getAbnormalAlarmList();
}

15
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlarmMergeService.java

@ -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);
}

13
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/AlertDefectService.java

@ -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<AlertVo> list);
}

40
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryAbnormalAlarmService.java

@ -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> {
HistoryAbnormalAlarmEntity getAbnormalAlarm(String station, String soeType);
IPage<HistoryAbnormalAlarmVo> list(IPage<HistoryAbnormalAlarmVo> page, String type);
IPage<HistoryAbnormalAlarmVo> getAlarmTime(Query query, HistoryAlarmVo entity);
IPage<HistoryAbnormalAlarmVo> queryByEntity(HistoryAlarmVo entity,Query query);
AlarmReustVo alarms(AlarmParamVo param);
// 智能告警数量: 时间范围当天
List<IntelligentAlarmCountVo> alarmCount();
// 告警数据:时间范围-当天
IPage<AlarmVo> alarmData(AlarmDataPageVo page,Query query);
List<String> queryStationName();
}

21
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/HistoryLevelAlarmService.java

@ -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<HistoryLevelAlarmEntity> {
IPage<HistoryLevelAlarmEntity> pageCondition(Query query, HistoryLevelAlarmEntity entity);
List<IntelligentAlarmCountVo> alarmCount();
}

12
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/LevelAlarmService.java

@ -1,12 +0,0 @@
package com.hnac.hzims.operational.alert.service;
/**
* 告警处理接口
* @author ysj
*/
public interface LevelAlarmService {
String sendMessage();
void receiveMessage(String message);
}

268
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java

@ -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<AbnormalAlarmMapper, AbnormalAlarmEntity> 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<StationEntity> 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<HzPage<SoeData>> result = soeClient.getByStationsAndTime(query);
// 未查询到告警信息
if(!result.isSuccess() || ObjectUtil.isEmpty(result.getData()) || CollectionUtil.isEmpty(result.getData().getRecords())) {
return;
}
List<SoeData> soes = result.getData().getRecords();
// 过滤已经当天存储得告警数据
List<HistoryAbnormalAlarmEntity> history = historyAbnormalAlarmService.list(Wrappers.<HistoryAbnormalAlarmEntity>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<StationEntity> 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<StationEntity> stations, List<SoeData> list) {
List<HistoryAbnormalAlarmEntity> historys = historyAbnormalAlarmService.list(Wrappers.<HistoryAbnormalAlarmEntity>lambdaQuery()
.in(HistoryAbnormalAlarmEntity::getAlarmId,list.stream().map(SoeData::getId).collect(Collectors.toList()))
);
List<String> 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<StationEntity> stations,String stationName) {
if(StringUtil.isEmpty(entity.getStationId())){
return;
}
List<Long> depts = stations.stream().filter(station -> station.getCode().equals(entity.getStationId())).map(StationEntity::getRefDept).collect(Collectors.toList());
if(CollectionUtil.isEmpty(depts)){
return;
}
List<User> 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<String> 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<User> parentAuthUser(Long deptId) {
List<User> users = new ArrayList<>();
R<List<User>> selfs = userClient.userListByDeptId(deptId);
if(selfs.isSuccess() && CollectionUtil.isNotEmpty(selfs.getData())){
users.addAll(selfs.getData());
}
R<Dept> dept = sysClient.getDept(deptId);
if(dept.isSuccess() && ObjectUtil.isNotEmpty(dept.getData())){
R<List<User>> parents = userClient.userByDeptId("200000",dept.getData().getParentId());
if(parents.isSuccess() && CollectionUtil.isNotEmpty(parents.getData())){
users.addAll(parents.getData());
}
}
return users;
}
/**
* 查询实时告警数据
* @return
*/
@Override
public List<String> getAbnormalAlarmList() {
List<String> alarmList = this.baseMapper.getAbnormalAlarmList();
if(CollectionUtil.isEmpty(alarmList)){
return new ArrayList<>();
}
return alarmList;
}
}

133
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertDefectServiceImpl.java

@ -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<AlertVo> list) {
if(!isOpen){
return;
}
// 查询保存告警类型配置
List<AlertDefectConfigEntity> configAll = this.defectConfigMapper.getConfigAll();
if(CollectionUtil.isEmpty(configAll)){
return;
}
List<Integer> saveAlertType = configAll.stream().filter(o->o.getIsOpen().equals(1)).map(AlertDefectConfigEntity::getAlertType).collect(Collectors.toList());
if(CollectionUtil.isEmpty(saveAlertType)){
return;
}
// 所有设备信息
List<EminfoAndEmParamVo> 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<EminfoAndEmParamVo> devices, String realid) {
if(CollectionUtil.isEmpty(devices) || StringUtil.isBlank(realid)){
return null;
}
// 遍历设备监测点
for(EminfoAndEmParamVo device : devices){
Map<String,String> map = device.getPoint();
if(MapUtils.isEmpty(map)){
continue;
}
if(map.containsKey(realid)){
return device;
}
}
return null;
}
}

125
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AlertMerageServiceImpl.java

@ -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<Long> depts = param.getDeptIds();
if(CollectionUtil.isEmpty(depts)){
return null;
}
// 查询站点
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>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<HistoryAbnormalAlarmEntity> faults = faultAlarmService.list(Wrappers.<HistoryAbnormalAlarmEntity>lambdaQuery()
.in(HistoryAbnormalAlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList()))
.eq(HistoryAbnormalAlarmEntity::getType, AbnormalAlarmConstant.FAULT)
.between(HistoryAbnormalAlarmEntity::getStartTime,start,end)
);
// 处理告警记录
List<AlarmHandleEntity> handles = alarmHandleService.handles(AbnormalAlarmConstant.LONG_TYPE_LIST,null);
List<AlarmMergeVo> 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<HistoryLevelAlarmEntity> levels = levelAlarmService.list(Wrappers.<HistoryLevelAlarmEntity>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())));
}
}

433
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java

@ -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<HistoryAbnormalAlarmMapper, HistoryAbnormalAlarmEntity> 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<HistoryAbnormalAlarmEntity> 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<HistoryAbnormalAlarmVo> list(IPage<HistoryAbnormalAlarmVo> page, String type) {
List<StationEntity> stations = stationService.getStationByType(HomePageConstant.HYDROPOWER, HomePageConstant.HYDROPOWER_SERVETYPE);
if (CollectionUtil.isEmpty(stations)) {
return null;
}
List<HistoryAbnormalAlarmVo> 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<HistoryAbnormalAlarmVo> getAlarmTime(Query query, HistoryAlarmVo entity) {
QueryWrapper<HistoryAbnormalAlarmEntity> alarmEntityQueryWrapper = getAlarmEntityQueryWrapper(entity);
List<HistoryAbnormalAlarmEntity> historyAbnormalAlarmEntity = this.baseMapper.selectList(alarmEntityQueryWrapper);
if (historyAbnormalAlarmEntity == null) {
return null;
}
List<HistoryAbnormalAlarmVo> 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<HistoryAbnormalAlarmVo> voList = historyAbnormalAlarmVos.parallelStream().peek(s -> s.setTimes((s.getEndTime().getTime() - s.getStartTime().getTime()))).collect(Collectors.toList());
//次数统计
Map<String, Long> timesList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName,
Collectors.counting()));
//时间统计
Map<String, Long> durationList = voList.stream().collect(Collectors.groupingBy(HistoryAbnormalAlarmEntity::getStationName,
Collectors.summingLong(HistoryAbnormalAlarmVo::getTimes)));
List<HistoryAbnormalAlarmVo> res = new ArrayList<>();
for (Map.Entry<String, Long> 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<HistoryAbnormalAlarmVo> 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<HistoryAbnormalAlarmEntity> getAlarmEntityQueryWrapper(HistoryAlarmVo entity) {
QueryWrapper<HistoryAbnormalAlarmEntity> 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<HistoryAbnormalAlarmVo> queryByEntity(HistoryAlarmVo entity, Query query) {
QueryWrapper<HistoryAbnormalAlarmEntity> alarmEntityQueryWrapper = getAlarmEntityQueryWrapper(entity);
IPage<HistoryAbnormalAlarmEntity> historyAbnormalAlarmEntityIPage = this.baseMapper.selectPage(Condition.getPage(query), alarmEntityQueryWrapper);
List<HistoryAbnormalAlarmEntity> records = historyAbnormalAlarmEntityIPage.getRecords();
List<HistoryAbnormalAlarmVo> voList =new ArrayList<>();
if (records.size()>0) {
List<HistoryAbnormalAlarmVo> 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<HistoryAbnormalAlarmVo> page = Condition.getPage(query);
page.setTotal(historyAbnormalAlarmEntityIPage.getTotal());
page.setRecords(voList);
return page;
}
/**
* 告警优化
* @param param
* @return
*/
@Override
public AlarmReustVo alarms(AlarmParamVo param) {
// 查询用户权限机构
R<List<Dept>> result = sysClient.getDeptByCurrentUser();
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){
return new AlarmReustVo();
}
// 查询站点
LambdaQueryWrapper<StationEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE);
wrapper.in(StationEntity::getRefDept,result.getData().stream().map(Dept::getId).collect(Collectors.toList()));
List<StationEntity> 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<String> types = Arrays.asList(param.getType().split(","));
condition.setTypes(types);
Result<HzPage<SoeData>> soe = alarmClient.getByStationsAndTime(condition);
if(!soe.isSuccess() || ObjectUtil.isEmpty(soe.getData()) || CollectionUtil.isEmpty(soe.getData().getRecords())){
return new AlarmReustVo();
}
// 查询当天类型处理告警
List<AlarmHandleEntity> handles = handleService.handles(types.stream().map(Long::parseLong).collect(Collectors.toList()),AbnormalAlarmConstant.SYSTEM_ALARM);
// 返回数据
AlarmReustVo response = new AlarmReustVo();
List<AlarmDataVo> 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<StationEntity> 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<String> getAlarmHandleIds() {
List<AlarmHandleEntity> handles = handleService.list();
if(CollectionUtil.isEmpty(handles)){
return null;
}
return handles.stream().map(AlarmHandleEntity::getAlarmId).collect(Collectors.toList());
}
/**
* 告警数量:时间范围-当天
* @return
*/
@Override
public List<IntelligentAlarmCountVo> alarmCount() {
// 查询用户权限机构
R<List<Dept>> result = sysClient.getDeptByCurrentUser();
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){
return new ArrayList<>();
}
// 步骤1.查询用户权限站点
LambdaQueryWrapper<StationEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE);
wrapper.in(StationEntity::getRefDept,result.getData().stream().map(Dept::getId).collect(Collectors.toList()));
List<StationEntity> 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<HzPage<SoeData>> 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<AlarmVo> alarmData(AlarmDataPageVo param,Query query) {
// 步骤1.查询用户权限站点
LambdaQueryWrapper<StationEntity> wappers = Wrappers.lambdaQuery();
if(StringUtils.isNotEmpty(param.getCode())){
wappers.eq(StationEntity::getCode,param.getCode());
}
List<StationEntity> stations = stationService.list(wappers);
// 步骤2.查询告警数据
List<String> 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<HzPage<SoeData>> result = alarmClient.getByStationsAndTime(condition);
IPage<AlarmVo> page = Condition.getPage(query);
if(result.isSuccess() && ObjectUtil.isNotEmpty(result)){
// 步骤3.过滤完成告警处理数据
List<AlarmVo> 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<String> 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<String> 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;
}
}

122
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryLevelAlarmServiceImpl.java

@ -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<HistoryLevelAlarmMapper, HistoryLevelAlarmEntity> implements HistoryLevelAlarmService {
private final IStationService stationService;
private final AlarmHandleService handleService;
/**
* 列表查询
* @param query
* @param entity
* @return
*/
@Override
public IPage<HistoryLevelAlarmEntity> pageCondition(Query query, HistoryLevelAlarmEntity entity) {
LambdaQueryWrapper<HistoryLevelAlarmEntity> 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<StationEntity> stations = stationService.list();
if(CollectionUtil.isNotEmpty(stations)){
wrapper.in(HistoryLevelAlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList()));
}
}
IPage<HistoryLevelAlarmEntity> page = super.page(Condition.getPage(query), wrapper);
List<HistoryLevelAlarmEntity> records = page.getRecords();
// 步骤2. 过滤已处理等級告警
List<AlarmHandleEntity> 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<IntelligentAlarmCountVo> alarmCount() {
// 步骤1.查询用户权限站点
List<StationEntity> stations = stationService.list();
if(CollectionUtil.isEmpty(stations)){
return null;
}
// 步骤2. 过滤已处理等級告警
LambdaQueryWrapper<AlarmHandleEntity> 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<AlarmHandleEntity> handles = handleService.list();
// 步骤2.查询告警数据
LambdaQueryWrapper<HistoryLevelAlarmEntity> 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<HistoryLevelAlarmEntity> 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());
}
}

237
hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java

@ -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<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery()
.eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE));
if(CollectionUtil.isEmpty(stations)){
throw new ServiceException("level send message is null");
}
Map<String,String> 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<LevelAlarmVo> alarms = JSONObject.parseArray(message,LevelAlarmVo.class);
if(CollectionUtil.isEmpty(alarms)){
return;
}
// 站点
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery()
.eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE));
if(CollectionUtil.isEmpty(stations)){
throw new ServiceException("level send message is null");
}
// 设备
List<EmInfoEntity> devices = deviceClient.list();
// 查询当天已经记录的告警
List<HistoryLevelAlarmEntity> historys = historyLevelAlarmService.list(Wrappers.<HistoryLevelAlarmEntity>lambdaQuery()
.ge(HistoryLevelAlarmEntity::getCreateTime,DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00")
);
// 数据过滤
List<HistoryLevelAlarmEntity> entitys = alarms.stream().filter(alarm -> CollectionUtil.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<EmInfoEntity> alarmDevices = devices.stream().filter(device->device.getNumber().equals(item.getDevicecode())).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(alarmDevices)){
// 找到站点
List<StationEntity> alarmStations = stations.stream().filter(station->station.getRefDept().equals(alarmDevices.get(0).getCreateDept())).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(alarmStations)){
entity.setStationId(alarmStations.get(0).getCode());
entity.setStationName(alarmStations.get(0).getName());
}
}
}
return entity;
}).collect(Collectors.toList());
if(CollectionUtil.isEmpty(entitys)){
return;
}
// 批量保存
historyLevelAlarmService.saveBatch(entitys);
// 消息推送
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<HistoryLevelAlarmEntity> entitys,List<StationEntity> stations) {
if(CollectionUtil.isEmpty(entitys)){
return;
}
// 告警等级 :一级、二级告警发送通知
List<HistoryLevelAlarmEntity> 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<Long> 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<List<User>> 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<String> 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<List<User>> 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<String> 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);
});
}
}

8
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();
}

9
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

38
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/HistoryAbnormalAlarmController.java

@ -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<IPage<HistoryAbnormalAlarmVo>> getStationMonitor(@RequestParam(value = "type",required = false) String type, Query query) {
return R.data(historyAbnormalAlarmService.list(Condition.getPage(query), type));
}
}

9
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<List<FaultVo>> getFaultList(@ApiParam(value = "站点编码") @RequestParam(required = false) String code) {
return R.data(stAlamRecordService.getFaultList(code));
}
/**
* 分页 获取告警记录列表

110
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/scheduled/StAlamRecordTask.java

@ -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<String>
*/
@XxlJob(STATION_DATA_COUNT)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> 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<String>
*/
@XxlJob(REAL_ID_DATA)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> 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<String>
*/
@XxlJob(REAL_TIME_DATA)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> 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<String>
*/
@XxlJob(CENTRALIZED_MONITORING)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> 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<String>
*/
@XxlJob(ALARM_DATA_HANDLE)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> alarmDataHandle(String param) throws Exception {
if (Func.isBlank(param)) {
param = DateUtil.format(new Date(), "yyyy-MM");
}
abnormalAlarmService.alarmDataHandle(param);
return new ReturnT<>("SUCCESS");
}
}

8
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<StAlarmRecordEntity> {
Long insertAlert(String stationId,String realId);
List<AnalyzeCodeBySignagesVO> getJointRelayInfo();
/**
* 获取故障列表
*
* @return
*/
List<FaultVo> getFaultList(String code);
}

46
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<StAlarmRecordMapper
private final IStationService stationService;
private final AlarmHandleService handleService;
private final ISoeClient soeClient;
private final RedisTemplate redisTemplate;
@ -723,39 +718,6 @@ public class StAlamRecordServiceImpl extends BaseServiceImpl<StAlarmRecordMapper
}
/**
* 获取故障列表
*
* @return
*/
@Override
public List<FaultVo> getFaultList(String code) {
List<StationEntity> 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<FaultVo> list = JSONArray.parseArray(result,FaultVo.class);
if(CollectionUtil.isEmpty(list)){
return null;
}
// 过滤已处理预警信息
List<AlarmHandleEntity> handles = handleService.handles(Collections.singletonList(AbnormalAlarmConstant.EARLY_WARNING),AbnormalAlarmConstant.INTELLIGENCE_ALARM);
Map<String,String> 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

79
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmHandler.java

@ -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);
}
}

58
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/AlarmSessionManager.java

@ -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<String, WebSocketSession> 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);
}
}

51
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java

@ -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());
}
}
}

125
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmWebSocket.java

@ -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;
}
}

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/SocketPool.java

@ -10,6 +10,4 @@ public class SocketPool {
public static Map<String, MessageHandler> pool = new ConcurrentHashMap<>();
public static Map<String, AlarmHandler> alarm_pool = new ConcurrentHashMap<>();
}

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/mapper/ImsDutyGroupPMapper.xml

@ -160,7 +160,7 @@
</where>
</select>
<select id="member" resultType="com.hnac.hzims.operational.duty.vo.DutyMemberVO">
SELECT PERSION_ID
SELECT PERSON_ID
FROM HZ_IMS_DUTY_GROUP_P
WHERE GROUP_ID = #{groupId}
</select>

16
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);
/**
* 获取发送前端文本消息

630
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<EminfoAndEmParamVo> devices = systemMonitoringService.getEmInfoList();
// 设备开关机集合监测点
List<String> switchOnOff = devices.stream().map(o->{
Map<String,String> 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<StationRealVo> stationRealVos = (List<StationRealVo>) redisTemplate.opsForValue().get(moniter_realId_key);
if(CollectionUtil.isEmpty(stationRealVos)){
return;
}
// 数据切割
int limit = countStep(stationRealVos.size());
List<List<StationRealVo>> 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);
// <real,value>
Map<String,String> valueMap = new ConcurrentHashMap<>();
// <real,<attribute,value>>
Map<String,Map<String,String>> keyMap = new ConcurrentHashMap<>();
CountDownLatch countDownLatch = new CountDownLatch(limit);
pool.execute(()-> list.forEach(stations -> {
stations.forEach(stationReal -> {
String[] realIdArr = stationReal.getRealId();
List<String> realIds = Stream.of(realIdArr).collect(Collectors.toList());
if(CollectionUtil.isEmpty(realIds)){
return;
}
log.error("real_time_data: {},{}",stationReal.getStation(),realIds);
List<String> 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<String,String> attribute = (Map<String, String>) 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<String, String> map = JSONObject.parseObject(json.toString(), new TypeReference<Map<String, String>>() {
});
if(MapUtils.isEmpty(map)){
return;
}
// 站点实时功率 key - stationCode,value - sumPower
Map<String,Double> realPowerMap = this.getPowerConversionMap(map);
if(MapUtils.isNotEmpty(realPowerMap)){
redisTemplate.opsForValue().set(active_power_key, realPowerMap);
}
// 站点开关机状态
List<EminfoAndEmParamVo> devices = systemMonitoringService.getEmInfoList();
if(CollectionUtil.isEmpty(devices)){
return;
}
// key->机构编号 value -> 设备集合
Map<Long,List<EminfoAndEmParamVo>> deviceMap = devices.stream().collect(Collectors.groupingBy(EminfoAndEmParamVo::getCreateDept));
Map<Long, JointRelayVo> data = new HashMap<>();
deviceMap.forEach((key, value) -> {
JointRelayVo jointRelay = new JointRelayVo();
List<String> 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<List<String>> off = Optional.ofNullable(relays.stream().filter("0"::equals).collect(Collectors.toList()));
jointRelay.setShutdownCount(off.map(List::size).orElse(0));
Optional<List<String>> 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<String, Map<String, String>> map = JSONObject.parseObject(json.toString(), new TypeReference<Map<String, Map<String, String>>>() {
});
if (MapUtils.isEmpty(map)) {
return;
}
log.info(thread.getName() + "步骤1获取检测点数据耗时 : {}",System.currentTimeMillis() - beginTime);
beginTime = System.currentTimeMillis();
// 获取所有设备重点属性
List<StationAttributeEntity> list = attbtService.list(new LambdaQueryWrapper<StationAttributeEntity>() {{
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<StAlarmRecordEntity> alertList = alertService.list(new LambdaQueryWrapper<StAlarmRecordEntity>() {{
orderByDesc(StAlarmRecordEntity::getCreateTime);
}});
log.info(thread.getName() + "步骤3获取告警记录 耗时 : {}",System.currentTimeMillis() - beginTime);
beginTime = System.currentTimeMillis();
List<String> alarmList = abnormalAlarmService.getAbnormalAlarmList();
log.info(thread.getName() + "步骤4获取数据中断告警记录 耗时 : {}",System.currentTimeMillis() - beginTime);
beginTime = System.currentTimeMillis();
// 获取所有故障记录
List<FdpFaultStatusVo> faultList = this.getFdpFaultAll();
log.info(thread.getName() + "步骤5获取故障记录 耗时 : {}",System.currentTimeMillis() - beginTime);
beginTime = System.currentTimeMillis();
// 所有设备分类
Map<String, List<String>> deviceClassifyMap = (Map<String, List<String>>) redisTemplate.opsForValue().get(device_classify_key);
log.info(thread.getName() + "步骤6获取设备分类 耗时 : {}",System.currentTimeMillis() - beginTime);
beginTime = System.currentTimeMillis();
// 所有设备
List<EminfoAndEmParamVo> emList = maintenanceTaskService.getEmInfoList();
log.info(thread.getName() + "步骤7获取设备信息 耗时 : {}",System.currentTimeMillis() - beginTime);
beginTime = System.currentTimeMillis();
// 根据站点分组
Map<String, List<StationAttributeEntity>> stationAttbtMap = list.stream().collect(Collectors.groupingBy(StationAttributeEntity::getStationId));
// 获取站点列表
List<StationEntity> stationEntityList = stationService.getStationByInCode(new ArrayList<>(stationAttbtMap.keySet()));
log.info(thread.getName() + "步骤8站点列表 耗时 : {}",System.currentTimeMillis() - beginTime);
beginTime = System.currentTimeMillis();
// 隐藏设备列表
List<String> hideList = stationAttrConfigService.getHideList();
// 分割,每个map限制10个长度
List<Map<String, List<StationAttributeEntity>>> 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<List<Dept>> deptAll = sysClient. getDeptList();
// 存储数据节点
List<RealStationVo> stationList = new CopyOnWriteArrayList<>();
pool.execute(()->{
// 线程处理数据
for(Map<String, List<StationAttributeEntity>> item : handleList){
item.forEach((key,value)->{
RealStationVo station = new RealStationVo();
// 站点编码
station.setStationCode(key);
// 名称、限制水位、服务类型、机构、排序
this.stationParam(stationEntityList,station,deptAll.getData());
// 根据设备名称分组
Map<String, List<StationAttributeEntity>> deviceAttbtMap = value.stream().filter(o -> !hideList.contains(o.getEmName())).collect(Collectors.groupingBy(StationAttributeEntity::getEmName));
List<RealDeviceVo> 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<RealDeviceVo> deviceList) {
deviceList.forEach(device->{
// 设备属性列表
List<RealAttributeVo> attbts = device.getAttbtList();
if(CollectionUtil.isEmpty(attbts)){
return;
}
// 功率属性记录
List<RealAttributeVo> 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<String> alarmList, RealStationVo station, String key,List<RealDeviceVo> deviceList) {
station.setStatus(0);
// 站点功率大于0为正常上送数据
double powerSum = deviceList.stream().mapToDouble(o->{
List<RealAttributeVo> attbts = o.getAttbtList();
if(CollectionUtil.isEmpty(attbts)){
return 0;
}
// 功率属性记录
List<RealAttributeVo> 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 <k>
* @param <v>
* @param chunkMap
* @return
*/
private <k, v> List<Map<k, v>> mapChunk(Map<k, v> chunkMap) {
if (chunkMap == null || RealMonitorServiceImpl.MAX_SEND <= 0) {
List<Map<k, v>> list = new ArrayList<>();
list.add(chunkMap);
return list;
}
Set<k> keySet = chunkMap.keySet();
Iterator<k> iterator = keySet.iterator();
int i = 1;
List<Map<k, v>> total = new ArrayList<>();
Map<k, v> 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<FdpFaultStatusVo> getFdpFaultAll() {
Object json = redisTemplate.opsForValue().get(fdp_fault_data_key);
if (ObjectUtil.isEmpty(json)) {
return new ArrayList<>();
}
return (List<FdpFaultStatusVo>) json;
}
/**
* 设备处理
*
* @param list
* @param map
* @param device
*/
private void handleDevice(List<StationAttributeEntity> list, Map<String, Map<String, String>> map,
RealDeviceVo device, List<StAlarmRecordEntity> alertList,
List<FdpFaultStatusVo> faultList) {
if (CollectionUtil.isEmpty(list) || MapUtils.isEmpty(map)) {
return;
}
List<RealAttributeVo> attbtList = new ArrayList<>();
list.forEach(item -> {
RealAttributeVo realAttributeVo = new RealAttributeVo();
// 设备重点属性处理 : 单条-item
Map<String, String> 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<EminfoAndEmParamVo> emList, Map<String, List<String>> deviceClassifyMap, List<RealDeviceVo> deviceList) {
if (CollectionUtil.isEmpty(emList) || CollectionUtil.isEmpty(deviceList) || MapUtils.isEmpty(deviceClassifyMap)) {
return;
}
List<String> faultList = deviceClassifyMap.get(HomePageConstant.FAULT);
List<String> maintaintList = deviceClassifyMap.get(HomePageConstant.MAINTAIN);
List<String> overhaultList = deviceClassifyMap.get(HomePageConstant.OVERHAUL);
List<String> runtList = deviceClassifyMap.get(HomePageConstant.RUN);
List<String> sparetList = deviceClassifyMap.get(HomePageConstant.SPARE);
deviceList.forEach(device -> {
if (StringUtil.isBlank(device.getDeviceCode())) {
device.setState(-1);
return;
}
List<EminfoAndEmParamVo> 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<String, String> real,
List<StAlarmRecordEntity> alertList, List<FdpFaultStatusVo> 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<String, String> 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<StAlarmRecordEntity> 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<StAlarmRecordEntity> handleList = alertList.stream().filter(o -> o.getStationId().equals(item.getStationId()) && o.getRealId().equals(attest.getRealId()) && o.getStatus() == 1).collect(Collectors.toList());
//查询出来未处理告警记录
List<StAlarmRecordEntity> 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<FdpFaultStatusVo> faultList, String value) {
if (CollectionUtil.isEmpty(faultList) || "-".equals(value)) {
return;
}
List<FdpFaultStatusVo> 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

Loading…
Cancel
Save