Browse Source

#告警弹框还原

zhongwei
yang_shj 3 months ago
parent
commit
ca171f38af
  1. 7
      hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/ws/alart/vo/AlartParamVo.java
  2. 3
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java
  3. 79
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java
  4. 14
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmHandler.java
  5. 1
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSessionManager.java
  6. 4
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketConfig.java
  7. 13
      hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketPool.java
  8. 1
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java

7
hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/ws/alart/vo/AlartParamVo.java

@ -13,6 +13,9 @@ import java.util.List;
@ApiModel(value = "告警websocket参数", description = "") @ApiModel(value = "告警websocket参数", description = "")
public class AlartParamVo { public class AlartParamVo {
@ApiModelProperty("站点集合") @ApiModelProperty("站点类型: 2-云服务 1-代运维")
private List<String> codes; private Integer serveType;
@ApiModelProperty("用户权限机构集合")
private List<Long> depts;
} }

3
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java

@ -8,6 +8,7 @@ import com.hnac.hzims.alarm.config.vo.AlarmHistoryVo;
import com.hnac.hzims.alarm.show.vo.AlarmHistoryParamVo; import com.hnac.hzims.alarm.show.vo.AlarmHistoryParamVo;
import com.hnac.hzims.alarm.show.vo.AlarmVideoVo; import com.hnac.hzims.alarm.show.vo.AlarmVideoVo;
import com.hnac.hzims.alarm.show.vo.ShowQueryVo; import com.hnac.hzims.alarm.show.vo.ShowQueryVo;
import com.hnac.hzims.business.ws.alart.vo.AlartParamVo;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
import java.util.List; import java.util.List;
@ -23,7 +24,7 @@ public interface AlarmService extends IService<AlarmEntity> {
List<AlarmEntity> broadcast(String startTime, String endTime,Integer serveType); List<AlarmEntity> broadcast(String startTime, String endTime,Integer serveType);
TextMessage majorAlarm(List<String> stations); TextMessage majorAlarm(AlartParamVo param);
List<AlarmVideoVo> alarmVideos(String stationCode, String deviceCode, String realId,Integer alarmType); List<AlarmVideoVo> alarmVideos(String stationCode, String deviceCode, String realId,Integer alarmType);

79
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java

@ -18,6 +18,7 @@ import com.hnac.hzims.alarm.show.vo.AlarmHistoryParamVo;
import com.hnac.hzims.alarm.show.vo.AlarmVideoVo; import com.hnac.hzims.alarm.show.vo.AlarmVideoVo;
import com.hnac.hzims.alarm.show.vo.ShowQueryVo; import com.hnac.hzims.alarm.show.vo.ShowQueryVo;
import com.hnac.hzims.alarm.source.service.MessageService; import com.hnac.hzims.alarm.source.service.MessageService;
import com.hnac.hzims.business.ws.alart.vo.AlartParamVo;
import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.entity.EmInfoEntity;
import com.hnac.hzims.equipment.entity.EmVideoBandingEntity; import com.hnac.hzims.equipment.entity.EmVideoBandingEntity;
import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.equipment.feign.IEmInfoClient;
@ -35,12 +36,14 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil; 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.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.message.dto.MailMessageDTO;
import org.springblade.message.fegin.IMessageClient; import org.springblade.message.fegin.IMessageClient;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -108,9 +111,6 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, AlarmEntity> impl
if(!StringUtil.isEmpty(showQuery.getAlarmType())){ if(!StringUtil.isEmpty(showQuery.getAlarmType())){
wrapper.eq("ALARM_TYPE",showQuery.getAlarmType()); wrapper.eq("ALARM_TYPE",showQuery.getAlarmType());
} }
if(!StringUtil.isEmpty(showQuery.getContent())){
wrapper.like("alarmContext",showQuery.getContent());
}
// 处理告警过滤 :当天处理告警 // 处理告警过滤 :当天处理告警
List<String> handles = alarmHandleService.handles(); List<String> handles = alarmHandleService.handles();
@ -140,18 +140,6 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, AlarmEntity> impl
} }
/** /**
* 获取权限站点
* @return
*/
private List<StationEntity> stationsByCodes(List<String> stations) {
R<List<StationEntity>> result = stationClient.querySatationByCodes(stations);
if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){
return new ArrayList<>();
}
return result.getData();
}
/**
* 查询告警数量 * 查询告警数量
* @return * @return
*/ */
@ -203,9 +191,6 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, AlarmEntity> impl
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
/** /**
* 播报告警 * 播报告警
* @param startTime * @param startTime
@ -233,25 +218,26 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, AlarmEntity> impl
/** /**
* 弹框告警 * 弹框告警
* @param codes * @param param
* @return * @return
*/ */
@Override @Override
public TextMessage majorAlarm(List<String> codes) { public TextMessage majorAlarm(AlartParamVo param) {
// 站点查询 // 站点查询
List<StationEntity> stations = this.stationsByCodes(codes); List<StationEntity> stations = this.stations(param.getServeType());
if(CollectionUtil.isEmpty(stations)){ if(CollectionUtil.isEmpty(stations) || CollectionUtil.isEmpty(param.getDepts())){
return new TextMessage(new ArrayList().toString());
}
List<String> effectives = stations.stream().filter(station->param.getDepts().contains(station.getRefDept())).map(StationEntity::getCode).collect(Collectors.toList());
if(CollectionUtil.isEmpty(effectives)){
return new TextMessage(new ArrayList().toString()); return new TextMessage(new ArrayList().toString());
} }
// 条件过滤 // 条件过滤
QueryWrapper<AlarmEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<AlarmEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(AlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); queryWrapper.lambda().in(AlarmEntity::getStationId,effectives);
queryWrapper.lambda().in(AlarmEntity::getAlarmType, AlarmConstants.WHOLE_ALARM_TYPE); queryWrapper.lambda().in(AlarmEntity::getAlarmType, Arrays.asList(AlarmConstants.FAULT,AlarmConstants.EARLY));
queryWrapper.lambda().eq(AlarmEntity::getIsRightTabulation,0); queryWrapper.lambda().eq(AlarmEntity::getIsShowAlert,0);
queryWrapper.lambda().ge(AlarmEntity::getAlarmTime, DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"); queryWrapper.lambda().eq(AlarmEntity::getStatus,0);
queryWrapper.lambda().le(AlarmEntity::getAlarmTime,DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME));
queryWrapper.lambda().orderByDesc(AlarmEntity::getAlarmTime);
//queryWrapper.lambda().eq(AlarmEntity::getStatus,0);
// 处理告警过滤 :当天处理告警 // 处理告警过滤 :当天处理告警
List<String> handles = alarmHandleService.handles(); List<String> handles = alarmHandleService.handles();
if(!CollectionUtil.isEmpty(handles)){ if(!CollectionUtil.isEmpty(handles)){
@ -261,9 +247,10 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, AlarmEntity> impl
if(CollectionUtil.isEmpty(alarms)){ if(CollectionUtil.isEmpty(alarms)){
return new TextMessage(new ArrayList().toString()); return new TextMessage(new ArrayList().toString());
} }
return new TextMessage(JSONObject.toJSONString(alarms.stream().skip(0).limit(1000).collect(Collectors.toList()))); return new TextMessage(JSONObject.toJSONString(alarms.stream().sorted(Comparator.comparing(AlarmEntity::getAlarmTime).reversed()).collect(Collectors.toList())));
} }
/** /**
* 验证设备编号是否绑定视频 * 验证设备编号是否绑定视频
* @param emInfo 设备信息 * @param emInfo 设备信息
@ -387,6 +374,35 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, AlarmEntity> impl
} }
/** /**
* websocket断联发送邮件
* @return
*/
public void sendMailByNum(Integer num,Integer maxConnent,String name) {
if (num>=maxConnent){
MailMessageDTO mailMessageDTO = new MailMessageDTO();
mailMessageDTO.setDeptId(200000L);
mailMessageDTO.setDeptName("华自科技");
mailMessageDTO.setBusinessClassify("system");
mailMessageDTO.setBusinessKey("Mail");
mailMessageDTO.setSubject("邮件发送");
mailMessageDTO.setContent(name+"websocket链接失败;"+"链接失败次数:"+num);
R<List<User>> res = userClient.userListByRoleAlias("200000", "sendMail");
if (!res.isSuccess()||CollectionUtil.isEmpty(res.getData())){
log.error("消息发送失败:无对应用户");
}
String userIds = res.getData().stream().map(s -> s.getId().toString()).collect(Collectors.joining(","));
mailMessageDTO.setUserIds(userIds);
mailMessageDTO.setIsHtml(false);
R<Boolean> booleanR = messageClient.sendMailMsgByUsers(mailMessageDTO);
if (!booleanR.isSuccess()){
log.error("消息发送失败:"+mailMessageDTO.getUserIds()+"--->"+booleanR.getMsg());
}
}
}
/**
* 获取告警视频信息 * 获取告警视频信息
* @param stationCode * @param stationCode
* @param deviceCode * @param deviceCode
@ -419,7 +435,6 @@ public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, AlarmEntity> impl
throw new ServiceException("未查询到告警视频信息!"); throw new ServiceException("未查询到告警视频信息!");
} }
/** /**
*查询站点绑定视频信息 *查询站点绑定视频信息
* @param stationCode * @param stationCode

14
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmHandler.java

@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.alarm.show.service.AlarmService; import com.hnac.hzims.alarm.show.service.AlarmService;
import com.hnac.hzims.business.ws.alart.vo.AlartParamVo; import com.hnac.hzims.business.ws.alart.vo.AlartParamVo;
import lombok.extern.slf4j.Slf4j; 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.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -14,8 +13,6 @@ import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler; import org.springframework.web.socket.handler.TextWebSocketHandler;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List;
/** /**
* @author ysj * @author ysj
@ -34,11 +31,13 @@ public class AlarmHandler extends TextWebSocketHandler {
session.getAttributes().put("userId", uid); session.getAttributes().put("userId", uid);
log.info("sessionId: " + session.getId()); log.info("sessionId: " + session.getId());
log.info("session connection successful!"); log.info("session connection successful!");
AlarmSocketPool.pool.put(session.getId(), this);
} }
@Override @Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
AlarmSessionManager.removeAndClose(session.getId()); AlarmSessionManager.removeAndClose(session.getId());
AlarmSocketPool.pool.remove(session.getId());
log.info("sessionId: " + session.getId()); log.info("sessionId: " + session.getId());
log.info("uri: " + session.getUri()); log.info("uri: " + session.getUri());
log.info("session closed successful!"); log.info("session closed successful!");
@ -47,6 +46,7 @@ public class AlarmHandler extends TextWebSocketHandler {
@Override @Override
public void handleTransportError(WebSocketSession session, Throwable exception) { public void handleTransportError(WebSocketSession session, Throwable exception) {
AlarmSessionManager.removeAndClose(session.getId()); AlarmSessionManager.removeAndClose(session.getId());
AlarmSocketPool.pool.remove(session.getId());
} }
@Override @Override
@ -56,13 +56,11 @@ public class AlarmHandler extends TextWebSocketHandler {
if(StringUtil.isBlank(message)){ if(StringUtil.isBlank(message)){
return; return;
} }
AlartParamVo param = JSONObject.parseObject(textMessage.getPayload(), AlartParamVo.class); AlartParamVo param = JSONObject.parseObject(message,AlartParamVo.class);
if(ObjectUtil.isEmpty(param) || CollectionUtil.isEmpty(param.getCodes())){ if(ObjectUtil.isEmpty(param)){
return; return;
} }
session.getAttributes().put("codes", param.getCodes()); TextMessage sendMessage = alarmService.majorAlarm(param);
AlarmSessionManager.SESSION_POOL.put(userId,session);
TextMessage sendMessage = alarmService.majorAlarm(param.getCodes());
session.sendMessage(sendMessage); session.sendMessage(sendMessage);
} }
} }

1
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSessionManager.java

@ -55,6 +55,7 @@ public class AlarmSessionManager {
throw new RuntimeException("关闭ws会话失败!", ex); throw new RuntimeException("关闭ws会话失败!", ex);
} }
} }
SESSION_POOL.remove(uid); SESSION_POOL.remove(uid);
} }

4
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketConfig.java

@ -18,11 +18,11 @@ public class AlarmSocketConfig implements WebSocketConfigurer{
@Override @Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
// 集中监控弹框处理器 // 集中监控弹框处理器
registry.addHandler(alarmHandler(), "/alarm/alart/{uid}").setAllowedOrigins("*"); registry.addHandler(monitorHandler(), "/alarm/alart/{uid}").setAllowedOrigins("*");
} }
@Bean @Bean
public WebSocketHandler alarmHandler() { public WebSocketHandler monitorHandler() {
return new AlarmHandler(); return new AlarmHandler();
} }

13
hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketPool.java

@ -0,0 +1,13 @@
package com.hnac.hzims.alarm.ws.alart;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author ysj
*/
public class AlarmSocketPool {
public static Map<String, AlarmHandler> pool = new ConcurrentHashMap<>();
}

1
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java

@ -69,7 +69,6 @@ public class UserDeptConfigServiceImpl extends ServiceImpl<UserDeptConfigMapper,
// 检查记录是否保存 // 检查记录是否保存
UserDeptConfigEntity userDeptConfig = this.getOne(Wrappers.<UserDeptConfigEntity>lambdaQuery() UserDeptConfigEntity userDeptConfig = this.getOne(Wrappers.<UserDeptConfigEntity>lambdaQuery()
.eq(UserDeptConfigEntity::getStationId,entity.getStationId())
.eq(UserDeptConfigEntity::getCreateUser,AuthUtil.getUserId()) .eq(UserDeptConfigEntity::getCreateUser,AuthUtil.getUserId())
); );
if(ObjectUtils.isEmpty(userDeptConfig)){ if(ObjectUtils.isEmpty(userDeptConfig)){

Loading…
Cancel
Save