Parcourir la source

Merge branch 'dev'
1

wangliang il y a 4 ans
Parent
commit
4b641f310a

+ 2 - 2
themis-business/src/main/resources/db/init.sql

@@ -743,11 +743,11 @@ INSERT INTO `t_b_role_privilege` VALUES (185, 'INSPECTION', 150);
 INSERT INTO `t_b_role_privilege` VALUES (186, 'INSPECTION', 151);
 INSERT INTO `t_b_role_privilege` VALUES (187, 'INSPECTION', 152);
 INSERT INTO `t_b_role_privilege` VALUES (188, 'INSPECTION', 153);
-INSERT INTO `t_b_role_privilege` VALUES (189, 'INVIGILATE', 154);
+INSERT INTO `t_b_role_privilege` VALUES (189, 'INSPECTION', 154);
 INSERT INTO `t_b_role_privilege` VALUES (190, 'ADMIN', 155);
 INSERT INTO `t_b_role_privilege` VALUES (191, 'INVIGILATE', 155);
 INSERT INTO `t_b_role_privilege` VALUES (192, 'ADMIN', 156);
-INSERT INTO `t_b_role_privilege` VALUES (193, 'INVIGILATE', 156);
+INSERT INTO `t_b_role_privilege` VALUES (193, 'INSPECTION', 156);
 COMMIT;
 
 -- ----------------------------

+ 13 - 1
themis-exam/src/main/java/com/qmth/themis/exam/config/ExamConstant.java

@@ -5,6 +5,7 @@ import com.qmth.themis.business.dto.WebsocketDto;
 import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
 import com.qmth.themis.business.enums.WebsocketTypeEnum;
 import com.qmth.themis.exam.websocket.WebSocketMobileServer;
+import com.qmth.themis.exam.websocket.WebSocketOeServer;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -21,11 +22,22 @@ import java.util.concurrent.ConcurrentHashMap;
 public class ExamConstant {
 
     /**
-     * 发送移动端考试结束msg
+     * 发送考试结束msg
      *
      * @param recordId
      */
     public static void sendExamStopMsg(Long recordId) {
+        //客户端考试结束
+        ConcurrentHashMap<Long, WebSocketOeServer> webSocketOeMap = WebSocketOeServer.getWebSocketMap();
+        if (Objects.nonNull(webSocketOeMap.get(recordId))) {
+            WebSocketOeServer webSocketOeServer = webSocketOeMap.get(recordId);
+            Map map = new HashMap<>();
+            map.put(SystemConstant.RECORD_ID, recordId);
+            WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.EXAM_STOP.name(), map);
+            webSocketOeServer.sendMessage(websocketDto);
+        }
+
+        //移动端考试结束
         ConcurrentHashMap<String, WebSocketMobileServer> webSocketMap = WebSocketMobileServer.getWebSocketMap();
         if (Objects.nonNull(webSocketMap.get(recordId + "-" + MonitorVideoSourceEnum.MOBILE_FIRST.name()))) {
             WebSocketMobileServer webSocketMobileServer = webSocketMap.get(recordId + "-" + MonitorVideoSourceEnum.MOBILE_FIRST.name());

+ 6 - 15
themis-exam/src/main/java/com/qmth/themis/exam/listener/service/impl/MqOeLogicServiceImpl.java

@@ -10,13 +10,17 @@ import com.qmth.themis.business.dto.WebsocketDto;
 import com.qmth.themis.business.entity.TEExamStudentLog;
 import com.qmth.themis.business.entity.TIeExamInvigilateNotice;
 import com.qmth.themis.business.entity.TMRocketMessage;
-import com.qmth.themis.business.enums.*;
+import com.qmth.themis.business.enums.FinishTypeEnum;
+import com.qmth.themis.business.enums.MessageTypeEnum;
+import com.qmth.themis.business.enums.MqTagEnum;
+import com.qmth.themis.business.enums.WebsocketTypeEnum;
 import com.qmth.themis.business.service.TEExamStudentLogService;
 import com.qmth.themis.business.service.TEExamStudentService;
 import com.qmth.themis.business.service.TIeExamInvigilateNoticeService;
 import com.qmth.themis.business.service.TMRocketMessageService;
 import com.qmth.themis.business.util.JacksonUtil;
 import com.qmth.themis.business.util.RedisUtil;
+import com.qmth.themis.exam.config.ExamConstant;
 import com.qmth.themis.exam.listener.service.MqOeLogicService;
 import com.qmth.themis.exam.websocket.WebSocketMobileServer;
 import com.qmth.themis.exam.websocket.WebSocketOeServer;
@@ -207,20 +211,7 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
         String tag = mqDto.getTag();
         if (Objects.equals(MqTagEnum.EXAM_STOP.name(), tag)) {//考试退出
             Long recordId = Long.parseLong(String.valueOf(mqDto.getBody()));
-            if (Objects.nonNull(webSocketMap.get(recordId + "-" + MonitorVideoSourceEnum.MOBILE_FIRST.name()))) {
-                WebSocketMobileServer webSocketMobileServer = webSocketMap.get(recordId + "-" + MonitorVideoSourceEnum.MOBILE_FIRST.name());
-                Map map = new HashMap<>();
-                map.put(SystemConstant.RECORD_ID, recordId);
-                WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.EXAM_STOP.name(), map);
-                webSocketMobileServer.sendMessage(websocketDto);
-            }
-            if (Objects.nonNull(webSocketMap.get(recordId + "-" + MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
-                WebSocketMobileServer webSocketMobileServer = webSocketMap.get(recordId + "-" + MonitorVideoSourceEnum.MOBILE_SECOND.name());
-                Map map = new HashMap<>();
-                map.put(SystemConstant.RECORD_ID, recordId);
-                WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.EXAM_STOP.name(), map);
-                webSocketMobileServer.sendMessage(websocketDto);
-            }
+            ExamConstant.sendExamStopMsg(recordId);
         }
         mqDto.setAck(SystemConstant.STANDARD_ACK_TYPE);
         TMRocketMessage tmRocketMessage = gson.fromJson(gson.toJson(mqDto), TMRocketMessage.class);

+ 30 - 22
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketMobileServer.java

@@ -8,6 +8,7 @@ import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.WebsocketDto;
 import com.qmth.themis.business.entity.TBSession;
+import com.qmth.themis.business.enums.ExamRecordStatusEnum;
 import com.qmth.themis.business.enums.MonitorStatusSourceEnum;
 import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
 import com.qmth.themis.business.enums.WebsocketTypeEnum;
@@ -19,6 +20,7 @@ import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.signature.SignatureInfo;
 import com.qmth.themis.common.signature.SignatureType;
+import com.qmth.themis.exam.config.ExamConstant;
 import com.qmth.themis.exam.listener.service.MqOeLogicService;
 import com.qmth.themis.exam.websocketTemplete.WebSocketMobileMessageTemplete;
 import com.qmth.themis.mq.templete.Concurrently;
@@ -100,30 +102,36 @@ public class WebSocketMobileServer 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 + "-" + this.source.name())) {
-                        webSocketMap.remove(this.recordId + "-" + this.source.name());
-                        webSocketMap.put(this.recordId + "-" + this.source.name(), this);
-                        //加入set中
+                    ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(this.recordId);
+                    if (Objects.nonNull(status) && Objects.equals(ExamRecordStatusEnum.BREAK_OFF, status)) {//如果是已中断状态,则给客户端和移动端发送考试停止的消息
+                        ExamConstant.sendExamStopMsg(recordId);
+                        throw new BusinessException("考试已中断,请重新登录");
                     } else {
-                        webSocketMap.put(this.recordId + "-" + this.source.name(), 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 + "-" + this.source.name())) {
+                            webSocketMap.remove(this.recordId + "-" + this.source.name());
+                            webSocketMap.put(this.recordId + "-" + this.source.name(), this);
+                            //加入set中
+                        } else {
+                            webSocketMap.put(this.recordId + "-" + this.source.name(), 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);
-                    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);
+                        log.info("ip[:{}]连接成功", this.ip);
+                        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);
                 }

+ 38 - 33
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketOeServer.java

@@ -102,42 +102,47 @@ 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);
+                        throw new BusinessException("考试已中断,请重新登录");
                     } 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);
                 }