mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 17:38:48 +08:00
socket代码异常处理及日志打印
This commit is contained in:
parent
4a7f767638
commit
fc4b5ca1ff
@ -8,12 +8,8 @@ import org.dromara.common.core.domain.model.LoginUser;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.websocket.constant.WebSocketConstants;
|
||||
import org.dromara.common.websocket.dto.WebSocketMessageDto;
|
||||
import org.dromara.common.websocket.handler.PlusWebSocketHandler;
|
||||
import org.dromara.common.websocket.handler.WebSocketApi;
|
||||
import org.dromara.common.websocket.holder.WebSocketSessionHolder;
|
||||
import org.dromara.common.websocket.utils.WebSocketUtils;
|
||||
import org.dromara.web.config.LastWebSocketParamDto;
|
||||
import org.dromara.web.controller.app.EqDeviceController;
|
||||
@ -23,13 +19,8 @@ import org.dromara.web.domain.vo.EqEquipmentDetailVo;
|
||||
import org.dromara.web.domain.vo.EqEquipmentVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.dromara.common.websocket.constant.WebSocketConstants.LOGIN_USER_KEY;
|
||||
|
||||
/**
|
||||
* @ClassName : WebSocketHandler
|
||||
@ -51,6 +42,8 @@ public class WebSocketBusinessHandler implements WebSocketApi {
|
||||
public void dealWithDetailMsg(LoginUser loginUser, String msg) {
|
||||
EqAppHomeBo bo = null;
|
||||
String sendMsg = "";
|
||||
R<EqEquipmentDetailVo> deviceMsg = null;
|
||||
boolean isTrue = true;
|
||||
try {
|
||||
bo = JSON.parseObject(msg, EqAppHomeBo.class);
|
||||
LastWebSocketParamDto dto = new LastWebSocketParamDto();
|
||||
@ -59,11 +52,21 @@ public class WebSocketBusinessHandler implements WebSocketApi {
|
||||
RedisUtils.setCacheObject(Constants.WEBSOCKET_METHOD+loginUser.getUserId(),dto);
|
||||
} catch (Exception e) {
|
||||
log.error("参数错误");
|
||||
sendMsg = "参数错误";
|
||||
isTrue = false;
|
||||
deviceMsg = R.fail("参数错误:"+e.getMessage());
|
||||
}
|
||||
R<EqEquipmentDetailVo> deviceMsg = controller.getDeviceMsg(bo);
|
||||
if (isTrue){
|
||||
try {
|
||||
deviceMsg = controller.getDeviceMsg(bo);
|
||||
} catch (Exception e) {
|
||||
deviceMsg = R.fail("设备详情获取失败:"+e.getMessage());
|
||||
log.error("设备详情获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
// EqEquipmentDetailVo data = deviceMsg.getData();
|
||||
sendMsg = JSON.toJSONString(deviceMsg);
|
||||
log.info("socket详情发送:{}",sendMsg);
|
||||
sendMsg(sendMsg,loginUser.getUserId());
|
||||
}
|
||||
|
||||
@ -71,6 +74,7 @@ public class WebSocketBusinessHandler implements WebSocketApi {
|
||||
public void dealWithListMsg(LoginUser loginUser, String msg) {
|
||||
EqAppHomeBo bo = null;
|
||||
String sendMsg = "";
|
||||
boolean isTure = true;
|
||||
try {
|
||||
bo = JSON.parseObject(msg, EqAppHomeBo.class);
|
||||
LastWebSocketParamDto dto = new LastWebSocketParamDto();
|
||||
@ -80,12 +84,23 @@ public class WebSocketBusinessHandler implements WebSocketApi {
|
||||
} catch (Exception e) {
|
||||
log.error("参数错误");
|
||||
sendMsg = "参数错误";
|
||||
isTure = false;
|
||||
}
|
||||
PageQuery pageQuery = new PageQuery();
|
||||
pageQuery.setPageNum(0);
|
||||
pageQuery.setPageSize(100);
|
||||
TableDataInfo<EqEquipmentVo> list = homeController.listForWebSocket(bo, pageQuery,loginUser);
|
||||
sendMsg = JSON.toJSONString(list);
|
||||
TableDataInfo<EqEquipmentVo> list = null;
|
||||
if (isTure){
|
||||
PageQuery pageQuery = new PageQuery();
|
||||
pageQuery.setPageNum(0);
|
||||
pageQuery.setPageSize(100);
|
||||
try {
|
||||
list = homeController.listForWebSocket(bo, pageQuery,loginUser);
|
||||
} catch (Exception e) {
|
||||
isTure = false;
|
||||
sendMsg = "获取设备列表失败"+e.getMessage();
|
||||
log.error("获取设备列表失败:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
sendMsg = isTure?JSON.toJSONString(list):sendMsg;
|
||||
log.info("socket列表发送:{}",sendMsg);
|
||||
sendMsg(sendMsg,loginUser.getUserId());
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ public class PlusWebSocketHandler extends AbstractWebSocketHandler {
|
||||
@Override
|
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||||
// 从WebSocket会话中获取登录用户信息
|
||||
log.info("socket:接受到消息 {}", message.getPayload());
|
||||
LoginUser loginUser = (LoginUser) session.getAttributes().get(LOGIN_USER_KEY);
|
||||
String currentPath = session.getUri().getPath();
|
||||
String lastPath = WebSocketSessionHolder.getSessions(loginUser.getUserId()).getUri().getPath();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user