|
@@ -1,6 +1,22 @@
|
|
package com.qmth.themis.business.templete.impl;
|
|
package com.qmth.themis.business.templete.impl;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FilenameFilter;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.qmth.themis.business.config.SystemConfig;
|
|
import com.qmth.themis.business.config.SystemConfig;
|
|
@@ -22,15 +38,8 @@ import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.util.FileUtil;
|
|
import com.qmth.themis.common.util.FileUtil;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
-import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 试卷导入
|
|
* @Description: 试卷导入
|
|
@@ -91,7 +100,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
try {
|
|
try {
|
|
dfile.mkdirs();
|
|
dfile.mkdirs();
|
|
FileUtil.unZip(dfile, file);
|
|
FileUtil.unZip(dfile, file);
|
|
- if (!hasErr(dir, examId, dfile, result)) {
|
|
|
|
|
|
+ if (!hasErr(map,dir, examId, dfile, result)) {
|
|
for (File courseDir : dfile.listFiles()) {
|
|
for (File courseDir : dfile.listFiles()) {
|
|
if (courseDir.isDirectory()) {
|
|
if (courseDir.isDirectory()) {
|
|
disposeCourseDir(dir, teExam, courseDir, map);
|
|
disposeCourseDir(dir, teExam, courseDir, map);
|
|
@@ -170,9 +179,15 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
paper.setCourseCode(course.getCourseCode());
|
|
paper.setCourseCode(course.getCourseCode());
|
|
paper.setDecryptVector(RandomStringUtils.randomAlphanumeric(16));
|
|
paper.setDecryptVector(RandomStringUtils.randomAlphanumeric(16));
|
|
}
|
|
}
|
|
- disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
|
|
- disposeStruct(rootDir, paper, paperFile);
|
|
|
|
- disposeAnswer(rootDir, paper, answerFile);
|
|
|
|
|
|
+ Boolean processPaper = (Boolean) map.get("processPaper");
|
|
|
|
+ Boolean processAnswer = (Boolean) map.get("processAnswer");
|
|
|
|
+ if(processPaper) {
|
|
|
|
+ disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
|
|
+ disposeStruct(rootDir, paper, paperFile);
|
|
|
|
+ }
|
|
|
|
+ if(processAnswer) {
|
|
|
|
+ disposeAnswer(rootDir, paper, answerFile);
|
|
|
|
+ }
|
|
|
|
|
|
teExamPaperService.saveOrUpdate(paper);
|
|
teExamPaperService.saveOrUpdate(paper);
|
|
}
|
|
}
|
|
@@ -207,11 +222,13 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
for (int j = 0; j < questions.size(); j++) {
|
|
for (int j = 0; j < questions.size(); j++) {
|
|
JSONObject question = questions.getJSONObject(j);
|
|
JSONObject question = questions.getJSONObject(j);
|
|
question.remove("body");
|
|
question.remove("body");
|
|
|
|
+ question.remove("options");
|
|
if (question.getInteger("structType").intValue() == 6) {
|
|
if (question.getInteger("structType").intValue() == 6) {
|
|
JSONArray subQuestions = question.getJSONArray("subQuestions");
|
|
JSONArray subQuestions = question.getJSONArray("subQuestions");
|
|
for (int k = 0; k < subQuestions.size(); k++) {
|
|
for (int k = 0; k < subQuestions.size(); k++) {
|
|
JSONObject subquestion = subQuestions.getJSONObject(k);
|
|
JSONObject subquestion = subQuestions.getJSONObject(k);
|
|
subquestion.remove("body");
|
|
subquestion.remove("body");
|
|
|
|
+ subquestion.remove("options");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -241,7 +258,9 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
result.append(msg).append("\r\n");
|
|
result.append(msg).append("\r\n");
|
|
}
|
|
}
|
|
|
|
|
|
- private boolean hasErr(String rootDir, Long examId, File dfile, StringBuilder result) {
|
|
|
|
|
|
+ private boolean hasErr(Map<String, Object> map,String rootDir, Long examId, File dfile, StringBuilder result) {
|
|
|
|
+ Boolean processPaper = (Boolean) map.get("processPaper");
|
|
|
|
+ Boolean processAnswer = (Boolean) map.get("processAnswer");
|
|
boolean hasErr = false;
|
|
boolean hasErr = false;
|
|
for (File courseDir : dfile.listFiles()) {// 校验每一个科目
|
|
for (File courseDir : dfile.listFiles()) {// 校验每一个科目
|
|
if (courseDir.isDirectory()) {
|
|
if (courseDir.isDirectory()) {
|
|
@@ -267,6 +286,34 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
hasErr = true;
|
|
hasErr = true;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ if(processPaper) {
|
|
|
|
+ String[] ps=paperDir.list(new FilenameFilter() {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean accept(File dir, String name) {
|
|
|
|
+ return name.equals("paper.json");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if(ps==null||ps.length==0) {
|
|
|
|
+ addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷文件");
|
|
|
|
+ hasErr = true;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(processAnswer) {
|
|
|
|
+ String[] ps=paperDir.list(new FilenameFilter() {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean accept(File dir, String name) {
|
|
|
|
+ return name.equals("answer.json");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if(ps==null||ps.length==0) {
|
|
|
|
+ addResult(result, "科目 " + courseCode + " 试卷 " + paperCode + " 没有答案文件");
|
|
|
|
+ hasErr = true;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
try {
|
|
try {
|
|
// 校验答案
|
|
// 校验答案
|
|
checkAnswerFile(rootDir, paperDirChilds, examId, courseCode, paperCode);
|
|
checkAnswerFile(rootDir, paperDirChilds, examId, courseCode, paperCode);
|
|
@@ -281,7 +328,7 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
}
|
|
}
|
|
return hasErr;
|
|
return hasErr;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
private void checkAnswerFile(String rootDir, File[] paperDirChilds, Long examId, String courseCode,
|
|
String paperCode) {
|
|
String paperCode) {
|
|
File paperFile = null;
|
|
File paperFile = null;
|