|
@@ -1,9 +1,22 @@
|
|
|
package cn.com.qmth.examcloud.tool.task.oe;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.annotation.Excel;
|
|
|
import cn.com.qmth.examcloud.tool.task.Task;
|
|
|
+import cn.com.qmth.examcloud.tool.utils.ExcelUtils;
|
|
|
+import lombok.Data;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 导出考试抓拍照片比对结果
|
|
@@ -13,13 +26,123 @@ public class ExportExamCaptureTask implements Task {
|
|
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(ExportExamCaptureTask.class);
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
@Override
|
|
|
public void start(String params) {
|
|
|
log.info("task start... " + params);
|
|
|
|
|
|
- // to do ...
|
|
|
+ // 待导出的考试列表
|
|
|
+ Set<Long> examIds = new HashSet<>();
|
|
|
+ // examIds.add(14L);
|
|
|
+ // examIds.add(2083L);
|
|
|
+ // examIds.add(2783L);
|
|
|
+
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
+ .append("select rd.id as exam_record_data_id, rd.exam_student_id, stu.photo_path ")
|
|
|
+ .append("from ec_oe_exam_record_data rd ")
|
|
|
+ .append("inner join ec_b_student stu on stu.id = rd.student_id ")
|
|
|
+ .append("where rd.id > %s ")
|
|
|
+ .append("and rd.exam_id = %s ")
|
|
|
+ .append("order by rd.id asc ")
|
|
|
+ .append("limit 0,1000");
|
|
|
+
|
|
|
+ List<ExamCaptureInfo> allList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Long examId : examIds) {
|
|
|
+ // 按考试ID分批导出
|
|
|
+
|
|
|
+ Long nextMinId = 0L;
|
|
|
+ while (true) {
|
|
|
+ log.info("query nextMinId:" + nextMinId);
|
|
|
+ List<ExamCaptureInfo> list = jdbcTemplate.query(String.format(querySql.toString(), nextMinId, examId),
|
|
|
+ new BeanPropertyRowMapper(ExamCaptureInfo.class));
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ nextMinId = list.get(list.size() - 1).getExamRecordDataId();
|
|
|
+
|
|
|
+ allList.addAll(this.queryCaptures(list));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ final String filePath = this.tempDir() + File.separator + "比对结果列表-" + System.currentTimeMillis() + ".xlsx";
|
|
|
+ ExcelUtils.exportExcel(ExamCaptureInfo.class, allList, new File(filePath));
|
|
|
|
|
|
log.info("task end...");
|
|
|
}
|
|
|
|
|
|
+ private List<ExamCaptureInfo> queryCaptures(List<ExamCaptureInfo> list) {
|
|
|
+ Map<Long, ExamCaptureInfo> examRecordDataMaps = list.stream().collect(Collectors.toMap(ExamCaptureInfo::getExamRecordDataId, v -> v, (k, v) -> v));
|
|
|
+
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
+ .append("select exam_record_data_id, face_compare_result, faceliveness_result, file_url, creation_time ")
|
|
|
+ .append("from ec_oe_exam_capture ")
|
|
|
+ .append("where exam_record_data_id in (").append(StringUtils.join(examRecordDataMaps.keySet(), ",")).append(")");
|
|
|
+
|
|
|
+ List<ExamCaptureInfo> captures = jdbcTemplate.query(querySql.toString(), new BeanPropertyRowMapper(ExamCaptureInfo.class));
|
|
|
+
|
|
|
+ for (ExamCaptureInfo capture : captures) {
|
|
|
+ ExamCaptureInfo info = examRecordDataMaps.get(capture.getExamRecordDataId());
|
|
|
+ capture.setExamStudentId(info.getExamStudentId());
|
|
|
+ capture.setPhotoPath(this.fixPhotoUrl(info.getPhotoPath()));
|
|
|
+ capture.setFileUrl(this.fixPhotoUrl(capture.getFileUrl()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return captures;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String fixPhotoUrl(String url) {
|
|
|
+ if (StringUtils.isEmpty(url)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (url.toLowerCase().startsWith("http")) {
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
+ final String prefix = "https://ecs-static.qmth.com.cn/";
|
|
|
+
|
|
|
+ if (url.startsWith("aliyun-1://")) {
|
|
|
+ return url.replace("aliyun-1://", prefix);
|
|
|
+ } else if (url.startsWith("aliyun-2://")) {
|
|
|
+ return url.replace("aliyun-2://", prefix);
|
|
|
+ } else if (url.startsWith("upyun-1://")) {
|
|
|
+ return url.replace("upyun-1://", prefix);
|
|
|
+ }
|
|
|
+
|
|
|
+ return prefix + url;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ static class ExamCaptureInfo implements Serializable {
|
|
|
+
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ @Excel(name = "examRecordDataId", orderNum = "0", width = 20)
|
|
|
+ private Long examRecordDataId;
|
|
|
+
|
|
|
+ @Excel(name = "examStudentId", orderNum = "0", width = 20)
|
|
|
+ private Long examStudentId;
|
|
|
+
|
|
|
+ @Excel(name = "Face++结果", orderNum = "1", width = 30)
|
|
|
+ private String faceCompareResult;
|
|
|
+
|
|
|
+ @Excel(name = "百度结果", orderNum = "2", width = 30)
|
|
|
+ private String facelivenessResult;
|
|
|
+
|
|
|
+ @Excel(name = "底照", orderNum = "3", width = 30)
|
|
|
+ private String photoPath;
|
|
|
+
|
|
|
+ @Excel(name = "抓拍照", orderNum = "4", width = 30)
|
|
|
+ private String fileUrl;
|
|
|
+
|
|
|
+ @Excel(name = "创建时间", orderNum = "5", width = 20)
|
|
|
+ private Date creationTime;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|