|
@@ -63,6 +63,7 @@ public class WebSocketOeServer implements Concurrently {
|
|
|
private RedisUtil redisUtil;
|
|
|
private Long updateTime = null;
|
|
|
private Map<String, Object> tranMap = null;
|
|
|
+ private String url = "/ws/oe";
|
|
|
|
|
|
/**
|
|
|
* 连接建立成功调用的方法
|
|
@@ -86,51 +87,56 @@ public class WebSocketOeServer implements Concurrently {
|
|
|
this.Authorization = String.valueOf(mapParameter.get("Authorization").get(0));
|
|
|
this.time = Long.parseLong(String.valueOf(mapParameter.get("time").get(0)));
|
|
|
this.recordId = Long.parseLong(String.valueOf(mapParameter.get("recordId").get(0)));
|
|
|
- String method = SystemConstant.GET;
|
|
|
- final SignatureInfo info = SignatureInfo
|
|
|
- .parse(Authorization);
|
|
|
- if (Objects.nonNull(info) && info.getType() == SignatureType.TOKEN) {
|
|
|
- String sessionId = info.getInvoker();
|
|
|
- redisUtil = SpringContextHolder.getBean(RedisUtil.class);
|
|
|
- TBSession tbSession = (TBSession) redisUtil.getUserSession(sessionId);
|
|
|
- if (Objects.isNull(tbSession)) {
|
|
|
- throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
|
|
|
- } else {
|
|
|
- if (info.validate(tbSession.getAccessToken()) && info.getTimestamp() < tbSession.getExpireTime()
|
|
|
- && platform.equalsIgnoreCase(tbSession.getPlatform()) && Objects.equals(deviceId, tbSession.getDeviceId())) {
|
|
|
- this.session = session;
|
|
|
- session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
|
|
|
- this.sessionId = tbSession.getId();
|
|
|
- if (webSocketMap.containsKey(this.recordId)) {
|
|
|
- webSocketMap.remove(this.recordId);
|
|
|
- webSocketMap.put(this.recordId, this);
|
|
|
+// final SignatureInfo info = SignatureInfo
|
|
|
+// .parse(Authorization);
|
|
|
+ if (!SystemConstant.expire(this.time.longValue())) {
|
|
|
+ final SignatureInfo info = SignatureInfo
|
|
|
+ .parse(SystemConstant.GET, url, this.time, this.Authorization);
|
|
|
+ if (Objects.nonNull(info) && info.getType() == SignatureType.TOKEN) {
|
|
|
+ String sessionId = info.getInvoker();
|
|
|
+ redisUtil = SpringContextHolder.getBean(RedisUtil.class);
|
|
|
+ TBSession tbSession = (TBSession) redisUtil.getUserSession(sessionId);
|
|
|
+ if (Objects.isNull(tbSession)) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
|
|
|
+ } else {
|
|
|
+ if (info.validate(tbSession.getAccessToken()) && info.getTimestamp() < tbSession.getExpireTime()
|
|
|
+ && platform.equalsIgnoreCase(tbSession.getPlatform()) && Objects.equals(deviceId, tbSession.getDeviceId())) {
|
|
|
+ this.session = session;
|
|
|
+ session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
|
|
|
+ this.sessionId = tbSession.getId();
|
|
|
+ if (webSocketMap.containsKey(this.recordId)) {
|
|
|
+ webSocketMap.remove(this.recordId);
|
|
|
+ webSocketMap.put(this.recordId, this);
|
|
|
+ } else {
|
|
|
+ webSocketMap.put(this.recordId, this);
|
|
|
+ addOnlineCount();
|
|
|
+ }
|
|
|
+ log.info("用户连接:{},当前在线人数为:{}", this.sessionId, getOnlineCount());
|
|
|
+ InetSocketAddress addr = (InetSocketAddress) WebsocketUtil.getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
|
|
|
+ this.ip = addr.toString().replace("/", "").split(":")[0];
|
|
|
+// this.sendMessage("ip[" + this.ip + "]连接成功");
|
|
|
+ log.info("ip[:{}]连接成功", this.ip);
|
|
|
+ ExamRecordCacheUtil.setClientWebsocketStatus(recordId, WebsocketStatusEnum.ON_LINE, false);
|
|
|
+ ExamRecordCacheUtil.setClientCurrentIp(recordId, this.ip, false);
|
|
|
+ ExamRecordCacheUtil.setClientWebsocketId(recordId, this.session.getId(), false);
|
|
|
+ Long clientLastSyncTime = System.currentTimeMillis();
|
|
|
+ ExamRecordCacheUtil.setClientLastSyncTime(recordId, clientLastSyncTime, false);
|
|
|
+ String[] columns = new String[]{ExamRecordFieldEnum.client_websocket_status.name(), ExamRecordFieldEnum.client_current_ip.name(), ExamRecordFieldEnum.client_websocket_id.name(), ExamRecordFieldEnum.client_last_sync_time.name()};
|
|
|
+ Object[] values = new Object[]{WebsocketStatusEnum.ON_LINE, this.ip, this.session.getId(), clientLastSyncTime};
|
|
|
+ TOeExamRecordService tOeExamRecordService = SpringContextHolder.getBean(TOeExamRecordService.class);
|
|
|
+ tOeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
+ tranMap = new HashMap<>();
|
|
|
+ tranMap.put("recordId", this.recordId);
|
|
|
+ tranMap.put("deviceId", this.deviceId);
|
|
|
+ tranMap.put("ip", this.ip);
|
|
|
+ this.updateTime = System.currentTimeMillis();
|
|
|
+ tranMap.put("updateTime", this.updateTime);
|
|
|
} else {
|
|
|
- webSocketMap.put(this.recordId, this);
|
|
|
- addOnlineCount();
|
|
|
+ throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
|
|
|
}
|
|
|
- log.info("用户连接:{},当前在线人数为:{}", this.sessionId, getOnlineCount());
|
|
|
- InetSocketAddress addr = (InetSocketAddress) WebsocketUtil.getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
|
|
|
- this.ip = addr.toString().replace("/", "").split(":")[0];
|
|
|
-// this.sendMessage("ip[" + this.ip + "]连接成功");
|
|
|
- log.info("ip[:{}]连接成功", this.ip);
|
|
|
- ExamRecordCacheUtil.setClientWebsocketStatus(recordId, WebsocketStatusEnum.ON_LINE, false);
|
|
|
- ExamRecordCacheUtil.setClientCurrentIp(recordId, this.ip, false);
|
|
|
- ExamRecordCacheUtil.setClientWebsocketId(recordId, this.session.getId(), false);
|
|
|
- Long clientLastSyncTime = System.currentTimeMillis();
|
|
|
- ExamRecordCacheUtil.setClientLastSyncTime(recordId, clientLastSyncTime, false);
|
|
|
- String[] columns = new String[]{ExamRecordFieldEnum.client_websocket_status.name(), ExamRecordFieldEnum.client_current_ip.name(), ExamRecordFieldEnum.client_websocket_id.name(), ExamRecordFieldEnum.client_last_sync_time.name()};
|
|
|
- Object[] values = new Object[]{WebsocketStatusEnum.ON_LINE, this.ip, this.session.getId(), clientLastSyncTime};
|
|
|
- TOeExamRecordService tOeExamRecordService = SpringContextHolder.getBean(TOeExamRecordService.class);
|
|
|
- tOeExamRecordService.dataUpdatesMq(recordId, columns, values);
|
|
|
- tranMap = new HashMap<>();
|
|
|
- tranMap.put("recordId", this.recordId);
|
|
|
- tranMap.put("deviceId", this.deviceId);
|
|
|
- tranMap.put("ip", this.ip);
|
|
|
- this.updateTime = System.currentTimeMillis();
|
|
|
- tranMap.put("updateTime", this.updateTime);
|
|
|
- } else {
|
|
|
- throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
|
|
|
}
|
|
|
} else {
|
|
|
throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
|