|
@@ -1,291 +1,293 @@
|
|
|
-package com.qmth.cqb.question.service;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
-import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Example;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
-import com.qmth.cqb.question.model.QuesOption;
|
|
|
-import com.qmth.cqb.question.model.Question;
|
|
|
-import com.qmth.cqb.question.model.QuestionSearchCondition;
|
|
|
-import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
-import com.qmth.cqb.utils.CommonUtils;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by songyue on 16/12/28.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class QuesService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- QuesRepo quesRepo;
|
|
|
-
|
|
|
- /**
|
|
|
- * 套题子题按序号自动生成ID
|
|
|
- *
|
|
|
- * @param question
|
|
|
- */
|
|
|
- private void updateSubId(Question question) {
|
|
|
- if (question.getSubQuestions() != null) {
|
|
|
- int index = 0;
|
|
|
- for (Question sub : question.getSubQuestions()) {
|
|
|
- index++;
|
|
|
- sub.setId(String.valueOf(index));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新已存在的试题信息
|
|
|
- *
|
|
|
- * @param previous
|
|
|
- * @param update
|
|
|
- */
|
|
|
- private void updateMainInfo(Question previous, Question update) {
|
|
|
- String now = CommonUtils.getCurDateTime();
|
|
|
- if (update.getScore() != null) {
|
|
|
- previous.setScore(update.getScore());
|
|
|
- }
|
|
|
- previous.setQuesAnswer(update.getQuesAnswer());
|
|
|
- previous.setQuesAnswerAnalysis(update.getQuesAnswerAnalysis());
|
|
|
- previous.setQuesBody(update.getQuesBody());
|
|
|
- if (update.getQuesOptions() != null && update.getQuesOptions().size() > 0) {
|
|
|
- List<QuesOption> quesOptions = update.getQuesOptions();
|
|
|
- List<QuesOption> saveQuesOptions = previous.getQuesOptions();
|
|
|
- if (saveQuesOptions.size() != quesOptions.size()) {
|
|
|
- previous.setQuesOptions(quesOptions);
|
|
|
- } else {
|
|
|
- for (int i = 0; i < quesOptions.size(); i++) {
|
|
|
- saveQuesOptions.get(i).setOptionBody(quesOptions.get(i).getOptionBody());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (update.getQuesParams() != null) {
|
|
|
- if (previous.getQuesParams() == null) {
|
|
|
- previous.setQuesParams(new HashMap<>());
|
|
|
- }
|
|
|
- for (String key : update.getQuesParams().keySet()) {
|
|
|
- previous.getQuesParams().put(key, update.getQuesParams().get(key));
|
|
|
- }
|
|
|
- }
|
|
|
- if (previous.getCreateTime() == null) {
|
|
|
- previous.setCreateTime(now);
|
|
|
- }
|
|
|
- if (update.getSubQuestions() != null) {
|
|
|
- if (previous.getSubQuestions() == null) {
|
|
|
- previous.setSubQuestions(new ArrayList<>());
|
|
|
- }
|
|
|
- int previousSize = previous.getSubQuestions().size();
|
|
|
- int updateSize = update.getSubQuestions().size();
|
|
|
- for (int i = 0; i < updateSize; i++) {
|
|
|
- if (previousSize <= i) {
|
|
|
- previous.getSubQuestions().add(update.getSubQuestions().get(i));
|
|
|
- } else {
|
|
|
- updateMainInfo(previous.getSubQuestions().get(i), update.getSubQuestions().get(i));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- previous.setUpdateTime(now);
|
|
|
- updateSubId(previous);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存试题
|
|
|
- *
|
|
|
- * @param question
|
|
|
- */
|
|
|
- public Question saveQues(Question question) {
|
|
|
- String now = CommonUtils.getCurDateTime();
|
|
|
- Question saveQues = null;
|
|
|
- if (StringUtils.isNotEmpty(question.getId())) {
|
|
|
- saveQues = quesRepo.findOne(question.getId());
|
|
|
- }
|
|
|
- if (saveQues == null) {
|
|
|
- question.setCreateTime(now);
|
|
|
- question.setUpdateTime(now);
|
|
|
- updateSubId(question);
|
|
|
- updateQuesWord(question);
|
|
|
- return quesRepo.save(question);
|
|
|
- } else {
|
|
|
- updateMainInfo(saveQues, question);
|
|
|
- updateQuesWord(saveQues);
|
|
|
- return quesRepo.save(saveQues);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存导入试题
|
|
|
- * @param question
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Question saveImportQues(Question question){
|
|
|
- String now = CommonUtils.getCurDateTime();
|
|
|
- Question saveQues = null;
|
|
|
- if (StringUtils.isNotEmpty(question.getId())) {
|
|
|
- saveQues = quesRepo.findOne(question.getId());
|
|
|
- }
|
|
|
- if (saveQues == null) {
|
|
|
- question.setCreateTime(now);
|
|
|
- question.setUpdateTime(now);
|
|
|
- updateSubId(question);
|
|
|
- return quesRepo.save(question);
|
|
|
- } else {
|
|
|
- updateMainInfo(saveQues, question);
|
|
|
- return quesRepo.save(saveQues);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量保存导入试题
|
|
|
- * @param list
|
|
|
- */
|
|
|
- public void saveImportQuesList(List<Question> list) {
|
|
|
- if (list != null) {
|
|
|
- for (Question question : list) {
|
|
|
- saveImportQues(question);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量保存试题
|
|
|
- *
|
|
|
- * @param list
|
|
|
- */
|
|
|
- public void saveQuesList(List<Question> list) {
|
|
|
- if (list != null) {
|
|
|
- for (Question question : list) {
|
|
|
- saveQues(question);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询所有试题
|
|
|
- *
|
|
|
- * @param searchCondition
|
|
|
- * @param curPage
|
|
|
- * @param pageSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<Question> findAll(QuestionSearchCondition searchCondition, int curPage, int pageSize) {
|
|
|
- Question ques = BeanCopierUtil.copyProperties(searchCondition, Question.class);
|
|
|
- Page<Question> list = quesRepo.findAll(Example.of(ques), new PageRequest(curPage - 1, pageSize));
|
|
|
- for (Question question : list) {
|
|
|
- formatQues(question);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询按ID过滤的试题
|
|
|
- *
|
|
|
- * @param idSet
|
|
|
- * @param curPage
|
|
|
- * @param pageSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<Question> findByIdExclude(Set<String> idSet, String courseNo, QuesStructType quesType, int curPage,
|
|
|
- int pageSize) {
|
|
|
- Pageable page = new PageRequest(curPage - 1, pageSize);
|
|
|
- Page<Question> list = quesType != null
|
|
|
- ? quesRepo.findByIdNotInAndCourseNoAndQuestionType(idSet, courseNo, quesType, page)
|
|
|
- : quesRepo.findByIdNotInAndCourseNo(idSet, courseNo, page);
|
|
|
- for (Question question : list) {
|
|
|
- formatQues(question);
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 按ID获取试题
|
|
|
- *
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Question findById(String id) {
|
|
|
- Question question = quesRepo.findOne(id);
|
|
|
- formatQues(question);
|
|
|
- return question;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 去除试题中的word
|
|
|
- *
|
|
|
- * @param question
|
|
|
- */
|
|
|
- public void formatQues(Question question) {
|
|
|
- formatQuesUnit(question);
|
|
|
- if (question.getSubQuestions() != null && question.getSubQuestions().size() > 0) {
|
|
|
- question.getSubQuestions().stream().forEach(subQues -> {
|
|
|
- formatQuesUnit(subQues);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void formatQuesUnit(Question question) {
|
|
|
- question.setQuesBodyWord(null);
|
|
|
- question.setQuesAnswerWord(null);
|
|
|
- question.setQuesAnswerAnalysisWord(null);
|
|
|
- question.setQuesPkg(new byte[0]);
|
|
|
- if (question.getQuesOptions() != null && question.getQuesOptions().size() > 0) {
|
|
|
- question.getQuesOptions().stream().forEach(quesOption -> {
|
|
|
- quesOption.setOptionBodyWord(null);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存后更新word
|
|
|
- * @param question
|
|
|
- */
|
|
|
- public void updateQuesWord(Question question){
|
|
|
- WordprocessingMLPackage wordMLPackage = null;
|
|
|
- try {
|
|
|
- wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
- updateQuesWordUnit(wordMLPackage,question);
|
|
|
- List<Question> subQuesList = question.getSubQuestions();
|
|
|
- if (subQuesList != null && subQuesList.size() > 0) {
|
|
|
- for(Question subQues:subQuesList){
|
|
|
- updateQuesWordUnit(wordMLPackage,subQues);
|
|
|
- }
|
|
|
- }
|
|
|
- question.setQuesPkg(DocxProcessUtil.getPkgByte(wordMLPackage));
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void updateQuesWordUnit(WordprocessingMLPackage wordMLPackage,
|
|
|
- Question question)throws Exception{
|
|
|
- String quesBody = StringEscapeUtils.unescapeHtml4(question.getQuesBody());
|
|
|
- String quesAnswer = StringEscapeUtils.unescapeHtml4(question.getQuesAnswer());
|
|
|
- question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,quesBody));
|
|
|
- DocxProcessUtil.initTmpPackage(wordMLPackage);
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,quesAnswer));
|
|
|
- DocxProcessUtil.initTmpPackage(wordMLPackage);
|
|
|
- List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
- if(quesOptions != null && quesOptions.size() > 0){
|
|
|
- for(QuesOption quesOption:quesOptions){
|
|
|
- quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,
|
|
|
- StringEscapeUtils.unescapeHtml4(quesOption.getOptionBody())));
|
|
|
- DocxProcessUtil.initTmpPackage(wordMLPackage);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+package com.qmth.cqb.question.service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
+import com.qmth.cqb.question.model.QuesOption;
|
|
|
+import com.qmth.cqb.question.model.Question;
|
|
|
+import com.qmth.cqb.question.model.QuestionSearchCondition;
|
|
|
+import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
+import com.qmth.cqb.utils.CommonUtils;
|
|
|
+import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by songyue on 16/12/28.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class QuesService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ QuesRepo quesRepo;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 套题子题按序号自动生成ID
|
|
|
+ *
|
|
|
+ * @param question
|
|
|
+ */
|
|
|
+ private void updateSubId(Question question) {
|
|
|
+ if (question.getSubQuestions() != null) {
|
|
|
+ int index = 0;
|
|
|
+ for (Question sub : question.getSubQuestions()) {
|
|
|
+ index++;
|
|
|
+ sub.setId(String.valueOf(index));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新已存在的试题信息
|
|
|
+ *
|
|
|
+ * @param previous
|
|
|
+ * @param update
|
|
|
+ */
|
|
|
+ private void updateMainInfo(Question previous, Question update) {
|
|
|
+ String now = CommonUtils.getCurDateTime();
|
|
|
+ if (update.getScore() != null) {
|
|
|
+ previous.setScore(update.getScore());
|
|
|
+ }
|
|
|
+ previous.setQuesAnswer(update.getQuesAnswer());
|
|
|
+ previous.setQuesAnswerAnalysis(update.getQuesAnswerAnalysis());
|
|
|
+ previous.setQuesBody(update.getQuesBody());
|
|
|
+ if (update.getQuesOptions() != null && update.getQuesOptions().size() > 0) {
|
|
|
+ List<QuesOption> quesOptions = update.getQuesOptions();
|
|
|
+ List<QuesOption> saveQuesOptions = previous.getQuesOptions();
|
|
|
+ if (saveQuesOptions.size() != quesOptions.size()) {
|
|
|
+ previous.setQuesOptions(quesOptions);
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < quesOptions.size(); i++) {
|
|
|
+ saveQuesOptions.get(i).setOptionBody(quesOptions.get(i).getOptionBody());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (update.getQuesParams() != null) {
|
|
|
+ if (previous.getQuesParams() == null) {
|
|
|
+ previous.setQuesParams(new HashMap<>());
|
|
|
+ }
|
|
|
+ for (String key : update.getQuesParams().keySet()) {
|
|
|
+ previous.getQuesParams().put(key, update.getQuesParams().get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (previous.getCreateTime() == null) {
|
|
|
+ previous.setCreateTime(now);
|
|
|
+ }
|
|
|
+ if (update.getSubQuestions() != null) {
|
|
|
+ if (previous.getSubQuestions() == null) {
|
|
|
+ previous.setSubQuestions(new ArrayList<>());
|
|
|
+ }
|
|
|
+ int previousSize = previous.getSubQuestions().size();
|
|
|
+ int updateSize = update.getSubQuestions().size();
|
|
|
+ for (int i = 0; i < updateSize; i++) {
|
|
|
+ if (previousSize <= i) {
|
|
|
+ previous.getSubQuestions().add(update.getSubQuestions().get(i));
|
|
|
+ } else {
|
|
|
+ updateMainInfo(previous.getSubQuestions().get(i), update.getSubQuestions().get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ previous.setUpdateTime(now);
|
|
|
+ updateSubId(previous);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存试题
|
|
|
+ *
|
|
|
+ * @param question
|
|
|
+ */
|
|
|
+ public Question saveQues(Question question) {
|
|
|
+ String now = CommonUtils.getCurDateTime();
|
|
|
+ Question saveQues = null;
|
|
|
+ if (StringUtils.isNotEmpty(question.getId())) {
|
|
|
+ saveQues = quesRepo.findOne(question.getId());
|
|
|
+ }
|
|
|
+ if (saveQues == null) {
|
|
|
+ question.setCreateTime(now);
|
|
|
+ question.setUpdateTime(now);
|
|
|
+ updateSubId(question);
|
|
|
+ updateQuesWord(question);
|
|
|
+ return quesRepo.save(question);
|
|
|
+ } else {
|
|
|
+ updateMainInfo(saveQues, question);
|
|
|
+ updateQuesWord(saveQues);
|
|
|
+ return quesRepo.save(saveQues);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存导入试题
|
|
|
+ *
|
|
|
+ * @param question
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Question saveImportQues(Question question) {
|
|
|
+ String now = CommonUtils.getCurDateTime();
|
|
|
+ Question saveQues = null;
|
|
|
+ if (StringUtils.isNotEmpty(question.getId())) {
|
|
|
+ saveQues = quesRepo.findOne(question.getId());
|
|
|
+ }
|
|
|
+ if (saveQues == null) {
|
|
|
+ question.setCreateTime(now);
|
|
|
+ question.setUpdateTime(now);
|
|
|
+ updateSubId(question);
|
|
|
+ return quesRepo.save(question);
|
|
|
+ } else {
|
|
|
+ updateMainInfo(saveQues, question);
|
|
|
+ return quesRepo.save(saveQues);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量保存导入试题
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ */
|
|
|
+ public void saveImportQuesList(List<Question> list) {
|
|
|
+ if (list != null) {
|
|
|
+ for (Question question : list) {
|
|
|
+ saveImportQues(question);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量保存试题
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ */
|
|
|
+ public void saveQuesList(List<Question> list) {
|
|
|
+ if (list != null) {
|
|
|
+ for (Question question : list) {
|
|
|
+ saveQues(question);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有试题
|
|
|
+ *
|
|
|
+ * @param searchCondition
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<Question> findAll(QuestionSearchCondition searchCondition, int curPage, int pageSize) {
|
|
|
+ Question ques = BeanCopierUtil.copyProperties(searchCondition, Question.class);
|
|
|
+ Page<Question> list = quesRepo.findAll(Example.of(ques), new PageRequest(curPage - 1, pageSize));
|
|
|
+ for (Question question : list) {
|
|
|
+ formatQues(question);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询按ID过滤的试题
|
|
|
+ *
|
|
|
+ * @param idSet
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<Question> findByIdExclude(Set<String> idSet, String courseNo, QuesStructType quesType, int curPage,
|
|
|
+ int pageSize) {
|
|
|
+ Pageable page = new PageRequest(curPage - 1, pageSize);
|
|
|
+ Page<Question> list = quesType != null
|
|
|
+ ? quesRepo.findByIdNotInAndCourseNoAndQuestionType(idSet, courseNo, quesType, page)
|
|
|
+ : quesRepo.findByIdNotInAndCourseNo(idSet, courseNo, page);
|
|
|
+ for (Question question : list) {
|
|
|
+ formatQues(question);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按ID获取试题
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Question findById(String id) {
|
|
|
+ Question question = quesRepo.findOne(id);
|
|
|
+ formatQues(question);
|
|
|
+ return question;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 去除试题中的word
|
|
|
+ *
|
|
|
+ * @param question
|
|
|
+ */
|
|
|
+ public void formatQues(Question question) {
|
|
|
+ formatQuesUnit(question);
|
|
|
+ if (question.getSubQuestions() != null && question.getSubQuestions().size() > 0) {
|
|
|
+ question.getSubQuestions().stream().forEach(subQues -> {
|
|
|
+ formatQuesUnit(subQues);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void formatQuesUnit(Question question) {
|
|
|
+ question.setQuesBodyWord(null);
|
|
|
+ question.setQuesAnswerWord(null);
|
|
|
+ question.setQuesAnswerAnalysisWord(null);
|
|
|
+ question.setQuesPkg(new byte[0]);
|
|
|
+ if (question.getQuesOptions() != null && question.getQuesOptions().size() > 0) {
|
|
|
+ question.getQuesOptions().stream().forEach(quesOption -> {
|
|
|
+ quesOption.setOptionBodyWord(null);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存后更新word
|
|
|
+ *
|
|
|
+ * @param question
|
|
|
+ */
|
|
|
+ public void updateQuesWord(Question question) {
|
|
|
+ WordprocessingMLPackage wordMLPackage = null;
|
|
|
+ try {
|
|
|
+ wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ updateQuesWordUnit(wordMLPackage, question);
|
|
|
+ List<Question> subQuesList = question.getSubQuestions();
|
|
|
+ if (subQuesList != null && subQuesList.size() > 0) {
|
|
|
+ for (Question subQues : subQuesList) {
|
|
|
+ updateQuesWordUnit(wordMLPackage, subQues);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ question.setQuesPkg(DocxProcessUtil.getPkgByte(wordMLPackage));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateQuesWordUnit(WordprocessingMLPackage wordMLPackage, Question question) throws Exception {
|
|
|
+ String quesBody = StringEscapeUtils.unescapeHtml4(question.getQuesBody());
|
|
|
+ String quesAnswer = StringEscapeUtils.unescapeHtml4(question.getQuesAnswer());
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, quesBody));
|
|
|
+ DocxProcessUtil.initTmpPackage(wordMLPackage);
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, quesAnswer));
|
|
|
+ DocxProcessUtil.initTmpPackage(wordMLPackage);
|
|
|
+ List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
+ if (quesOptions != null && quesOptions.size() > 0) {
|
|
|
+ for (QuesOption quesOption : quesOptions) {
|
|
|
+ quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,
|
|
|
+ StringEscapeUtils.unescapeHtml4(quesOption.getOptionBody())));
|
|
|
+ DocxProcessUtil.initTmpPackage(wordMLPackage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|