|
@@ -2,16 +2,19 @@ package com.qmth.cqb.question.service.impl;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.docx4j.openpackaging.exceptions.InvalidFormatException;
|
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.domain.Sort.Order;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
@@ -19,6 +22,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
|
|
+import com.qmth.cqb.base.dao.CourseRepo;
|
|
|
import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
import com.qmth.cqb.question.dao.QuestionAudioRepo;
|
|
|
import com.qmth.cqb.question.model.QuesOption;
|
|
@@ -39,16 +43,30 @@ import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
@Service("quesService")
|
|
|
public class QuesServiceImpl implements QuesService{
|
|
|
@Autowired
|
|
|
- QuesRepo quesRepo;
|
|
|
+ private QuesRepo quesRepo;
|
|
|
|
|
|
@Autowired
|
|
|
- QuestionAudioService questionAudioService;
|
|
|
+ private QuestionAudioService questionAudioService;
|
|
|
|
|
|
@Autowired
|
|
|
- MongoTemplate mongoTemplate;
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
- QuestionAudioRepo questionAudioRepo;
|
|
|
+ private QuestionAudioRepo questionAudioRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CourseRepo courseRepo;
|
|
|
+
|
|
|
+ private static WordprocessingMLPackage wordMLPackage = null;
|
|
|
+
|
|
|
+ static{
|
|
|
+ try {
|
|
|
+ wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 套题子题按序号自动生成ID
|
|
|
*
|
|
@@ -133,6 +151,7 @@ public class QuesServiceImpl implements QuesService{
|
|
|
} else {
|
|
|
question.setUpdateTime(now);
|
|
|
}
|
|
|
+ setSelectQuestionAnswer(question,"");
|
|
|
updateSubId(question);
|
|
|
updateQuesWord(question);
|
|
|
if(question.getHasAudio()!=null&&question.getHasAudio()){
|
|
@@ -226,20 +245,29 @@ public class QuesServiceImpl implements QuesService{
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
- public Page<Question> findByIdExclude(Set<String> idSet,
|
|
|
- String courseNo,
|
|
|
- QuesStructType quesType,
|
|
|
- int curPage,
|
|
|
- int pageSize,
|
|
|
- Long orgId) {
|
|
|
- Pageable page = new PageRequest(curPage - 1, pageSize);
|
|
|
- Page<Question> list = quesType != null
|
|
|
- ? quesRepo.findByIdNotInAndCourseNoAndQuestionTypeAndOrgId(idSet, courseNo, quesType, orgId.toString(),page)
|
|
|
- : quesRepo.findByIdNotInAndCourseNoAndOrgId(idSet, courseNo,orgId.toString(),page);
|
|
|
- for (Question question : list) {
|
|
|
+ public Page<Question> findByIdExclude(Set<String> idSet,String courseNo,QuesStructType quesType,int curPage,int pageSize,Long orgId,String quesBody) {
|
|
|
+ Query query = new Query();
|
|
|
+ if(quesType!=null){
|
|
|
+ query.addCriteria(Criteria.where("questionType").is(quesType));
|
|
|
+ }
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(orgId+""));
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(courseNo));
|
|
|
+ query.addCriteria(Criteria.where("id").nin(idSet));
|
|
|
+ //模糊匹配
|
|
|
+ if(StringUtils.isNotBlank(quesBody)){
|
|
|
+ Pattern pattern = Pattern.compile("^.*"+quesBody+".*$", Pattern.CASE_INSENSITIVE);
|
|
|
+ query.addCriteria(Criteria.where("quesBody").regex(pattern));
|
|
|
+ }
|
|
|
+ long total = this.mongoTemplate.count(query, Question.class);
|
|
|
+ query.with(new Sort(new Order(Direction.DESC,"id")));
|
|
|
+ query.limit(pageSize);
|
|
|
+ query.skip((curPage - 1) * pageSize);
|
|
|
+ List<Question> questionList = this.mongoTemplate.find(query,Question.class);
|
|
|
+ Page<Question> questionPageList = new PageImpl<Question>(questionList,new PageRequest(curPage - 1, pageSize), total);
|
|
|
+ for (Question question : questionPageList) {
|
|
|
formatQues(question);
|
|
|
}
|
|
|
- return list;
|
|
|
+ return questionPageList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -291,9 +319,10 @@ public class QuesServiceImpl implements QuesService{
|
|
|
* @param question
|
|
|
*/
|
|
|
public void updateQuesWord(Question question) {
|
|
|
- WordprocessingMLPackage wordMLPackage = null;
|
|
|
try {
|
|
|
- wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ if(wordMLPackage==null){
|
|
|
+ wordMLPackage = WordprocessingMLPackage.createPackage();
|
|
|
+ }
|
|
|
updateQuesWordUnit(wordMLPackage, question);
|
|
|
List<Question> subQuesList = question.getSubQuestions();
|
|
|
if (subQuesList != null && subQuesList.size() > 0) {
|
|
@@ -314,10 +343,15 @@ public class QuesServiceImpl implements QuesService{
|
|
|
question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, quesBody));
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(quesAnswer)
|
|
|
- && question.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
|
|
|
- && question.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
+ && (question.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
|
|
|
+ || question.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION)){
|
|
|
question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, quesAnswer));
|
|
|
}
|
|
|
+ if(!StringUtils.isEmpty(quesAnswer)&&
|
|
|
+ (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ ||question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION)){
|
|
|
+ question.setQuesAnswerWord(makeQuesAnswerWord(quesAnswer));
|
|
|
+ }
|
|
|
List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
if (quesOptions != null && quesOptions.size() > 0) {
|
|
|
for (QuesOption quesOption : quesOptions) {
|
|
@@ -328,6 +362,19 @@ public class QuesServiceImpl implements QuesService{
|
|
|
}
|
|
|
question.setQuesPkg(DocxProcessUtil.getPkgByte(wordMLPackage));
|
|
|
}
|
|
|
+
|
|
|
+ private String makeQuesAnswerWord(String quesAnswer){
|
|
|
+ String template = "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:rsidR=\"00F65544\" w:rsidP=\"00F65544\" w:rsidRDefault=\"001738E2\">"+
|
|
|
+ "<w:r w:rsidR=\"00F65544\">"+
|
|
|
+ "<w:rPr>"+
|
|
|
+ "<w:rFonts w:hint=\"eastAsia\"/>"+
|
|
|
+ "<w:szCs w:val=\"21\"/>"+
|
|
|
+ "</w:rPr>"+
|
|
|
+ "<w:t>quesAnswer</w:t>"+
|
|
|
+ "</w:r>"+
|
|
|
+ "</w:p>";
|
|
|
+ return template.replace("quesAnswer", quesAnswer);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取试题有效文本
|
|
@@ -350,5 +397,56 @@ public class QuesServiceImpl implements QuesService{
|
|
|
}
|
|
|
return quesText.toString();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setSelectQuestionAnswer(Question question, String optionOrder) {
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ question.setQuesAnswer(getSelectQuestionAnswer(question, optionOrder));
|
|
|
+ } else if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
+ List<Question> subQuestions = question.getSubQuestions();
|
|
|
+ int index = 0;
|
|
|
+ for (int k = 0; k < subQuestions.size(); k++) {
|
|
|
+ Question subQuestion = subQuestions.get(k);
|
|
|
+ if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ if(StringUtils.isNotEmpty(optionOrder) && optionOrder.contains(";")){
|
|
|
+ subQuestion.setQuesAnswer(getSelectQuestionAnswer(subQuestion, optionOrder.split(";")[index]));
|
|
|
+ }else{
|
|
|
+ subQuestion.setQuesAnswer(getSelectQuestionAnswer(subQuestion, ""));
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getSelectQuestionAnswer(Question question,String optionOrder){
|
|
|
+ String answer = "";
|
|
|
+ List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
+ if(quesOptions == null || quesOptions.size() == 0){
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(optionOrder)){
|
|
|
+ int j = 0;
|
|
|
+ for(QuesOption quesOption : quesOptions){
|
|
|
+ if(quesOption.getIsCorrect() == 1){
|
|
|
+ answer += CommonUtils.getOptionNum(j);
|
|
|
+ }
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ String [] order = optionOrder.split(",");
|
|
|
+ for(int i = 0;i < order.length;i++){
|
|
|
+ for(QuesOption quesOption : quesOptions){
|
|
|
+ if(order[i].equals(quesOption.getNumber()) && quesOption.getIsCorrect() == 1){
|
|
|
+ answer += CommonUtils.getOptionNum(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return answer;
|
|
|
+ }
|
|
|
}
|
|
|
|