|
@@ -102,42 +102,46 @@ public class WebSocketOeServer implements Concurrently {
|
|
|
} else {
|
|
|
if (info.validate(tbSession.getAccessToken()) && info.getTimestamp() < tbSession.getExpireTime().getTime()
|
|
|
&& 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);
|
|
|
- //加入set中
|
|
|
+ ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(this.recordId);
|
|
|
+ if (Objects.nonNull(status) && Objects.equals(ExamRecordStatusEnum.BREAK_OFF, status)) {//如果是已中断状态,则给客户端和移动端发送考试停止的消息
|
|
|
+ ExamConstant.sendExamStopMsg(recordId);
|
|
|
} else {
|
|
|
- webSocketMap.put(this.recordId, this);
|
|
|
- //加入set中
|
|
|
- addOnlineCount();
|
|
|
- //在线数加1
|
|
|
- }
|
|
|
- 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.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);
|
|
|
+ //加入set中
|
|
|
+ } else {
|
|
|
+ webSocketMap.put(this.recordId, this);
|
|
|
+ //加入set中
|
|
|
+ addOnlineCount();
|
|
|
+ //在线数加1
|
|
|
+ }
|
|
|
+ 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);
|
|
|
- ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(recordId);
|
|
|
- if (!Objects.equals(ExamRecordStatusEnum.PERSISTED, status) || !Objects.equals(ExamRecordStatusEnum.FINISHED, status)) {
|
|
|
- ExamRecordCacheUtil.setClientWebsocketStatus(recordId, WebsocketStatusEnum.ON_LINE, false);
|
|
|
- ExamRecordCacheUtil.setClientCurrentIp(recordId, this.ip, false);
|
|
|
- ExamRecordCacheUtil.setClientWebsocketId(recordId, this.session.getId(), false);
|
|
|
- Date clientLastSyncTime = new Date();
|
|
|
- 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);
|
|
|
+ log.info("ip[:{}]连接成功", this.ip);
|
|
|
+ if (!Objects.equals(ExamRecordStatusEnum.PERSISTED, status) || !Objects.equals(ExamRecordStatusEnum.FINISHED, status)) {
|
|
|
+ ExamRecordCacheUtil.setClientWebsocketStatus(recordId, WebsocketStatusEnum.ON_LINE, false);
|
|
|
+ ExamRecordCacheUtil.setClientCurrentIp(recordId, this.ip, false);
|
|
|
+ ExamRecordCacheUtil.setClientWebsocketId(recordId, this.session.getId(), false);
|
|
|
+ Date clientLastSyncTime = new Date();
|
|
|
+ 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);
|
|
|
}
|
|
|
- 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);
|
|
|
}
|