|
@@ -95,20 +95,11 @@ public class ImportPaperService {
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Object> ImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
|
|
|
+ public Paper ImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
|
|
|
File file) throws Exception {
|
|
|
- Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
- String errorInfo = paperService.checkPaperName(paperName, user.getRootOrgId().toString());
|
|
|
- if (errorInfo == null) {
|
|
|
- msgMap = processImportPaper(paperName, courseNo, courseName, user, file);
|
|
|
- String errorMsg = (String)msgMap.get("msg");
|
|
|
- if(StringUtils.isNotEmpty(errorMsg)){
|
|
|
- throw new PaperException(errorMsg);
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new PaperException(errorInfo);
|
|
|
- }
|
|
|
- return msgMap;
|
|
|
+ paperService.checkPaperNameNew(paperName, user.getRootOrgId().toString());
|
|
|
+ Paper paper = processImportPaper(paperName,courseNo,courseName,user,file);
|
|
|
+ return paper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -148,6 +139,30 @@ public class ImportPaperService {
|
|
|
return tempPaper;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 清空试卷对象,加速回收
|
|
|
+ * @param paper
|
|
|
+ * @param paperDetails
|
|
|
+ * @param paperDetailUnits
|
|
|
+ * @param questions
|
|
|
+ */
|
|
|
+ public void clearPaper(Paper paper,
|
|
|
+ List<PaperDetail> paperDetails,
|
|
|
+ List<PaperDetailUnit> paperDetailUnits,
|
|
|
+ List<Question> questions){
|
|
|
+ paper = null;
|
|
|
+ paperDetails.clear();
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
+ paperDetailUnit.setQuestion(null);
|
|
|
+ }
|
|
|
+ for(Question question:questions){
|
|
|
+ question.setQuesPkg(null);
|
|
|
+ }
|
|
|
+ paperDetailUnits.clear();
|
|
|
+ questions.clear();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理导入试卷
|
|
|
*
|
|
@@ -158,7 +173,7 @@ public class ImportPaperService {
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Object> processImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
|
|
|
+ public Paper processImportPaper(String paperName, String courseNo, String courseName, AccessUser user,
|
|
|
File file) throws Exception {
|
|
|
Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
WordprocessingMLPackage wordMLPackage;
|
|
@@ -234,6 +249,9 @@ public class ImportPaperService {
|
|
|
|
|
|
} else if (pText.matches("^\\d{1,}\\.[\\s\\S]*")
|
|
|
|| (isNested(importPaperCheck) && !pText.startsWith("["))) {
|
|
|
+
|
|
|
+ ++subQuesNum;
|
|
|
+
|
|
|
// 处理试题
|
|
|
|
|
|
// 创建小题类和试题类
|
|
@@ -241,7 +259,7 @@ public class ImportPaperService {
|
|
|
Question question = new Question();
|
|
|
|
|
|
// 初始化小题类和试题类
|
|
|
- initPaperDetail(paper, paperDetail, paperDetailUnit, question, ++subQuesNum, importPaperCheck);
|
|
|
+ initPaperDetail(paper, paperDetail, paperDetailUnit, question, subQuesNum , importPaperCheck);
|
|
|
|
|
|
// 处理客观题
|
|
|
if (importPaperCheck.quesType.equals("单选") || importPaperCheck.quesType.equals("多选")) {
|
|
@@ -267,7 +285,6 @@ public class ImportPaperService {
|
|
|
importPaperCheck, tmpWordMlPackage, false);
|
|
|
}
|
|
|
// 设置WordMlPackage二进制数据
|
|
|
- // setPkgByte(question, writePkg);
|
|
|
question.setQuesPkg(writeByte);
|
|
|
// 设置question与Unit集合数据
|
|
|
question.setCourseNo(paper.getCourseNo());
|
|
@@ -280,26 +297,23 @@ public class ImportPaperService {
|
|
|
i = importPaperCheck.index - 1;
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(importPaperCheck.errorInfo)) {
|
|
|
- msgMap.put("msg", importPaperCheck.errorInfo);
|
|
|
- return msgMap;
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
}
|
|
|
}
|
|
|
if (paperDetails.size() == 0) {
|
|
|
importPaperCheck.setErrorInfo("导入文件格式有误!");
|
|
|
- msgMap.put("msg", importPaperCheck.errorInfo);
|
|
|
- return msgMap;
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
}
|
|
|
paper.setPaperDetailCount(mainQuesNum);
|
|
|
// 保存导入试卷信息
|
|
|
paper = savePaper(paper, paperDetails, paperDetailUnits, questions, importPaperCheck);
|
|
|
+ clearPaper(paper, paperDetails, paperDetailUnits, questions);
|
|
|
wordMLPackage = null;
|
|
|
tmpWordMlPackage = null;
|
|
|
writePkg = null;
|
|
|
writeByte = null;
|
|
|
FileUtils.deleteQuietly(file);
|
|
|
- msgMap.put("msg", importPaperCheck.errorInfo);
|
|
|
- msgMap.put("paper", paper);
|
|
|
- return msgMap;
|
|
|
+ return paper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -351,7 +365,7 @@ public class ImportPaperService {
|
|
|
|
|
|
question.setQuestionType(getQuesStructType(importPaperCheck.quesType));
|
|
|
question.setScore(Double.parseDouble(importPaperCheck.quesScore));
|
|
|
- paperDetailUnit.setNumber(++subQuesNum);
|
|
|
+ paperDetailUnit.setNumber(subQuesNum);
|
|
|
paperDetailUnit.setQuestion(question);
|
|
|
paperDetailUnit.setPaperDetail(paperDetail);
|
|
|
paperDetailUnit.setQuestionType(getQuesStructType(importPaperCheck.quesType));
|
|
@@ -681,9 +695,11 @@ public class ImportPaperService {
|
|
|
// 创建小题集合
|
|
|
List<Question> subQuesList = new ArrayList<Question>();
|
|
|
|
|
|
+ Question subQues = null;
|
|
|
+
|
|
|
int beginNum = importPaperCheck.index;
|
|
|
|
|
|
- int tempNum = 0;
|
|
|
+ int quesTypeNum = 0;
|
|
|
|
|
|
int subQuesNum = 0;
|
|
|
for (int i = beginNum; i < pList.size(); i++) {
|
|
@@ -697,9 +713,9 @@ public class ImportPaperService {
|
|
|
|
|
|
nestedQuesType = tmpText.replaceAll("\\[小题型\\]", "").replaceAll("[:|:]", "").trim();
|
|
|
importPaperCheck.index++;
|
|
|
- tempNum = i;
|
|
|
+ quesTypeNum++;
|
|
|
|
|
|
- } else if (tmpText.matches("^\\d\\.[\\s\\S]*")) {
|
|
|
+ } else if (tmpText.matches("^\\d{1,}\\.[\\s\\S]*")) {
|
|
|
|
|
|
++subQuesNum;
|
|
|
|
|
@@ -709,7 +725,7 @@ public class ImportPaperService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- Question subQues = new Question();
|
|
|
+ subQues = new Question();
|
|
|
subQues.setQuestionType(getQuesStructType(nestedQuesType));
|
|
|
if (StringUtils.isNumeric(importPaperCheck.getQuesScore())) {
|
|
|
subQues.setScore(Double.parseDouble(importPaperCheck.getQuesScore()));
|
|
@@ -742,18 +758,21 @@ public class ImportPaperService {
|
|
|
subQuesList.add(subQues);
|
|
|
i = importPaperCheck.index - 1;
|
|
|
nestedQuesType = "";
|
|
|
- }else if(tmpText.startsWith("[")){
|
|
|
- break;
|
|
|
- }else{
|
|
|
- if(i == tempNum + 1){
|
|
|
- importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum + 1)
|
|
|
- +"小题型后面只能为小题题干,且必须以数字开头,不能以其他格式开头\n");
|
|
|
- return;
|
|
|
- }else if (StringUtils.isEmpty(nestedQuesType)) {
|
|
|
- importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum + 1)
|
|
|
+
|
|
|
+ }else if(subQuesNum != quesTypeNum){
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(nestedQuesType)) {
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, quesTypeNum)
|
|
|
+ "小题型为空或格式不正确\n");
|
|
|
return;
|
|
|
+ }else{
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, quesTypeNum)
|
|
|
+ + "题干为空或格式不正确,必须以数字.开头\n");
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ }else if(tmpText.startsWith("[")){
|
|
|
+ break;
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(importPaperCheck.errorInfo)) {
|
|
|
return;
|