|
@@ -1,9 +1,9 @@
|
|
package com.qmth.cqb.paper.service;
|
|
package com.qmth.cqb.paper.service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -30,6 +30,7 @@ import cn.com.qmth.examcloud.common.dto.question.PaperDetailUnitDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.PaperDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.PaperDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.QuesOptionDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.QuesOptionDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.QuestionDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.QuestionDto;
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.SubQuestionDto;
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -50,20 +51,49 @@ public class ExtractService {
|
|
@Autowired
|
|
@Autowired
|
|
PaperDetailUnitRepo paperDetailUnitRepo;
|
|
PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperService paperService;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
QuesRepo questionRepo;
|
|
QuesRepo questionRepo;
|
|
|
|
|
|
|
|
+ private Map<String, AtomicInteger> randomMap = new HashMap<String, AtomicInteger>();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 注意:单机版计数器,重启后重新归零;用于随机抽取试卷的规则
|
|
|
|
+ *
|
|
|
|
+ * @param key
|
|
|
|
+ * @param totalCount
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private int randomNumber(String key, int totalCount) {
|
|
|
|
+ AtomicInteger counter = randomMap.get(key);
|
|
|
|
+ if (counter == null) {
|
|
|
|
+ synchronized (ExtractService.class) {
|
|
|
|
+ counter = randomMap.get(key);
|
|
|
|
+ if (counter == null) {
|
|
|
|
+ counter = new AtomicInteger();
|
|
|
|
+ randomMap.put(key, counter);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return counter.incrementAndGet() % totalCount;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 随机抽一张试卷
|
|
* 随机抽一张试卷
|
|
*
|
|
*
|
|
* @param papers
|
|
* @param papers
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public Map<String, Object> randomPaper(List<Paper> papers) {
|
|
|
|
|
|
+ public Map<String, Object> randomPaper(Long examId, String courseCode, String groupCode) {
|
|
String msg = "";
|
|
String msg = "";
|
|
|
|
+ List<Paper> papers = paperService.listExamPapers(examId, courseCode, groupCode);
|
|
Map<String, Object> paperMap = new HashMap<String, Object>();
|
|
Map<String, Object> paperMap = new HashMap<String, Object>();
|
|
if (papers.size() > 0) {
|
|
if (papers.size() > 0) {
|
|
- Collections.shuffle(papers);
|
|
|
|
|
|
+ papers.get(this.randomNumber(examId + courseCode + groupCode, papers.size()));
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
msg = "没有可用的抽取试卷,请检查";
|
|
msg = "没有可用的抽取试卷,请检查";
|
|
paperMap.put("msg", msg);
|
|
paperMap.put("msg", msg);
|
|
@@ -86,20 +116,21 @@ public class ExtractService {
|
|
if (StringUtils.isNotEmpty(paperDetailUnits.get(j).getQuestion().getQuesAnswer())) {
|
|
if (StringUtils.isNotEmpty(paperDetailUnits.get(j).getQuestion().getQuesAnswer())) {
|
|
String answer = DocxProcessUtil
|
|
String answer = DocxProcessUtil
|
|
.getTextInHtml(paperDetailUnits.get(j).getQuestion().getQuesAnswer());
|
|
.getTextInHtml(paperDetailUnits.get(j).getQuestion().getQuesAnswer());
|
|
-
|
|
|
|
unitDto.setAnswer(answer);
|
|
unitDto.setAnswer(answer);
|
|
}
|
|
}
|
|
if (unitDto.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {// 假如是套题
|
|
if (unitDto.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {// 假如是套题
|
|
List<Question> subQuesList = paperDetailUnits.get(j).getQuestion().getSubQuestions();
|
|
List<Question> subQuesList = paperDetailUnits.get(j).getQuestion().getSubQuestions();
|
|
- List<QuestionDto> quesDtos = BeanCopierUtil.copyPropertiesOfList(subQuesList, QuestionDto.class);
|
|
|
|
|
|
+ List<SubQuestionDto> subQuesDtos = BeanCopierUtil.copyPropertiesOfList(subQuesList,
|
|
|
|
+ SubQuestionDto.class);
|
|
for (int m = 0; m < subQuesList.size(); m++) {
|
|
for (int m = 0; m < subQuesList.size(); m++) {
|
|
List<QuesOptionDto> quesOptionDtos = BeanCopierUtil
|
|
List<QuesOptionDto> quesOptionDtos = BeanCopierUtil
|
|
.copyPropertiesOfList(subQuesList.get(m).getQuesOptions(), QuesOptionDto.class);
|
|
.copyPropertiesOfList(subQuesList.get(m).getQuesOptions(), QuesOptionDto.class);
|
|
- quesDtos.get(m).setQuesOptions(quesOptionDtos);
|
|
|
|
- quesDtos.get(m)
|
|
|
|
|
|
+ subQuesDtos.get(m).setQuesOptions(quesOptionDtos);
|
|
|
|
+ subQuesDtos.get(m)
|
|
.setQuesAnswer(DocxProcessUtil.getTextInHtml(subQuesList.get(m).getQuesAnswer()));
|
|
.setQuesAnswer(DocxProcessUtil.getTextInHtml(subQuesList.get(m).getQuesAnswer()));
|
|
|
|
+ subQuesDtos.get(m).setNumber(m + 1);
|
|
}
|
|
}
|
|
- unitDto.setSubQuestions(quesDtos);
|
|
|
|
|
|
+ unitDto.setSubQuestions(subQuesDtos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
paperDetailDtos.get(i).setPaperDetailUnits(paperDetailUnitDtos);
|
|
paperDetailDtos.get(i).setPaperDetailUnits(paperDetailUnitDtos);
|
|
@@ -123,14 +154,16 @@ public class ExtractService {
|
|
Map<String, Object> quesMap = new HashMap<String, Object>();
|
|
Map<String, Object> quesMap = new HashMap<String, Object>();
|
|
Question ques = questionRepo.findOne(id);
|
|
Question ques = questionRepo.findOne(id);
|
|
QuestionDto dto = BeanCopierUtil.copyProperties(ques, QuestionDto.class);
|
|
QuestionDto dto = BeanCopierUtil.copyProperties(ques, QuestionDto.class);
|
|
- if (ques.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {// 假如是套题
|
|
|
|
|
|
+ if (ques.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
List<Question> subQuesList = ques.getSubQuestions();
|
|
List<Question> subQuesList = ques.getSubQuestions();
|
|
- List<QuestionDto> quesDtos = BeanCopierUtil.copyPropertiesOfList(subQuesList, QuestionDto.class);
|
|
|
|
|
|
+ List<SubQuestionDto> subQuesDtos = BeanCopierUtil.copyPropertiesOfList(subQuesList, SubQuestionDto.class);
|
|
for (int m = 0; m < subQuesList.size(); m++) {
|
|
for (int m = 0; m < subQuesList.size(); m++) {
|
|
List<QuesOptionDto> quesOptionDtos = BeanCopierUtil
|
|
List<QuesOptionDto> quesOptionDtos = BeanCopierUtil
|
|
.copyPropertiesOfList(subQuesList.get(m).getQuesOptions(), QuesOptionDto.class);
|
|
.copyPropertiesOfList(subQuesList.get(m).getQuesOptions(), QuesOptionDto.class);
|
|
- quesDtos.get(m).setQuesOptions(quesOptionDtos);
|
|
|
|
- dto.setSubQuestions(quesDtos);
|
|
|
|
|
|
+ subQuesDtos.get(m).setQuesOptions(quesOptionDtos);
|
|
|
|
+ subQuesDtos.get(m).setQuesAnswer(DocxProcessUtil.getTextInHtml(subQuesList.get(m).getQuesAnswer()));
|
|
|
|
+ subQuesDtos.get(m).setNumber(m + 1);
|
|
|
|
+ dto.setSubQuestions(subQuesDtos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
msg = "success";
|
|
msg = "success";
|