|
@@ -0,0 +1,156 @@
|
|
|
|
+package com.qmth.themis.business.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.qmth.themis.business.cache.RedisKeyHelper;
|
|
|
|
+import com.qmth.themis.business.dto.WarningDto;
|
|
|
|
+import com.qmth.themis.business.entity.TEConfig;
|
|
|
|
+import com.qmth.themis.business.entity.TIeInvigilateWarnInfo;
|
|
|
|
+import com.qmth.themis.business.entity.TOeFaceVerifyHistory;
|
|
|
|
+import com.qmth.themis.business.enums.WarningEnum;
|
|
|
|
+import com.qmth.themis.business.enums.WarningLevelEnum;
|
|
|
|
+import com.qmth.themis.business.service.TEConfigService;
|
|
|
|
+import com.qmth.themis.business.service.TIeInvigilateWarnInfoService;
|
|
|
|
+import com.qmth.themis.business.service.TOeFaceVerifyHistoryService;
|
|
|
|
+import com.qmth.themis.business.service.WarningService;
|
|
|
|
+import com.qmth.themis.business.util.RedisUtil;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Description: 预警规则公用
|
|
|
|
+ * @Param:
|
|
|
|
+ * @return:
|
|
|
|
+ * @Author: wangliang
|
|
|
|
+ * @Date: 2020/8/18
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class WarningServiceImpl implements WarningService {
|
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(WarningServiceImpl.class);
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ TEConfigService teConfigService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ TOeFaceVerifyHistoryService faceVerifyHistoryService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ TIeInvigilateWarnInfoService tIeInvigilateWarnInfoService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 人脸数量异常
|
|
|
|
+ *
|
|
|
|
+ * @param warningDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void faceCountError(WarningDto warningDto) {
|
|
|
|
+ Long recordId = warningDto.getRecordId();
|
|
|
|
+ Integer faceCount = warningDto.getFaceCount();
|
|
|
|
+ WarningEnum warningEnum = warningDto.getWarningEnum();
|
|
|
|
+ TEConfig teConfig = teConfigService.getGlobalConfig();
|
|
|
|
+ Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
+ Long examId = Long.parseLong(String.valueOf(objectMap.get("examId")));
|
|
|
|
+ Long examStudentId = Long.parseLong(String.valueOf(objectMap.get("examStudentId")));
|
|
|
|
+ Long examActivityId = Long.parseLong(String.valueOf(objectMap.get("examActivityId")));
|
|
|
|
+ QueryWrapper<TOeFaceVerifyHistory> tOeFaceVerifyHistoryQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ if (faceCount > 1) {//多张人脸
|
|
|
|
+ tOeFaceVerifyHistoryQueryWrapper.lambda().eq(TOeFaceVerifyHistory::getExamRecordId, recordId).ge(TOeFaceVerifyHistory::getFaceCount, 1).eq(TOeFaceVerifyHistory::getException, warningEnum.name());
|
|
|
|
+ int count = faceVerifyHistoryService.count(tOeFaceVerifyHistoryQueryWrapper);
|
|
|
|
+ count++;
|
|
|
|
+ if (count >= teConfig.getMultipleFaceCountError()) {
|
|
|
|
+ TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(1), WarningLevelEnum.valueOf(warningEnum.getLevel().get(1)).getDesc(), warningEnum);
|
|
|
|
+ tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
|
|
|
|
+ }
|
|
|
|
+ } else if (faceCount <= 0) {//未检测到人脸
|
|
|
|
+ tOeFaceVerifyHistoryQueryWrapper.lambda().eq(TOeFaceVerifyHistory::getExamRecordId, recordId).le(TOeFaceVerifyHistory::getFaceCount, 0).eq(TOeFaceVerifyHistory::getException, warningEnum.name());
|
|
|
|
+ int count = faceVerifyHistoryService.count(tOeFaceVerifyHistoryQueryWrapper);
|
|
|
|
+ count++;
|
|
|
|
+ if (count >= teConfig.getNoFaceCountError()) {
|
|
|
|
+ TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(0), WarningLevelEnum.valueOf(warningEnum.getLevel().get(0)).getDesc(), warningEnum);
|
|
|
|
+ tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 人脸比对异常
|
|
|
|
+ *
|
|
|
|
+ * @param warningDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void faceCompareError(WarningDto warningDto) {
|
|
|
|
+ Long recordId = warningDto.getRecordId();
|
|
|
|
+ WarningEnum warningEnum = warningDto.getWarningEnum();
|
|
|
|
+ TEConfig teConfig = teConfigService.getGlobalConfig();
|
|
|
|
+ Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
+ Long examId = Long.parseLong(String.valueOf(objectMap.get("examId")));
|
|
|
|
+ Long examStudentId = Long.parseLong(String.valueOf(objectMap.get("examStudentId")));
|
|
|
|
+ Long examActivityId = Long.parseLong(String.valueOf(objectMap.get("examActivityId")));
|
|
|
|
+ QueryWrapper<TOeFaceVerifyHistory> tOeFaceVerifyHistoryQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ tOeFaceVerifyHistoryQueryWrapper.lambda().eq(TOeFaceVerifyHistory::getExamRecordId, recordId).eq(TOeFaceVerifyHistory::getException, warningEnum.name());
|
|
|
|
+ int count = faceVerifyHistoryService.count(tOeFaceVerifyHistoryQueryWrapper);
|
|
|
|
+ count++;
|
|
|
|
+ if (count >= teConfig.getMatchFaceCompareErrorCount()) {
|
|
|
|
+ TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(0), WarningLevelEnum.valueOf(warningEnum.getLevel().get(0)).getDesc(), warningEnum);
|
|
|
|
+ tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
|
|
|
|
+ }
|
|
|
|
+ if (count >= teConfig.getTotalFaceCompareErrorCount()) {
|
|
|
|
+ TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(1), WarningLevelEnum.valueOf(warningEnum.getLevel().get(1)).getDesc(), warningEnum);
|
|
|
|
+ tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 闭眼检测异常
|
|
|
|
+ *
|
|
|
|
+ * @param warningDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void eyeCloseError(WarningDto warningDto) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 活体动作异常
|
|
|
|
+ *
|
|
|
|
+ * @param warningDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void livenessActionError(WarningDto warningDto) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 真实性异常
|
|
|
|
+ *
|
|
|
|
+ * @param warningDto
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void realnessError(WarningDto warningDto) {
|
|
|
|
+ Long recordId = warningDto.getRecordId();
|
|
|
|
+ WarningEnum warningEnum = warningDto.getWarningEnum();
|
|
|
|
+ TEConfig teConfig = teConfigService.getGlobalConfig();
|
|
|
|
+ Map<String, Object> objectMap = redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
|
+ Long examId = Long.parseLong(String.valueOf(objectMap.get("examId")));
|
|
|
|
+ Long examStudentId = Long.parseLong(String.valueOf(objectMap.get("examStudentId")));
|
|
|
|
+ Long examActivityId = Long.parseLong(String.valueOf(objectMap.get("examActivityId")));
|
|
|
|
+ QueryWrapper<TOeFaceVerifyHistory> tOeFaceVerifyHistoryQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ tOeFaceVerifyHistoryQueryWrapper.lambda().eq(TOeFaceVerifyHistory::getExamRecordId, recordId).eq(TOeFaceVerifyHistory::getException, warningEnum.name());
|
|
|
|
+ int count = faceVerifyHistoryService.count(tOeFaceVerifyHistoryQueryWrapper);
|
|
|
|
+ count++;
|
|
|
|
+ if (count > teConfig.getRealnessCount()) {
|
|
|
|
+ TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(0), WarningLevelEnum.valueOf(warningEnum.getLevel().get(0)).getDesc(), warningEnum);
|
|
|
|
+ tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|