|
@@ -1,160 +1,150 @@
|
|
package cn.com.qmth.examcloud.core.questions.service.temp;
|
|
package cn.com.qmth.examcloud.core.questions.service.temp;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.IdUtils;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.enums.PaperStatus;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.word.DocxProcessUtil;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.*;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.*;
|
|
|
|
-import cn.com.qmth.examcloud.core.questions.service.impl.CourseService;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
|
|
+import javax.xml.parsers.DocumentBuilder;
|
|
|
|
+import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
+
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
-import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.NamedNodeMap;
|
|
import org.w3c.dom.NamedNodeMap;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
|
|
-import javax.xml.parsers.DocumentBuilder;
|
|
|
|
-import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.regex.Matcher;
|
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
public class CqdxService {
|
|
public class CqdxService {
|
|
private static final Logger log = LoggerFactory.getLogger(CqdxService.class);
|
|
private static final Logger log = LoggerFactory.getLogger(CqdxService.class);
|
|
final Long rootOrgId = 1407L;
|
|
final Long rootOrgId = 1407L;
|
|
final String rootDir = "D:/paper/cqu/temps";
|
|
final String rootDir = "D:/paper/cqu/temps";
|
|
- @Autowired
|
|
|
|
- private CourseService courseService;
|
|
|
|
- @Autowired
|
|
|
|
- private QuesRepo quesRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private PaperRepo paperRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private PaperDetailRepo paperDetailRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
- @Autowired
|
|
|
|
- private QuesPkgPathRepo quesPkgPathRepo;
|
|
|
|
-
|
|
|
|
- public void bulidPaper() throws Exception {
|
|
|
|
- // 获取所有xml的路径
|
|
|
|
- List<String> files = this.loadFiles();
|
|
|
|
-
|
|
|
|
- //试卷名称(后缀)
|
|
|
|
- final String paperNameSuffix = "192";
|
|
|
|
-
|
|
|
|
- int i = 0;
|
|
|
|
- log.debug("XML的文件数:" + files.size());
|
|
|
|
- for (String filePath : files) {
|
|
|
|
- log.debug("第" + (++i) + "个xml文件开始处理,文件名为:" + filePath);
|
|
|
|
-
|
|
|
|
-// if (i < 30) {
|
|
|
|
-// continue;
|
|
|
|
|
|
+// @Autowired
|
|
|
|
+// private CourseService courseService;
|
|
|
|
+// @Autowired
|
|
|
|
+// private QuesRepo quesRepo;
|
|
|
|
+// @Autowired
|
|
|
|
+// private PaperRepo paperRepo;
|
|
|
|
+// @Autowired
|
|
|
|
+// private PaperDetailRepo paperDetailRepo;
|
|
|
|
+// @Autowired
|
|
|
|
+// private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
+// @Autowired
|
|
|
|
+// private QuesPkgPathRepo quesPkgPathRepo;
|
|
|
|
+
|
|
|
|
+// public void bulidPaper() throws Exception {
|
|
|
|
+// // 获取所有xml的路径
|
|
|
|
+// List<String> files = this.loadFiles();
|
|
|
|
+//
|
|
|
|
+// //试卷名称(后缀)
|
|
|
|
+// final String paperNameSuffix = "192";
|
|
|
|
+//
|
|
|
|
+// int i = 0;
|
|
|
|
+// log.debug("XML的文件数:" + files.size());
|
|
|
|
+// for (String filePath : files) {
|
|
|
|
+// log.debug("第" + (++i) + "个xml文件开始处理,文件名为:" + filePath);
|
|
|
|
+//
|
|
|
|
+//// if (i < 30) {
|
|
|
|
+//// continue;
|
|
|
|
+//// }
|
|
|
|
+//
|
|
|
|
+// Map<Object, Object> paperInfoMap = this.readXml(filePath, paperNameSuffix);
|
|
|
|
+// // 查询课程
|
|
|
|
+// Course course = courseService.getCourse(rootOrgId, paperInfoMap.get("courseCode").toString());
|
|
|
|
+// // 初始化试卷
|
|
|
|
+// Paper paper = initPaper(paperInfoMap, course);
|
|
|
|
+// // 大题集合
|
|
|
|
+// List<PaperDetail> paperDetails = initPaperDetails(paperInfoMap, paper);
|
|
|
|
+// // 试题---资源 对应关系
|
|
|
|
+// Map<Question, QuestionPkgPath> questionMaps = new HashMap<>();
|
|
|
|
+//
|
|
|
|
+// // 定义小题集合
|
|
|
|
+// List<PaperDetailUnit> paperDetailUnits;
|
|
|
|
+// try {
|
|
|
|
+// paperDetailUnits = initpaperDetailUnits(paper, paperDetails, questionMaps, paperInfoMap, course);
|
|
|
|
+// if (paperDetailUnits == null) {
|
|
|
|
+// log.debug("-->有错误的XML:" + filePath);
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.debug("==>有错误的XML:" + filePath + " Error:" + e.getMessage());
|
|
|
|
+// break;
|
|
// }
|
|
// }
|
|
-
|
|
|
|
- Map<Object, Object> paperInfoMap = this.readXml(filePath, paperNameSuffix);
|
|
|
|
- // 查询课程
|
|
|
|
- Course course = courseService.getCourse(rootOrgId, paperInfoMap.get("courseCode").toString());
|
|
|
|
- // 初始化试卷
|
|
|
|
- Paper paper = initPaper(paperInfoMap, course);
|
|
|
|
- // 大题集合
|
|
|
|
- List<PaperDetail> paperDetails = initPaperDetails(paperInfoMap, paper);
|
|
|
|
- // 试题---资源 对应关系
|
|
|
|
- Map<Question, QuestionPkgPath> questionMaps = new HashMap<>();
|
|
|
|
-
|
|
|
|
- // 定义小题集合
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits;
|
|
|
|
- try {
|
|
|
|
- paperDetailUnits = initpaperDetailUnits(paper, paperDetails, questionMaps, paperInfoMap, course);
|
|
|
|
- if (paperDetailUnits == null) {
|
|
|
|
- log.debug("-->有错误的XML:" + filePath);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.debug("==>有错误的XML:" + filePath + " Error:" + e.getMessage());
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 保存试题资源
|
|
|
|
- /*quesPkgPathRepo.saveAll(questionMaps.values());
|
|
|
|
- for (Map.Entry<Question, QuestionPkgPath> entry : questionMaps.entrySet()) {
|
|
|
|
- entry.getKey().setQuesPkgPathId(entry.getValue().getId());
|
|
|
|
- }
|
|
|
|
- quesRepo.saveAll(questionMaps.keySet());
|
|
|
|
- paperRepo.save(paper);
|
|
|
|
- paperDetailRepo.saveAll(paperDetails);
|
|
|
|
- paperDetailUnitRepo.saveAll(paperDetailUnits);*/
|
|
|
|
-
|
|
|
|
- // 将正常文件移动到新目录
|
|
|
|
- /*File okFile = new File(rootDir + "/" + filePath);
|
|
|
|
- String newFilePath = rootDir + "/ok/" + okFile.getName();
|
|
|
|
- File newFile = new File(newFilePath);
|
|
|
|
- okFile.renameTo(newFile);*/
|
|
|
|
-
|
|
|
|
- log.debug("第" + i + "个xml文件已经处理完,文件名为:" + filePath);
|
|
|
|
- }
|
|
|
|
- log.debug("处理完成...");
|
|
|
|
- }
|
|
|
|
|
|
+//
|
|
|
|
+// // 保存试题资源
|
|
|
|
+// /*quesPkgPathRepo.saveAll(questionMaps.values());
|
|
|
|
+// for (Map.Entry<Question, QuestionPkgPath> entry : questionMaps.entrySet()) {
|
|
|
|
+// entry.getKey().setQuesPkgPathId(entry.getValue().getId());
|
|
|
|
+// }
|
|
|
|
+// quesRepo.saveAll(questionMaps.keySet());
|
|
|
|
+// paperRepo.save(paper);
|
|
|
|
+// paperDetailRepo.saveAll(paperDetails);
|
|
|
|
+// paperDetailUnitRepo.saveAll(paperDetailUnits);*/
|
|
|
|
+//
|
|
|
|
+// // 将正常文件移动到新目录
|
|
|
|
+// /*File okFile = new File(rootDir + "/" + filePath);
|
|
|
|
+// String newFilePath = rootDir + "/ok/" + okFile.getName();
|
|
|
|
+// File newFile = new File(newFilePath);
|
|
|
|
+// okFile.renameTo(newFile);*/
|
|
|
|
+//
|
|
|
|
+// log.debug("第" + i + "个xml文件已经处理完,文件名为:" + filePath);
|
|
|
|
+// }
|
|
|
|
+// log.debug("处理完成...");
|
|
|
|
+// }
|
|
|
|
|
|
// 初始化试卷
|
|
// 初始化试卷
|
|
- private Paper initPaper(Map<Object, Object> paperInfoMap, Course course) {
|
|
|
|
- Paper paper = new Paper();
|
|
|
|
- paper.setName((String) paperInfoMap.get("name"));
|
|
|
|
- paper.setTitle((String) paperInfoMap.get("name"));
|
|
|
|
- paper.setPaperType(PaperType.IMPORT);
|
|
|
|
- paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
- paper.setOrgId(course.getOrgId());
|
|
|
|
- paper.setCreator("feng");
|
|
|
|
- paper.setTotalScore(Double.valueOf((String) paperInfoMap
|
|
|
|
- .get("totalScore")));
|
|
|
|
- paper.setCourse(course);
|
|
|
|
- paper.setCourseName(course.getName());
|
|
|
|
- paper.setCourseNo(course.getCode());
|
|
|
|
- paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- paper.setPaperDetailCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
- .get("detailCount")));
|
|
|
|
- paper.setUnitCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
- .get("unitCount")));
|
|
|
|
- paper.setDifficultyDegree(0.5);
|
|
|
|
- return paper;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 初始化大题集合
|
|
|
|
- private List<PaperDetail> initPaperDetails(
|
|
|
|
- Map<Object, Object> paperInfoMap, Paper paper) {
|
|
|
|
- // 定义大题集合
|
|
|
|
- List<PaperDetail> paperDetails = new ArrayList<PaperDetail>();
|
|
|
|
- int length = paperInfoMap.size() - 5;
|
|
|
|
- for (int i = 0; i < length; i++) {
|
|
|
|
- QuestionsTemp detailInfo = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
- .valueOf(i + 1));
|
|
|
|
- PaperDetail paperDetail = new PaperDetail();
|
|
|
|
- paperDetail.setPaper(paper);
|
|
|
|
- paperDetail.setNumber(Integer.valueOf(detailInfo.getNumber()));
|
|
|
|
- paperDetail.setName(detailInfo.getName());
|
|
|
|
- paperDetail.setScore(Double.valueOf(detailInfo.getTotalScore()));
|
|
|
|
- paperDetail.setUnitCount(Integer.valueOf(detailInfo.getCount()));
|
|
|
|
- paperDetail.setCreator("feng");
|
|
|
|
- paperDetail.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- paperDetails.add(paperDetail);
|
|
|
|
- }
|
|
|
|
- return paperDetails;
|
|
|
|
- }
|
|
|
|
|
|
+// private Paper initPaper(Map<Object, Object> paperInfoMap, Course course) {
|
|
|
|
+// Paper paper = new Paper();
|
|
|
|
+// paper.setName((String) paperInfoMap.get("name"));
|
|
|
|
+// paper.setTitle((String) paperInfoMap.get("name"));
|
|
|
|
+// paper.setPaperType(PaperType.IMPORT);
|
|
|
|
+// paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
+// paper.setOrgId(course.getOrgId());
|
|
|
|
+// paper.setCreator("feng");
|
|
|
|
+// paper.setTotalScore(Double.valueOf((String) paperInfoMap
|
|
|
|
+// .get("totalScore")));
|
|
|
|
+// paper.setCourse(course);
|
|
|
|
+// paper.setCourseName(course.getName());
|
|
|
|
+// paper.setCourseNo(course.getCode());
|
|
|
|
+// paper.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+// paper.setPaperDetailCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
+// .get("detailCount")));
|
|
|
|
+// paper.setUnitCount(Integer.valueOf((String) paperInfoMap
|
|
|
|
+// .get("unitCount")));
|
|
|
|
+// paper.setDifficultyDegree(0.5);
|
|
|
|
+// return paper;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 初始化大题集合
|
|
|
|
+// private List<PaperDetail> initPaperDetails(
|
|
|
|
+// Map<Object, Object> paperInfoMap, Paper paper) {
|
|
|
|
+// // 定义大题集合
|
|
|
|
+// List<PaperDetail> paperDetails = new ArrayList<PaperDetail>();
|
|
|
|
+// int length = paperInfoMap.size() - 5;
|
|
|
|
+// for (int i = 0; i < length; i++) {
|
|
|
|
+// QuestionsTemp detailInfo = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
+// .valueOf(i + 1));
|
|
|
|
+// PaperDetail paperDetail = new PaperDetail();
|
|
|
|
+// paperDetail.setPaper(paper);
|
|
|
|
+// paperDetail.setNumber(Integer.valueOf(detailInfo.getNumber()));
|
|
|
|
+// paperDetail.setName(detailInfo.getName());
|
|
|
|
+// paperDetail.setScore(Double.valueOf(detailInfo.getTotalScore()));
|
|
|
|
+// paperDetail.setUnitCount(Integer.valueOf(detailInfo.getCount()));
|
|
|
|
+// paperDetail.setCreator("feng");
|
|
|
|
+// paperDetail.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+// paperDetails.add(paperDetail);
|
|
|
|
+// }
|
|
|
|
+// return paperDetails;
|
|
|
|
+// }
|
|
|
|
|
|
public Map<Object, Object> readXml(String xmlPath, String paperNameSuffix) throws Exception {
|
|
public Map<Object, Object> readXml(String xmlPath, String paperNameSuffix) throws Exception {
|
|
Map<Object, Object> paperInfoMap = new HashedMap<>();
|
|
Map<Object, Object> paperInfoMap = new HashedMap<>();
|
|
@@ -347,189 +337,189 @@ public class CqdxService {
|
|
}
|
|
}
|
|
|
|
|
|
// 初始化小题集合
|
|
// 初始化小题集合
|
|
- private List<PaperDetailUnit> initpaperDetailUnits(Paper paper, List<PaperDetail> paperDetails, Map<Question, QuestionPkgPath> map,
|
|
|
|
- Map<Object, Object> paperInfoMap, Course course) throws Exception {
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
- int detailCount = paperDetails.size();
|
|
|
|
- int nm = 0;
|
|
|
|
- for (int i = 0; i < detailCount; i++) {
|
|
|
|
- PaperDetail detail = paperDetails.get(i);
|
|
|
|
- QuestionsTemp detailTemp = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
- .valueOf(i + 1));
|
|
|
|
- Map<Object, Object> detailInfoMap = detailTemp.getQues();
|
|
|
|
- int quesCount = detailInfoMap.size();
|
|
|
|
- for (int j = 0; j < quesCount; j++) {
|
|
|
|
- WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
|
|
|
|
- .createPackage();
|
|
|
|
- QuestionsTemp quesTemp = (QuestionsTemp) detailInfoMap
|
|
|
|
- .get(String.valueOf(j + 1));
|
|
|
|
- Question question = new Question();
|
|
|
|
- question.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- question.setScore(Double.valueOf(quesTemp.getScore()));
|
|
|
|
- question.setCourse(course);
|
|
|
|
- question.setOrgId(course.getOrgId());
|
|
|
|
- question.setHasAudio(false);
|
|
|
|
- question.setDifficulty("中");
|
|
|
|
- question.setDifficultyDegree(0.5);
|
|
|
|
- question.setPublicity(true);
|
|
|
|
- question.setQuestionType(quesTemp.getType());
|
|
|
|
-
|
|
|
|
- String body = imgList(quesTemp.getBody());
|
|
|
|
- question.setQuesBody(replaceBlank(body));
|
|
|
|
- try {
|
|
|
|
- question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.debug("错误题干信息:" + question.getQuesBody());
|
|
|
|
- throw new IllegalArgumentException("题干信息错误!");
|
|
|
|
- }
|
|
|
|
- if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
|
|
|
|
- question.setQuesAnswer(quesTemp.getAnswer());
|
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>" + question.getQuesAnswer() + "</p>")));
|
|
|
|
- } else {
|
|
|
|
- question.setQuesAnswer(imgList(quesTemp.getAnswer()));
|
|
|
|
- try {
|
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.debug("错误答案信息:" + question.getQuesAnswer());
|
|
|
|
- throw new IllegalArgumentException("答案信息错误!");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 存在选项
|
|
|
|
- if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
- || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
- List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
|
- Map<Object, Object> optionMap = quesTemp.getOptions();
|
|
|
|
- int optionCount = optionMap.size();
|
|
|
|
- for (int k = 0; k < optionCount; k++) {
|
|
|
|
- QuesOption quesOption = new QuesOption();
|
|
|
|
- quesOption.setNumber(String.valueOf(k + 1));
|
|
|
|
-
|
|
|
|
- String optionBody = imgList((String) optionMap.get(String.valueOf(k + 1)));
|
|
|
|
- if (optionBody.startsWith("<p><p") || optionBody.startsWith("<P><P")) {
|
|
|
|
- quesOption.setOptionBody(replaceFirstP(optionBody));
|
|
|
|
- } else {
|
|
|
|
- quesOption.setOptionBody(optionBody);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesOption.getOptionBody())));
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.debug("错误的选项:" + quesOption.getOptionBody());
|
|
|
|
- throw new IllegalArgumentException("选项信息错误!");
|
|
|
|
- }
|
|
|
|
- if (question.getQuesAnswer().contains(String.valueOf(k + 1))) {
|
|
|
|
- quesOption.setIsCorrect((short) 1);
|
|
|
|
- } else {
|
|
|
|
- quesOption.setIsCorrect((short) 0);
|
|
|
|
- }
|
|
|
|
- quesOptions.add(quesOption);
|
|
|
|
- }
|
|
|
|
- question.setQuesOptions(quesOptions);
|
|
|
|
- String[] answers = question.getQuesAnswer()
|
|
|
|
- .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
- .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
- .split(",");
|
|
|
|
- String answer = "";
|
|
|
|
- for (int a = 0; a < answers.length; a++) {
|
|
|
|
- char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
- if (a == 0) {
|
|
|
|
- answer = String.valueOf(c1);
|
|
|
|
- } else {
|
|
|
|
- answer = answer + "," + c1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- question.setQuesAnswer("<p>" + answer + "</p>");
|
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
- }
|
|
|
|
- // 存在子题
|
|
|
|
- if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
|
- List<Question> subQuestions = new ArrayList<>();
|
|
|
|
- int subQuesCount = quesTemp.getSubQues().size();
|
|
|
|
- BigDecimal totalScore = BigDecimal.valueOf(question.getScore());
|
|
|
|
- BigDecimal sum = BigDecimal.valueOf(subQuesCount);
|
|
|
|
- double score = totalScore.divide(sum).doubleValue();
|
|
|
|
- for (int s = 0; s < subQuesCount; s++) {
|
|
|
|
- QuestionsTemp subQuesTmp = (QuestionsTemp) quesTemp.getSubQues().get(String.valueOf(s + 1));
|
|
|
|
- Question subQuestion = new Question();
|
|
|
|
- subQuestion.setId(IdUtils.uuid());
|
|
|
|
- subQuestion.setQuestionType(subQuesTmp.getType());
|
|
|
|
- subQuestion.setDifficulty("中");
|
|
|
|
- subQuestion.setDifficultyDegree(0.5);
|
|
|
|
- subQuestion.setPublicity(true);
|
|
|
|
- subQuestion.setScore(score);
|
|
|
|
-
|
|
|
|
- String subBody = imgList(subQuesTmp.getBody());
|
|
|
|
- question.setQuesBody(replaceBlank(body));
|
|
|
|
- subQuestion.setQuesBody(subBody);
|
|
|
|
-
|
|
|
|
- subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuestion.getQuesBody())));
|
|
|
|
- subQuestion.setQuesAnswer(imgList(subQuesTmp.getAnswer()));
|
|
|
|
- subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuestion.getQuesAnswer())));
|
|
|
|
- // 存在选项
|
|
|
|
- if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
- || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
- List<QuesOption> subQuesOptions = new ArrayList<QuesOption>();
|
|
|
|
- Map<Object, Object> subOptionMap = subQuesTmp.getOptions();
|
|
|
|
- int subOptionCount = subOptionMap.size();
|
|
|
|
- for (int k = 0; k < subOptionCount; k++) {
|
|
|
|
- QuesOption subQuesOption = new QuesOption();
|
|
|
|
- subQuesOption.setNumber(String.valueOf(k));
|
|
|
|
-
|
|
|
|
- String optionBody = imgList((String) subOptionMap.get(String.valueOf(k + 1)));
|
|
|
|
- if (optionBody.startsWith("<p><p") || optionBody.startsWith("<P><P")) {
|
|
|
|
- subQuesOption.setOptionBody(replaceFirstP(optionBody));
|
|
|
|
- } else {
|
|
|
|
- subQuesOption.setOptionBody(optionBody);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- subQuesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuesOption.getOptionBody())));
|
|
|
|
- if (subQuestion.getQuesAnswer().contains(String.valueOf(k + 1))) {
|
|
|
|
- subQuesOption.setIsCorrect((short) 1);
|
|
|
|
- } else {
|
|
|
|
- subQuesOption.setIsCorrect((short) 0);
|
|
|
|
- }
|
|
|
|
- subQuesOptions.add(subQuesOption);
|
|
|
|
- }
|
|
|
|
- subQuestion.setQuesOptions(subQuesOptions);
|
|
|
|
- String[] answers = subQuestion.getQuesAnswer()
|
|
|
|
- .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
- .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
- .split(",");
|
|
|
|
- String answer = "";
|
|
|
|
- for (int a = 0; a < answers.length; a++) {
|
|
|
|
- char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
- if (a == 0) {
|
|
|
|
- answer = String.valueOf(c1);
|
|
|
|
- } else {
|
|
|
|
- answer = answer + "," + c1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- subQuestion.setQuesAnswer(answer);
|
|
|
|
- subQuestion.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>" + subQuestion.getQuesAnswer() + "</p>")));
|
|
|
|
- }
|
|
|
|
- subQuestions.add(subQuestion);
|
|
|
|
- }
|
|
|
|
- question.setSubQuestions(subQuestions);
|
|
|
|
- }
|
|
|
|
- byte[] pkgByte = DocxProcessUtil.getPkgByte(wordMLPackage);
|
|
|
|
- QuestionPkgPath quesPkgPath = new QuestionPkgPath(pkgByte);
|
|
|
|
- map.put(question, quesPkgPath);
|
|
|
|
- // 包装小题
|
|
|
|
- PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
|
|
- paperDetailUnit.setPaper(paper);
|
|
|
|
- paperDetailUnit.setNumber(nm + 1);
|
|
|
|
- paperDetailUnit.setScore(question.getScore());
|
|
|
|
- paperDetailUnit.setPaperDetail(detail);
|
|
|
|
- paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
|
|
- paperDetailUnit.setCreator("feng");
|
|
|
|
- paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- paperDetailUnit.setQuestion(question);
|
|
|
|
- paperDetailUnits.add(paperDetailUnit);
|
|
|
|
- nm++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return paperDetailUnits;
|
|
|
|
- }
|
|
|
|
|
|
+// private List<PaperDetailUnit> initpaperDetailUnits(Paper paper, List<PaperDetail> paperDetails, Map<Question, QuestionPkgPath> map,
|
|
|
|
+// Map<Object, Object> paperInfoMap, Course course) throws Exception {
|
|
|
|
+// List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
+// int detailCount = paperDetails.size();
|
|
|
|
+// int nm = 0;
|
|
|
|
+// for (int i = 0; i < detailCount; i++) {
|
|
|
|
+// PaperDetail detail = paperDetails.get(i);
|
|
|
|
+// QuestionsTemp detailTemp = (QuestionsTemp) paperInfoMap.get(String
|
|
|
|
+// .valueOf(i + 1));
|
|
|
|
+// Map<Object, Object> detailInfoMap = detailTemp.getQues();
|
|
|
|
+// int quesCount = detailInfoMap.size();
|
|
|
|
+// for (int j = 0; j < quesCount; j++) {
|
|
|
|
+// WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
|
|
|
|
+// .createPackage();
|
|
|
|
+// QuestionsTemp quesTemp = (QuestionsTemp) detailInfoMap
|
|
|
|
+// .get(String.valueOf(j + 1));
|
|
|
|
+// Question question = new Question();
|
|
|
|
+// question.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+// question.setScore(Double.valueOf(quesTemp.getScore()));
|
|
|
|
+// question.setCourse(course);
|
|
|
|
+// question.setOrgId(course.getOrgId());
|
|
|
|
+// question.setHasAudio(false);
|
|
|
|
+// question.setDifficulty("中");
|
|
|
|
+// question.setDifficultyDegree(0.5);
|
|
|
|
+// question.setPublicity(true);
|
|
|
|
+// question.setQuestionType(quesTemp.getType());
|
|
|
|
+//
|
|
|
|
+// String body = imgList(quesTemp.getBody());
|
|
|
|
+// question.setQuesBody(replaceBlank(body));
|
|
|
|
+// try {
|
|
|
|
+// question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.debug("错误题干信息:" + question.getQuesBody());
|
|
|
|
+// throw new IllegalArgumentException("题干信息错误!");
|
|
|
|
+// }
|
|
|
|
+// if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
|
|
|
|
+// question.setQuesAnswer(quesTemp.getAnswer());
|
|
|
|
+// question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>" + question.getQuesAnswer() + "</p>")));
|
|
|
|
+// } else {
|
|
|
|
+// question.setQuesAnswer(imgList(quesTemp.getAnswer()));
|
|
|
|
+// try {
|
|
|
|
+// question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.debug("错误答案信息:" + question.getQuesAnswer());
|
|
|
|
+// throw new IllegalArgumentException("答案信息错误!");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// // 存在选项
|
|
|
|
+// if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
+// || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
+// List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
|
+// Map<Object, Object> optionMap = quesTemp.getOptions();
|
|
|
|
+// int optionCount = optionMap.size();
|
|
|
|
+// for (int k = 0; k < optionCount; k++) {
|
|
|
|
+// QuesOption quesOption = new QuesOption();
|
|
|
|
+// quesOption.setNumber(String.valueOf(k + 1));
|
|
|
|
+//
|
|
|
|
+// String optionBody = imgList((String) optionMap.get(String.valueOf(k + 1)));
|
|
|
|
+// if (optionBody.startsWith("<p><p") || optionBody.startsWith("<P><P")) {
|
|
|
|
+// quesOption.setOptionBody(replaceFirstP(optionBody));
|
|
|
|
+// } else {
|
|
|
|
+// quesOption.setOptionBody(optionBody);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// try {
|
|
|
|
+// quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesOption.getOptionBody())));
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.debug("错误的选项:" + quesOption.getOptionBody());
|
|
|
|
+// throw new IllegalArgumentException("选项信息错误!");
|
|
|
|
+// }
|
|
|
|
+// if (question.getQuesAnswer().contains(String.valueOf(k + 1))) {
|
|
|
|
+// quesOption.setIsCorrect((short) 1);
|
|
|
|
+// } else {
|
|
|
|
+// quesOption.setIsCorrect((short) 0);
|
|
|
|
+// }
|
|
|
|
+// quesOptions.add(quesOption);
|
|
|
|
+// }
|
|
|
|
+// question.setQuesOptions(quesOptions);
|
|
|
|
+// String[] answers = question.getQuesAnswer()
|
|
|
|
+// .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
+// .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
+// .split(",");
|
|
|
|
+// String answer = "";
|
|
|
|
+// for (int a = 0; a < answers.length; a++) {
|
|
|
|
+// char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
+// if (a == 0) {
|
|
|
|
+// answer = String.valueOf(c1);
|
|
|
|
+// } else {
|
|
|
|
+// answer = answer + "," + c1;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// question.setQuesAnswer("<p>" + answer + "</p>");
|
|
|
|
+// question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
|
+// }
|
|
|
|
+// // 存在子题
|
|
|
|
+// if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
|
+// List<Question> subQuestions = new ArrayList<>();
|
|
|
|
+// int subQuesCount = quesTemp.getSubQues().size();
|
|
|
|
+// BigDecimal totalScore = BigDecimal.valueOf(question.getScore());
|
|
|
|
+// BigDecimal sum = BigDecimal.valueOf(subQuesCount);
|
|
|
|
+// double score = totalScore.divide(sum).doubleValue();
|
|
|
|
+// for (int s = 0; s < subQuesCount; s++) {
|
|
|
|
+// QuestionsTemp subQuesTmp = (QuestionsTemp) quesTemp.getSubQues().get(String.valueOf(s + 1));
|
|
|
|
+// Question subQuestion = new Question();
|
|
|
|
+// subQuestion.setId(IdUtils.uuid());
|
|
|
|
+// subQuestion.setQuestionType(subQuesTmp.getType());
|
|
|
|
+// subQuestion.setDifficulty("中");
|
|
|
|
+// subQuestion.setDifficultyDegree(0.5);
|
|
|
|
+// subQuestion.setPublicity(true);
|
|
|
|
+// subQuestion.setScore(score);
|
|
|
|
+//
|
|
|
|
+// String subBody = imgList(subQuesTmp.getBody());
|
|
|
|
+// question.setQuesBody(replaceBlank(body));
|
|
|
|
+// subQuestion.setQuesBody(subBody);
|
|
|
|
+//
|
|
|
|
+// subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuestion.getQuesBody())));
|
|
|
|
+// subQuestion.setQuesAnswer(imgList(subQuesTmp.getAnswer()));
|
|
|
|
+// subQuestion.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuestion.getQuesAnswer())));
|
|
|
|
+// // 存在选项
|
|
|
|
+// if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
+// || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
+// List<QuesOption> subQuesOptions = new ArrayList<QuesOption>();
|
|
|
|
+// Map<Object, Object> subOptionMap = subQuesTmp.getOptions();
|
|
|
|
+// int subOptionCount = subOptionMap.size();
|
|
|
|
+// for (int k = 0; k < subOptionCount; k++) {
|
|
|
|
+// QuesOption subQuesOption = new QuesOption();
|
|
|
|
+// subQuesOption.setNumber(String.valueOf(k));
|
|
|
|
+//
|
|
|
|
+// String optionBody = imgList((String) subOptionMap.get(String.valueOf(k + 1)));
|
|
|
|
+// if (optionBody.startsWith("<p><p") || optionBody.startsWith("<P><P")) {
|
|
|
|
+// subQuesOption.setOptionBody(replaceFirstP(optionBody));
|
|
|
|
+// } else {
|
|
|
|
+// subQuesOption.setOptionBody(optionBody);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// subQuesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(subQuesOption.getOptionBody())));
|
|
|
|
+// if (subQuestion.getQuesAnswer().contains(String.valueOf(k + 1))) {
|
|
|
|
+// subQuesOption.setIsCorrect((short) 1);
|
|
|
|
+// } else {
|
|
|
|
+// subQuesOption.setIsCorrect((short) 0);
|
|
|
|
+// }
|
|
|
|
+// subQuesOptions.add(subQuesOption);
|
|
|
|
+// }
|
|
|
|
+// subQuestion.setQuesOptions(subQuesOptions);
|
|
|
|
+// String[] answers = subQuestion.getQuesAnswer()
|
|
|
|
+// .replaceAll("<p>", "").replaceAll("</p>", "")
|
|
|
|
+// .replaceAll("<P>", "").replaceAll("</P>", "")
|
|
|
|
+// .split(",");
|
|
|
|
+// String answer = "";
|
|
|
|
+// for (int a = 0; a < answers.length; a++) {
|
|
|
|
+// char c1 = (char) (Integer.valueOf(answers[a]) + 64);
|
|
|
|
+// if (a == 0) {
|
|
|
|
+// answer = String.valueOf(c1);
|
|
|
|
+// } else {
|
|
|
|
+// answer = answer + "," + c1;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// subQuestion.setQuesAnswer(answer);
|
|
|
|
+// subQuestion.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml("<p>" + subQuestion.getQuesAnswer() + "</p>")));
|
|
|
|
+// }
|
|
|
|
+// subQuestions.add(subQuestion);
|
|
|
|
+// }
|
|
|
|
+// question.setSubQuestions(subQuestions);
|
|
|
|
+// }
|
|
|
|
+// byte[] pkgByte = DocxProcessUtil.getPkgByte(wordMLPackage);
|
|
|
|
+// QuestionPkgPath quesPkgPath = new QuestionPkgPath(pkgByte);
|
|
|
|
+// map.put(question, quesPkgPath);
|
|
|
|
+// // 包装小题
|
|
|
|
+// PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
|
|
+// paperDetailUnit.setPaper(paper);
|
|
|
|
+// paperDetailUnit.setNumber(nm + 1);
|
|
|
|
+// paperDetailUnit.setScore(question.getScore());
|
|
|
|
+// paperDetailUnit.setPaperDetail(detail);
|
|
|
|
+// paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
|
|
+// paperDetailUnit.setCreator("feng");
|
|
|
|
+// paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+// paperDetailUnit.setQuestion(question);
|
|
|
|
+// paperDetailUnits.add(paperDetailUnit);
|
|
|
|
+// nm++;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// return paperDetailUnits;
|
|
|
|
+// }
|
|
|
|
|
|
public String imgList(String str) throws Exception {
|
|
public String imgList(String str) throws Exception {
|
|
if (StringUtils.isBlank(str)) {
|
|
if (StringUtils.isBlank(str)) {
|