Selaa lähdekoodia

update face verify api

deason 3 vuotta sitten
vanhempi
commit
adbe181678

+ 12 - 1
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/api/controller/client/ExamProcessController.java

@@ -8,6 +8,7 @@ import cn.com.qmth.examcloud.core.oe.student.base.utils.Check;
 import cn.com.qmth.examcloud.core.oe.student.bean.*;
 import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceCaptureResult;
 import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceCompareResult;
+import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyInfo;
 import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyResult;
 import cn.com.qmth.examcloud.core.oe.student.service.*;
 import cn.com.qmth.examcloud.support.Constants;
@@ -60,6 +61,9 @@ public class ExamProcessController extends ControllerSupport {
     @Autowired
     private FaceProcessService faceProcessService;
 
+    @Autowired
+    private ExamFaceLiveVerifyService examFaceLiveVerifyService;
+
     @Autowired
     private RedisClient redisClient;
 
@@ -213,12 +217,19 @@ public class ExamProcessController extends ControllerSupport {
         faceProcessService.saveFaceCaptureResult(req);
     }
 
+    @ApiOperation(value = "开始人脸活体验证")
+    @PostMapping("/startFaceLiveVerify")
+    public FaceLiveVerifyInfo startFaceLiveVerify(@RequestParam Long examRecordDataId) {
+        User user = getAccessUser();
+        return examFaceLiveVerifyService.startFaceLiveVerify(examRecordDataId, user.getUserId());
+    }
+
     @ApiOperation(value = "保存人脸活体验证结果")
     @PostMapping("/saveFaceLiveVerifyResult")
     public void saveFaceLiveVerifyResult(@RequestBody FaceLiveVerifyResult req) {
         User user = getAccessUser();
         req.setStudentId(user.getUserId());
-        faceProcessService.saveFaceLiveVerifyResult(req);
+        examFaceLiveVerifyService.saveFaceLiveVerifyResult(req);
     }
 
 }

+ 14 - 0
examcloud-core-oe-student-dao/src/main/java/cn/com/qmth/examcloud/core/oe/student/dao/entity/ExamFaceLiveVerifyEntity.java

@@ -27,6 +27,12 @@ public class ExamFaceLiveVerifyEntity extends JpaEntity {
     @Column(nullable = false)
     private Long examRecordDataId;
 
+    /**
+     * 是否完成
+     */
+    @Column(nullable = false)
+    private Boolean finished;
+
     /**
      * 验证状态
      */
@@ -82,6 +88,14 @@ public class ExamFaceLiveVerifyEntity extends JpaEntity {
         this.examRecordDataId = examRecordDataId;
     }
 
+    public Boolean getFinished() {
+        return finished;
+    }
+
+    public void setFinished(Boolean finished) {
+        this.finished = finished;
+    }
+
     public FaceLiveVerifyStatus getStatus() {
         return status;
     }

+ 21 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/bean/client/FaceLiveVerifyInfo.java

@@ -0,0 +1,21 @@
+package cn.com.qmth.examcloud.core.oe.student.bean.client;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+import io.swagger.annotations.ApiModelProperty;
+
+public class FaceLiveVerifyInfo implements JsonSerializable {
+
+    private static final long serialVersionUID = 3567311334163339241L;
+
+    @ApiModelProperty(value = "当前活检记录ID")
+    private Long faceLiveVerifyId;
+
+    public Long getFaceLiveVerifyId() {
+        return faceLiveVerifyId;
+    }
+
+    public void setFaceLiveVerifyId(Long faceLiveVerifyId) {
+        this.faceLiveVerifyId = faceLiveVerifyId;
+    }
+
+}

+ 11 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/bean/client/FaceLiveVerifyResult.java

@@ -16,6 +16,9 @@ public class FaceLiveVerifyResult implements JsonSerializable {
     @ApiModelProperty(value = "学生ID", hidden = true)
     private Long studentId;
 
+    @ApiModelProperty(value = "当前活检记录ID")
+    private Long faceLiveVerifyId;
+
     @ApiModelProperty(value = "考试记录ID")
     private Long examRecordDataId;
 
@@ -48,6 +51,14 @@ public class FaceLiveVerifyResult implements JsonSerializable {
         this.studentId = studentId;
     }
 
+    public Long getFaceLiveVerifyId() {
+        return faceLiveVerifyId;
+    }
+
+    public void setFaceLiveVerifyId(Long faceLiveVerifyId) {
+        this.faceLiveVerifyId = faceLiveVerifyId;
+    }
+
     public Long getExamRecordDataId() {
         return examRecordDataId;
     }

+ 12 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/ExamFaceLiveVerifyService.java

@@ -0,0 +1,12 @@
+package cn.com.qmth.examcloud.core.oe.student.service;
+
+import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyInfo;
+import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyResult;
+
+public interface ExamFaceLiveVerifyService {
+
+    FaceLiveVerifyInfo startFaceLiveVerify(Long examRecordDataId, Long studentId);
+
+    void saveFaceLiveVerifyResult(FaceLiveVerifyResult req);
+
+}

+ 0 - 3
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/FaceProcessService.java

@@ -2,7 +2,6 @@ package cn.com.qmth.examcloud.core.oe.student.service;
 
 import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceCaptureResult;
 import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceCompareResult;
-import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyResult;
 
 /**
  * 人脸照片处理相关接口
@@ -13,6 +12,4 @@ public interface FaceProcessService {
 
     void saveFaceCaptureResult(FaceCaptureResult req);
 
-    void saveFaceLiveVerifyResult(FaceLiveVerifyResult req);
-
 }

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

@@ -0,0 +1,105 @@
+package cn.com.qmth.examcloud.core.oe.student.service.impl;
+
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.util.JsonMapper;
+import cn.com.qmth.examcloud.core.oe.student.base.utils.Check;
+import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyInfo;
+import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyResult;
+import cn.com.qmth.examcloud.core.oe.student.dao.ExamFaceLiveVerifyRepo;
+import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamFaceLiveVerifyEntity;
+import cn.com.qmth.examcloud.core.oe.student.dao.enums.FaceLiveVerifyStatus;
+import cn.com.qmth.examcloud.core.oe.student.service.ExamFaceLiveVerifyService;
+import cn.com.qmth.examcloud.core.oe.student.service.ExamRecordDataService;
+import cn.com.qmth.examcloud.core.oe.student.service.ExamingSessionService;
+import cn.com.qmth.examcloud.support.enums.ExamRecordStatus;
+import cn.com.qmth.examcloud.support.examing.ExamRecordData;
+import cn.com.qmth.examcloud.support.examing.ExamingSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.Optional;
+
+@Service
+public class ExamFaceLiveVerifyServiceImpl implements ExamFaceLiveVerifyService {
+
+    private static final Logger log = LoggerFactory.getLogger(ExamFaceLiveVerifyServiceImpl.class);
+
+    @Autowired
+    private ExamRecordDataService examRecordDataService;
+
+    @Autowired
+    private ExamingSessionService examingSessionService;
+
+    @Autowired
+    private ExamFaceLiveVerifyRepo examFaceLiveVerifyRepo;
+
+    @Override
+    public FaceLiveVerifyInfo startFaceLiveVerify(Long examRecordDataId, Long studentId) {
+        Check.isNull(studentId, "学生ID不能为空");
+        Check.isNull(examRecordDataId, "考试记录ID不能为空");
+
+        ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(examRecordDataId);
+        if (examRecordData == null || ExamRecordStatus.EXAM_ING != examRecordData.getExamRecordStatus()) {
+            throw new StatusException("考试记录无效");
+        }
+
+        ExamingSession examingSession = examingSessionService.getExamingSession(studentId);
+        if (examingSession == null) {
+            throw new StatusException("考试会话已过期");
+        }
+
+        ExamFaceLiveVerifyEntity entity = new ExamFaceLiveVerifyEntity();
+        entity.setExamRecordDataId(examRecordDataId);
+        entity.setFinished(false);
+        entity.setStatus(FaceLiveVerifyStatus.ERROR);
+        examFaceLiveVerifyRepo.save(entity);
+
+        // todo check
+
+        FaceLiveVerifyInfo info = new FaceLiveVerifyInfo();
+        info.setFaceLiveVerifyId(entity.getId());
+        return info;
+    }
+
+    @Override
+    public void saveFaceLiveVerifyResult(FaceLiveVerifyResult req) {
+        Check.isNull(req.getStudentId(), "学生ID不能为空");
+        Check.isNull(req.getFaceLiveVerifyId(), "当前活检记录ID不能为空");
+        Check.isNull(req.getExamRecordDataId(), "考试记录ID不能为空");
+        Check.isNull(req.getStatus(), "人脸活体验证状态不能为空");
+
+        ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
+        if (examRecordData == null || ExamRecordStatus.EXAM_ING != examRecordData.getExamRecordStatus()) {
+            log.warn("考试记录无效!examRecordDataId = {}, studentId = {}", req.getExamRecordDataId(), req.getStudentId());
+            return;
+        }
+
+        ExamingSession examingSession = examingSessionService.getExamingSession(req.getStudentId());
+        if (examingSession == null) {
+            log.warn("考试会话已过期!examRecordDataId = {}, studentId = {}", req.getExamRecordDataId(), req.getStudentId());
+            return;
+        }
+
+        Optional<ExamFaceLiveVerifyEntity> optional = examFaceLiveVerifyRepo.findById(req.getFaceLiveVerifyId());
+        if (!optional.isPresent()) {
+            log.warn("当前活检记录不存在!faceLiveVerifyId = {}", req.getFaceLiveVerifyId());
+            return;
+        }
+
+        ExamFaceLiveVerifyEntity entity = optional.get();
+        entity.setFinished(true);
+        entity.setStatus(req.getStatus());
+        entity.setFaceCount(req.getFaceCount());
+        entity.setSimilarity(req.getSimilarity());
+        entity.setRealness(req.getRealness());
+        entity.setErrorMsg(req.getErrorMsg());
+        entity.setProcessTime(req.getProcessTime() != null ? req.getProcessTime() : 1L);
+        entity.setActions(new JsonMapper().toJson(req.getActions()));
+        entity.setUpdateTime(new Date());
+        examFaceLiveVerifyRepo.save(entity);
+    }
+
+}

+ 1 - 34
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/FaceProcessServiceImpl.java

@@ -1,16 +1,12 @@
 package cn.com.qmth.examcloud.core.oe.student.service.impl;
 
 import cn.com.qmth.examcloud.commons.util.FileUtil;
-import cn.com.qmth.examcloud.commons.util.JsonMapper;
 import cn.com.qmth.examcloud.core.oe.student.base.bean.CompareFaceSyncInfo;
 import cn.com.qmth.examcloud.core.oe.student.base.utils.Check;
 import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceCaptureResult;
 import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceCompareResult;
-import cn.com.qmth.examcloud.core.oe.student.bean.client.FaceLiveVerifyResult;
 import cn.com.qmth.examcloud.core.oe.student.dao.ExamCaptureRepo;
-import cn.com.qmth.examcloud.core.oe.student.dao.ExamFaceLiveVerifyRepo;
 import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamCaptureEntity;
-import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamFaceLiveVerifyEntity;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamRecordDataService;
 import cn.com.qmth.examcloud.core.oe.student.service.FaceProcessService;
 import cn.com.qmth.examcloud.support.Constants;
@@ -39,9 +35,6 @@ public class FaceProcessServiceImpl implements FaceProcessService {
     @Autowired
     private ExamCaptureRepo examCaptureRepo;
 
-    @Autowired
-    private ExamFaceLiveVerifyRepo examFaceLiveVerifyRepo;
-
     @Autowired
     private RedisClient redisClient;
 
@@ -72,8 +65,7 @@ public class FaceProcessServiceImpl implements FaceProcessService {
 
         ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
         if (examRecordData == null || ExamRecordStatus.EXAM_ING != examRecordData.getExamRecordStatus()) {
-            // 考试记录无效
-            log.warn("Skip saveFaceCaptureResult... examRecordDataId = {}", req.getExamRecordDataId());
+            log.warn("考试记录无效!examRecordDataId = {}, studentId = {}", req.getExamRecordDataId(), req.getStudentId());
             return;
         }
 
@@ -113,29 +105,4 @@ public class FaceProcessServiceImpl implements FaceProcessService {
         examCaptureRepo.save(entity);
     }
 
-    @Override
-    public void saveFaceLiveVerifyResult(FaceLiveVerifyResult req) {
-        Check.isNull(req.getStudentId(), "学生ID不能为空");
-        Check.isNull(req.getExamRecordDataId(), "考试记录ID不能为空");
-        Check.isNull(req.getStatus(), "人脸活体验证状态不能为空");
-
-        ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(req.getExamRecordDataId());
-        if (examRecordData == null || ExamRecordStatus.EXAM_ING != examRecordData.getExamRecordStatus()) {
-            // 考试记录无效
-            log.warn("Skip saveFaceLiveVerifyResult... examRecordDataId = {}", req.getExamRecordDataId());
-            return;
-        }
-
-        ExamFaceLiveVerifyEntity entity = new ExamFaceLiveVerifyEntity();
-        entity.setExamRecordDataId(req.getExamRecordDataId());
-        entity.setStatus(req.getStatus());
-        entity.setFaceCount(req.getFaceCount());
-        entity.setSimilarity(req.getSimilarity());
-        entity.setRealness(req.getRealness());
-        entity.setErrorMsg(req.getErrorMsg());
-        entity.setProcessTime(req.getProcessTime() != null ? req.getProcessTime() : 1L);
-        entity.setActions(new JsonMapper().toJson(req.getActions()));
-        examFaceLiveVerifyRepo.save(entity);
-    }
-
 }