From ca171f38afd7549c86c48e5f2cab565a7783dc1f Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 3 Sep 2024 15:32:27 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=91=8A=E8=AD=A6=E5=BC=B9=E6=A1=86=E8=BF=98?= =?UTF-8?q?=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/business/ws/alart/vo/AlartParamVo.java | 7 +- .../hzims/alarm/show/service/AlarmService.java | 3 +- .../alarm/show/service/impl/AlarmServiceImpl.java | 79 +++++++++++++--------- .../hnac/hzims/alarm/ws/alart/AlarmHandler.java | 14 ++-- .../hzims/alarm/ws/alart/AlarmSessionManager.java | 1 + .../hzims/alarm/ws/alart/AlarmSocketConfig.java | 4 +- .../hnac/hzims/alarm/ws/alart/AlarmSocketPool.java | 13 ++++ .../service/impl/UserDeptConfigServiceImpl.java | 1 - 8 files changed, 76 insertions(+), 46 deletions(-) create mode 100644 hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketPool.java diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/ws/alart/vo/AlartParamVo.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/ws/alart/vo/AlartParamVo.java index 4c5a13b..462bccc 100644 --- a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/business/ws/alart/vo/AlartParamVo.java +++ b/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 = "") public class AlartParamVo { - @ApiModelProperty("站点集合") - private List codes; + @ApiModelProperty("站点类型: 2-云服务 1-代运维") + private Integer serveType; + + @ApiModelProperty("用户权限机构集合") + private List depts; } \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java index 46abe4b..020b84a 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/AlarmService.java +++ b/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.AlarmVideoVo; import com.hnac.hzims.alarm.show.vo.ShowQueryVo; +import com.hnac.hzims.business.ws.alart.vo.AlartParamVo; import org.springframework.web.socket.TextMessage; import java.util.List; @@ -23,7 +24,7 @@ public interface AlarmService extends IService { List broadcast(String startTime, String endTime,Integer serveType); - TextMessage majorAlarm(List stations); + TextMessage majorAlarm(AlartParamVo param); List alarmVideos(String stationCode, String deviceCode, String realId,Integer alarmType); diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java index 063d5b5..25e2f6d 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/show/service/impl/AlarmServiceImpl.java @@ -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.ShowQueryVo; 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.EmVideoBandingEntity; import com.hnac.hzims.equipment.feign.IEmInfoClient; @@ -35,12 +36,14 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.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.message.dto.MailMessageDTO; import org.springblade.message.fegin.IMessageClient; +import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -108,9 +111,6 @@ public class AlarmServiceImpl extends ServiceImpl impl if(!StringUtil.isEmpty(showQuery.getAlarmType())){ wrapper.eq("ALARM_TYPE",showQuery.getAlarmType()); } - if(!StringUtil.isEmpty(showQuery.getContent())){ - wrapper.like("alarmContext",showQuery.getContent()); - } // 处理告警过滤 :当天处理告警 List handles = alarmHandleService.handles(); @@ -140,18 +140,6 @@ public class AlarmServiceImpl extends ServiceImpl impl } /** - * 获取权限站点 - * @return - */ - private List stationsByCodes(List stations) { - R> result = stationClient.querySatationByCodes(stations); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return new ArrayList<>(); - } - return result.getData(); - } - - /** * 查询告警数量 * @return */ @@ -203,9 +191,6 @@ public class AlarmServiceImpl extends ServiceImpl impl }).collect(Collectors.toList()); } - - - /** * 播报告警 * @param startTime @@ -233,25 +218,26 @@ public class AlarmServiceImpl extends ServiceImpl impl /** * 弹框告警 - * @param codes + * @param param * @return */ @Override - public TextMessage majorAlarm(List codes) { + public TextMessage majorAlarm(AlartParamVo param) { // 站点查询 - List stations = this.stationsByCodes(codes); - if(CollectionUtil.isEmpty(stations)){ + List stations = this.stations(param.getServeType()); + if(CollectionUtil.isEmpty(stations) || CollectionUtil.isEmpty(param.getDepts())){ + return new TextMessage(new ArrayList().toString()); + } + List 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()); } // 条件过滤 QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.lambda().in(AlarmEntity::getStationId,stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); - queryWrapper.lambda().in(AlarmEntity::getAlarmType, AlarmConstants.WHOLE_ALARM_TYPE); - queryWrapper.lambda().eq(AlarmEntity::getIsRightTabulation,0); - queryWrapper.lambda().ge(AlarmEntity::getAlarmTime, DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"); - queryWrapper.lambda().le(AlarmEntity::getAlarmTime,DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME)); - queryWrapper.lambda().orderByDesc(AlarmEntity::getAlarmTime); - //queryWrapper.lambda().eq(AlarmEntity::getStatus,0); + queryWrapper.lambda().in(AlarmEntity::getStationId,effectives); + queryWrapper.lambda().in(AlarmEntity::getAlarmType, Arrays.asList(AlarmConstants.FAULT,AlarmConstants.EARLY)); + queryWrapper.lambda().eq(AlarmEntity::getIsShowAlert,0); + queryWrapper.lambda().eq(AlarmEntity::getStatus,0); // 处理告警过滤 :当天处理告警 List handles = alarmHandleService.handles(); if(!CollectionUtil.isEmpty(handles)){ @@ -261,9 +247,10 @@ public class AlarmServiceImpl extends ServiceImpl impl if(CollectionUtil.isEmpty(alarms)){ 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 设备信息 @@ -387,6 +374,35 @@ public class AlarmServiceImpl extends ServiceImpl 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> 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 booleanR = messageClient.sendMailMsgByUsers(mailMessageDTO); + if (!booleanR.isSuccess()){ + log.error("消息发送失败:"+mailMessageDTO.getUserIds()+"--->"+booleanR.getMsg()); + } + } + } + + /** * 获取告警视频信息 * @param stationCode * @param deviceCode @@ -419,7 +435,6 @@ public class AlarmServiceImpl extends ServiceImpl impl throw new ServiceException("未查询到告警视频信息!"); } - /** *查询站点绑定视频信息 * @param stationCode diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmHandler.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmHandler.java index 34d6196..f6052a0 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmHandler.java +++ b/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.business.ws.alart.vo.AlartParamVo; 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; @@ -14,8 +13,6 @@ import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; import java.io.IOException; -import java.util.Collections; -import java.util.List; /** * @author ysj @@ -34,11 +31,13 @@ public class AlarmHandler extends TextWebSocketHandler { session.getAttributes().put("userId", uid); log.info("sessionId: " + session.getId()); log.info("session connection successful!"); + AlarmSocketPool.pool.put(session.getId(), this); } @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { AlarmSessionManager.removeAndClose(session.getId()); + AlarmSocketPool.pool.remove(session.getId()); log.info("sessionId: " + session.getId()); log.info("uri: " + session.getUri()); log.info("session closed successful!"); @@ -47,6 +46,7 @@ public class AlarmHandler extends TextWebSocketHandler { @Override public void handleTransportError(WebSocketSession session, Throwable exception) { AlarmSessionManager.removeAndClose(session.getId()); + AlarmSocketPool.pool.remove(session.getId()); } @Override @@ -56,13 +56,11 @@ public class AlarmHandler extends TextWebSocketHandler { if(StringUtil.isBlank(message)){ return; } - AlartParamVo param = JSONObject.parseObject(textMessage.getPayload(), AlartParamVo.class); - if(ObjectUtil.isEmpty(param) || CollectionUtil.isEmpty(param.getCodes())){ + AlartParamVo param = JSONObject.parseObject(message,AlartParamVo.class); + if(ObjectUtil.isEmpty(param)){ return; } - session.getAttributes().put("codes", param.getCodes()); - AlarmSessionManager.SESSION_POOL.put(userId,session); - TextMessage sendMessage = alarmService.majorAlarm(param.getCodes()); + TextMessage sendMessage = alarmService.majorAlarm(param); session.sendMessage(sendMessage); } } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSessionManager.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSessionManager.java index d2227b9..b54e6b2 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSessionManager.java +++ b/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); } } + SESSION_POOL.remove(uid); } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketConfig.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketConfig.java index 051da5a..bbceab3 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketConfig.java +++ b/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 public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { // 集中监控弹框处理器 - registry.addHandler(alarmHandler(), "/alarm/alart/{uid}").setAllowedOrigins("*"); + registry.addHandler(monitorHandler(), "/alarm/alart/{uid}").setAllowedOrigins("*"); } @Bean - public WebSocketHandler alarmHandler() { + public WebSocketHandler monitorHandler() { return new AlarmHandler(); } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketPool.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/ws/alart/AlarmSocketPool.java new file mode 100644 index 0000000..c7bc6cc --- /dev/null +++ b/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 pool = new ConcurrentHashMap<>(); + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java index 0441766..14c71de 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/UserDeptConfigServiceImpl.java @@ -69,7 +69,6 @@ public class UserDeptConfigServiceImpl extends ServiceImpllambdaQuery() - .eq(UserDeptConfigEntity::getStationId,entity.getStationId()) .eq(UserDeptConfigEntity::getCreateUser,AuthUtil.getUserId()) ); if(ObjectUtils.isEmpty(userDeptConfig)){