增加报警数据websocket 消息推送
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
package org.dromara.resource.api;
|
||||||
|
|
||||||
|
import org.dromara.resource.api.domain.WebSocketMsgType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* websocket 消息推送
|
||||||
|
*
|
||||||
|
* @author lxj
|
||||||
|
*/
|
||||||
|
public interface RemoteWebSocketMessageService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送消息
|
||||||
|
*
|
||||||
|
* @param sessionKey session主键 一般为用户id
|
||||||
|
* @param webSocketMsgType webSocket消息类型
|
||||||
|
* @param data 消息数据
|
||||||
|
*/
|
||||||
|
void publishMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, Object data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布订阅的消息(群发)
|
||||||
|
*
|
||||||
|
* @param webSocketMsgType webSocket消息类型
|
||||||
|
* @param data 消息数据
|
||||||
|
*/
|
||||||
|
void publishAll(WebSocketMsgType webSocketMsgType, Object data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向指定的用户的指定会话发送消息
|
||||||
|
*
|
||||||
|
* @param userId 要发送消息的用户id
|
||||||
|
* @param webSocketMsgType webSocket消息类型
|
||||||
|
* @param data 消息数据
|
||||||
|
*/
|
||||||
|
void sendMessage(Long userId, WebSocketMsgType webSocketMsgType, Object data);
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
package org.dromara.resource.api.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* websocket 消息推送类型枚举
|
||||||
|
*
|
||||||
|
* @author lxj
|
||||||
|
*/
|
||||||
|
public enum WebSocketMsgType {
|
||||||
|
|
||||||
|
ALARM_MSG(100);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息类型编码
|
||||||
|
* 大类型 - 100,200,300,400 累加100
|
||||||
|
* 小类型 - 101, 102, 103 累加1
|
||||||
|
*/
|
||||||
|
private final Integer code;
|
||||||
|
|
||||||
|
WebSocketMsgType(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
@@ -35,7 +35,7 @@ public class PlusWebSocketHandler extends AbstractWebSocketHandler {
|
|||||||
}
|
}
|
||||||
WebSocketSessionHolder.addSession(loginUser.getUserId(), session);
|
WebSocketSessionHolder.addSession(loginUser.getUserId(), session);
|
||||||
log.info("[connect] sessionId: {},userId:{},userType:{}", session.getId(), loginUser.getUserId(), loginUser.getUserType());
|
log.info("[connect] sessionId: {},userId:{},userType:{}", session.getId(), loginUser.getUserId(), loginUser.getUserType());
|
||||||
System.out.println(WebSocketSessionHolder.getSessions(loginUser.getUserId()));
|
log.info("WebSocketSession={}", WebSocketSessionHolder.getSessions(loginUser.getUserId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -13,8 +13,8 @@ import org.dromara.property.api.RemoteAttendanceService;
|
|||||||
import org.dromara.property.api.RemoteFloorService;
|
import org.dromara.property.api.RemoteFloorService;
|
||||||
import org.dromara.property.api.domain.vo.RemoteAttendanceUserGroupVo;
|
import org.dromara.property.api.domain.vo.RemoteAttendanceUserGroupVo;
|
||||||
import org.dromara.property.api.domain.vo.RemoteFloorVo;
|
import org.dromara.property.api.domain.vo.RemoteFloorVo;
|
||||||
import org.dromara.sis.domain.entity.SisAlarmEvents;
|
|
||||||
import org.dromara.sis.domain.bo.alarm.AlarmAssignmentBo;
|
import org.dromara.sis.domain.bo.alarm.AlarmAssignmentBo;
|
||||||
|
import org.dromara.sis.domain.entity.SisAlarmEvents;
|
||||||
import org.dromara.sis.domain.enums.ControlTypeEnum;
|
import org.dromara.sis.domain.enums.ControlTypeEnum;
|
||||||
import org.dromara.sis.domain.enums.EventSmallTypeEnum;
|
import org.dromara.sis.domain.enums.EventSmallTypeEnum;
|
||||||
import org.dromara.sis.domain.enums.RosterTypeEnum;
|
import org.dromara.sis.domain.enums.RosterTypeEnum;
|
||||||
|
@@ -23,14 +23,16 @@ import org.dromara.common.satoken.utils.LoginHelper;
|
|||||||
import org.dromara.property.api.RemoteAttendanceService;
|
import org.dromara.property.api.RemoteAttendanceService;
|
||||||
import org.dromara.property.api.domain.vo.RemoteAttendanceUserGroupVo;
|
import org.dromara.property.api.domain.vo.RemoteAttendanceUserGroupVo;
|
||||||
import org.dromara.resource.api.RemoteFileService;
|
import org.dromara.resource.api.RemoteFileService;
|
||||||
|
import org.dromara.resource.api.RemoteWebSocketMessageService;
|
||||||
import org.dromara.resource.api.domain.RemoteFile;
|
import org.dromara.resource.api.domain.RemoteFile;
|
||||||
|
import org.dromara.resource.api.domain.WebSocketMsgType;
|
||||||
|
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
||||||
|
import org.dromara.sis.domain.bo.alarm.AlarmAssignmentBo;
|
||||||
|
import org.dromara.sis.domain.bo.alarm.AlarmCompleteBo;
|
||||||
import org.dromara.sis.domain.entity.SisAlarmEventAttachments;
|
import org.dromara.sis.domain.entity.SisAlarmEventAttachments;
|
||||||
import org.dromara.sis.domain.entity.SisAlarmEventProcess;
|
import org.dromara.sis.domain.entity.SisAlarmEventProcess;
|
||||||
import org.dromara.sis.domain.entity.SisAlarmEvents;
|
import org.dromara.sis.domain.entity.SisAlarmEvents;
|
||||||
import org.dromara.sis.domain.entity.SisDeviceManage;
|
import org.dromara.sis.domain.entity.SisDeviceManage;
|
||||||
import org.dromara.sis.domain.bo.SisAlarmEventsBo;
|
|
||||||
import org.dromara.sis.domain.bo.alarm.AlarmAssignmentBo;
|
|
||||||
import org.dromara.sis.domain.bo.alarm.AlarmCompleteBo;
|
|
||||||
import org.dromara.sis.domain.enums.AlarmStatus;
|
import org.dromara.sis.domain.enums.AlarmStatus;
|
||||||
import org.dromara.sis.domain.enums.EventBigTypeEnum;
|
import org.dromara.sis.domain.enums.EventBigTypeEnum;
|
||||||
import org.dromara.sis.domain.enums.EventSmallTypeEnum;
|
import org.dromara.sis.domain.enums.EventSmallTypeEnum;
|
||||||
@@ -44,6 +46,9 @@ import org.dromara.sis.service.ISisDeviceManageService;
|
|||||||
import org.dromara.system.api.RemoteDictService;
|
import org.dromara.system.api.RemoteDictService;
|
||||||
import org.dromara.system.api.domain.vo.RemoteDictDataVo;
|
import org.dromara.system.api.domain.vo.RemoteDictDataVo;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.system.api.model.LoginUser;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -58,7 +63,7 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService, ApplicationContextAware {
|
||||||
|
|
||||||
private final SisAlarmEventsMapper baseMapper;
|
private final SisAlarmEventsMapper baseMapper;
|
||||||
private final ISisDeviceManageService deviceManageService;
|
private final ISisDeviceManageService deviceManageService;
|
||||||
@@ -71,6 +76,9 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
|||||||
private RemoteAttendanceService remoteAttendanceService;
|
private RemoteAttendanceService remoteAttendanceService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private RemoteDictService remoteDictService;
|
private RemoteDictService remoteDictService;
|
||||||
|
@DubboReference
|
||||||
|
private RemoteWebSocketMessageService webSocketMessageService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询告警
|
* 查询告警
|
||||||
@@ -303,8 +311,16 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
|
|||||||
process.setTenantId(sisAlarmEvents.getTenantId());
|
process.setTenantId(sisAlarmEvents.getTenantId());
|
||||||
Boolean insert = alarmEventProcessService.insert(process);
|
Boolean insert = alarmEventProcessService.insert(process);
|
||||||
log.info("事件处理信息写入完成,result= {}", insert);
|
log.info("事件处理信息写入完成,result= {}", insert);
|
||||||
//TODO 推送到执行客户端
|
// 进行消息推送
|
||||||
|
webSocketMessageService.publishMessage(List.of(bo.getSolveId()), WebSocketMsgType.ALARM_MSG, sisAlarmEvents);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,63 @@
|
|||||||
|
package org.dromara.resource.dubbo;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
|
import org.dromara.common.websocket.dto.WebSocketMessageDto;
|
||||||
|
import org.dromara.common.websocket.utils.WebSocketUtils;
|
||||||
|
import org.dromara.resource.api.RemoteWebSocketMessageService;
|
||||||
|
import org.dromara.resource.api.domain.WebSocketMsgType;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* websocket 消息推送实现类
|
||||||
|
*
|
||||||
|
* @author lxj
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@DubboService
|
||||||
|
public class RemoteWebSocketMessageServiceImpl implements RemoteWebSocketMessageService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publishMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, Object data) {
|
||||||
|
WebSocketMessageDto dto = new WebSocketMessageDto();
|
||||||
|
dto.setSessionKeys(sessionKey);
|
||||||
|
dto.setMessage(createMsg(webSocketMsgType, data));
|
||||||
|
try {
|
||||||
|
WebSocketUtils.publishMessage(dto);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送分布式消息失败,error:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publishAll(WebSocketMsgType webSocketMsgType, Object data) {
|
||||||
|
try {
|
||||||
|
WebSocketUtils.publishAll(createMsg(webSocketMsgType, data));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("群发消息失败,error:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(Long userId, WebSocketMsgType webSocketMsgType, Object data) {
|
||||||
|
try {
|
||||||
|
WebSocketUtils.sendMessage(userId, createMsg(webSocketMsgType, data));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送指定消息失败,error:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createMsg(WebSocketMsgType webSocketMsgType, Object data) {
|
||||||
|
JSONObject msg = new JSONObject();
|
||||||
|
msg.put("code", webSocketMsgType.getCode());
|
||||||
|
msg.put("data", data);
|
||||||
|
return msg.toJSONString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user