|
@@ -4,7 +4,6 @@ import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.helpers.JsonHttpResponseHolder;
|
|
|
import cn.com.qmth.examcloud.core.oe.common.base.Constants;
|
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureEntity;
|
|
|
-import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureQueueEntity;
|
|
|
import cn.com.qmth.examcloud.core.oe.common.enums.ExamCaptureQueueStatus;
|
|
|
import cn.com.qmth.examcloud.core.oe.common.enums.ExamProperties;
|
|
|
import cn.com.qmth.examcloud.core.oe.common.repository.ExamCaptureQueueRepo;
|
|
@@ -15,6 +14,7 @@ import cn.com.qmth.examcloud.core.oe.student.face.service.ExamCaptureQueueServic
|
|
|
import cn.com.qmth.examcloud.core.oe.student.face.service.ExamCaptureService;
|
|
|
import cn.com.qmth.examcloud.core.oe.student.face.service.FaceCompareService;
|
|
|
import cn.com.qmth.examcloud.core.oe.student.face.service.bean.CompareFaceSyncInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.face.service.bean.ExamCaptureQueueInfo;
|
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.ExamRecordPropertyCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
@@ -37,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
* @author chenken
|
|
@@ -80,7 +81,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void disposeFaceCompare(ExamCaptureQueueEntity examCaptureQueue) {
|
|
|
+ public void disposeFaceCompare(ExamCaptureQueueInfo examCaptureQueue) {
|
|
|
//将队列记录修改为处理中
|
|
|
examCaptureQueueRepo.updateExamCaptureQueueStatusWithProcessing(examCaptureQueue.getId());
|
|
|
examCaptureQueue.setFaceCompareStartTime(System.currentTimeMillis());
|
|
@@ -130,13 +131,15 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
}
|
|
|
examCaptureQueue.setFaceCompareResult(faceCompareResult.toString());
|
|
|
|
|
|
+ //人脸比对出错的处理
|
|
|
if (faceCompareResult.containsKey(Constants.ERROR_MSG)) {
|
|
|
String errMsg = faceCompareResult.getString(Constants.ERROR_MSG);
|
|
|
|
|
|
//如果API并发次数超过上限,则保存错误信息到队列,并抛出异常,用于协调满载队列线程
|
|
|
if (errMsg.contains(Constants.FACE_COMPARE_CONCURRENCY_LIMIT_EXCEEDED)) {
|
|
|
- examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
|
|
|
- "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(), ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
|
|
|
+ examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
|
|
|
+ "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(),
|
|
|
+ ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
|
|
|
|
|
|
captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对接口超过最大并发次数");
|
|
|
|
|
@@ -181,27 +184,30 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
|
|
|
captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,即将重试,errMsg:" + errMsg);
|
|
|
// 其它错误类型,保存错误信息到队列中,待自动重新服务处理
|
|
|
- examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
|
|
|
- "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(), ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
|
|
|
+ examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
|
|
|
+ "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceCompareResult.toString(),
|
|
|
+ ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
|
|
|
ExamCaptureProcessStatisticController.increaseFaceCompareFailedCount();//增加错误次数
|
|
|
captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对出现错误,增加错误次数后failedCount:" +
|
|
|
- ExamCaptureProcessStatisticController.getFaceCompareFailedCount()+",totalCount="+
|
|
|
+ ExamCaptureProcessStatisticController.getFaceCompareFailedCount() + ",totalCount=" +
|
|
|
ExamCaptureProcessStatisticController.getFaceCompareCount());
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ //人脸比对没有出错的情况
|
|
|
+ else {
|
|
|
//face++的结果检测到人脸,才执行百度活体检测
|
|
|
if (faceCompareResult.containsKey("confidence")) {
|
|
|
- examCaptureQueue.setIsPass(calculateFaceCompareIsPass(faceCompareResult));
|
|
|
- examCaptureQueue.setIsStranger(calculateFaceCompareIsStranger(examCaptureQueue.getExamRecordDataId(), faceCompareResult));
|
|
|
+ examCaptureQueue.setPass(calculateFaceCompareIsPass(faceCompareResult));
|
|
|
+ examCaptureQueue.setStranger(calculateFaceCompareIsStranger(examCaptureQueue.getExamRecordDataId(), faceCompareResult));
|
|
|
//更新队列状态为face++比对完成
|
|
|
examCaptureQueue.setStatus(ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_COMPLETE);
|
|
|
- examCaptureQueueRepo.save(examCaptureQueue);
|
|
|
+ disposeFaceCompareSuccessful(examCaptureQueue);
|
|
|
|
|
|
captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对完成,即将进行百度活体检测,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
|
|
|
}
|
|
|
//face++ 没有检测到人脸,直接保存人脸检测最终结果并删除队列
|
|
|
else {
|
|
|
- examCaptureQueue.setIsPass(false);
|
|
|
- examCaptureQueue.setIsStranger(false);
|
|
|
+ examCaptureQueue.setPass(false);
|
|
|
+ examCaptureQueue.setStranger(false);
|
|
|
saveExamCaptureAndDeleteQueue(examCaptureQueue);
|
|
|
|
|
|
captureLog.debug("[DISPOSE_FACE_COMPARE] face++人脸比对完成,且未检测到人脸,耗时:" + (System.currentTimeMillis() - startTime) + " ms");
|
|
@@ -210,20 +216,12 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
} while (retry);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- //face++人脸比对失败时,需要将状态置为失败,并清空批次号
|
|
|
- public void disposeFaceCompareFaild(ExamCaptureQueueEntity examCaptureQueue) {
|
|
|
- examCaptureQueue.setStatus(ExamCaptureQueueStatus.PROCESS_FACE_COMPARE_FAILED);
|
|
|
- examCaptureQueue.setProcessBatchNum("000000");
|
|
|
- examCaptureQueueRepo.save(examCaptureQueue);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- //百度活体检测失败时,需要将状态置为失败,并清空批次号
|
|
|
- public void disposeBaiDuFaceLivenessFaild(ExamCaptureQueueEntity examCaptureQueue) {
|
|
|
- examCaptureQueue.setStatus(ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
|
|
|
- examCaptureQueue.setProcessBatchNum("000000");
|
|
|
- examCaptureQueueRepo.save(examCaptureQueue);
|
|
|
+ //人脸比较成功时的处理
|
|
|
+ public void disposeFaceCompareSuccessful(ExamCaptureQueueInfo examCaptureQueueInfo) {
|
|
|
+ examCaptureQueueRepo.saveExamCaptureQueueEntityBySuccessful(examCaptureQueueInfo.getId(),
|
|
|
+ examCaptureQueueInfo.getPass(), examCaptureQueueInfo.getStranger(),
|
|
|
+ examCaptureQueueInfo.getStatus().toString(), examCaptureQueueInfo.getFaceCompareResult(),
|
|
|
+ examCaptureQueueInfo.getFaceCompareStartTime(), new Date());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -233,7 +231,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
* @param examCaptureQueue 抓拍照片队列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public void disposeBaiDuFaceLiveness(ExamCaptureQueueEntity examCaptureQueue) {
|
|
|
+ public void disposeBaiDuFaceLiveness(ExamCaptureQueueInfo examCaptureQueue) {
|
|
|
//活体检测超时次数
|
|
|
int facelivenessTimeOutTimes = 0;
|
|
|
//百度活检超时最大重试次数
|
|
@@ -275,8 +273,9 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
|
|
|
//如果API并发次数超过上限,则保存错误信息到队列,并抛出异常,用于协调满载队列线程
|
|
|
if (errCode.equals(Constants.BAIDU_FACELIVENESS_QPS_LIMIT_EXCEEDED_CODE)) {
|
|
|
- examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
|
|
|
- "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
|
|
|
+ examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
|
|
|
+ "SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceLivenessResultJson.toString(),
|
|
|
+ ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
|
|
|
|
|
|
captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度在线活体API接口超过最大并发次数");
|
|
|
|
|
@@ -321,7 +320,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
|
|
|
captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测出现错误,即将重试,错误码:" + errCode);
|
|
|
// 其它错误类型,保存错误信息到队列中,待自动重新服务处理
|
|
|
- examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue,
|
|
|
+ examCaptureQueueService.saveExamCaptureQueueEntityByFailed(examCaptureQueue.getId(),
|
|
|
"SatusCode:" + jsonHttpResponseHolder.getStatusCode() + " | " + faceLivenessResultJson.toString(), ExamCaptureQueueStatus.PROCESS_FACELIVENESS_FAILED);
|
|
|
ExamCaptureProcessStatisticController.increaseFaceLivenessDetectFailedCount();//增加错误次数
|
|
|
captureLog.debug("[DISPOSE_BAIDUFACELIVENESS] 百度活体检测出现错误,增加错误次数后failedCount:" + ExamCaptureProcessStatisticController.getFaceLivenessDetectFailedCount());
|
|
@@ -344,7 +343,7 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void saveExamCaptureAndDeleteQueue(ExamCaptureQueueEntity examCaptureQueue) {
|
|
|
+ public void saveExamCaptureAndDeleteQueue(ExamCaptureQueueInfo examCaptureQueue) {
|
|
|
ExamCaptureEntity examCapture = getExamCaptureFromQueue(examCaptureQueue);
|
|
|
|
|
|
//同一考试记录下如果有重复的照片,则直接跳过
|
|
@@ -357,10 +356,10 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
examCaptureRepo.save(examCapture);
|
|
|
}
|
|
|
//删除队列中的记录
|
|
|
- examCaptureQueueRepo.delete(examCaptureQueue);
|
|
|
+ examCaptureQueueRepo.deleteById(examCaptureQueue.getId());
|
|
|
}
|
|
|
|
|
|
- private ExamCaptureEntity getExamCaptureFromQueue(ExamCaptureQueueEntity queue) {
|
|
|
+ private ExamCaptureEntity getExamCaptureFromQueue(ExamCaptureQueueInfo queue) {
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
long createTimeMillis = queue.getCreationTime().getTime();
|
|
|
long faceCompareStartTimeMillis = queue.getFaceCompareStartTime();
|
|
@@ -374,8 +373,8 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
|
|
|
resultEntity.setFileName(queue.getFileName());
|
|
|
resultEntity.setFileUrl(queue.getFileUrl());
|
|
|
resultEntity.setHasVirtualCamera(queue.getHasVirtualCamera());
|
|
|
- resultEntity.setIsStranger(queue.getIsStranger());
|
|
|
- resultEntity.setIsPass(queue.getIsPass());
|
|
|
+ resultEntity.setIsStranger(queue.getStranger());
|
|
|
+ resultEntity.setIsPass(queue.getPass());
|
|
|
resultEntity.setProcessTime(currentTimeMillis - createTimeMillis);//从进队列到处理完毕的时间
|
|
|
resultEntity.setUsedTime(currentTimeMillis - faceCompareStartTimeMillis);//从开始处理到处理完毕的时间
|
|
|
return resultEntity;
|