|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|