Ver código fonte

网考代码优化

lideyin 5 anos atrás
pai
commit
7e09d4043d

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

@@ -834,7 +834,7 @@ public class ExamControlServiceImpl implements ExamControlService {
 
     @Override
     public void cleanTempFileAnswers() {
-        //默认删除7天以前的数据
+        //默认删除1天以前的数据
         int days = PropertyHolder.getInt("oe.cleanTempFileAnswer.thresholdDays", 1);
         Date dateBeforeDays = DateUtils.addDays(new Date(), -1 * days);
         examFileAnswerTempRepo.deleteByCreationTime(dateBeforeDays);
@@ -1317,6 +1317,9 @@ public class ExamControlServiceImpl implements ExamControlService {
 
     @Override
     public CheckQrCodeInfo checkQrCode(String param) {
+        long st = System.currentTimeMillis();
+
+        long startTime = System.currentTimeMillis();
         String str;
         str = UrlUtil.decode(param);
         Map<String, String> map = Splitter.on("&").withKeyValueSeparator("=").split(str);
@@ -1335,12 +1338,19 @@ public class ExamControlServiceImpl implements ExamControlService {
         if (!hexAscii.equals(token)) {
             throw new StatusException("100005", "无效的二维码");
         }
+        if (log.isDebugEnabled()) {
+            log.debug("1 签名校验耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+        }
 
+        startTime = System.currentTimeMillis();
         //判断考生是否存在
         ExamStudentEntity examStudentEntity = examStudentRepo.findByExamStudentId(Long.valueOf(examStudentId));
         if (examStudentEntity == null) {
             throw new StatusException("100012", "考生不存在");
         }
+        if (log.isDebugEnabled()) {
+            log.debug("2 考生是否存在校验耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+        }
 
         String clientId;
         //未开启环境检测,才进行如下校验
@@ -1377,8 +1387,14 @@ public class ExamControlServiceImpl implements ExamControlService {
 
         res.setCourseId(courseBean.getId());
         res.setCourseName(courseBean.getName());
+
+        startTime = System.currentTimeMillis();
         ExamRecordQuestionsEntity examRecordQuestionsEntity = examRecordQuestionsService.
                 getExamRecordQuestionsAndFixExamRecordDataIfNecessary(Long.valueOf(examRecordDataId));
+        if (log.isDebugEnabled()) {
+            log.debug("3 获取作答记录耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+        }
+
         List<ExamQuestionEntity> examQuestionList = examRecordQuestionsEntity.getExamQuestionEntities();
 
         if (examRecordQuestionsEntity == null || examQuestionList == null || examQuestionList.isEmpty()) {
@@ -1394,10 +1410,18 @@ public class ExamControlServiceImpl implements ExamControlService {
         res.setQuestionOrder(eqe.getOrder());
         res.setQuestionMainNumber(eqe.getMainNumber());
         res.setSubNumber(getSubNumber(examRecordQuestionsEntity, Integer.valueOf(order)));
+        startTime = System.currentTimeMillis();
         try {
             this.sendScanQrCodeToWebSocket(clientId, Long.valueOf(examRecordDataId), Integer.valueOf(order));
         } catch (Exception e) {
-            throw new StatusException("100011", "消息通知失败", e);
+        	throw new StatusException("100011", "消息通知失败", e);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("4 发websocket耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("5 合计 耗时:" + (System.currentTimeMillis() - st) + " ms");
         }
         return res;
     }
@@ -1415,6 +1439,9 @@ public class ExamControlServiceImpl implements ExamControlService {
     @Override
     @Transactional
     public ExamFileAnswerTempEntity saveUploadedFile(SaveUploadedFileReq req, User user) {
+        long st = System.currentTimeMillis();
+
+        long startTime = System.currentTimeMillis();
         // 判断考试是否结束
         ExamStudentEntity examStudentEntity = examStudentRepo.findByExamStudentId(req.getExamStudentId());
         if (examStudentEntity == null) {
@@ -1436,7 +1463,11 @@ public class ExamControlServiceImpl implements ExamControlService {
                 throw new StatusException("100008", "考试已结束");
             }
         }
+        if (log.isDebugEnabled()) {
+            log.debug("1 判断考试是否结束耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+        }
 
+        startTime = System.currentTimeMillis();
         ExamFileAnswerTempEntity et = new ExamFileAnswerTempEntity();
         et.setExamRecordDataId(req.getExamRecordDataId());
         et.setExamStudentId(req.getExamStudentId());
@@ -1444,7 +1475,15 @@ public class ExamControlServiceImpl implements ExamControlService {
         et.setFilePath(req.getFilePath());
         et.setStatus(FileAnswerAcknowledgeStatus.UNCONFIRMED);
         et.setTransferFileType(req.getTransferFileType());
-        return examFileAnswerTempRepo.save(et);
+        ExamFileAnswerTempEntity result = examFileAnswerTempRepo.save(et);
+        if (log.isDebugEnabled()) {
+            log.debug("2 保存文件临时作答记录耗时:" + (System.currentTimeMillis() - startTime) + " ms");
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("3 合计 耗时:" + (System.currentTimeMillis() - st) + " ms");
+        }
+        return result;
 
     }