|
@@ -1,11 +1,19 @@
|
|
|
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.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;
|
|
@@ -16,7 +24,10 @@ 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;
|
|
|
|
|
|
/**
|
|
|
* 启动人脸比对任务
|
|
@@ -29,12 +40,21 @@ public class ProcessFaceCompareQueueTask implements ApplicationRunner {
|
|
|
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();
|
|
|
+ //失败率预警阈值
|
|
|
+ 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 FacePPCompareWorker());
|
|
|
+ concurrentTask.setWorker(new FacePPCompareWorker(statisticController));
|
|
|
concurrentTask.start();
|
|
|
//当前获取数据的批次号(默认用时间戳)
|
|
|
String processBatchNum = "A_" + System.currentTimeMillis();
|
|
@@ -81,11 +101,40 @@ public class ProcessFaceCompareQueueTask 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) {
|
|
|
new Thread(() -> {
|
|
|
start();
|
|
|
}).start();
|
|
|
}
|
|
|
-
|
|
|
}
|