增加移动端推送title content

This commit is contained in:
15683799673
2025-09-13 16:47:44 +08:00
parent 791195e2c6
commit 07a64e5395
3 changed files with 35 additions and 1 deletions

View File

@@ -21,6 +21,17 @@ public interface RemoteWebSocketMessageService {
*/
void publishMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, String data);
/**
* 推送移动端消息
*
* @param sessionKey session主键 一般为用户id
* @param webSocketMsgType webSocket消息类型
* @param title 推送title
* @param content 推送内容
* @param data 推送数据
*/
void pushMobileMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, String title, String content, String data);
/**
* 发布订阅的消息(群发)
*

View File

@@ -310,7 +310,9 @@ public class SisAlarmEventsServiceImpl implements ISisAlarmEventsService {
Boolean insert = alarmEventProcessService.insert(process);
log.info("事件处理信息写入完成,result= {}", insert);
// 进行消息推送
webSocketMessageService.publishMessage(List.of(bo.getSolveId()), WebSocketMsgType.ALARM_MSG, JSONObject.toJSONString(sisAlarmEvents));
String title = "视频预警";
String content = "您有一条" + sisAlarmEvents.getSolveName() + "预警数据";
webSocketMessageService.pushMobileMessage(List.of(bo.getSolveId()), WebSocketMsgType.ALARM_MSG, title, content, JSONObject.toJSONString(sisAlarmEvents));
return true;
}

View File

@@ -33,6 +33,18 @@ public class RemoteWebSocketMessageServiceImpl implements RemoteWebSocketMessage
}
}
@Override
public void pushMobileMessage(List<Long> sessionKey, WebSocketMsgType webSocketMsgType, String title, String content, String data) {
WebSocketMessageDto dto = new WebSocketMessageDto();
dto.setSessionKeys(sessionKey);
dto.setMessage(createMsg(webSocketMsgType, title, content, data));
try {
WebSocketUtils.publishMessage(dto);
} catch (Exception e) {
log.error("发送分布式消息失败,error:{}", e.getMessage());
}
}
@Override
public void publishAll(WebSocketMsgType webSocketMsgType, String data) {
try {
@@ -60,4 +72,13 @@ public class RemoteWebSocketMessageServiceImpl implements RemoteWebSocketMessage
return msg.toJSONString();
}
private String createMsg(WebSocketMsgType webSocketMsgType, String title, String content, Object data) {
JSONObject msg = new JSONObject();
msg.put("type", webSocketMsgType.getCode());
msg.put("title", title);
msg.put("content", content);
msg.put("data", data);
return msg.toJSONString();
}
}