|
|
@@ -53,6 +53,7 @@ public class WebSocketServer {
|
|
|
// 在线数加1
|
|
|
onlineCount.incrementAndGet();
|
|
|
}
|
|
|
+ editStatus(userId);
|
|
|
log.info("用户连接:" + userId + ",当前在线人数为:" + onlineCount);
|
|
|
sendMessage("连接成功");
|
|
|
}
|
|
|
@@ -72,6 +73,7 @@ public class WebSocketServer {
|
|
|
|
|
|
@OnClose
|
|
|
public void onClose(@PathParam("userId") String userId, Session session) {
|
|
|
+ delStatus(userId);
|
|
|
sessionClientMap.remove(userId);
|
|
|
log.info("断联成功!");
|
|
|
}
|
|
|
@@ -81,6 +83,24 @@ public class WebSocketServer {
|
|
|
log.info("websocket异常,错误信息:{}", throwable.getMessage());
|
|
|
}
|
|
|
|
|
|
+ private void delStatus(String userId) {
|
|
|
+ SysGeographyPositionService sysGeographyPositionService= SpringContextUtils.getBean(SysGeographyPositionService.class);
|
|
|
+ SysGeographyPosition sysGeographyPosition = sysGeographyPositionService.getById(userId);
|
|
|
+ if (sysGeographyPosition != null) {
|
|
|
+ sysGeographyPosition.setStatus(0);
|
|
|
+ sysGeographyPositionService.updateById(sysGeographyPosition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void editStatus(String userId) {
|
|
|
+ SysGeographyPositionService sysGeographyPositionService= SpringContextUtils.getBean(SysGeographyPositionService.class);
|
|
|
+ SysGeographyPosition sysGeographyPosition = sysGeographyPositionService.getById(userId);
|
|
|
+ if (sysGeographyPosition != null) {
|
|
|
+ sysGeographyPosition.setStatus(1);
|
|
|
+ sysGeographyPositionService.updateById(sysGeographyPosition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void sendMessage(String message) {
|
|
|
this.session.getAsyncRemote().sendText(message);
|
|
|
}
|