Răsfoiți Sursa

just format code style, ignore...

deason 1 an în urmă
părinte
comite
2801f0af1d

+ 55 - 122
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/provider/SyncExamDataCloudServiceProvider.java

@@ -132,70 +132,56 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
 
     /**
      * 同步考试记录数据
-     *
-     * @param req
-     * @return
      */
     @ApiOperation(value = "同步考试记录相关数据")
     @PostMapping("/syncExamData")
     @Transactional
     @Override
     public SyncExamDataResp syncExamData(@RequestBody SyncExamDataReq req) {
-
-        long st = System.currentTimeMillis();
-
         long startTime = System.currentTimeMillis();
 
-        Long transitionExamRecordDataId = req.getExamRecordData().getId();
+        //临时考试记录
+        ExamRecordDataBean tempExamRecordData = req.getExamRecordData();
 
         //校验考试记录是否已同步,如果已同步,则直接返回
-        if (hasSynced(transitionExamRecordDataId)) {
+        if (hasSynced(tempExamRecordData.getId())) {
             return new SyncExamDataResp();
         }
 
-        startTime = this.debugCost("1 校验考试记录是否已同步", transitionExamRecordDataId, startTime);
+        Long tempExamRecordDataId = tempExamRecordData.getId();
+        Long examStudentId = tempExamRecordData.getExamStudentId();
+        Long studentId = tempExamRecordData.getStudentId();
+        Long examId = tempExamRecordData.getExamId();
+        Long rootOrgId = tempExamRecordData.getRootOrgId();
 
-        //临时考试记录
-        ExamRecordDataBean transitionExamRecordData = req.getExamRecordData();
-
-        //必须先更新考生的考试次数,同步考试记录会用
-        Long examStudentId = transitionExamRecordData.getExamStudentId();
+        //先更新考生的考试次数
         updateExamStudent(examStudentId);
 
-        startTime = this.debugCost("2 更新考生考试次数", transitionExamRecordDataId, startTime);
-
         //同步考试记录,并返回真实的考试记录id
-        Long realExamRecordDataId = syncExamRecordData(transitionExamRecordData);
+        Long realExamRecordDataId = syncExamRecordData(tempExamRecordData);
+
+        //添加同步记录
+        addExamRecordDataSync(tempExamRecordDataId, realExamRecordDataId);
 
         // 违纪-非法考生端应用
-        String reason = redisClient.get(CacheConstants.CACHE_OE_DISCIPLINE_ILLEGAL_CLIENT + transitionExamRecordDataId, String.class);
+        String reason = redisClient.get(CacheConstants.CACHE_OE_DISCIPLINE_ILLEGAL_CLIENT + tempExamRecordDataId, String.class);
         if (StringUtils.isNotEmpty(reason)) {
             examAuditService.saveExamAuditForIllegalClient(realExamRecordDataId, reason);
         }
 
         //header校验错误
-        Boolean hasWarn = redisClient.get(CacheConstants.CACHE_OE_DISCIPLINE_ILLEGAL_DATA + transitionExamRecordDataId, Boolean.class);
+        Boolean hasWarn = redisClient.get(CacheConstants.CACHE_OE_DISCIPLINE_ILLEGAL_DATA + tempExamRecordDataId, Boolean.class);
         if (hasWarn != null && hasWarn) {
             examAuditService.saveHeaderWarnAudit(realExamRecordDataId);
         }
 
         //切屏次数超限
-        if (transitionExamRecordData.getExceedMaxSwitchScreenCount() != null && transitionExamRecordData.getExceedMaxSwitchScreenCount()) {
+        if (tempExamRecordData.getExceedMaxSwitchScreenCount() != null && tempExamRecordData.getExceedMaxSwitchScreenCount()) {
             examAuditService.saveExceedMaxSwitchScreenCount(realExamRecordDataId);
         }
 
-        startTime = this.debugCost("3 同步考试记录表", transitionExamRecordDataId, startTime);
-
-        //添加同步记录
-        addExamRecordDataSync(transitionExamRecordData.getId(), realExamRecordDataId);
-
-        startTime = this.debugCost("4 添加同步关系表", transitionExamRecordDataId, startTime);
-
         //同步考试分数表
-        Long examScoreId = syncExamScore(transitionExamRecordData, realExamRecordDataId);
-
-        startTime = this.debugCost("5 同步考试分数表", transitionExamRecordDataId, startTime);
-
+        Long examScoreId = syncExamScore(tempExamRecordData, realExamRecordDataId);
 
         //同步断点续考记录表
         if (null != req.getExamContinuedRecords() && !req.getExamContinuedRecords().isEmpty()) {
@@ -212,82 +198,84 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
             syncExamSyncCapture(req.getExamSyncCapture(), realExamRecordDataId);
         } else {
             //且开启摄像头
-            if (FaceBiopsyHelper.isFaceEnable(transitionExamRecordData.getRootOrgId()
-                    , transitionExamRecordData.getExamId(), transitionExamRecordData.getStudentId())) {
+            if (FaceBiopsyHelper.isFaceEnable(rootOrgId, examId, studentId)) {
                 examAuditService.saveHeaderWarnAudit(realExamRecordDataId);
             }
         }
 
-        startTime = this.debugCost("6 同步抓拍照片结果(同步抓拍的数据)", transitionExamRecordDataId, startTime);
-
         //同步抓拍照片结果(异步抓拍的数据)
         if (null != req.getExamCaptures()) {
-
             syncExamCapture(req.getExamCaptures(), realExamRecordDataId);
         }
 
-        startTime = this.debugCost("7 同步抓拍照片结果(异步抓拍的数据)", transitionExamRecordDataId, startTime);
-
         //同步face id活体检测数据
         if (null != req.getExamFaceLivenessVerifies()) {
-
             syncExamFaceLivenessVerify(req.getExamFaceLivenessVerifies(), realExamRecordDataId);
         }
 
-        startTime = this.debugCost("8 同步face id活体检测数据", transitionExamRecordDataId, startTime);
-
         //同步新活检
         if (null != req.getFaceBiopsy()) {
-
             syncFaceBiopsy(req.getFaceBiopsy(), realExamRecordDataId);
         }
 
         //同步C端活体检测记录
         syncFaceLiveVerifyRecords(req.getFaceLiveVerifyRecords(), realExamRecordDataId);
 
-        startTime = this.debugCost("9 同步face id活体检测数据", transitionExamRecordDataId, startTime);
-
         //同步考试记录对应的试卷结构
         syncExamRecordPaperStruct(req.getExamRecordPaperStruct(), realExamRecordDataId);
 
-        startTime = this.debugCost("10 同步考试记录对应的试卷结构", transitionExamRecordDataId, startTime);
-
         //同步作答记录
         syncExamRecordQuestions(req.getExamRecordQuestions(), realExamRecordDataId);
 
-        startTime = this.debugCost("11 同步作答记录", transitionExamRecordDataId, startTime);
-
         //如果开启了活检
-        if (FaceBiopsyHelper.isFaceEnable(transitionExamRecordData.getRootOrgId(), transitionExamRecordData.getExamId(), transitionExamRecordData.getStudentId())) {
+        if (FaceBiopsyHelper.isFaceEnable(rootOrgId, examId, studentId)) {
             //计算违纪自动审核结果(无人脸或活检失败)
             boolean isNoPhotoAndIllegality = (null == req.getExamCaptures() || req.getExamCaptures().isEmpty());//是否无照片
-            saveAutoAudit(transitionExamRecordData, isNoPhotoAndIllegality, realExamRecordDataId);
+            saveAutoAudit(tempExamRecordData, isNoPhotoAndIllegality, realExamRecordDataId);
         }
 
-        startTime = this.debugCost("12 如果开启了活检,计算违纪自动审核结果", transitionExamRecordDataId, startTime);
-
         //若开启审核全通过
-        auditPassExamRecordData(transitionExamRecordData.getExamId(), realExamRecordDataId);
+        auditPassExamRecordData(examId, realExamRecordDataId);
 
         //***************这个步骤必须放在最后,所有改变违纪、警告、审核状态的操作之后********************************
         //计算最终分数
-        String examType = ExamCacheTransferHelper.getDefaultCachedExam(transitionExamRecordData.getExamId()).getExamType();
+        String examType = ExamCacheTransferHelper.getDefaultCachedExam(examId).getExamType();
         if (ExamType.ONLINE.name().equals(examType) || ExamType.ONLINE_HOMEWORK.name().equals(examType)
                 || ExamType.OFFLINE.name().equals(examType)) {
             examStudentFinalScoreService.calcAndSaveFinalScore(examStudentId);
         }
 
-        startTime = this.debugCost("13 计算最终考试分数", transitionExamRecordDataId, startTime);
+        LOG.warn("tempExamRecordDataId:{} realExamRecordDataId:{} cost:{}ms syncExamData ok...",
+                tempExamRecordDataId, realExamRecordDataId, System.currentTimeMillis() - startTime);
 
         //同步后续处理
-        processAfterSyncExamData(realExamRecordDataId, examScoreId, transitionExamRecordData.getObjectiveScore(),
-                examStudentId, transitionExamRecordDataId);
+        processAfterSyncExamData(realExamRecordDataId, examScoreId, tempExamRecordData.getObjectiveScore(),
+                examStudentId, tempExamRecordDataId);
 
-        this.debugCost("14 同步后续处理 - 共计", transitionExamRecordDataId, startTime);
+        return new SyncExamDataResp();
+    }
 
-        this.debugCost("100 同步考试记录相关数据 - 共计", transitionExamRecordDataId, st);
+    /**
+     * 同步后的后续操作
+     */
+    private void processAfterSyncExamData(Long realExamRecordDataId, Long examScoreId, Double objectiveScore,
+                                          Long examStudentId, Long tempExamRecordDataId) {
+        long startTime = System.currentTimeMillis();
 
-        return new SyncExamDataResp();
+        // 保存阅卷相关数据
+        examRecordForMarkingService.saveExamRecordForMarking(realExamRecordDataId, objectiveScore);
+
+        // 保存考试分数数据到推分队列
+        examScorePushQueueService.saveScoreDataInfoToQueue(realExamRecordDataId, examScoreId);
+
+        // 保存考试分数数据到分数获取队列
+        examScoreObtainQueueService.saveExamScoreObtainQueue(realExamRecordDataId);
+
+        //刷新考生的缓存
+        examStudentCache.refresh(examStudentId);
+
+        LOG.warn("tempExamRecordDataId:{} realExamRecordDataId:{} cost:{}ms processAfterSyncExamData ok...",
+                tempExamRecordDataId, realExamRecordDataId, System.currentTimeMillis() - startTime);
     }
 
     private void auditPassExamRecordData(Long examId, Long realExamRecordDataId) {
@@ -310,7 +298,6 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         }
     }
 
-
     private void syncExamContinuedRecords(List<ExamContinuedRecordBean> examContinuedRecords, Long realExamRecordDataId) {
         for (ExamContinuedRecordBean bean : examContinuedRecords) {
             ExamContinuedRecordEntity entity = copyExamContinuedRecordFrom(bean, realExamRecordDataId);
@@ -340,15 +327,12 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         examScoreEntity.setSuccPercent(transitionExamRecordData.getSuccPercent());
 
         ExamScoreEntity result = examScoreRepo.saveAndFlush(examScoreEntity);
-
         return result.getId();
     }
 
     /**
      * 更新考生相关信息
      * 增加考试次数,修改考试状态为已完成
-     *
-     * @param examStudentId
      */
     private void updateExamStudent(Long examStudentId) {
         //更新数据库中的已考次数
@@ -357,10 +341,7 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
             throw new StatusException("100101", "考生id不正确");
         }
 
-        Integer usedTimes = examStudentEntity.getUsedNum() == null
-                ? 0
-                : examStudentEntity.getUsedNum();
-
+        Integer usedTimes = examStudentEntity.getUsedNum() == null ? 0 : examStudentEntity.getUsedNum();
         examStudentEntity.setUsedNum(usedTimes + 1);
         examStudentEntity.setFinished(true);
 
@@ -369,9 +350,6 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
 
     /**
      * 添加考试记录的同步记录
-     *
-     * @param cacheId
-     * @param dbId
      */
     private void addExamRecordDataSync(Long cacheId, Long dbId) {
         ExamRecordDataSyncEntity entity = new ExamRecordDataSyncEntity();
@@ -383,9 +361,6 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
 
     /**
      * 考试记录表是否已同步
-     *
-     * @param cacheExamRecordDataId
-     * @return
      */
     private boolean hasSynced(Long cacheExamRecordDataId) {
         ExamRecordDataSyncEntity query = new ExamRecordDataSyncEntity();
@@ -398,7 +373,6 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         ExamRecordDataEntity examRecordDataEntity = copyExamRecordDataEntityFrom(examRecordData);
 
         ExamRecordDataEntity result = examRecordDataRepo.saveAndFlush(examRecordDataEntity);
-
         return result.getId();
     }
 
@@ -583,9 +557,7 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
             questionEntity.setCorrectAnswer(questionBean.getCorrectAnswer());
             questionEntity.setOptionPermutation(questionBean.getOptionPermutation());
             questionEntity.setAudioPlayTimes(questionBean.getAudioPlayTimes());
-
             if (null != questionBean.getAnswerType()) {
-
                 questionEntity.setAnswerType(AnswerType.valueOf(questionBean.getAnswerType()));
             }
 
@@ -593,7 +565,6 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         }
 
         entity.setExamQuestionEntities(examQuestionEntityList);
-
         return entity;
     }
 
@@ -682,8 +653,9 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         return entity;
     }
 
-    private List<FaceBiopsyItemStepEntity> copyFaceBiopsyItemStepFrom(List<FaceBiopsyItemStepBean> faceBiopsyItemSteps,
-                                                                      Long faceBiopsyItemId, Long examRecordDataId) {
+    private List<FaceBiopsyItemStepEntity> copyFaceBiopsyItemStepFrom(
+            List<FaceBiopsyItemStepBean> faceBiopsyItemSteps,
+            Long faceBiopsyItemId, Long examRecordDataId) {
         List<FaceBiopsyItemStepEntity> faceBiopsyItemStepEntityList = new ArrayList<>();
         for (FaceBiopsyItemStepBean bean : faceBiopsyItemSteps) {
             FaceBiopsyItemStepEntity entity = new FaceBiopsyItemStepEntity();
@@ -789,7 +761,9 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
                 } else {
                     ci.setVirtualCamera(false);
                 }
-                List<ExamCaptureCameraInfoEntity> olds = examCaptureCameraInfoRepo.findByExamRecordDataIdAndPidAndVidAndName(examCaptureEntity.getExamRecordDataId(), ci.getPid(), ci.getVid(), ci.getName());
+
+                List<ExamCaptureCameraInfoEntity> olds = examCaptureCameraInfoRepo.findByExamRecordDataIdAndPidAndVidAndName(
+                        examCaptureEntity.getExamRecordDataId(), ci.getPid(), ci.getVid(), ci.getName());
                 if (CollectionUtils.isEmpty(olds)) {
                     examCaptureCameraInfoRepo.saveAndFlush(ci);
                 } else {
@@ -857,45 +831,4 @@ public class SyncExamDataCloudServiceProvider extends ControllerSupport implemen
         return entity;
     }
 
-    /**
-     * 同步后的后续操作
-     *
-     * @param realExamRecordDataId
-     * @param examScoreId
-     */
-    private void processAfterSyncExamData(Long realExamRecordDataId, Long examScoreId, Double objectiveScore,
-                                          Long examStudentId, Long transitionExamRecordDataId) {
-        long startTime = System.currentTimeMillis();
-
-        // 保存阅卷相关数据
-        examRecordForMarkingService.saveExamRecordForMarking(realExamRecordDataId, objectiveScore);
-
-        startTime = this.debugCost("14.1 同步后续处理 - 保存阅卷相关数据", transitionExamRecordDataId, startTime);
-
-        // 保存考试分数数据到推分队列
-        examScorePushQueueService.saveScoreDataInfoToQueue(realExamRecordDataId, examScoreId);
-
-        startTime = this.debugCost("14.2 同步后续处理 - 保存考试分数数据到推分队列", transitionExamRecordDataId, startTime);
-
-        // 保存考试分数数据到分数获取队列
-        examScoreObtainQueueService.saveExamScoreObtainQueue(realExamRecordDataId);
-
-        startTime = this.debugCost("14.3 同步后续处理 - 保存考试分数数据到推分队列", transitionExamRecordDataId, startTime);
-
-        //刷新考生的缓存
-        examStudentCache.refresh(examStudentId);
-
-        this.debugCost("14.4 同步后续处理 - 刷新考生的缓存", transitionExamRecordDataId, startTime);
-    }
-
-    //记录耗时
-    private Long debugCost(String msg, Long examRecordDataId, Long startTime) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("[SYNC_EXAM_DATA_CLOUD_SERVICE_PROVIDER-" + examRecordDataId + "]:" + msg +
-                    " 耗时:" + (System.currentTimeMillis() - startTime) + " ms");
-        }
-
-        return System.currentTimeMillis();
-    }
-
 }