|
@@ -1,17 +1,26 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.task.service.job;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.base.utils.DateUtils;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.dao.ExamCaptureQueueRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.dao.ExamRecordDataRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamCaptureQueueEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamRecordDataEntity;
|
|
|
import cn.com.qmth.examcloud.starters.face.verify.model.FaceResult;
|
|
|
import cn.com.qmth.examcloud.starters.face.verify.model.param.FaceApiType;
|
|
|
import cn.com.qmth.examcloud.starters.face.verify.model.param.FaceParam;
|
|
|
import cn.com.qmth.examcloud.starters.face.verify.model.param.ImageBase64Parm;
|
|
|
import cn.com.qmth.examcloud.starters.face.verify.service.FaceVerifyService;
|
|
|
+import cn.com.qmth.examcloud.support.enums.ExamRecordStatus;
|
|
|
+import cn.com.qmth.examcloud.support.enums.SyncStatus;
|
|
|
import cn.com.qmth.examcloud.support.sms.SmsHelper;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -26,36 +35,102 @@ public class WarningJobHandler {
|
|
|
@Autowired
|
|
|
private FaceVerifyService faceVerifyService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordDataRepo examRecordDataRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamCaptureQueueRepo examCaptureQueueRepo;
|
|
|
+
|
|
|
public void run(int shardTotal, int shardIndex, String jobParam) throws Exception {
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
List<String> phones = this.parseJobParam(jobParam);
|
|
|
|
|
|
+ try {
|
|
|
+ this.handleBaiduAuthApiWaring(phones);
|
|
|
+ this.handleExamCaptureQueueWaring(phones);
|
|
|
+ this.handleExamRecordDataWaring(phones);
|
|
|
+
|
|
|
+ long cost = System.currentTimeMillis() - startTime;
|
|
|
+ log.warn("系统预警任务_{}_{} cost:{}ms", shardTotal, shardIndex, cost);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handleBaiduAuthApiWaring(List<String> phones) {
|
|
|
try {
|
|
|
FaceResult result = faceVerifyService.faceVerify(FaceParam.builder()
|
|
|
.images(new ImageBase64Parm(TEST_IMG))
|
|
|
.apiType(FaceApiType.PRIVATE_BAIDU_API));
|
|
|
+ log.warn("百度人脸服务请求结果:{}", result.getJsonResult());
|
|
|
|
|
|
- log.warn(result.getJsonResult());
|
|
|
- if (result.getError() != null && result.getError().contains("222290")) {
|
|
|
+ if (result.getError() != null && result.getError().contains("222290") && !phones.isEmpty()) {
|
|
|
// 错误示例:{"error_code":222290,"error_msg":"(auth)can not connect to AUTH server"}
|
|
|
- this.sendBaiduAuthApiWaring(phones);
|
|
|
+
|
|
|
+ Map<String, String> templateParams = new HashMap<>();
|
|
|
+ templateParams.put("name", "baidu-auth-api");
|
|
|
+ templateParams.put("time", new SimpleDateFormat("HH:mm:ss").format(new Date()));
|
|
|
+ templateParams.put("status", "222290");
|
|
|
+ templateParams.put("msg", "百度人脸鉴权服务连接异常");
|
|
|
+ SmsHelper.send("启明泰和", "SMS_246635756", phones, templateParams);
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- long cost = System.currentTimeMillis() - startTime;
|
|
|
- log.warn("系统预警任务_{}_{} cost:{}ms", shardTotal, shardIndex, cost);
|
|
|
+ private void handleExamCaptureQueueWaring(List<String> phones) {
|
|
|
+ try {
|
|
|
+ int hours = -1;
|
|
|
+ Date date = DateUtils.addHours(new Date(), hours);
|
|
|
+ Specification<ExamCaptureQueueEntity> spec = (root, query, builder) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ // predicates.add(builder.greaterThan(root.get("errorNum"), 1));
|
|
|
+ predicates.add(builder.lessThanOrEqualTo(root.get("creationTime"), date));
|
|
|
+ return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ long count = examCaptureQueueRepo.count(spec);
|
|
|
+ log.warn("超过{}小时仍未人脸比对的记录数量:{}", Math.abs(hours), count);
|
|
|
+
|
|
|
+ if (count > 0 && !phones.isEmpty()) {
|
|
|
+ Map<String, String> templateParams = new HashMap<>();
|
|
|
+ templateParams.put("name", "face-compare");
|
|
|
+ templateParams.put("time", new SimpleDateFormat("HH:mm:ss").format(new Date()));
|
|
|
+ templateParams.put("status", "119");
|
|
|
+ templateParams.put("msg", "人脸比对任务处理拥堵,数量:" + count);
|
|
|
+ SmsHelper.send("启明泰和", "SMS_246635756", phones, templateParams);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void sendBaiduAuthApiWaring(List<String> phones) {
|
|
|
- if (!phones.isEmpty()) {
|
|
|
- Map<String, String> templateParams = new HashMap<>();
|
|
|
- templateParams.put("name", "baidu-auth-api");
|
|
|
- templateParams.put("time", new SimpleDateFormat("HH:mm:ss").format(new Date()));
|
|
|
- templateParams.put("status", "222290");
|
|
|
- templateParams.put("msg", "百度鉴权服务通讯异常");
|
|
|
- SmsHelper.send("启明泰和", "SMS_246635756", phones, templateParams);
|
|
|
+ private void handleExamRecordDataWaring(List<String> phones) {
|
|
|
+ try {
|
|
|
+ int hours = -6;
|
|
|
+ Date date = DateUtils.addHours(new Date(), hours);
|
|
|
+ Specification<ExamRecordDataEntity> spec = (root, query, builder) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(builder.equal(root.get("syncStatus"), SyncStatus.UNSYNC));
|
|
|
+ predicates.add(builder.notEqual(root.get("examRecordStatus"), ExamRecordStatus.EXAM_ERROR));
|
|
|
+ predicates.add(builder.lessThanOrEqualTo(root.get("creationTime"), date));
|
|
|
+ return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ long count = examRecordDataRepo.count(spec);
|
|
|
+ log.warn("超过{}小时仍未同步的考试记录数量:{}", Math.abs(hours), count);
|
|
|
+
|
|
|
+ if (count > 0 && !phones.isEmpty()) {
|
|
|
+ Map<String, String> templateParams = new HashMap<>();
|
|
|
+ templateParams.put("name", "exam-record-data-sync");
|
|
|
+ templateParams.put("time", new SimpleDateFormat("HH:mm:ss").format(new Date()));
|
|
|
+ templateParams.put("status", "119");
|
|
|
+ templateParams.put("msg", "考试记录同步任务处理拥堵,数量:" + count);
|
|
|
+ SmsHelper.send("启明泰和", "SMS_246635756", phones, templateParams);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|