|
@@ -5,38 +5,15 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-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.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.io.FileUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
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.dao.enums.ExportTaskStatus;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.enums.ExportTaskType;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.service.AsyncExportService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.service.ExamScoreService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.service.ExamStudentService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.service.ExportTaskService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.service.*;
|
|
|
+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.core.oe.admin.service.bean.examrecord.ExamRecordInfo;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.examrecord.ExamRecordQuery;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.examscore.ExamScoreInfo;
|
|
@@ -50,9 +27,24 @@ import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.excel.ExcelExportUtil;
|
|
|
import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
|
|
|
+import cn.com.qmth.examcloud.support.helper.IdentityNumberHelper;
|
|
|
import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 异步导出相关接口
|
|
@@ -60,335 +52,335 @@ import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
|
@Service
|
|
|
public class AsyncExportServiceImpl implements AsyncExportService {
|
|
|
|
|
|
- private static final Logger LOG = LoggerFactory.getLogger(AsyncExportServiceImpl.class);
|
|
|
-
|
|
|
- private static final String TASK_EXPORT_DIR = "task_export";
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ExportTaskService exportTaskService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ExamRecordService examRecordService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ExamScoreService examScoreService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SystemProperties systemConfig;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ExamStudentService examStudentService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ExamAuditService examAuditService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void exportExamScheduling(String jsonParams, User user) {
|
|
|
- ExamStudentQuery req = new JsonMapper().parseJson(jsonParams, 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.EXAM_SCHEDULING);
|
|
|
- task.setStatus(ExportTaskStatus.WAITING);
|
|
|
- task.setCreator(user.getUserId());
|
|
|
- task.setJsonParams(jsonParams);
|
|
|
- exportTaskService.addExportTask(task);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void asyncExportExamScheduling(Long taskId, ExamStudentQuery req) {
|
|
|
- List<ExamStudentExcel> examRecords;
|
|
|
- List<ExamStudentInfo> examStudentInfoList;
|
|
|
- try {
|
|
|
- examStudentInfoList = examStudentService.getExamStudentInfoListForAsync(req);
|
|
|
- if (CollectionUtils.isEmpty(examStudentInfoList)) {
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
- return;
|
|
|
- }
|
|
|
- examRecords = ExamStudentEntityConvert.ofExcel(examStudentInfoList);
|
|
|
-
|
|
|
- } 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;
|
|
|
- }
|
|
|
- // 导出文件的存储路径
|
|
|
- Long examId = examStudentInfoList.get(0).getExamId();
|
|
|
- ExamSettingsCacheBean exam = CacheHelper.getExamSettings(examId);
|
|
|
- final String filePath = String.format("/%s/%s/%s/%s/%s_考试进度详情.xlsx", TASK_EXPORT_DIR, req.getRootOrgId(),
|
|
|
- dateDir(), randomUUID(), exam.getName());
|
|
|
- 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(ExamStudentExcel.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("asyncExportExamScheduling finished... " + oss.getRelativePath());
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.error("asyncExportExamScheduling error... " + e);
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
- } finally {
|
|
|
- FileUtils.deleteQuietly(tempFile);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void exportExamRecordDetails(String jsonParams, User user) {
|
|
|
- ExamRecordQuery req = new JsonMapper().parseJson(jsonParams, ExamRecordQuery.class);
|
|
|
- req.setRootOrgId(user.getRootOrgId());
|
|
|
- Check.isNull(req, "请求参数不能为空!");
|
|
|
- Check.isNull(req.getRootOrgId(), "学校ID不能为空!");
|
|
|
- Check.isNull(req.getExamId(), "考试ID不能为空!");
|
|
|
- Check.isNull(req.getCreator(), "创建人ID不能为空!");
|
|
|
-
|
|
|
-
|
|
|
- // 创建导出任务
|
|
|
- ExportTaskInfo task = new ExportTaskInfo();
|
|
|
- task.setRootOrgId(req.getRootOrgId());
|
|
|
- task.setExamId(req.getExamId());
|
|
|
- task.setType(ExportTaskType.EXAM_DETAIL);
|
|
|
- task.setStatus(ExportTaskStatus.WAITING);
|
|
|
- task.setCreator(req.getCreator());
|
|
|
- task.setJsonParams(jsonParams);
|
|
|
- exportTaskService.addExportTask(task);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void asyncExportExamRecordDetails(Long taskId, ExamRecordQuery req) {
|
|
|
- List<ExamRecordInfo> examRecords;
|
|
|
- try {
|
|
|
- examRecords = examRecordService.getExamRecordDetailListForAsync(req);
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(examRecords)) {
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- } 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 = 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(), e);
|
|
|
- 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("asyncExportExamRecordDetails finished... " + oss.getRelativePath());
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.info("asyncExportExamRecordDetails error... " + e.getMessage());
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
- } finally {
|
|
|
- FileUtils.deleteQuietly(tempFile);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void exportExamScoreStatistics(String jsonParams, User user) {
|
|
|
- ExamScoreQuery req = new JsonMapper().parseJson(jsonParams, ExamScoreQuery.class);
|
|
|
- req.setRootOrgId(user.getRootOrgId());
|
|
|
- Check.isNull(req, "请求参数不能为空!");
|
|
|
- Check.isNull(req.getRootOrgId(), "学校ID不能为空!");
|
|
|
- Check.isNull(req.getExamId(), "考试ID不能为空!");
|
|
|
- Check.isNull(req.getCreator(), "创建人ID不能为空!");
|
|
|
-
|
|
|
- // 创建导出任务
|
|
|
- ExportTaskInfo task = new ExportTaskInfo();
|
|
|
- task.setRootOrgId(req.getRootOrgId());
|
|
|
- task.setExamId(req.getExamId());
|
|
|
- task.setType(ExportTaskType.SCORE_STATISTIC);
|
|
|
- task.setStatus(ExportTaskStatus.WAITING);
|
|
|
- task.setCreator(req.getCreator());
|
|
|
- task.setJsonParams(jsonParams);
|
|
|
- exportTaskService.addExportTask(task);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void asyncExportExamScoreStatistics(Long taskId, ExamScoreQuery req) {
|
|
|
- List<ExamScoreInfo> examScores;
|
|
|
- try {
|
|
|
- examScores = examScoreService.exportExamScoreListForAsync(req);
|
|
|
- if (CollectionUtils.isEmpty(examScores)) {
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
- return;
|
|
|
- }
|
|
|
- } 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 = examScores.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(ExamScoreInfo.class, examScores, 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("asyncExportExamScoreStatistics finished... " + oss.getRelativePath());
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.info("asyncExportExamScoreStatistics error... " + e.getMessage());
|
|
|
- exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
- } finally {
|
|
|
- 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() {
|
|
|
- return UUID.randomUUID().toString().replace("-", "");
|
|
|
- }
|
|
|
-
|
|
|
- private String dateDir() {
|
|
|
- final String pattern = "yyyyMM";
|
|
|
- return new SimpleDateFormat(pattern).format(new Date());
|
|
|
- }
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(AsyncExportServiceImpl.class);
|
|
|
+
|
|
|
+ private static final String TASK_EXPORT_DIR = "task_export";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExportTaskService exportTaskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamRecordService examRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamScoreService examScoreService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SystemProperties systemConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentService examStudentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamAuditService examAuditService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportExamScheduling(String jsonParams, User user) {
|
|
|
+ ExamStudentQuery req = new JsonMapper().parseJson(jsonParams, 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.EXAM_SCHEDULING);
|
|
|
+ task.setStatus(ExportTaskStatus.WAITING);
|
|
|
+ task.setCreator(user.getUserId());
|
|
|
+ task.setJsonParams(jsonParams);
|
|
|
+ exportTaskService.addExportTask(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void asyncExportExamScheduling(Long taskId, ExamStudentQuery req) {
|
|
|
+ List<ExamStudentExcel> examRecords;
|
|
|
+ List<ExamStudentInfo> examStudentInfoList;
|
|
|
+ try {
|
|
|
+ examStudentInfoList = examStudentService.getExamStudentInfoListForAsync(req);
|
|
|
+ if (CollectionUtils.isEmpty(examStudentInfoList)) {
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ examRecords = ExamStudentEntityConvert.ofExcel(examStudentInfoList);
|
|
|
+
|
|
|
+ } 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;
|
|
|
+ }
|
|
|
+ // 导出文件的存储路径
|
|
|
+ Long examId = examStudentInfoList.get(0).getExamId();
|
|
|
+ ExamSettingsCacheBean exam = CacheHelper.getExamSettings(examId);
|
|
|
+ final String filePath = String.format("/%s/%s/%s/%s/%s_考试进度详情.xlsx", TASK_EXPORT_DIR, req.getRootOrgId(),
|
|
|
+ dateDir(), randomUUID(), exam.getName());
|
|
|
+ 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(ExamStudentExcel.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("asyncExportExamScheduling finished... " + oss.getRelativePath());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.error("asyncExportExamScheduling error... " + e);
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(tempFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportExamRecordDetails(String jsonParams, User user) {
|
|
|
+ ExamRecordQuery req = new JsonMapper().parseJson(jsonParams, ExamRecordQuery.class);
|
|
|
+ req.setRootOrgId(user.getRootOrgId());
|
|
|
+ Check.isNull(req, "请求参数不能为空!");
|
|
|
+ Check.isNull(req.getRootOrgId(), "学校ID不能为空!");
|
|
|
+ Check.isNull(req.getExamId(), "考试ID不能为空!");
|
|
|
+ Check.isNull(req.getCreator(), "创建人ID不能为空!");
|
|
|
+
|
|
|
+
|
|
|
+ // 创建导出任务
|
|
|
+ ExportTaskInfo task = new ExportTaskInfo();
|
|
|
+ task.setRootOrgId(req.getRootOrgId());
|
|
|
+ task.setExamId(req.getExamId());
|
|
|
+ task.setType(ExportTaskType.EXAM_DETAIL);
|
|
|
+ task.setStatus(ExportTaskStatus.WAITING);
|
|
|
+ task.setCreator(req.getCreator());
|
|
|
+ task.setJsonParams(jsonParams);
|
|
|
+ exportTaskService.addExportTask(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void asyncExportExamRecordDetails(Long taskId, ExamRecordQuery req) {
|
|
|
+ List<ExamRecordInfo> examRecords;
|
|
|
+ try {
|
|
|
+ examRecords = examRecordService.getExamRecordDetailListForAsync(req);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(examRecords)) {
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ } 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 = 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(), e);
|
|
|
+ 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("asyncExportExamRecordDetails finished... " + oss.getRelativePath());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.info("asyncExportExamRecordDetails error... " + e.getMessage());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(tempFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportExamScoreStatistics(String jsonParams, User user) {
|
|
|
+ ExamScoreQuery req = new JsonMapper().parseJson(jsonParams, ExamScoreQuery.class);
|
|
|
+ req.setRootOrgId(user.getRootOrgId());
|
|
|
+ Check.isNull(req, "请求参数不能为空!");
|
|
|
+ Check.isNull(req.getRootOrgId(), "学校ID不能为空!");
|
|
|
+ Check.isNull(req.getExamId(), "考试ID不能为空!");
|
|
|
+ Check.isNull(req.getCreator(), "创建人ID不能为空!");
|
|
|
+
|
|
|
+ // 创建导出任务
|
|
|
+ ExportTaskInfo task = new ExportTaskInfo();
|
|
|
+ task.setRootOrgId(req.getRootOrgId());
|
|
|
+ task.setExamId(req.getExamId());
|
|
|
+ task.setType(ExportTaskType.SCORE_STATISTIC);
|
|
|
+ task.setStatus(ExportTaskStatus.WAITING);
|
|
|
+ task.setCreator(req.getCreator());
|
|
|
+ task.setJsonParams(jsonParams);
|
|
|
+ exportTaskService.addExportTask(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void asyncExportExamScoreStatistics(Long taskId, ExamScoreQuery req) {
|
|
|
+ List<ExamScoreInfo> examScores;
|
|
|
+ try {
|
|
|
+ examScores = examScoreService.exportExamScoreListForAsync(req);
|
|
|
+ if (CollectionUtils.isEmpty(examScores)) {
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "当前条件暂无数据,任务终止");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } 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 = examScores.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(ExamScoreInfo.class, examScores, 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("asyncExportExamScoreStatistics finished... " + oss.getRelativePath());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.SUCCESS, null, oss.getRelativePath());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.info("asyncExportExamScoreStatistics error... " + e.getMessage());
|
|
|
+ exportTaskService.updateExportTaskStatus(taskId, ExportTaskStatus.ERROR, "上传至文件服务器异常");
|
|
|
+ } finally {
|
|
|
+ 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() {
|
|
|
+ return UUID.randomUUID().toString().replace("-", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String dateDir() {
|
|
|
+ final String pattern = "yyyyMM";
|
|
|
+ return new SimpleDateFormat(pattern).format(new Date());
|
|
|
+ }
|
|
|
|
|
|
}
|