Преглед изворни кода

添加活体检测的新接口

lideyin пре 5 година
родитељ
комит
8101215edf

+ 58 - 1
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/controller/FaceBiopsyController.java

@@ -13,9 +13,11 @@ import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemStepRepo;
 import cn.com.qmth.examcloud.core.oe.student.bean.*;
+import cn.com.qmth.examcloud.core.oe.student.service.ExamFaceLivenessVerifyService;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamSessionInfoService;
 import cn.com.qmth.examcloud.core.oe.student.service.FaceBiopsyService;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
+import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
@@ -47,7 +49,62 @@ public class FaceBiopsyController extends ControllerSupport {
     @Autowired
     private ExamRecordDataRepo examRecordDataRepo;
 
-    @ApiOperation(value = "获取人脸活体检测基本信息")
+    @Autowired
+    private ExamFaceLivenessVerifyService examFaceLivenessVerifyService;
+
+    private final String NEW_FACE_BIOPSY_SCHEME = "S2";
+
+    @ApiOperation(value = "获取活体检测基本信息")
+    @GetMapping("/getFaceBiopsyBaseInfo")
+    public FaceBiopsyBaseInfo getFaceBiopsyBaseInfo(@RequestParam Long examRecordDataId) {
+        User user = getAccessUser();
+        Long studentId = user.getUserId();
+        String sequenceLockKey = Constants.GET_FACE_BIOPSY_INFO_PREFIX + studentId;
+        //系统在请求结束后会,自动释放锁,无需手动解锁
+        SequenceLockHelper.getLock(sequenceLockKey);
+
+        //判断考试记录id是否有效
+        ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId,
+                ExamRecordDataEntity.class);
+        if (examRecordData == null) {
+            throw new StatusException("200101", "无效的考试记录");
+        }
+
+        // 获取考试会话,判断考生是否已结束考试
+        ExamSessionInfo examSessionInfo = examSessionInfoService.getExamSessionInfo(studentId);
+        if (examSessionInfo == null) {
+            throw new StatusException("200102", "考试会话已过期");
+        }
+
+        //考试未开启人脸活体检测,不允许获取活检信息
+        String isFaceVerifyStr = ExamCacheTransferHelper.getCachedExamProperty(examRecordData.getExamId(),
+                examRecordData.getOrgId(), examRecordData.getStudentId(),
+                ExamProperties.IS_FACE_VERIFY.name()).getValue();
+        if (!Constants.isTrue.equals(isFaceVerifyStr)) {
+            throw new StatusException("200103", "本场考试未开启人脸活体检测");
+        }
+
+        FaceBiopsyBaseInfo faceBiopsyBaseInfo = new FaceBiopsyBaseInfo();
+        OrgPropertyCacheBean orgProperty = CacheHelper.getOrgProperty(user.getRootOrgId(),
+                Constants.IDENTIFICATION_OF_LIVING_BODY_SCHEME_KEY);
+        faceBiopsyBaseInfo.setIdentificationOfLivingBodyScheme(orgProperty.getValue());
+        Integer faceVerifyMinute = null;
+        // 如果是新活体检测方案,则使用新的计算方案计算活检开始时间
+        if (NEW_FACE_BIOPSY_SCHEME.equals(orgProperty.getValue())) {
+            faceVerifyMinute = faceBiopsyService.getFaceBiopsyStartMinute(examRecordDataId);
+        }
+        // 非新活检,默认使用旧的活检计算方式
+        else {
+            faceVerifyMinute = examFaceLivenessVerifyService.getFaceLivenessVerifyMinute(
+                    examRecordData.getOrgId(), examRecordData.getExamId(), studentId,
+                    examRecordData.getId(), examSessionInfo.getHeartbeat());
+        }
+
+        faceBiopsyBaseInfo.setFaceVerifyMinute(faceVerifyMinute);
+        return faceBiopsyBaseInfo;
+    }
+
+    @ApiOperation(value = "获取人脸活体检测详细步骤")
     @GetMapping("/getFaceBiopsyInfo")
     public FaceBiopsyInfo getFaceBiopsyInfo(@RequestParam Long examRecordDataId) {
         User user = getAccessUser();

+ 38 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/bean/FaceBiopsyBaseInfo.java

@@ -0,0 +1,38 @@
+package cn.com.qmth.examcloud.core.oe.student.bean;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.List;
+
+/**
+ * @Description 人脸活体检测基础信息信息
+ * @Author lideyin
+ * @Date 2019/10/14 11:21
+ * @Version 1.0
+ */
+public class FaceBiopsyBaseInfo implements JsonSerializable {
+    private static final long serialVersionUID = 3639013689409712841L;
+
+    @ApiModelProperty(value = "活体检测方案", notes = "S1:旧方案;S2:新方案", required = true)
+    private String identificationOfLivingBodyScheme;
+
+    @ApiModelProperty(value = "活体检测开始分钟数", required = true)
+    private Integer faceVerifyMinute;
+
+    public String getIdentificationOfLivingBodyScheme() {
+        return identificationOfLivingBodyScheme;
+    }
+
+    public void setIdentificationOfLivingBodyScheme(String identificationOfLivingBodyScheme) {
+        this.identificationOfLivingBodyScheme = identificationOfLivingBodyScheme;
+    }
+
+    public Integer getFaceVerifyMinute() {
+        return faceVerifyMinute;
+    }
+
+    public void setFaceVerifyMinute(Integer faceVerifyMinute) {
+        this.faceVerifyMinute = faceVerifyMinute;
+    }
+}

+ 20 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/FaceBiopsyServiceImpl.java

@@ -121,10 +121,30 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
      */
     @Override
     public Integer getFaceBiopsyStartMinute(Long examRecordDataId) {
+
         FaceBiopsyEntity faceBiopsyEntity = faceBiopsyRepo.findByExamRecordDataId(examRecordDataId);
         if (faceBiopsyEntity == null) {
             return null;
         }
+
+        //判断考试记录id是否有效
+        ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId,
+                ExamRecordDataEntity.class);
+
+        //如果冻结时间外不添加活体检测,则已活检测次数为>=2次,超过两次,则返回null
+        if (!addFaceVerifyOutFreezeTime(examRecordData.getExamId(), examRecordData.getOrgId(),
+                examRecordData.getStudentId())) {
+            if (faceBiopsyEntity.getVerifiedTimes() >= 2) {
+                return null;
+            }
+        }
+        //如果冻结时间外添加新活检,则已最大活检次数>=3次,则返回null
+        else {
+            if (faceBiopsyEntity.getVerifiedTimes() >= 3) {
+                return null;
+            }
+        }
+
         return calculateFaceBiopsyStartMinute(examRecordDataId, faceBiopsyEntity.getVerifiedTimes());
     }