WANG hace 5 años
padre
commit
af4cc9c54e

+ 100 - 78
examcloud-core-oe-face-starter/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/starter/config/ProcessBaiduFaceLivenessAlarmTask.java

@@ -1,23 +1,24 @@
 package cn.com.qmth.examcloud.core.oe.student.face.starter.config;
 
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+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 cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 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 处理抓拍照片预警任务
@@ -29,71 +30,92 @@ import java.util.List;
 @Order(203)
 public class ProcessBaiduFaceLivenessAlarmTask 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(() -> {
-            faceLivenessDectectAlarm();
-        }).start();
-    }
-
-    /**
-     * 活体检测,如果有必要则发短信
-     */
-    private void faceLivenessDectectAlarm() {
-        while (true) {
-            try {
-                if (captureLog.isDebugEnabled()) {
-                    captureLog.debug("[FACE_LIVENESS_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()) {
-                        captureLog.error("[FACE_LIVENESS_ALARM.] 未配置人脸比对的短信模板代码,totalCount=" + ExamCaptureProcessStatisticController.getFaceCompareCount() + ",errorCount=" + ExamCaptureProcessStatisticController.getFaceCompareFailedCount());
-                        throw new StatusException("300003", "未配置人脸活体检测的短信模板代码");
-                    }
-                    SysPropertyCacheBean smsPhoneProperty = CacheHelper.getSysProperty("capture.sms.phones");
-                    if (!smsPhoneProperty.getHasValue()) {
-                        captureLog.error("[FACE_LIVENESS_ALARM.] 未配置图片处理失败的通知手机号,totalCount=" + ExamCaptureProcessStatisticController.getFaceCompareCount() + ",errorCount=" + ExamCaptureProcessStatisticController.getFaceCompareFailedCount());
-                        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.resetAllFaceLivenessDetectCount();
-            } catch (StatusException e) {
-                captureLog.error("[FACE_LIVENESS_ALARM.] 活体检测预警出现异常", e);
-            }
-
-            //每分钟轮循一次
-            Util.sleep(60);
-        }
-
-    }
+	private static ExamCloudLog captureLog = ExamCloudLogFactory
+			.getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
+
+	// 失败率预警阈值
+	private static final double RATE_WARN_THRESHOLD = 0.5;
+
+	// 总数量预警阈值
+	private static final int COUNT_WARN_THRESHOLD = 10;
+
+	@Autowired
+	SmsCloudService smsCloudService;
+
+	@Override
+	public void run(ApplicationArguments args) throws Exception {
+		new Thread(() -> {
+			while (true) {
+				try {
+					faceLivenessDectectAlarm();
+				} catch (Exception e) {
+					captureLog.error("[FACE_LIVENESS_ALARM.] 活体检测预警出现异常", e);
+				}
+
+				// 每分钟轮循一次
+				Util.sleep(60);
+			}
+		}).start();
+	}
+
+	/**
+	 * 活体检测,如果有必要则发短信
+	 */
+	private void faceLivenessDectectAlarm() {
+		if (captureLog.isDebugEnabled()) {
+			captureLog.debug("[FACE_LIVENESS_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()) {
+				captureLog.error("[FACE_LIVENESS_ALARM.] 未配置人脸比对的短信模板代码,totalCount="
+						+ ExamCaptureProcessStatisticController.getFaceCompareCount()
+						+ ",errorCount="
+						+ ExamCaptureProcessStatisticController.getFaceCompareFailedCount());
+				throw new StatusException("300003", "未配置人脸活体检测的短信模板代码");
+			}
+			SysPropertyCacheBean smsPhoneProperty = CacheHelper
+					.getSysProperty("capture.sms.phones");
+			if (!smsPhoneProperty.getHasValue()) {
+				captureLog.error("[FACE_LIVENESS_ALARM.] 未配置图片处理失败的通知手机号,totalCount="
+						+ ExamCaptureProcessStatisticController.getFaceCompareCount()
+						+ ",errorCount="
+						+ ExamCaptureProcessStatisticController.getFaceCompareFailedCount());
+				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.resetAllFaceLivenessDetectCount();
+
+	}
+
 }