|
@@ -1,20 +1,19 @@
|
|
package com.qmth.cqb.paper.service;
|
|
package com.qmth.cqb.paper.service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
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;
|
|
import org.springframework.data.domain.Example;
|
|
import org.springframework.data.domain.Example;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.PaperDetailDto;
|
|
|
|
-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.QuesOptionDto;
|
|
|
|
-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;
|
|
|
|
|
|
import com.qmth.cqb.paper.dao.ExtractConfigRepo;
|
|
import com.qmth.cqb.paper.dao.ExtractConfigRepo;
|
|
@@ -26,10 +25,8 @@ import com.qmth.cqb.paper.model.ExtractConfig;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
|
|
+import com.qmth.cqb.question.model.QuesOption;
|
|
import com.qmth.cqb.question.model.Question;
|
|
import com.qmth.cqb.question.model.Question;
|
|
-import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
|
-import com.qmth.cqb.utils.CommonUtils;
|
|
|
|
-import com.qmth.cqb.utils.word.DocxProcessUtil;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
@@ -50,6 +47,9 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
@Autowired
|
|
@Autowired
|
|
private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailUnitService paperDetailUnitService;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
PaperService paperService;
|
|
PaperService paperService;
|
|
|
|
|
|
@@ -88,66 +88,73 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
return extractConfigRepo.findOne(id);
|
|
return extractConfigRepo.findOne(id);
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> randomPaper(String extractConfigId,Long examId, String courseCode,String groupCode) {
|
|
|
|
|
|
+ public Map<String, String> makePaperByConfig(String extractConfigId) {
|
|
|
|
+ Map<String, String> finishedPaperIdMap = new HashMap<String, String>();
|
|
|
|
+ //取出调卷规则
|
|
ExtractConfig extractConfig = this.findConfig(new ExtractConfig(extractConfigId));
|
|
ExtractConfig extractConfig = this.findConfig(new ExtractConfig(extractConfigId));
|
|
//获得抽取好的试卷
|
|
//获得抽取好的试卷
|
|
- ExamPaper examPaper = this.getExamPaperByProbability(extractConfig.getExamPaperList());
|
|
|
|
- List<Paper> papers = paperService.listExamPapers(examPaper.getExamId(),examPaper.getCourseCode(),examPaper.getGroupCode());
|
|
|
|
- if(papers==null||papers.size()==0){
|
|
|
|
|
|
+ Map<String,Paper> paperMap = this.getExamPaperByProbability(extractConfig.getExamPaperList());
|
|
|
|
+ if(paperMap==null){
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- Map<String, Object> paperMap = new HashMap<String, Object>();
|
|
|
|
- Paper paper = papers.get(0);
|
|
|
|
- PaperDto paperDto = BeanCopierUtil.copyProperties(paper, PaperDto.class);
|
|
|
|
- // 获取大题
|
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
- List<PaperDetailDto> paperDetailDtos = BeanCopierUtil.copyPropertiesOfList(paperDetails, PaperDetailDto.class);
|
|
|
|
- paperDto.setPaperDetails(paperDetailDtos);
|
|
|
|
- // 封装小题
|
|
|
|
- for (int i = 0; i < paperDetailDtos.size(); i++) {
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetail(paperDetails.get(i));
|
|
|
|
- List<PaperDetailUnitDto> paperDetailUnitDtos = BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,
|
|
|
|
- PaperDetailUnitDto.class);
|
|
|
|
- for (int j = 0; j < paperDetailUnitDtos.size(); j++) {
|
|
|
|
- PaperDetailUnitDto unitDto = paperDetailUnitDtos.get(j);
|
|
|
|
- unitDto.setQuesId(paperDetailUnits.get(j).getQuestion().getId());
|
|
|
|
- if (StringUtils.isNotEmpty(paperDetailUnits.get(j).getQuestion().getQuesAnswer())) {
|
|
|
|
- String answer = DocxProcessUtil
|
|
|
|
- .getTextInHtml(paperDetailUnits.get(j).getQuestion().getQuesAnswer());
|
|
|
|
- unitDto.setAnswer(answer);
|
|
|
|
- }
|
|
|
|
- if (unitDto.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {// 假如是套题
|
|
|
|
- List<Question> subQuesList = paperDetailUnits.get(j).getQuestion().getSubQuestions();
|
|
|
|
- List<SubQuestionDto> subQuesDtos = BeanCopierUtil.copyPropertiesOfList(subQuesList,
|
|
|
|
- SubQuestionDto.class);
|
|
|
|
- for (int m = 0; m < subQuesList.size(); m++) {
|
|
|
|
- List<QuesOptionDto> quesOptionDtos = BeanCopierUtil
|
|
|
|
- .copyPropertiesOfList(subQuesList.get(m).getQuesOptions(), QuesOptionDto.class);
|
|
|
|
- subQuesDtos.get(m).setQuesOptions(quesOptionDtos);
|
|
|
|
- subQuesDtos.get(m)
|
|
|
|
- .setQuesAnswer(DocxProcessUtil.getTextInHtml(subQuesList.get(m).getQuesAnswer()));
|
|
|
|
- subQuesDtos.get(m).setNumber(m + 1);
|
|
|
|
- }
|
|
|
|
- unitDto.setSubQuestions(subQuesDtos);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- paperDetailDtos.get(i).setPaperDetailUnits(paperDetailUnitDtos);
|
|
|
|
- paperDetailDtos.get(i).setCnNum(CommonUtils.toCHNum(paperDetailDtos.get(i).getNumber()));
|
|
|
|
|
|
+ Iterator<String> paperMapIterator = paperMap.keySet().iterator();
|
|
|
|
+ while(paperMapIterator.hasNext()){
|
|
|
|
+ String key = paperMapIterator.next();
|
|
|
|
+ //根据原有试卷重组新试卷
|
|
|
|
+ Paper newPaper = this.recombinationPaper(paperMap.get(paperMapIterator.next()),
|
|
|
|
+ extractConfig.getScrambling_the_question_order(),
|
|
|
|
+ extractConfig.getScrambling_the_option_order());
|
|
|
|
+ finishedPaperIdMap.put(key, newPaper.getId());
|
|
}
|
|
}
|
|
- paperMap.put("paperDto", paperDto);
|
|
|
|
- paperMap.put("msg","success");
|
|
|
|
- return paperMap;
|
|
|
|
|
|
+ return finishedPaperIdMap;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 根据设定好的几率取出一套试卷
|
|
|
|
- * @param examPaperList
|
|
|
|
|
|
+ * 每个试卷类型取出一套试卷
|
|
|
|
+ * {
|
|
|
|
+ * A:Paper,
|
|
|
|
+ * B:Paper
|
|
|
|
+ * }
|
|
|
|
+ * A是试卷类型 Paper是A类型下选定的试卷
|
|
|
|
+ * @param examPaperList
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private ExamPaper getExamPaperByProbability(List<ExamPaper> examPaperList){
|
|
|
|
|
|
+ private Map<String,Paper> getExamPaperByProbability(List<ExamPaper> examPaperList){
|
|
|
|
+ Map<String,Paper> paperByTypeMap = new HashMap<String,Paper>();
|
|
if(examPaperList == null || examPaperList.size() == 0) {
|
|
if(examPaperList == null || examPaperList.size() == 0) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+ Map<String,List<ExamPaper>> examPaperMap = new HashMap<String,List<ExamPaper>>();
|
|
|
|
+ for(int i = 0;i<examPaperList.size();i++){
|
|
|
|
+ ExamPaper examPaper = examPaperList.get(i);
|
|
|
|
+ if(!examPaperMap.containsKey(examPaper.getGroupCode())){
|
|
|
|
+ if(examPaper.getPaper()!=null){
|
|
|
|
+ List<ExamPaper> epList = new ArrayList<ExamPaper>();
|
|
|
|
+ epList.add(examPaper);
|
|
|
|
+ examPaperMap.put(examPaper.getGroupCode(), epList);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ if(examPaper.getPaper()!=null){
|
|
|
|
+ List<ExamPaper> epList = examPaperMap.get(examPaper.getGroupCode());
|
|
|
|
+ epList.add(examPaper);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Set<String> keys = examPaperMap.keySet();
|
|
|
|
+ Iterator<String> it = keys.iterator();
|
|
|
|
+ while (it.hasNext()) {
|
|
|
|
+ String key = it.next();
|
|
|
|
+ Paper paper = this.getPaperByProbability(examPaperMap.get(key));
|
|
|
|
+ paperByTypeMap.put(key,paper);
|
|
|
|
+ }
|
|
|
|
+ return paperByTypeMap;
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 根据设定几率取出一套试卷
|
|
|
|
+ * @param examPaperList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Paper getPaperByProbability(List<ExamPaper> examPaperList){
|
|
int sum = 0;
|
|
int sum = 0;
|
|
for (int i = 0;i<examPaperList.size();i++) {
|
|
for (int i = 0;i<examPaperList.size();i++) {
|
|
sum += examPaperList.get(i).getWeight();
|
|
sum += examPaperList.get(i).getWeight();
|
|
@@ -158,10 +165,54 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
rand -= examPaperList.get(i).getWeight();
|
|
rand -= examPaperList.get(i).getWeight();
|
|
// 选中
|
|
// 选中
|
|
if (rand <= 0) {
|
|
if (rand <= 0) {
|
|
- return examPaperList.get(i);
|
|
|
|
|
|
+ return examPaperList.get(i).getPaper();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 重组试卷,生成新的试卷
|
|
|
|
+ * @param paper 选中的试卷
|
|
|
|
+ * @param upSetQuestionOrder 小题乱序 1:乱序 0:不乱序
|
|
|
|
+ * @param upSetOptionOrder 选项乱序 1:乱序 0:不乱序
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Paper recombinationPaper(Paper paper,int upSetQuestionOrder,int upSetOptionOrder){
|
|
|
|
+ paper.setId(null);
|
|
|
|
+ Paper newPaper = paper;
|
|
|
|
+ newPaper = paperRepo.save(newPaper);//重新保存paper
|
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
+ for(int i = 0;i<paperDetails.size();i++){
|
|
|
|
+ PaperDetail paperDetail = paperDetails.get(i);
|
|
|
|
+ paperDetail.setPaper(newPaper);//关联新Paper
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitService.getUnitsByPaperDetail(paperDetail);
|
|
|
|
+ //小题乱序
|
|
|
|
+ if(upSetQuestionOrder==1){
|
|
|
|
+ Collections.shuffle(paperDetailUnits);
|
|
|
|
+ for(int j = 0;i<paperDetailUnits.size();j++){
|
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnits.get(j);
|
|
|
|
+ paperDetailUnit.setPaper(newPaper);//关联新Paper
|
|
|
|
+ paperDetailUnit.setPaperDetail(paperDetail);//关联新paperDetail
|
|
|
|
+ paperDetailUnit.setNumber(j+1);//重新设置序号
|
|
|
|
+ //选项乱序
|
|
|
|
+ if(upSetOptionOrder==1){
|
|
|
|
+ //如果题目类型为单选或多选
|
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
|
+ QuesStructType quesStructType = question.getQuestionType();
|
|
|
|
+ if(quesStructType==QuesStructType.SINGLE_ANSWER_QUESTION||
|
|
|
|
+ quesStructType==QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
|
+ List<QuesOption> options = question.getQuesOptions();
|
|
|
|
+ Collections.shuffle(options);
|
|
|
|
+ for(int k = 0;k<options.size();k++){
|
|
|
|
+ QuesOption quesOption = options.get(k);
|
|
|
|
+ Character num = (char) (0+64+1);
|
|
|
|
+ quesOption.setNumber(String.valueOf(num));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return newPaper;
|
|
|
|
+ }
|
|
}
|
|
}
|