|
@@ -13,15 +13,21 @@ import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.ExamAuditService;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.ExamCaptureService;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.examaudit.ExamAuditInfo;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.examaudit.ExamAuditQuery;
|
|
|
|
+import cn.com.qmth.examcloud.support.helper.IdentityNumberHelper;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
|
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
|
import cn.com.qmth.examcloud.commons.util.JsonMapper;
|
|
import cn.com.qmth.examcloud.commons.util.JsonMapper;
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.enums.ExportTaskStatus;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.enums.ExportTaskStatus;
|
|
@@ -54,7 +60,7 @@ import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
@Service
|
|
@Service
|
|
public class AsyncExportServiceImpl implements AsyncExportService {
|
|
public class AsyncExportServiceImpl implements AsyncExportService {
|
|
|
|
|
|
- private static final ExamCloudLog log = ExamCloudLogFactory.getLog(AsyncExportServiceImpl.class);
|
|
|
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(AsyncExportServiceImpl.class);
|
|
|
|
|
|
private static final String TASK_EXPORT_DIR = "task_export";
|
|
private static final String TASK_EXPORT_DIR = "task_export";
|
|
|
|
|
|
@@ -73,6 +79,9 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
@Autowired
|
|
@Autowired
|
|
private ExamStudentService examStudentService;
|
|
private ExamStudentService examStudentService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamAuditService examAuditService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void exportExamScheduling(String jsonParams, User user) {
|
|
public void exportExamScheduling(String jsonParams, User user) {
|
|
ExamStudentQuery req = new JsonMapper().parseJson(jsonParams, ExamStudentQuery.class);
|
|
ExamStudentQuery req = new JsonMapper().parseJson(jsonParams, ExamStudentQuery.class);
|
|
@@ -104,7 +113,7 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
examRecords = ExamStudentEntityConvert.ofExcel(examStudentInfoList);
|
|
examRecords = ExamStudentEntityConvert.ofExcel(examStudentInfoList);
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error(e.getMessage(),e);
|
|
|
|
|
|
+ LOG.error(e.getMessage(), e);
|
|
if (e instanceof StatusException) {
|
|
if (e instanceof StatusException) {
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
((StatusException) e).getDesc());
|
|
((StatusException) e).getDesc());
|
|
@@ -124,7 +133,7 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
tempFile.getParentFile().mkdirs();
|
|
tempFile.getParentFile().mkdirs();
|
|
tempFile.createNewFile();
|
|
tempFile.createNewFile();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- log.error(e.getMessage(),e);
|
|
|
|
|
|
+ LOG.error(e.getMessage(), e);
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -138,10 +147,10 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
env.setRelativePath(filePath);
|
|
env.setRelativePath(filePath);
|
|
YunPathInfo oss = FileStorageUtil.saveFile(TASK_EXPORT_DIR, env, tempFile, null);
|
|
YunPathInfo oss = FileStorageUtil.saveFile(TASK_EXPORT_DIR, env, tempFile, null);
|
|
|
|
|
|
- log.info("asyncExportExamScheduling finished... " + oss.getRelativePath());
|
|
|
|
|
|
+ LOG.info("asyncExportExamScheduling finished... " + oss.getRelativePath());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("asyncExportExamScheduling error... " + e);
|
|
|
|
|
|
+ LOG.error("asyncExportExamScheduling error... " + e);
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
} finally {
|
|
} finally {
|
|
FileUtils.deleteQuietly(tempFile);
|
|
FileUtils.deleteQuietly(tempFile);
|
|
@@ -181,7 +190,7 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
}
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error(e.getMessage(),e);
|
|
|
|
|
|
+ LOG.error(e.getMessage(),e);
|
|
if (e instanceof StatusException) {
|
|
if (e instanceof StatusException) {
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
((StatusException) e).getDesc());
|
|
((StatusException) e).getDesc());
|
|
@@ -200,7 +209,7 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
tempFile.getParentFile().mkdirs();
|
|
tempFile.getParentFile().mkdirs();
|
|
tempFile.createNewFile();
|
|
tempFile.createNewFile();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- log.error(e.getMessage(),e);
|
|
|
|
|
|
+ LOG.error(e.getMessage(), e);
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -214,10 +223,10 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
env.setRelativePath(filePath);
|
|
env.setRelativePath(filePath);
|
|
YunPathInfo oss = FileStorageUtil.saveFile(TASK_EXPORT_DIR, env, tempFile, null);
|
|
YunPathInfo oss = FileStorageUtil.saveFile(TASK_EXPORT_DIR, env, tempFile, null);
|
|
|
|
|
|
- log.info("asyncExportExamRecordDetails finished... " + oss.getRelativePath());
|
|
|
|
|
|
+ LOG.info("asyncExportExamRecordDetails finished... " + oss.getRelativePath());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.info("asyncExportExamRecordDetails error... " + e.getMessage());
|
|
|
|
|
|
+ LOG.info("asyncExportExamRecordDetails error... " + e.getMessage());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
} finally {
|
|
} finally {
|
|
FileUtils.deleteQuietly(tempFile);
|
|
FileUtils.deleteQuietly(tempFile);
|
|
@@ -254,7 +263,7 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error(e.getMessage(),e);
|
|
|
|
|
|
+ LOG.error(e.getMessage(), e);
|
|
if (e instanceof StatusException) {
|
|
if (e instanceof StatusException) {
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
((StatusException) e).getDesc());
|
|
((StatusException) e).getDesc());
|
|
@@ -273,7 +282,7 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
tempFile.getParentFile().mkdirs();
|
|
tempFile.getParentFile().mkdirs();
|
|
tempFile.createNewFile();
|
|
tempFile.createNewFile();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- log.error(e.getMessage(),e);
|
|
|
|
|
|
+ LOG.error(e.getMessage(), e);
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -286,16 +295,93 @@ public class AsyncExportServiceImpl implements AsyncExportService {
|
|
env.setRelativePath(filePath);
|
|
env.setRelativePath(filePath);
|
|
YunPathInfo oss = FileStorageUtil.saveFile(TASK_EXPORT_DIR, env, tempFile, null);
|
|
YunPathInfo oss = FileStorageUtil.saveFile(TASK_EXPORT_DIR, env, tempFile, null);
|
|
|
|
|
|
- log.info("asyncExportExamScoreStatistics finished... " + oss.getRelativePath());
|
|
|
|
|
|
+ LOG.info("asyncExportExamScoreStatistics finished... " + oss.getRelativePath());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.info("asyncExportExamScoreStatistics error... " + e.getMessage());
|
|
|
|
|
|
+ LOG.info("asyncExportExamScoreStatistics error... " + e.getMessage());
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
} finally {
|
|
} finally {
|
|
FileUtils.deleteQuietly(tempFile);
|
|
FileUtils.deleteQuietly(tempFile);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void asyncExportExamAuditList(Long taskId, ExamAuditQuery req) {
|
|
|
|
+ List<ExamAuditInfo> auditInfos;
|
|
|
|
+ try {
|
|
|
|
+ auditInfos = examAuditService.getExamAudit(req);
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isEmpty(auditInfos)) {
|
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for (ExamAuditInfo examAuditInfo : auditInfos) {
|
|
|
|
+ examAuditInfo.setIdentityNumber(
|
|
|
|
+ IdentityNumberHelper.conceal(req.getRootOrgId(), examAuditInfo.getIdentityNumber()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ LOG.error(e.getMessage(), e);
|
|
|
|
+ if (e instanceof StatusException) {
|
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR,
|
|
|
|
+ ((StatusException) e).getDesc());
|
|
|
|
+ } else {
|
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "导出数据异常");
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 导出文件的存储路径
|
|
|
|
+ String examName = auditInfos.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(), e);
|
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "生成导出文件异常");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ try (FileOutputStream out = new FileOutputStream(tempFile);) {
|
|
|
|
+
|
|
|
|
+ ExcelExportUtil.exportExcel(ExamAuditInfo.class, auditInfos, 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("asyncExportExamAuditList finished... " + oss.getRelativePath());
|
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ LOG.info("asyncExportExamAuditList error... " + e.getMessage());
|
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
|
+ } finally {
|
|
|
|
+ FileUtils.deleteQuietly(tempFile);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void exportExamAuditList(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.AUDIT);
|
|
|
|
+ task.setStatus(ExportTaskStatus.WAITING);
|
|
|
|
+ task.setCreator(user.getUserId());
|
|
|
|
+ task.setJsonParams(query);
|
|
|
|
+ exportTaskService.addExportTask(task);
|
|
|
|
+ }
|
|
|
|
+
|
|
private String randomUUID() {
|
|
private String randomUUID() {
|
|
return UUID.randomUUID().toString().replace("-", "");
|
|
return UUID.randomUUID().toString().replace("-", "");
|
|
}
|
|
}
|