|
@@ -13,6 +13,9 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.ExamCaptureService;
|
|
|
+import cn.com.qmth.examcloud.support.helper.IdentityNumberHelper;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -73,6 +76,9 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
|
@Autowired
|
|
|
private ExamStudentService examStudentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamCaptureService examCaptureService;
|
|
|
+
|
|
|
@Override
|
|
|
public void exportExamScheduling(String jsonParams, User user) {
|
|
|
ExamStudentQuery req = new JsonMapper().parseJson(jsonParams, ExamStudentQuery.class);
|
|
@@ -296,6 +302,87 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void asyncExportWaitingAudit(Long taskId, ExamRecordQuery req) {
|
|
|
+ List<ExamRecordInfo> examRecords;
|
|
|
+ try {
|
|
|
+ examRecords = examRecordService.getExamRecordWaitingAudit(req);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(examRecords)) {
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String examType = examRecords.get(0).getExamType();
|
|
|
+ for (ExamRecordInfo examRecordInfo : examRecords) {
|
|
|
+ examRecordInfo.setIdentityNumber(
|
|
|
+ IdentityNumberHelper.conceal(examRecordInfo.getRootOrgId(), examRecordInfo.getIdentityNumber()));
|
|
|
+ if (ExamType.ONLINE.name().equals(examType) || ExamType.ONLINE_HOMEWORK.name().equals(examType)) {
|
|
|
+ examRecordInfo.setVirtualCameraNames(examCaptureService.getVirtualCameraNames(examRecordInfo.getDataId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.error(e.getMessage());
|
|
|
+ if (e instanceof StatusException) {
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
|
+ ((StatusException) e).getDesc());
|
|
|
+ } else {
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "导出数据异常");
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 导出文件的存储路径
|
|
|
+ String examName = examRecords.get(0).getExamName();
|
|
|
+ final String filePath = String.format("/%s/%s/%s/%s/%s_监考待审.xlsx", TASK_EXPORT_DIR, req.getRootOrgId(),
|
|
|
+ dateDir(), randomUUID(), examName);
|
|
|
+ String tempFilePath = systemConfig.getTempDataDir() + File.separator + filePath;
|
|
|
+ File tempFile = new File(tempFilePath);
|
|
|
+ try {
|
|
|
+ tempFile.getParentFile().mkdirs();
|
|
|
+ tempFile.createNewFile();
|
|
|
+ } catch (IOException e) {
|
|
|
+ LOG.error(e.getMessage());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try (FileOutputStream out = new FileOutputStream(tempFile);) {
|
|
|
+
|
|
|
+ ExcelExportUtil.exportExcel(ExamRecordInfo.class, examRecords, out);
|
|
|
+
|
|
|
+ // 上传至文件服务器
|
|
|
+ FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
+ env.setRootOrgId(String.valueOf(req.getRootOrgId()));
|
|
|
+ env.setRelativePath(filePath);
|
|
|
+ YunPathInfo oss = FileStorageUtil.saveFile(TASK_EXPORT_DIR, env, tempFile, null);
|
|
|
+
|
|
|
+ LOG.info("asyncExportWaitingAudit finished... " + oss.getRelativePath());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.info("asyncExportWaitingAudit error... " + e.getMessage());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(tempFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportWaitingAudit(String query, User user) {
|
|
|
+ ExamStudentQuery req = new JsonMapper().parseJson(query, ExamStudentQuery.class);
|
|
|
+ req.setRootOrgId(user.getRootOrgId());
|
|
|
+ Check.isNull(req, "请求参数不能为空!");
|
|
|
+ Check.isNull(req.getExamId(), "请先选择考试批次!");
|
|
|
+
|
|
|
+ // 创建导出任务
|
|
|
+ ExportTaskInfo task = new ExportTaskInfo();
|
|
|
+ task.setRootOrgId(user.getRootOrgId());
|
|
|
+ task.setExamId(req.getExamId());
|
|
|
+ task.setType(ExportTaskType.WAITING_AUDIT);
|
|
|
+ task.setStatus(ExportTaskStatus.WAITING);
|
|
|
+ task.setCreator(user.getUserId());
|
|
|
+ task.setJsonParams(query);
|
|
|
+ exportTaskService.addExportTask(task);
|
|
|
+ }
|
|
|
+
|
|
|
private String randomUUID() {
|
|
|
return UUID.randomUUID().toString().replace("-", "");
|
|
|
}
|