|
@@ -1,6 +1,23 @@
|
|
|
package com.qmth.cqb.paper.service;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
+import org.docx4j.wml.P;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
+
|
|
|
import com.google.gson.Gson;
|
|
|
import com.qmth.cqb.base.dao.CourseRepo;
|
|
|
import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
@@ -19,21 +36,8 @@ import com.qmth.cqb.utils.enums.PaperStatus;
|
|
|
import com.qmth.cqb.utils.enums.PaperType;
|
|
|
import com.qmth.cqb.utils.enums.QuesUnit;
|
|
|
import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
-import org.docx4j.wml.P;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
|
|
@Service
|
|
|
public class ImportPaperService {
|
|
@@ -93,12 +97,18 @@ public class ImportPaperService {
|
|
|
*/
|
|
|
public String ImportPaper(String paperName, String courseNo, File file) {
|
|
|
String errorInfo = paperService.checkPaperName(paperName);
|
|
|
- errorInfo += processImportPaper(paperName, courseNo, file);
|
|
|
- if (StringUtils.isEmpty(errorInfo)) {
|
|
|
- return "success";
|
|
|
+ if (errorInfo == null) {
|
|
|
+ errorInfo = "";
|
|
|
+ errorInfo += processImportPaper(paperName, courseNo, file);
|
|
|
+ if (StringUtils.isEmpty(errorInfo)) {
|
|
|
+ return "success";
|
|
|
+ } else {
|
|
|
+ return errorInfo;
|
|
|
+ }
|
|
|
} else {
|
|
|
return errorInfo;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -164,6 +174,8 @@ public class ImportPaperService {
|
|
|
|
|
|
paper.setCourseNo(courseNo);
|
|
|
|
|
|
+ paper.setCourseNo(courseRepo.findByCourseNo(courseNo).getCourseNo());
|
|
|
+
|
|
|
// 设置试卷
|
|
|
initPaper(paper, paperName);
|
|
|
|
|
@@ -206,8 +218,8 @@ public class ImportPaperService {
|
|
|
// 设置大题类
|
|
|
initQuesHeader(paper, paperDetail, paperDetails, ++mainQuesNum, importPaperCheck);
|
|
|
|
|
|
- } else if (pText.matches("^\\d{1,}\\.[\\s\\S]*") || (isNested(importPaperCheck) && !pText
|
|
|
- .startsWith("["))) {
|
|
|
+ } else if (pText.matches("^\\d{1,}\\.[\\s\\S]*")
|
|
|
+ || (isNested(importPaperCheck) && !pText.startsWith("["))) {
|
|
|
// 处理试题
|
|
|
|
|
|
// 创建小题类和试题类
|
|
@@ -243,7 +255,8 @@ public class ImportPaperService {
|
|
|
}
|
|
|
// 设置WordMlPackage二进制数据
|
|
|
setPkgByte(question, writePkg);
|
|
|
-
|
|
|
+ Map<String, String> quesParams = new HashMap<String, String>();
|
|
|
+ quesParams.put("courseName", paper.getCourseName());
|
|
|
// 设置question与Unit集合数据
|
|
|
questions.add(question);
|
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
@@ -299,10 +312,11 @@ public class ImportPaperService {
|
|
|
paperDetail.setPaper(paper);
|
|
|
|
|
|
// 不从word中提取课程信息,统一从页面设置好
|
|
|
- //if (StringUtils.isEmpty(paper.getCourseNo()) || StringUtils.isEmpty(paper.getCourseName())) {
|
|
|
- // paper.setCourseNo(getCourseNo(importPaperCheck));
|
|
|
- // paper.setCourseName(getCourseName(importPaperCheck));
|
|
|
- //}
|
|
|
+ // if (StringUtils.isEmpty(paper.getCourseNo()) ||
|
|
|
+ // StringUtils.isEmpty(paper.getCourseName())) {
|
|
|
+ // paper.setCourseNo(getCourseNo(importPaperCheck));
|
|
|
+ // paper.setCourseName(getCourseName(importPaperCheck));
|
|
|
+ // }
|
|
|
// 设置大题信息
|
|
|
paperDetail.setName(importPaperCheck.quesName);
|
|
|
paperDetail.setUnitCount(Integer.parseInt(importPaperCheck.quesCount));
|
|
@@ -478,8 +492,8 @@ public class ImportPaperService {
|
|
|
ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
|
|
|
|
// 定义试题选项wordml和html
|
|
|
- //String quesOptionWordMl = "";
|
|
|
- //String quesOptionHtml = "";
|
|
|
+ // String quesOptionWordMl = "";
|
|
|
+ // String quesOptionHtml = "";
|
|
|
// 定义选项集合
|
|
|
List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
// 定义选项数量
|
|
@@ -547,7 +561,7 @@ public class ImportPaperService {
|
|
|
StringBuilder answerWordML = new StringBuilder("");
|
|
|
StringBuilder answerHTML = new StringBuilder("");
|
|
|
String quesScore = "";
|
|
|
- //Map<String, String> quesParams = new HashMap<String, String>();
|
|
|
+ // Map<String, String> quesParams = new HashMap<String, String>();
|
|
|
int i = 0;
|
|
|
// 是否刚刚检测到答案内容
|
|
|
boolean answerStart = false;
|
|
@@ -680,7 +694,7 @@ public class ImportPaperService {
|
|
|
}
|
|
|
}
|
|
|
question.setSubQuestions(subQuesList);
|
|
|
- //计算套题总分
|
|
|
+ // 计算套题总分
|
|
|
double totalScore = 0;
|
|
|
for (Question child : subQuesList) {
|
|
|
Double score = child.getScore();
|