|
@@ -11,14 +11,18 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.Check;
|
|
|
+import cn.com.qmth.examcloud.core.print.common.utils.FileUtils;
|
|
|
import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
|
|
|
import cn.com.qmth.examcloud.core.print.entity.CourseStatistic;
|
|
|
+import cn.com.qmth.examcloud.core.print.entity.ObjectiveQuestionStructure;
|
|
|
+import cn.com.qmth.examcloud.core.print.entity.SubjectiveQuestionStructure;
|
|
|
import cn.com.qmth.examcloud.core.print.enums.PaperStatus;
|
|
|
import cn.com.qmth.examcloud.core.print.repository.CoursePaperRepository;
|
|
|
import cn.com.qmth.examcloud.core.print.repository.CourseStatisticRepository;
|
|
|
import cn.com.qmth.examcloud.core.print.service.CoursePaperService;
|
|
|
import cn.com.qmth.examcloud.core.print.service.QuestionStructureService;
|
|
|
import cn.com.qmth.examcloud.core.print.service.bean.coursepaper.*;
|
|
|
+import javafx.util.Pair;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -30,7 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.io.File;
|
|
|
import java.util.*;
|
|
|
|
|
|
-import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
|
|
|
+import static cn.com.qmth.examcloud.core.print.common.Constants.*;
|
|
|
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
@@ -252,6 +256,53 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
Check.isNull(req.getOrgId(), "学校ID不能为空!");
|
|
|
Check.isNull(req.getExamId(), "考试ID不能为空!");
|
|
|
Check.isNull(req.required(), "至少选择一种导出内容!");
|
|
|
+
|
|
|
+ SearchBuilder searches = new SearchBuilder();
|
|
|
+ searches.eq("orgId", req.getOrgId());
|
|
|
+ searches.eq("examId", req.getExamId());
|
|
|
+ searches.eq("paperStatus", PaperStatus.已有.getIndex());
|
|
|
+ Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
|
|
|
+ List<CourseStatistic> statistics = courseStatisticRepository.findAll(spec);
|
|
|
+ if (statistics == null || statistics.isEmpty()) {
|
|
|
+ log.warn(String.format("No paper to export! orgId = %s examId = %s", req.getOrgId(), req.getExamId()));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //封装待导出的文件列表
|
|
|
+ List<ExportFileInfo> exportFiles = new ArrayList<>();
|
|
|
+ //封装试卷结构-客观题数据
|
|
|
+ List<ObjectiveQuestionStructure> objectiveStructures = new ArrayList<>();
|
|
|
+ //封装试卷结构-主观题数据
|
|
|
+ List<SubjectiveQuestionStructure> subjectiveStructures = new ArrayList<>();
|
|
|
+ for (CourseStatistic statistic : statistics) {
|
|
|
+ CoursePaper paper = statistic.getCoursePaper();
|
|
|
+ if (paper == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //命名规则:试卷名_课程代码_试卷类型_试卷或答案
|
|
|
+ final String title = String.format("%s_%s_%s_", paper.getPaperName(), paper.getCourseCode(), statistic.getPaperType());
|
|
|
+ ExportFileInfo info = new ExportFileInfo();
|
|
|
+ if (req.getNeedPaper()) {
|
|
|
+ info.setPaperWord(new Pair<>(title + PAPER_DOC_NAME, paper.getPaperWordUrl()));
|
|
|
+ info.setPaperPdf(new Pair<>(title + PAPER_PDF_NAME, paper.getPaperPdfUrl()));
|
|
|
+ }
|
|
|
+ if (req.getNeedAnswer()) {
|
|
|
+ info.setAnswerWord(new Pair<>(title + ANSWER_DOC_NAME, paper.getAnswerWordUrl()));
|
|
|
+ info.setAnswerPdf(new Pair<>(title + ANSWER_PDF_NAME, paper.getAnswerPdfUrl()));
|
|
|
+ }
|
|
|
+ if (req.getNeedStruct()) {
|
|
|
+ //todo
|
|
|
+ //objectiveStructures.add(...)
|
|
|
+ //subjectiveStructures.add(...)
|
|
|
+ }
|
|
|
+ exportFiles.add(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //文件根目录
|
|
|
+ final String rootDir = ExportFileInfo.class.getClassLoader().getResource("").getPath() + "/files";
|
|
|
+ final String tempPath = rootDir + "/" + FileUtils.randomUUID();
|
|
|
+ FileUtils.makeDirs(tempPath);
|
|
|
+
|
|
|
//todo
|
|
|
return null;
|
|
|
}
|