Sfoglia il codice sorgente

人脸活检改成hash缓存

xiatian 4 anni fa
parent
commit
ad1da59601

+ 10 - 0
themis-business/src/main/java/com/qmth/themis/business/cache/ExamRecordCacheUtil.java

@@ -133,4 +133,14 @@ public class ExamRecordCacheUtil {
 	public static Integer getBreachStatus(Long recordId) {
 		return (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "breachStatus");
 	}
+	
+	public static void setInProcessLivenessVerifyCount(Long recordId, Integer inProcessLivenessVerifyCount) {
+		redisUtil.set(RedisKeyHelper.examRecordCacheKey(recordId), "inProcessLivenessVerifyCount", inProcessLivenessVerifyCount);
+	}
+	
+	public static Integer getInProcessLivenessVerifyCount(Long recordId) {
+		return (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "inProcessLivenessVerifyCount");
+	}
+	
+	
 }

+ 25 - 0
themis-business/src/main/java/com/qmth/themis/business/cache/FaceVerifyCacheUtil.java

@@ -0,0 +1,25 @@
+package com.qmth.themis.business.cache;
+
+import com.qmth.themis.business.cache.bean.FaceVerifyCacheBean;
+import com.qmth.themis.business.constant.SpringContextHolder;
+import com.qmth.themis.business.util.RedisUtil;
+
+/**
+ * 人脸缓存
+ * 
+ * @Description:
+ * @Author: xiatian
+ * @Date: 2020-08-11
+ */
+public class FaceVerifyCacheUtil {
+	private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
+
+	public static void setFaceVerifyCacheBean(Long examRecordId, Long id, FaceVerifyCacheBean bean) {
+		redisUtil.set(RedisKeyHelper.faceVerifyCacheKey(examRecordId), id.toString(), bean);
+	}
+
+	public static FaceVerifyCacheBean getFaceVerifyCacheBean(Long examRecordId, Long id) {
+		return (FaceVerifyCacheBean) redisUtil.get(RedisKeyHelper.faceVerifyCacheKey(examRecordId), id.toString());
+	}
+
+}

+ 23 - 0
themis-business/src/main/java/com/qmth/themis/business/cache/LivenessVerifyCacheUtil.java

@@ -0,0 +1,23 @@
+package com.qmth.themis.business.cache;
+
+import com.qmth.themis.business.cache.bean.LivenessVerifyCacheBean;
+import com.qmth.themis.business.constant.SpringContextHolder;
+import com.qmth.themis.business.util.RedisUtil;
+
+/**活检缓存
+ * @Description: 
+ * @Author: xiatian
+ * @Date: 2020-08-11
+ */
+public class LivenessVerifyCacheUtil {
+	private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
+
+	public static void setLivenessVerifyCacheBean(Long examRecordId, Long id, LivenessVerifyCacheBean bean) {
+		redisUtil.set(RedisKeyHelper.livenessVerifyCacheKey(examRecordId), id.toString(), bean);
+	}
+
+	public static LivenessVerifyCacheBean getLivenessVerifyCacheBean(Long examRecordId, Long id) {
+		return (LivenessVerifyCacheBean) redisUtil.get(RedisKeyHelper.livenessVerifyCacheKey(examRecordId), id.toString());
+	}
+
+}

+ 8 - 8
themis-business/src/main/java/com/qmth/themis/business/cache/RedisKeyHelper.java

@@ -125,23 +125,23 @@ public class RedisKeyHelper {
 	}
 	
 	/**
-	 * 人脸验证
+	 * 人脸验证 大key
 	 * 
-	 * @param id
+	 * @param examRecordId
 	 * @return
 	 */
-	public static String faceVerifyCacheKey(Long id) {
-		return faceVerifyKeyPrefix + id;
+	public static String faceVerifyCacheKey(Long examRecordId) {
+		return faceVerifyKeyPrefix + examRecordId;
 	}
 	
 	/**
-	 * 活体验证
+	 * 活体验证 大key
 	 * 
-	 * @param id
+	 * @param examRecordId
 	 * @return
 	 */
-	public static String livenessVerifyCacheKey(Long id) {
-		return livenessVerifyKeyPrefix + id;
+	public static String livenessVerifyCacheKey(Long examRecordId) {
+		return livenessVerifyKeyPrefix + examRecordId;
 	}
 	
 	/**断点缓存大key

+ 6 - 6
themis-business/src/main/java/com/qmth/themis/business/service/TOeExamRecordService.java

@@ -2,6 +2,8 @@ package com.qmth.themis.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.themis.business.entity.TOeExamRecord;
+import com.qmth.themis.business.enums.ExamTypeEnum;
+import com.qmth.themis.business.enums.LivenessTypeEnum;
 import com.qmth.themis.business.enums.VerifyExceptionEnum;
 
 import java.util.Map;
@@ -39,12 +41,10 @@ public interface TOeExamRecordService extends IService<TOeExamRecord> {
 	 */
 	public void saveDataByCache(Long recordId);
 
-	/**首次开考验证结果保存
-	 * @param recordId
-	 * @param entryAuthenticationId
-	 * @param entryAuthenticationResult
-	 */
-	void saveAuthenticationResultOnStart(Long recordId, Long entryAuthenticationId,
+	void saveFaceVerify(ExamTypeEnum type, Long recordId, Long entryAuthenticationId,
+			VerifyExceptionEnum entryAuthenticationResult);
+
+	void saveLivenessVerify(LivenessTypeEnum type, Long recordId, Long entryAuthenticationId,
 			VerifyExceptionEnum entryAuthenticationResult);
 
 }

+ 2 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/CommonServiceImpl.java

@@ -51,6 +51,8 @@ public class CommonServiceImpl implements CommonService {
 			redisUtil.delete(RedisKeyHelper.examRecordCacheKey(recordId));
 			redisUtil.delete(RedisKeyHelper.examAnswerKey(recordId));
 			redisUtil.delete(RedisKeyHelper.audioLeftPlayCountKey(recordId));
+			redisUtil.delete(RedisKeyHelper.livenessVerifyCacheKey(recordId));
+			redisUtil.delete(RedisKeyHelper.faceVerifyCacheKey(recordId));
 		} finally {
 			redisUtil.releaseLock(lockKey);
 		}

+ 21 - 8
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -35,6 +35,8 @@ import com.qmth.themis.business.entity.TEExamStudent;
 import com.qmth.themis.business.entity.TOeExamAnswer;
 import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.ExamRecordStatusEnum;
+import com.qmth.themis.business.enums.ExamTypeEnum;
+import com.qmth.themis.business.enums.LivenessTypeEnum;
 import com.qmth.themis.business.enums.ObjectiveScorePolicyEnum;
 import com.qmth.themis.business.enums.VerifyExceptionEnum;
 import com.qmth.themis.business.service.TEExamPaperService;
@@ -341,15 +343,26 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
         return UUID.randomUUID().toString().replaceAll("-", "");
     }
 	
-	/**首次开考验证结果保存
-	 * @param recordId
-	 * @param entryAuthenticationId
-	 * @param entryAuthenticationResult
-	 */
+	
+	@Override
+	public void saveFaceVerify(ExamTypeEnum type,Long recordId, Long entryAuthenticationId, VerifyExceptionEnum entryAuthenticationResult) {
+		if(ExamTypeEnum.FIRST.equals(type)) {
+			ExamRecordCacheUtil.setEntryAuthenticationId(recordId, entryAuthenticationId);
+			ExamRecordCacheUtil.setEntryAuthenticationResult(recordId, entryAuthenticationResult);
+		}else if(ExamTypeEnum.PROCESS.equals(type)) {
+			
+		}
+	}
+	
 	@Override
-	public void saveAuthenticationResultOnStart(Long recordId, Long entryAuthenticationId, VerifyExceptionEnum entryAuthenticationResult) {
-		ExamRecordCacheUtil.setEntryAuthenticationId(recordId, entryAuthenticationId);
-		ExamRecordCacheUtil.setEntryAuthenticationResult(recordId, entryAuthenticationResult);
+	public void saveLivenessVerify(LivenessTypeEnum type,Long recordId, Long entryAuthenticationId, VerifyExceptionEnum entryAuthenticationResult) {
+		if(LivenessTypeEnum.FIRST_START.equals(type)) {
+			ExamRecordCacheUtil.setEntryAuthenticationId(recordId, entryAuthenticationId);
+			ExamRecordCacheUtil.setEntryAuthenticationResult(recordId, entryAuthenticationResult);
+		}else if(LivenessTypeEnum.IN_PROCESS.equals(type)) {
+			Integer count=ExamRecordCacheUtil.getInProcessLivenessVerifyCount(recordId);
+			ExamRecordCacheUtil.setInProcessLivenessVerifyCount(recordId, (count==null?0:count+1));
+		}
 	}
 	
 }

+ 4 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeFaceVerifyHistoryServiceImpl.java

@@ -9,7 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.bean.exam.FaceVerifyBean;
-import com.qmth.themis.business.cache.RedisKeyHelper;
+import com.qmth.themis.business.cache.FaceVerifyCacheUtil;
 import com.qmth.themis.business.cache.bean.FaceVerifyCacheBean;
 import com.qmth.themis.business.dao.TOeFaceVerifyHistoryMapper;
 import com.qmth.themis.business.entity.TOeFaceVerifyHistory;
@@ -54,14 +54,14 @@ public class TOeFaceVerifyHistoryServiceImpl extends ServiceImpl<TOeFaceVerifyHi
 		cache.setSimilarity(similarity);
 		cache.setType(ExamTypeEnum.valueOf(type));
 		cache.setTime(time);
-		redisUtil.set(RedisKeyHelper.faceVerifyCacheKey(cache.getId()), cache);
+		FaceVerifyCacheUtil.setFaceVerifyCacheBean(recordId, cache.getId(), cache);
 		FaceVerifyBean ret=new FaceVerifyBean();
 		ret.setId(cache.getId());
 		ret.setUpdateTime(new Date().getTime());
 		if(ExamTypeEnum.RECOVER.equals(cache.getType())) {
 			examBreakHistoryService.saveAuthenticationResult(recordId, cache.getId(), cache.getException());
-		}else if(ExamTypeEnum.FIRST.equals(cache.getType())) {
-			examRecordService.saveAuthenticationResultOnStart(recordId, cache.getId(), cache.getException());
+		}else {
+			examRecordService.saveFaceVerify(cache.getType(),recordId, cache.getId(), cache.getException());
 		}
 		return ret;
 	}

+ 4 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeLivenessVerifyHistoryServiceImpl.java

@@ -9,7 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.bean.exam.LivenessVerifyBean;
-import com.qmth.themis.business.cache.RedisKeyHelper;
+import com.qmth.themis.business.cache.LivenessVerifyCacheUtil;
 import com.qmth.themis.business.cache.bean.LivenessVerifyCacheBean;
 import com.qmth.themis.business.dao.TOeLivenessVerifyHistoryMapper;
 import com.qmth.themis.business.entity.TOeLivenessVerifyHistory;
@@ -52,14 +52,14 @@ public class TOeLivenessVerifyHistoryServiceImpl extends ServiceImpl<TOeLiveness
 		cache.setStartTime(new Date(startTime));
 		cache.setFinishTime(new Date(finishTime));
 		cache.setException(VerifyExceptionEnum.valueOf(exception));
-		redisUtil.set(RedisKeyHelper.livenessVerifyCacheKey(cache.getId()), cache);
+		LivenessVerifyCacheUtil.setLivenessVerifyCacheBean(recordId,cache.getId(), cache);
 		LivenessVerifyBean ret=new LivenessVerifyBean();
 		ret.setId(cache.getId());
 		ret.setUpdateTime(new Date().getTime());
 		if(LivenessTypeEnum.RESUME_START.equals(cache.getType())) {
 			examBreakHistoryService.saveAuthenticationResult(recordId, cache.getId(), cache.getException());
-		}else if(LivenessTypeEnum.FIRST_START.equals(cache.getType())) {
-			examRecordService.saveAuthenticationResultOnStart(recordId, cache.getId(), cache.getException());
+		}else  {
+			examRecordService.saveLivenessVerify(cache.getType(),recordId, cache.getId(), cache.getException());
 		}
 		return ret;
 	}