|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|