Browse Source

处理:【异常】过程活体不通过 和 【违纪】指定动作失败

deason 1 year ago
parent
commit
6d82acb633

+ 59 - 60
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/ExamRecordDataServiceImpl.java

@@ -5,6 +5,7 @@ import cn.com.qmth.examcloud.api.commons.enums.ExamStageStartExamStatus;
 import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.helpers.QuestionOptionHelper;
+import cn.com.qmth.examcloud.commons.util.StringUtil;
 import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
 import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
 import cn.com.qmth.examcloud.core.basic.api.request.GetCoursesByIdListReq;
@@ -33,12 +34,10 @@ import cn.com.qmth.examcloud.examwork.api.request.ModifyExamStageStartExamStatus
 import cn.com.qmth.examcloud.question.commons.core.question.QuestionType;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
+import cn.com.qmth.examcloud.support.cache.bean.ExamPropertyCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.QuestionAnswerCacheBean;
-import cn.com.qmth.examcloud.support.enums.ExamRecordStatus;
-import cn.com.qmth.examcloud.support.enums.FaceBiopsyScheme;
-import cn.com.qmth.examcloud.support.enums.IsSuccess;
-import cn.com.qmth.examcloud.support.enums.SyncStatus;
+import cn.com.qmth.examcloud.support.enums.*;
 import cn.com.qmth.examcloud.support.examing.ExamQuestion;
 import cn.com.qmth.examcloud.support.examing.ExamRecordData;
 import cn.com.qmth.examcloud.support.examing.ExamRecordQuestions;
@@ -299,74 +298,74 @@ public class ExamRecordDataServiceImpl implements ExamRecordDataService {
     public CalcFaceBiopsyResultResp calcFaceBiopsyResult(CalcFaceBiopsyResultReq req) {
         ExamRecordData examRecordData = this.getExamRecordDataCache(req.getExamRecordDataId());
 
-        //如果活检结果不为空,且活检失败,则判定为违纪有警告
-        if (null != examRecordData.getFaceVerifyResult()) {
-            if (IsSuccess.FAILED == examRecordData.getFaceVerifyResult()) {
+        Long examId = examRecordData.getExamId();
+        Long rootOrgId = examRecordData.getRootOrgId();
+        Long studentId = examRecordData.getStudentId();
+
+        //是否开启考中人脸活体检测
+        if (!FaceBiopsyHelper.isFaceVerify(rootOrgId, examId, studentId)) {
+            return new CalcFaceBiopsyResultResp();
+        }
+
+        // 是否考中活体不通过强制退出
+        ExamPropertyCacheBean examProperty = CacheHelper.getExamProperty(examId, ExamProperties.FACE_VERIFY_FORCE_EXIT.name());
+        boolean isFaceVerifyForceExit = examProperty != null && StringUtil.isTrue(examProperty.getValue());
+
+        if (examRecordData.getFaceVerifyResult() != null) {
+            //如果活检结果不为空,且强制活检失败,则判定为违纪有警告
+            if (IsSuccess.SUCCESS == examRecordData.getFaceVerifyResult()) {
+                return new CalcFaceBiopsyResultResp(IsSuccess.SUCCESS);
+            }
+            if (isFaceVerifyForceExit) {
                 return new CalcFaceBiopsyResultResp(true, true, IsSuccess.FAILED);
             }
             return new CalcFaceBiopsyResultResp();
         }
 
         //如果考试记录中的活检记录为空,需要再次计算一次,并更新到考试记录中
-        else {
-            Long examId = examRecordData.getExamId();
-            Long rootOrgId = examRecordData.getRootOrgId();
-            Long studentId = examRecordData.getStudentId();
-
-            //是否进行活体检测
-            if (FaceBiopsyHelper.isFaceVerify(rootOrgId, examId, studentId)) {
-                FaceBiopsyScheme faceBiopsyScheme = FaceBiopsyHelper.getFaceBiopsyScheme(rootOrgId);
-
-                if (FaceBiopsyScheme.FACE_CLIENT == faceBiopsyScheme) {
-                    // C端活体检测方案
-                    List<ExamFaceLiveVerifyEntity> entities = examFaceLiveVerifyRepo.findByExamRecordDataId(examRecordData.getId());
-                    if (CollectionUtils.isEmpty(entities)) {
-                        return new CalcFaceBiopsyResultResp(true, true, IsSuccess.FAILED);
-                    }
-
-                    // 最后一次活检成功,则认为成功
-                    ExamFaceLiveVerifyEntity entity = entities.stream().max((a, b) -> {
-                        if (a.getId() > b.getId()) {
-                            return 1;
-                        }
-                        return -1;
-                    }).get();
-
-                    if (FaceLiveVerifyStatus.SUCCESS == entity.getStatus()) {
-                        return new CalcFaceBiopsyResultResp(IsSuccess.SUCCESS);
-                    }
-
-                    return new CalcFaceBiopsyResultResp(true, true, IsSuccess.FAILED);
-                } else if (faceBiopsyScheme == FaceBiopsyScheme.FACE_MOTION) {
-                    // Electron Client 自研活体检测方案
-                    FaceBiopsyEntity faceBiopsy = faceBiopsyRepo.findByExamRecordDataId(examRecordData.getId());
-
-                    //如果活检结果最终为true,只需要更新活检状态即可
-                    if (faceBiopsy != null && faceBiopsy.getResult() != null && faceBiopsy.getResult()) {
-                        return new CalcFaceBiopsyResultResp(IsSuccess.SUCCESS);
-                    }
-
-                    return new CalcFaceBiopsyResultResp(true, true, IsSuccess.FAILED);
-                } else {
-                    // FaceID活体检测方案
-                    List<ExamFaceLivenessVerifyEntity> faceVerifies = examFaceLivenessVerifyRepo.findByExamRecordDataIdOrderById(examRecordData.getId());
-
-                    if (null != faceVerifies && faceVerifies.size() > 0) {
-                        ExamFaceLivenessVerifyEntity latestFaceVerify = faceVerifies.get(faceVerifies.size() - 1);
-                        //最后一次活检成功,则认为成功,并更新考试记录相关属性
-                        if (latestFaceVerify != null && latestFaceVerify.getVerifyResult() != null &&
-                                latestFaceVerify.getVerifyResult() == FaceVerifyResult.VERIFY_SUCCESS) {
-
-                            return new CalcFaceBiopsyResultResp(IsSuccess.SUCCESS);
-                        }
+        FaceBiopsyScheme faceBiopsyScheme = FaceBiopsyHelper.getFaceBiopsyScheme(rootOrgId);
+        if (FaceBiopsyScheme.FACE_CLIENT == faceBiopsyScheme) {
+            // S3 C端活体检测方案
+            List<ExamFaceLiveVerifyEntity> verifies = examFaceLiveVerifyRepo.findByExamRecordDataId(examRecordData.getId());
+
+            if (!CollectionUtils.isEmpty(verifies)) {
+                // 最后一次活检成功,则认为成功
+                ExamFaceLiveVerifyEntity lastVerify = verifies.stream().max((a, b) -> {
+                    if (a.getId() > b.getId()) {
+                        return 1;
                     }
+                    return -1;
+                }).get();
+                if (lastVerify.getStatus() != null && FaceLiveVerifyStatus.SUCCESS == lastVerify.getStatus()) {
+                    return new CalcFaceBiopsyResultResp(IsSuccess.SUCCESS);
+                }
+            }
+        } else if (faceBiopsyScheme == FaceBiopsyScheme.FACE_MOTION) {
+            // S2 自研活体检测方案
+            FaceBiopsyEntity lastVerify = faceBiopsyRepo.findByExamRecordDataId(examRecordData.getId());
 
-                    return new CalcFaceBiopsyResultResp(true, true, IsSuccess.FAILED);
+            //如果活检结果最终为true,只需要更新活检状态即可
+            if (lastVerify != null && lastVerify.getResult() != null && lastVerify.getResult()) {
+                return new CalcFaceBiopsyResultResp(IsSuccess.SUCCESS);
+            }
+        } else {
+            // S1 FaceID活体检测方案
+            List<ExamFaceLivenessVerifyEntity> verifies = examFaceLivenessVerifyRepo.findByExamRecordDataIdOrderById(examRecordData.getId());
+
+            if (!CollectionUtils.isEmpty(verifies)) {
+                // 最后一次活检成功,则认为成功
+                ExamFaceLivenessVerifyEntity lastVerify = verifies.get(verifies.size() - 1);
+                if (lastVerify.getVerifyResult() != null && FaceVerifyResult.VERIFY_SUCCESS == lastVerify.getVerifyResult()) {
+                    return new CalcFaceBiopsyResultResp(IsSuccess.SUCCESS);
                 }
             }
+        }
 
-            return new CalcFaceBiopsyResultResp();
+        if (isFaceVerifyForceExit) {
+            return new CalcFaceBiopsyResultResp(true, true, IsSuccess.FAILED);
         }
+
+        return new CalcFaceBiopsyResultResp();
     }
 
     /**