|
@@ -255,8 +255,12 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
Check.isFalse(req.required(), "至少选择一种导出内容!");
|
|
|
|
|
|
SearchBuilder searches = new SearchBuilder();
|
|
|
- searches.in("id", req.getIds());
|
|
|
searches.eq("paperStatus", PaperStatus.已有.getIndex());
|
|
|
+ if (req.getIds().size() == 1) {
|
|
|
+ searches.eq("id", req.getIds().get(0));
|
|
|
+ } else {
|
|
|
+ searches.in("id", req.getIds());
|
|
|
+ }
|
|
|
Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
|
|
|
|
|
|
List<CourseStatistic> statistics = courseStatisticRepository.findAll(spec);
|
|
@@ -271,9 +275,9 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
Check.isFalse(req.required(), "至少选择一种导出内容!");
|
|
|
|
|
|
SearchBuilder searches = new SearchBuilder();
|
|
|
+ searches.eq("paperStatus", PaperStatus.已有.getIndex());
|
|
|
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);
|
|
@@ -286,10 +290,12 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- //封装待导出的试卷文件列表
|
|
|
+ //封装待导出的试卷或答案文件信息列表
|
|
|
List<ExportFileInfo> exportFiles = new ArrayList<>();
|
|
|
+
|
|
|
//封装试卷结构-客观题数据
|
|
|
List<ObjectiveQuestionStructure> allObjectives = new ArrayList<>();
|
|
|
+
|
|
|
//封装试卷结构-主观题数据
|
|
|
List<SubjectiveQuestionStructure> allSubjectives = new ArrayList<>();
|
|
|
|
|
@@ -322,17 +328,32 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
List<SubjectiveQuestionStructure> subjectives = questionStructureService.getSubjectiveQuestionStructureList(paper.getExamId(), paper.getPaperId());
|
|
|
allSubjectives.addAll(subjectives);
|
|
|
}
|
|
|
+
|
|
|
exportFiles.add(info);
|
|
|
}
|
|
|
|
|
|
+ //文件存放目录
|
|
|
+ final String targetDir = Constants.rootFileDir() + "/" + FileUtils.randomUUID();
|
|
|
+ FileUtils.makeDirs(targetDir);
|
|
|
+
|
|
|
+ //优先处理试卷或答案文件(需要网络下载)
|
|
|
+ if (needPaper || needAnswer) {
|
|
|
+ this.doPaperAndAnswerFiles(exportFiles, targetDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理试卷结构文件
|
|
|
+ if (needStruct) {
|
|
|
+ this.doStructureFiles(allObjectives, allSubjectives, targetDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("All files finished.");
|
|
|
+
|
|
|
//打包所有文件
|
|
|
- return packageFiles(exportFiles, allObjectives, allSubjectives, needStruct);
|
|
|
+ return packageFiles(targetDir);
|
|
|
}
|
|
|
|
|
|
- private File packageFiles(List<ExportFileInfo> exportFiles, List<ObjectiveQuestionStructure> allObjectives, List<SubjectiveQuestionStructure> allSubjectives, boolean needStruct) {
|
|
|
- //文件存放目录
|
|
|
- final String rootDir = Constants.rootFileDir();
|
|
|
- final String targetDir = rootDir + "/" + FileUtils.randomUUID();
|
|
|
+ private void doPaperAndAnswerFiles(List<ExportFileInfo> exportFiles, final String targetDir) {
|
|
|
+ //试卷或答案存放目录
|
|
|
final String paperDir = targetDir + "/" + PAPER_DIR;
|
|
|
final String answerDir = targetDir + "/" + ANSWER_DIR;
|
|
|
FileUtils.makeDirs(paperDir);
|
|
@@ -345,16 +366,17 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
this.loadFile(answerDir, info.getAnswerWord());
|
|
|
this.loadFile(answerDir, info.getAnswerPdf());
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //生成试卷结构文件
|
|
|
- if (needStruct) {
|
|
|
- final String objectiveFile = targetDir + "/" + OBJECTIVE_EXCEL_NAME;
|
|
|
- ExcelUtils.exportExcel(ObjectiveQuestionStructure.class, allObjectives, new File(objectiveFile), OBJECTIVE_TITLE);
|
|
|
+ private void doStructureFiles(List<ObjectiveQuestionStructure> allObjectives, List<SubjectiveQuestionStructure> allSubjectives, final String targetDir) {
|
|
|
+ final String objectiveFile = targetDir + "/" + OBJECTIVE_EXCEL_NAME;
|
|
|
+ ExcelUtils.exportExcel(ObjectiveQuestionStructure.class, allObjectives, new File(objectiveFile), OBJECTIVE_TITLE);
|
|
|
|
|
|
- final String subjectiveFile = targetDir + "/" + SUBJECTIVE_EXCEL_NAME;
|
|
|
- ExcelUtils.exportExcel(SubjectiveQuestionStructure.class, allSubjectives, new File(subjectiveFile), SUBJECTIVE_TITLE);
|
|
|
- }
|
|
|
+ final String subjectiveFile = targetDir + "/" + SUBJECTIVE_EXCEL_NAME;
|
|
|
+ ExcelUtils.exportExcel(SubjectiveQuestionStructure.class, allSubjectives, new File(subjectiveFile), SUBJECTIVE_TITLE);
|
|
|
+ }
|
|
|
|
|
|
+ private File packageFiles(final String targetDir) {
|
|
|
//压缩打包所有文件
|
|
|
File target = new File(targetDir);
|
|
|
File zipFile = new File(targetDir + SUFFIX_ZIP);
|