瀏覽代碼

网考环境检测时,取消与配置oe.testDev.*和缓存OE_ERD、OE_ANSWER的强依赖

deason 2 年之前
父節點
當前提交
416d3be84c

+ 15 - 6
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/api/controller/ExamControlController.java

@@ -211,6 +211,9 @@ public class ExamControlController extends ControllerSupport {
     public GetYunSignDomain getYunSignature(@ModelAttribute @Valid GetYunSignatureReq req) {
         FileStorageType fileStorageType = FileStorageUtil.getFileStorageType();
 
+        // 是否为环境监测场景
+        boolean isTestDev = Constants.OE_ENV_CHECK_EXAM_RECORD_DATA_ID.equals(req.getExamRecordDataId());
+
         if (FileStorageType.UPYUN.equals(fileStorageType)) {
             GetUpyunSignDomain result = new GetUpyunSignDomain();
             Map<String, String> params = Maps.newHashMap();
@@ -232,17 +235,23 @@ public class ExamControlController extends ControllerSupport {
             }
             fileSuffix = !fileSuffix.contains(".") ? "." + fileSuffix : fileSuffix;
 
-            ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
-            if (examRecordData == null) {
-                log.warn("ExamRecordDataCache not exist! examRecordDataId = {}", req.getExamRecordDataId());
-                throw new StatusException("5002", "请求参数值有误!");
+            Long examStudentId;
+            if (isTestDev) {
+                examStudentId = Constants.OE_ENV_CHECK_EXAM_STUDENT_ID;
+            } else {
+                ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
+                if (examRecordData == null) {
+                    log.warn("ExamRecordDataCache not exist! examRecordDataId = {}", req.getExamRecordDataId());
+                    throw new StatusException("5002", "请求参数值有误!");
+                }
+                examStudentId = examRecordData.getExamStudentId();
             }
 
             StringBuffer filePath = new StringBuffer();
             filePath.append(OE_ANSWER_FILE_PATH).append(SEPARATOR)
-                    .append(examRecordData.getExamStudentId()).append(SEPARATOR).append(req.getExamRecordDataId())
+                    .append(examStudentId).append(SEPARATOR).append(req.getExamRecordDataId())
                     .append(SEPARATOR).append(req.getOrder()).append(SEPARATOR)
-                    .append(examRecordData.getExamStudentId()).append(UNDERLINE).append(req.getExamRecordDataId())
+                    .append(examStudentId).append(UNDERLINE).append(req.getExamRecordDataId())
                     .append(UNDERLINE).append(req.getOrder()).append(UNDERLINE).append(System.currentTimeMillis())
                     .append(RandomUtils.nextInt(8999) + 1000);
 

+ 76 - 93
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/ExamControlServiceImpl.java

@@ -18,9 +18,7 @@ import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamQuestionBean;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordDataBean;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordPaperStructBean;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordQuestionsBean;
-import cn.com.qmth.examcloud.core.oe.admin.api.request.GetPartialExamRecordDataReq;
 import cn.com.qmth.examcloud.core.oe.admin.api.request.SyncExamDataReq;
-import cn.com.qmth.examcloud.core.oe.admin.api.response.GetPartialExamRecordDataResp;
 import cn.com.qmth.examcloud.core.oe.student.api.bean.StuExamQuestionBean;
 import cn.com.qmth.examcloud.core.oe.student.api.request.CalcExamScoreReq;
 import cn.com.qmth.examcloud.core.oe.student.api.request.GetExamRecordPaperStructReq;
@@ -911,18 +909,22 @@ public class ExamControlServiceImpl implements ExamControlService {
 
     @Override
     public CheckQrCodeInfo checkQrCode(String qrCode) {
-        String str;
-        str = UrlUtil.decode(qrCode);
+        String str = UrlUtil.decode(qrCode);
         Map<String, String> map = Splitter.on("&").withKeyValueSeparator("=").split(str);
         String examStudentId = map.get("examStudentId");
         String examRecordDataId = map.get("examRecordDataId");
         String order = map.get("order");
         String key = map.get("key");
         String token = map.get("token");
+        Map<String, Long> values = this.parseUserKey(key);
+        Long rootOrgId = values.get("rootOrgId");
+        Long userId = values.get("userId");
+
         // 需要签名的参数
         StringBuffer sourStr = new StringBuffer();
         sourStr.append(order).append(UNDERLINE).append(examRecordDataId).append(UNDERLINE).append(key).append(UNDERLINE)
                 .append(examStudentId);
+
         // 签名
         byte[] bytes = SHA256.encode(sourStr.toString());
         String hexAscii = ByteUtil.toHexAscii(bytes);
@@ -930,71 +932,80 @@ public class ExamControlServiceImpl implements ExamControlService {
             throw new StatusException("100005", "无效的二维码");
         }
 
-        ExamStudentCacheBean examStudent = CacheHelper.getExamStudent(Long.valueOf(examStudentId));
-        if (examStudent == null) {
-            throw new StatusException("100012", "考生不存在");
+        int sessionTimeout = PropertyHolder.getInt(SESSION_TIMEOUT, 3600);
+        User user = redisClient.get(key, User.class, sessionTimeout);
+        if (null == user) {
+            throw new StatusException("100007", "登录信息已失效");
         }
 
-        ExamingSession examSessionInfo = examingSessionService.getExamingSession(examStudent.getStudentId());
-        String clientId;
+        CheckQrCodeInfo res = new CheckQrCodeInfo();
+        res.setExamRecordDataId(Long.valueOf(examRecordDataId));
+        res.setExamStudentId(Long.valueOf(examStudentId));
+        res.setKey(key);
+        res.setToken(user.getToken());
 
-        Map<String, Long> values = this.parseUserKey(key);
-        Long rootOrgId = values.get("rootOrgId");
-        Long userId = values.get("userId");
+        // 是否为环境监测场景
+        if (this.isTestDev(Long.valueOf(examRecordDataId))) {
+            res.setCourseId(0L);
+            res.setCourseName("环境检测课程");
+            res.setQuestionMainNumber(1);
+            res.setSubNumber(1);
+            res.setQuestionOrder(Constants.OE_ENV_CHECK_QUESTION_ORDER);
 
-        // 未开启环境检测,才进行如下校验
-        if (!isTestDev(Long.valueOf(examRecordDataId))) {
-            // 非环境检测,clientId即examRecordDataId
-            clientId = examRecordDataId;
-            // 判断考试是否结束
-            if (examSessionInfo == null) {
-                throw new StatusException("100006", "考试已结束");
-            }
-            if (examSessionInfo.getExamRecordDataId().longValue() != Long.valueOf(examRecordDataId).longValue()
-                    || examSessionInfo.getExamStudentId().longValue() != Long.valueOf(examStudentId).longValue()) {
-                throw new StatusException("100008", "无效的二维码");
+            // 环境检测时,clientId即用户ID
+            String clientId = userId.toString();
+
+            try {
+                this.sendScanQrCodeToWebSocket(clientId, Long.valueOf(examRecordDataId), Integer.valueOf(order), userId, rootOrgId);
+            } catch (Exception e) {
+                throw new StatusException("100011", "消息通知失败", e);
             }
-        } else {
-            // 环境检测时,clientId即用户id
-            clientId = userId.toString();
+            return res;
         }
 
-        // 校验通过
-        CheckQrCodeInfo res = new CheckQrCodeInfo();
-        res.setExamRecordDataId(Long.valueOf(examRecordDataId));
-        res.setExamStudentId(Long.valueOf(examStudentId));
-        res.setKey(key);
-        int sessionTimeout = PropertyHolder.getInt(SESSION_TIMEOUT, 3600);
-        User user = redisClient.get(key, User.class, sessionTimeout);
-        if (null == user) {
-            throw new StatusException("100007", "登录信息已失效");
+        ExamStudentCacheBean examStudent = CacheHelper.getExamStudent(Long.valueOf(examStudentId));
+        if (examStudent == null) {
+            throw new StatusException("100012", "考生不存在");
+        }
+
+        ExamingSession examSessionInfo = examingSessionService.getExamingSession(examStudent.getStudentId());
+        // 判断考试是否结束
+        if (examSessionInfo == null) {
+            throw new StatusException("100006", "考试已结束");
+        }
+        if (examSessionInfo.getExamRecordDataId().longValue() != Long.valueOf(examRecordDataId).longValue()
+                || examSessionInfo.getExamStudentId().longValue() != Long.valueOf(examStudentId).longValue()) {
+            throw new StatusException("100008", "无效的二维码");
         }
-        res.setToken(user.getToken());
-        CourseCacheBean courseBean = ExamCacheTransferHelper.getCachedCourse(examStudent.getCourseId());
 
+        CourseCacheBean courseBean = ExamCacheTransferHelper.getCachedCourse(examStudent.getCourseId());
         res.setCourseId(courseBean.getId());
         res.setCourseName(courseBean.getName());
 
-        ExamRecordQuestions examRecordQuestions = examRecordQuestionsService
-                .getExamRecordQuestions(Long.valueOf(examRecordDataId));
-
+        ExamRecordQuestions examRecordQuestions = examRecordQuestionsService.getExamRecordQuestions(Long.valueOf(examRecordDataId));
+        if (examRecordQuestions == null) {
+            throw new StatusException("100008", "无效的二维码");
+        }
         List<ExamQuestion> examQuestionList = examRecordQuestions.getExamQuestions();
-
-        if (examRecordQuestions == null || examQuestionList == null || examQuestionList.isEmpty()) {
+        if (examQuestionList == null || examQuestionList.isEmpty()) {
             throw new StatusException("100008", "无效的二维码");
         }
+
         List<ExamQuestion> filterList = examQuestionList.stream()
                 .filter(p -> p.getOrder().equals(Integer.valueOf(order))).collect(Collectors.toList());
         if (filterList == null || filterList.isEmpty()) {
             throw new StatusException("100008", "无效的二维码");
         }
-        ExamQuestion eqe = filterList.get(0);
 
+        ExamQuestion eqe = filterList.get(0);
         res.setQuestionOrder(eqe.getOrder());
         res.setQuestionMainNumber(eqe.getMainNumber());
         res.setSubNumber(getSubNumber(examRecordQuestions, Integer.valueOf(order)));
+
+        // 未开启环境检测时,clientId即examRecordDataId
+        String clientId = examRecordDataId;
+
         try {
-            // ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(Long.valueOf(examRecordDataId));
             this.sendScanQrCodeToWebSocket(clientId, Long.valueOf(examRecordDataId), Integer.valueOf(order), userId, rootOrgId);
         } catch (Exception e) {
             throw new StatusException("100011", "消息通知失败", e);
@@ -1032,22 +1043,22 @@ public class ExamControlServiceImpl implements ExamControlService {
     @Override
     public void sendFileAnswerToWebSocket(Long examRecordDataId, Integer order, String fileUrl, String transferFileType,
                                           Long userId, Long rootOrgId) throws Exception {
-        Map<String, Object> data = new HashMap<String, Object>();
+        Long clientId;
+        if (this.isTestDev(examRecordDataId)) {
+            // 如果是环境检测,则使用用户id(即学生id)作为clientId
+            clientId = userId;
+        } else {
+            // 不是环境检测,仍然使用考试记录id作为clientId
+            clientId = examRecordDataId;
+        }
+
+        Map<String, Object> data = new HashMap<>();
         data.put("examRecordDataId", examRecordDataId);
         data.put("order", order);
         data.put("fileUrl", fileUrl);
         data.put("transferFileType", transferFileType);
 
         SendFileAnswerMessageReq sendMessageReq = new SendFileAnswerMessageReq();
-        Long clientId;
-        // 如果是环境检测,则使用用户id(即学生id)作为clientId
-        if (isTestDev(examRecordDataId)) {
-            clientId = userId;
-        }
-        // 不是环境检测,仍然使用考试记录id作为clientId
-        else {
-            clientId = examRecordDataId;
-        }
         sendMessageReq.setClientId(clientId);
         sendMessageReq.setEventType(WebSocketEventType.GET_FILE_ANSWER.toString());
         sendMessageReq.setIsSuccess(true);
@@ -1176,40 +1187,11 @@ public class ExamControlServiceImpl implements ExamControlService {
                     || examSessionInfo.getExamStudentId().longValue() != req.getExamStudentId().longValue()) {
                 throw new StatusException("100008", "无效的请求");
             }
-        }
-
-        //环境监测时,需要特殊处理考试记录和orderId
-        else {
-
-            //考试记录id
-            SysPropertyCacheBean examRecordDataIdObject = CacheHelper.getSysProperty("oe.testDev.examRecordDataId");
-            //题号id
-            SysPropertyCacheBean orderObject = CacheHelper.getSysProperty("oe.testDev.order");
-
-            Long examRecordDataId;
-            if (!examRecordDataIdObject.getHasValue()) {
-                throw new StatusException("100014", "未找到环境监测的考试记录id");
-            } else {
-                examRecordDataId = Long.valueOf(examRecordDataIdObject.getValue().toString());
-                req.setExamRecordDataId(examRecordDataId);
-            }
-
-            if (!orderObject.getHasValue()) {
-                throw new StatusException("100015", "未找到环境监测的小题序号");
-            } else {
-                req.setOrder(Integer.parseInt((orderObject).getValue().toString()));
-            }
-
-            // 环境检测时,需要重新给考生id赋值
-            GetPartialExamRecordDataReq gedReq = new GetPartialExamRecordDataReq();
-            gedReq.setExamRecordDataId(examRecordDataId);
-            GetPartialExamRecordDataResp gedResp = examRecordCloudService.getPartialExamRecordData(gedReq);
-
-            if (null == gedResp.getExamStudentId()) {
-                throw new StatusException("100016", "环境监测中配置的考试记录id不正确");
-            }
-
-            req.setExamStudentId(gedResp.getExamStudentId());
+        } else {
+            //环境监测时,需要特殊处理考试记录和orderId
+            req.setExamRecordDataId(Constants.OE_ENV_CHECK_EXAM_RECORD_DATA_ID);
+            req.setOrder(Constants.OE_ENV_CHECK_QUESTION_ORDER);
+            req.setExamStudentId(Constants.OE_ENV_CHECK_EXAM_STUDENT_ID);
         }
 
         String key = user.getKey();
@@ -2136,11 +2118,12 @@ public class ExamControlServiceImpl implements ExamControlService {
      * @return
      */
     private boolean isTestDev(Long examRecordDataId) {
-        // 用于环境检测的考试记录id
-        SysPropertyCacheBean examRecordDataIdObject = CacheHelper.getSysProperty("oe.testDev.examRecordDataId");
-        // 是否开启了环境检测(请求的考试记录id等于用于环境检测的考试记录时,则认为开启了环境检测)
-        return examRecordDataIdObject.getHasValue()
-                && examRecordDataId.equals(Long.valueOf(examRecordDataIdObject.getValue().toString()));
+        // // 用于环境检测的考试记录id
+        // SysPropertyCacheBean examRecordDataIdObject = CacheHelper.getSysProperty("oe.testDev.examRecordDataId");
+        // // 是否开启了环境检测(请求的考试记录id等于用于环境检测的考试记录时,则认为开启了环境检测)
+        // return examRecordDataIdObject.getHasValue()
+        //         && examRecordDataId.equals(Long.valueOf(examRecordDataIdObject.getValue().toString()));
+        return Constants.OE_ENV_CHECK_EXAM_RECORD_DATA_ID.equals(examRecordDataId);
     }
 
     private ExamRecordDataBean copyExamRecordDataFrom(ExamRecordData examRecordData) {