yang_shj
11 months ago
109 changed files with 1484 additions and 4702 deletions
@ -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; |
@ -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; |
@ -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; |
@ -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; |
||||
|
||||
/** |
@ -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> |
@ -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 >= #{param.startTime} |
||||
</if> |
||||
<if test="param.endTime != null"> |
||||
AND H.CREATE_TIME <= #{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 > #{end} OR DETAIL.DELAY_TIME IS NULL) |
||||
</where> |
||||
</select> |
||||
</mapper> |
@ -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; |
||||
|
||||
/** |
@ -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; |
@ -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; |
@ -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; |
@ -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> |
@ -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; |
@ -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; |
||||
|
@ -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; |
||||
|
@ -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; |
||||
|
@ -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; |
||||
|
@ -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; |
||||
|
@ -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; |
||||
|
@ -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; |
@ -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; |
@ -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; |
@ -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; |
@ -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; |
@ -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")); |
||||
} |
||||
} |
@ -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()); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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)); |
||||
} |
||||
|
||||
} |
@ -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()); |
||||
} |
||||
|
||||
} |
@ -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(); |
||||
} |
@ -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> |
@ -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 >= #{param.startTime} |
||||
</if> |
||||
<if test="param.endTime != null"> |
||||
and h.create_time <= #{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 > #{end} or detail.DELAY_TIME is null) |
||||
</where> |
||||
</select> |
||||
</mapper> |
@ -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(); |
||||
} |
@ -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> |
@ -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(); |
||||
} |
@ -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 > #{startTime} |
||||
</if> |
||||
<if test="endTime != null"> |
||||
and end_time <= #{endTime} |
||||
</if> |
||||
</select> |
||||
</mapper> |
@ -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> { |
||||
|
||||
} |
@ -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> |
@ -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(); |
||||
} |
@ -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); |
||||
} |
@ -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); |
||||
} |
@ -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(); |
||||
} |
@ -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(); |
||||
} |
@ -1,12 +0,0 @@
|
||||
package com.hnac.hzims.operational.alert.service; |
||||
|
||||
/** |
||||
* 告警处理接口 |
||||
* @author ysj |
||||
*/ |
||||
public interface LevelAlarmService { |
||||
|
||||
String sendMessage(); |
||||
|
||||
void receiveMessage(String message); |
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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()))); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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()); |
||||
} |
||||
|
||||
} |
@ -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); |
||||
}); |
||||
} |
||||
} |
@ -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)); |
||||
} |
||||
|
||||
} |
@ -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"); |
||||
} |
||||
|
||||
|
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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()); |
||||
} |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue