Ver código fonte

优化和完善处理短信代码

lideyin 5 anos atrás
pai
commit
1bfc4c6873

+ 27 - 32
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/impl/BaiduFaceLivenessWorker.java

@@ -12,42 +12,37 @@ import org.apache.commons.logging.LogFactory;
 
 /**
  * 百度活体检测工作线程
- * 
+ *
  * @author lideyin 20190620
  */
 public class BaiduFaceLivenessWorker implements Worker {
-	private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
-    private ExamCaptureProcessStatisticController statisticController;
-
-    public BaiduFaceLivenessWorker(ExamCaptureProcessStatisticController statisticController) {
-        this.statisticController = statisticController;
-    }
+    private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
 
     @Override
-	public void process(WorkerController controller, Object element) {
-        statisticController.increaseCount();
-		ExamCaptureService examCaptureService = SpringContextHolder.getBean(ExamCaptureService.class);
-		ExamCaptureQueueEntity examCaptureQueue = (ExamCaptureQueueEntity) element;
-		try {
-			examCaptureService.disposeBaiDuFaceLiveness(examCaptureQueue);
-		} catch (StatusException e) {
+    public void process(WorkerController controller, Object element) {
+        ExamCaptureProcessStatisticController.increaseFaceLivenessDetectCount();
+        ExamCaptureService examCaptureService = SpringContextHolder.getBean(ExamCaptureService.class);
+        ExamCaptureQueueEntity examCaptureQueue = (ExamCaptureQueueEntity) element;
+        try {
+            examCaptureService.disposeBaiDuFaceLiveness(examCaptureQueue);
+        } catch (StatusException e) {
 
-			//异常处理
-			examCaptureQueue.setErrorMsg(e.getDesc());
-			examCaptureService.disposeBaiDuFaceLivenessFaild(examCaptureQueue);
-			if ((e.getCode().equals(Constants.BAIDU_FACELIVENESS_QPS_LIMIT_EXCEEDED_CODE))) {
-				// 如果超过并发次数,则添加异常次数
-				controller.addConcurrencyWarn();
-			}else {
-                statisticController.increaseFailureCount();
-				captureLog.error("[BAIDU_FACELIVENESS_WORKER.] 自定义异常 "+e.getDesc(),e);
-			}
-		} catch (Exception e) {
-            statisticController.increaseFailureCount();
-			//异常处理
-			examCaptureQueue.setErrorMsg(e.getMessage());
-			examCaptureService.disposeBaiDuFaceLivenessFaild(examCaptureQueue);
-			captureLog.error("[BAIDU_FACELIVENESS_WORKER.] 系统异常 "+e.getMessage(),e);
-		}
-	}
+            //异常处理
+            examCaptureQueue.setErrorMsg(e.getDesc());
+            examCaptureService.disposeBaiDuFaceLivenessFaild(examCaptureQueue);
+            if ((e.getCode().equals(Constants.BAIDU_FACELIVENESS_QPS_LIMIT_EXCEEDED_CODE))) {
+                // 如果超过并发次数,则添加异常次数
+                controller.addConcurrencyWarn();
+            } else {
+                ExamCaptureProcessStatisticController.increaseFaceLivenessDetectCount();
+                captureLog.error("[BAIDU_FACELIVENESS_WORKER.] 自定义异常 " + e.getDesc(), e);
+            }
+        } catch (Exception e) {
+            ExamCaptureProcessStatisticController.increaseFaceLivenessDetectCount();
+            //异常处理
+            examCaptureQueue.setErrorMsg(e.getMessage());
+            examCaptureService.disposeBaiDuFaceLivenessFaild(examCaptureQueue);
+            captureLog.error("[BAIDU_FACELIVENESS_WORKER.] 系统异常 " + e.getMessage(), e);
+        }
+    }
 }

+ 91 - 23
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/impl/ExamCaptureProcessStatisticController.java

@@ -9,56 +9,124 @@ import java.util.concurrent.atomic.AtomicInteger;
  * @Version 1.0
  */
 public class ExamCaptureProcessStatisticController {
-    //处理数量
-    private AtomicInteger count = new AtomicInteger(0);
-    //处理失败数量
-    private AtomicInteger failureCount = new AtomicInteger(0);
+    //人脸比对处理数量
+    private static AtomicInteger faceCompareCount = new AtomicInteger(0);
+    //人脸比对处理失败数量
+    private static AtomicInteger faceCompareFailedCount = new AtomicInteger(0);
 
     /**
-     * 总数量自增
+     * 人脸比对总数量自增
      */
-    public void increaseCount() {
-        count.incrementAndGet();
+    public static void increaseFaceCompareCount() {
+        faceCompareCount.incrementAndGet();
     }
 
     /**
-     * 错误数量自增
+     * 人脸比对错误数量自增
      */
-    public void increaseFailureCount() {
-        failureCount.incrementAndGet();
+    public static void increaseFaceCompareFailedCount() {
+        faceCompareFailedCount.incrementAndGet();
     }
 
     /**
-     * 重置总数量
+     * 重置人脸比对总数量
      */
-    public void resetCount() {
-        count.set(0);
+    public static void resetFaceCompareCount() {
+        faceCompareCount.set(0);
     }
 
     /**
-     * 重置失败数量
+     * 重置人脸比对失败数量
      */
-    public void resetFailureCount() {
-        failureCount.set(0);
+    public static void resetFaceCompareFailureCount() {
+        faceCompareFailedCount.set(0);
     }
 
     /**
-     * 总数量
+     * 人脸比对总数量
+     * @return int
+     */
+    public static int getFaceCompareCount(){
+        return faceCompareCount.get();
+    }
+
+    /**
+     * 人脸比对失败数量
+     * @return int
+     */
+    public static int getFaceCompareFailedCount(){
+        return faceCompareFailedCount.get();
+    }
+
+    /**
+     * 人脸比对失败率
+     *
+     * @return double
+     */
+    public static double getFaceCompareFailureRate() {
+        if (faceCompareCount.get() == 0) {
+            return 0;
+        }
+        return (double) faceCompareFailedCount.get() / (double) faceCompareCount.get();
+    }
+
+    //活体检测处理数量
+    private static AtomicInteger faceLivenessDetectCount = new AtomicInteger(0);
+    //活体检测处理失败数量
+    private static AtomicInteger faceLivenessDetectFailedCount = new AtomicInteger(0);
+
+    /**
+     * 活体检测总数量自增
+     */
+    public static void increaseFaceLivenessDetectCount() {
+        faceLivenessDetectCount.incrementAndGet();
+    }
+
+    /**
+     * 活体检测错误数量自增
+     */
+    public static void increaseFaceLivenessDetectFailedCount() {
+        faceLivenessDetectFailedCount.incrementAndGet();
+    }
+
+    /**
+     * 重置活体检测总数量
+     */
+    public static void resetFaceLivenessDetectCount() {
+        faceLivenessDetectCount.set(0);
+    }
+
+    /**
+     * 重置活体检测失败数量
+     */
+    public static void resetFaceLivenessDetectFailureCount() {
+        faceLivenessDetectFailedCount.set(0);
+    }
+
+    /**
+     * 活体检测总数量
+     * @return
+     */
+    public static int getFaceLivenessDetectCount(){
+        return faceLivenessDetectCount.get();
+    }
+    /**
+     * 活体检测失败数量
      * @return
      */
-    public int getCount(){
-        return count.get();
+    public static int getFaceLivenessDetectFailedCount(){
+        return faceLivenessDetectFailedCount.get();
     }
 
     /**
-     * 失败率
+     * 活体检测失败率
      *
      * @return
      */
-    public double getFailureRate() {
-        if (count.get() == 0) {
+    public static double getFaceLivenessDetectFailureRate() {
+        if (faceLivenessDetectCount.get() == 0) {
             return 0;
         }
-        return (double) failureCount.get() / (double) count.get();
+        return (double) faceLivenessDetectFailedCount.get() / (double) faceLivenessDetectCount.get();
     }
 }

+ 3 - 8
examcloud-core-oe-face-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/service/impl/FacePPCompareWorker.java

@@ -19,16 +19,11 @@ import org.slf4j.LoggerFactory;
  */
 public class FacePPCompareWorker implements Worker {
     private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
-    private ExamCaptureProcessStatisticController statisticController;
-
-    public FacePPCompareWorker(ExamCaptureProcessStatisticController statisticController) {
-        this.statisticController = statisticController;
-    }
 
     @Override
     public void process(WorkerController controller, Object element) {
         //图片处理数量+1
-        statisticController.increaseCount();
+        ExamCaptureProcessStatisticController.increaseFaceCompareCount();
         ExamCaptureService examCaptureService = SpringContextHolder
                 .getBean(ExamCaptureService.class);
         ExamCaptureQueueEntity examCaptureQueueEntity = (ExamCaptureQueueEntity) element;
@@ -42,11 +37,11 @@ public class FacePPCompareWorker implements Worker {
                 // 如果超过并发次数,则添加异常次数
                 controller.addConcurrencyWarn();
             } else {
-                statisticController.increaseFailureCount();
+                ExamCaptureProcessStatisticController.increaseFaceCompareFailedCount();
                 captureLog.error("[BAIDU_FACELIVENESS_WORKER.] 自定义异常 " + e.getDesc(), e);
             }
         } catch (Exception e) {
-            statisticController.increaseFailureCount();
+            ExamCaptureProcessStatisticController.increaseFaceCompareFailedCount();
             //异常处理
             examCaptureQueueEntity.setErrorMsg(e.getMessage());
             examCaptureService.disposeFaceCompareFaild(examCaptureQueueEntity);

+ 2 - 48
examcloud-core-oe-face-starter/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/starter/config/ProcessBaiduFacelivenessTask.java

@@ -1,16 +1,10 @@
 package cn.com.qmth.examcloud.core.oe.student.face.starter.config;
 
-import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.helpers.concurrency.simple.ConcurrentTask;
 import cn.com.qmth.examcloud.commons.util.Util;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureQueueEntity;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamCaptureQueueRepo;
 import cn.com.qmth.examcloud.core.oe.student.face.service.impl.BaiduFaceLivenessWorker;
-import cn.com.qmth.examcloud.core.oe.student.face.service.impl.ExamCaptureProcessStatisticController;
-import cn.com.qmth.examcloud.exchange.inner.api.SmsCloudService;
-import cn.com.qmth.examcloud.exchange.inner.api.request.SendSmsReq;
-import cn.com.qmth.examcloud.support.cache.CacheHelper;
-import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -22,10 +16,7 @@ import org.springframework.boot.ApplicationRunner;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
-import java.util.Arrays;
 import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
 
 /**
  * 启动百度活体检测任务
@@ -38,21 +29,12 @@ public class ProcessBaiduFacelivenessTask implements ApplicationRunner {
     @Autowired
     ExamCaptureQueueRepo examCaptureQueueRepo;
     private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
-    private final ExamCaptureProcessStatisticController statisticController = new ExamCaptureProcessStatisticController();
-    //失败率预警阈值
-    private static final double RATE_WARN_THRESHOLD = 0.5;
-    //总数量预警阈值
-    private static final int COUNT_WARN_THRESHOLD = 10;
-    @Autowired
-    SmsCloudService smsCloudService;
 
     private void start() {
-        sendAlarmSmsIfNecessary();
-
         ConcurrentTask concurrentTask = new ConcurrentTask();
         concurrentTask.setMaxActiveThreadSize(PropertyHolder.getInt("$capture.thread.maxActiveThreadSize", 100));
         concurrentTask.setMinThreadSize(PropertyHolder.getInt("$capture.thread.minThreadSize", 2));
-        concurrentTask.setWorker(new BaiduFaceLivenessWorker(statisticController));
+        concurrentTask.setWorker(new BaiduFaceLivenessWorker());
         concurrentTask.start();
         //当前获取数据的批次号(默认用时间戳)
         String processBatchNum = "B_" + System.currentTimeMillis();
@@ -97,35 +79,7 @@ public class ProcessBaiduFacelivenessTask implements ApplicationRunner {
         }
     }
 
-    /**
-     * 如果有必要则发短信
-     */
-    private void sendAlarmSmsIfNecessary() {
-        //每分钟判断是否需要发短信报警
-        Timer timer = new Timer();
-        timer.scheduleAtFixedRate(new TimerTask() {
-            @Override
-            public void run() {
-                //如果每分钟失败率超过50%则发短信报警,且总数不少于10次则短信报警
-                if (statisticController.getCount() > COUNT_WARN_THRESHOLD &&
-                        statisticController.getFailureRate() > RATE_WARN_THRESHOLD) {
-                    SysPropertyCacheBean smsPhoneProperty = CacheHelper.getSysProperty("capture.sms.phones");
-                    if (!smsPhoneProperty.getHasValue()) {
-                        throw new StatusException("300001", "未配置图片处理失败的通知手机号");
-                    }
-                    List<String> phoneList = Arrays.asList(smsPhoneProperty.getValue().toString().split(","));
-                    SendSmsReq sendSmsReq = new SendSmsReq();
-                    sendSmsReq.setPhoneList(phoneList);
-                    sendSmsReq.setSmsAssemblyCode("CAPTURE");
-                    sendSmsReq.setParams(null);
-                    smsCloudService.sendSms(sendSmsReq);
-                }
-                //每1分钟重置一次总数量与失败数量
-                statisticController.resetCount();
-                statisticController.resetFailureCount();
-            }
-        }, 100, 60 * 1000);
-    }
+
 
     @Override
     public void run(ApplicationArguments args) {

+ 2 - 46
examcloud-core-oe-face-starter/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/starter/config/ProcessFaceCompareQueueTask.java

@@ -1,6 +1,5 @@
 package cn.com.qmth.examcloud.core.oe.student.face.starter.config;
 
-import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.helpers.concurrency.simple.ConcurrentTask;
 import cn.com.qmth.examcloud.commons.util.Util;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamCaptureQueueEntity;
@@ -8,26 +7,16 @@ import cn.com.qmth.examcloud.core.oe.common.repository.ExamCaptureQueueRepo;
 import cn.com.qmth.examcloud.core.oe.student.face.service.impl.ExamCaptureProcessStatisticController;
 import cn.com.qmth.examcloud.core.oe.student.face.service.impl.FacePPCompareWorker;
 import cn.com.qmth.examcloud.exchange.inner.api.SmsCloudService;
-import cn.com.qmth.examcloud.exchange.inner.api.client.SmsCloudServiceClient;
-import cn.com.qmth.examcloud.exchange.inner.api.request.SendSmsReq;
-import cn.com.qmth.examcloud.support.cache.CacheHelper;
-import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
-import com.google.common.collect.Lists;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
-import java.util.Arrays;
 import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
 
 /**
  * 启动人脸比对任务
@@ -38,7 +27,6 @@ public class ProcessFaceCompareQueueTask implements ApplicationRunner {
 
     @Autowired
     ExamCaptureQueueRepo examCaptureQueueRepo;
-    private static final Logger log = LoggerFactory.getLogger(ProcessFaceCompareQueueTask.class);
     private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
     private final ExamCaptureProcessStatisticController statisticController = new ExamCaptureProcessStatisticController();
     //失败率预警阈值
@@ -49,12 +37,10 @@ public class ProcessFaceCompareQueueTask implements ApplicationRunner {
     SmsCloudService smsCloudService;
 
     private void start() {
-        sendAlarmSmsIfNecessary();
-
         ConcurrentTask concurrentTask = new ConcurrentTask();
         concurrentTask.setMaxActiveThreadSize(PropertyHolder.getInt("$capture.thread.maxActiveThreadSize", 100));
         concurrentTask.setMinThreadSize(PropertyHolder.getInt("$capture.thread.minThreadSize", 2));
-        concurrentTask.setWorker(new FacePPCompareWorker(statisticController));
+        concurrentTask.setWorker(new FacePPCompareWorker());
         concurrentTask.start();
         //当前获取数据的批次号(默认用时间戳)
         String processBatchNum = "A_" + System.currentTimeMillis();
@@ -93,43 +79,13 @@ public class ProcessFaceCompareQueueTask implements ApplicationRunner {
                     }
                 }
             } catch (Exception e) {
-                log.error("300001", "启动图片队列出现异常", e);
-
                 captureLog.error("[PROCESS_FACEPP." + processBatchNum + "] 百度活体检测出出异常,3秒后重试", e);
                 Util.sleep(3);
             }
         }
     }
 
-    /**
-     * 如果有必要则发短信
-     */
-    private void sendAlarmSmsIfNecessary() {
-        //每分钟判断是否需要发短信报警
-        Timer timer = new Timer();
-        timer.scheduleAtFixedRate(new TimerTask() {
-            @Override
-            public void run() {
-                //如果每分钟失败率超过50%则发短信报警,且总数不少于10次则短信报警
-                if (statisticController.getCount() > COUNT_WARN_THRESHOLD &&
-                        statisticController.getFailureRate() > RATE_WARN_THRESHOLD) {
-                    SysPropertyCacheBean smsPhoneProperty = CacheHelper.getSysProperty("capture.sms.phones");
-                    if (!smsPhoneProperty.getHasValue()) {
-                        throw new StatusException("300001", "未配置图片处理失败的通知手机号");
-                    }
-                    List<String> phoneList = Arrays.asList(smsPhoneProperty.getValue().toString().split(","));
-                    SendSmsReq sendSmsReq = new SendSmsReq();
-                    sendSmsReq.setPhoneList(phoneList);
-                    sendSmsReq.setSmsAssemblyCode("CAPTURE");
-                    sendSmsReq.setParams(null);
-                    smsCloudService.sendSms(sendSmsReq);
-                }
-                //每1分钟重置一次总数量与失败数量
-                statisticController.resetCount();
-                statisticController.resetFailureCount();
-            }
-        }, 100, 60 * 1000);
-    }
+
 
     @Override
     public void run(ApplicationArguments args) {

+ 141 - 0
examcloud-core-oe-face-starter/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/starter/config/ProcessPhotoAlarmTask.java

@@ -0,0 +1,141 @@
+package cn.com.qmth.examcloud.core.oe.student.face.starter.config;
+
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.util.Util;
+import cn.com.qmth.examcloud.core.oe.student.face.service.impl.ExamCaptureProcessStatisticController;
+import cn.com.qmth.examcloud.exchange.inner.api.SmsCloudService;
+import cn.com.qmth.examcloud.exchange.inner.api.request.SendSmsReq;
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
+import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @Description 处理抓拍照片预警任务
+ * @Author lideyin
+ * @Date 2019/9/12 10:52
+ * @Version 1.0
+ */
+@Component
+@Order(51)
+public class ProcessPhotoAlarmTask implements ApplicationRunner {
+
+    //失败率预警阈值
+    private static final double RATE_WARN_THRESHOLD = 0.5;
+    //总数量预警阈值
+    private static final int COUNT_WARN_THRESHOLD = 10;
+    @Autowired
+    SmsCloudService smsCloudService;
+    private final Log captureLog = LogFactory.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+        new Thread(() -> {
+            faceCompareAlarm();
+        }).start();
+        new Thread(() -> {
+            faceLivenessDectectAlarm();
+        }).start();
+    }
+
+    /**
+     * 人脸比对,如果有必要则发短信
+     */
+    private void faceCompareAlarm() {
+        while (true) {
+            captureLog.debug("[FACE_COMPARE_ALARM] 进入人脸" + System.currentTimeMillis() + "....totalCount=" +
+                    ExamCaptureProcessStatisticController.getFaceCompareCount() + " ,failCount=" +
+                    ExamCaptureProcessStatisticController.getFaceCompareFailedCount());
+            //如果每分钟失败率超过50%则发短信报警,且总数不少于10次则短信报警
+            if (ExamCaptureProcessStatisticController.getFaceCompareCount() > COUNT_WARN_THRESHOLD &&
+                    ExamCaptureProcessStatisticController.getFaceCompareFailureRate() > RATE_WARN_THRESHOLD) {
+                SysPropertyCacheBean faceCompareSmsAssemblyCodeProperty = CacheHelper.getSysProperty("capture.faceCompare.smsAssemblyCode");
+                if (!faceCompareSmsAssemblyCodeProperty.getHasValue()) {
+                    throw new StatusException("300001", "未配置人脸比对的短信模板代码");
+                }
+                SysPropertyCacheBean smsPhoneProperty = CacheHelper.getSysProperty("capture.sms.phones");
+                if (!smsPhoneProperty.getHasValue()) {
+                    throw new StatusException("300002", "未配置图片处理失败的通知手机号");
+                }
+
+                List<String> phoneList = Arrays.asList(smsPhoneProperty.getValue().toString().split(","));
+//                List<String> phoneList = Arrays.asList("13717595977");
+                SendSmsReq sendSmsReq = new SendSmsReq();
+                sendSmsReq.setPhoneList(phoneList);
+                sendSmsReq.setSmsAssemblyCode(faceCompareSmsAssemblyCodeProperty.getValue().toString());
+//                sendSmsReq.setSmsAssemblyCode("FACECOMPARE");
+
+                HashMap<String, String> params = new HashMap<>();
+                params.put("totalCount", String.valueOf(ExamCaptureProcessStatisticController.getFaceCompareCount()));
+                params.put("errorCount", String.valueOf(ExamCaptureProcessStatisticController.getFaceCompareFailedCount()));
+                sendSmsReq.setParams(params);
+                try {
+                    smsCloudService.sendSms(sendSmsReq);
+                } catch (Exception e) {
+                    captureLog.error("[PROCESS_FACEPP.] 发送短信出现异常", e);
+                }
+            }
+            //每1分钟重置一次总数量与失败数量
+            ExamCaptureProcessStatisticController.resetFaceCompareCount();
+            ExamCaptureProcessStatisticController.resetFaceCompareFailureCount();
+
+            //每分钟轮循一次
+            Util.sleep(60);
+        }
+
+    }
+
+    /**
+     * 活体检测,如果有必要则发短信
+     */
+    private void faceLivenessDectectAlarm() {
+        while (true) {
+            captureLog.debug("[FACE_COMPARE_ALARM] 进入活体检测" + System.currentTimeMillis() + "....totalCount=" +
+                    ExamCaptureProcessStatisticController.getFaceLivenessDetectCount() + " ,failCount=" +
+                    ExamCaptureProcessStatisticController.getFaceLivenessDetectFailedCount());
+            //如果每分钟失败率超过50%则发短信报警,且总数不少于10次则短信报警
+            if (ExamCaptureProcessStatisticController.getFaceLivenessDetectCount() > COUNT_WARN_THRESHOLD &&
+                    ExamCaptureProcessStatisticController.getFaceLivenessDetectFailureRate() > RATE_WARN_THRESHOLD) {
+                SysPropertyCacheBean faceLivenessSmsAssemblyCodeProperty = CacheHelper.getSysProperty("capture.faceLiveness.smsAssemblyCode");
+                if (!faceLivenessSmsAssemblyCodeProperty.getHasValue()) {
+                    throw new StatusException("300003", "未配置人脸活体检测的短信模板代码");
+                }
+                SysPropertyCacheBean smsPhoneProperty = CacheHelper.getSysProperty("capture.sms.phones");
+                if (!smsPhoneProperty.getHasValue()) {
+                    throw new StatusException("300004", "未配置图片处理失败的通知手机号");
+                }
+
+                List<String> phoneList = Arrays.asList(smsPhoneProperty.getValue().toString().split(","));
+                SendSmsReq sendSmsReq = new SendSmsReq();
+                sendSmsReq.setPhoneList(phoneList);
+                sendSmsReq.setSmsAssemblyCode(faceLivenessSmsAssemblyCodeProperty.getValue().toString());
+
+                HashMap<String, String> params = new HashMap<>();
+                params.put("totalCount", String.valueOf(ExamCaptureProcessStatisticController.getFaceLivenessDetectCount()));
+                params.put("errorCount", String.valueOf(ExamCaptureProcessStatisticController.getFaceLivenessDetectFailedCount()));
+                sendSmsReq.setParams(params);
+                try {
+                    smsCloudService.sendSms(sendSmsReq);
+                } catch (Exception e) {
+                    captureLog.error("[PROCESS_FACE_LIVENESS.] 发送短信出现异常", e);
+                }
+            }
+            //每1分钟重置一次总数量与失败数量
+            ExamCaptureProcessStatisticController.resetFaceLivenessDetectCount();
+            ExamCaptureProcessStatisticController.resetFaceLivenessDetectFailureCount();
+
+            //每分钟轮循一次
+            Util.sleep(60);
+        }
+
+    }
+}