|
@@ -0,0 +1,161 @@
|
|
|
|
+package com.qmth.cqb.paper.service;
|
|
|
|
+
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Random;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
|
+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 com.qmth.cqb.paper.dao.ExtractConfigRepo;
|
|
|
|
+import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
|
|
+import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
|
|
+import com.qmth.cqb.paper.dao.PaperRepo;
|
|
|
|
+import com.qmth.cqb.paper.model.ExamPaper;
|
|
|
|
+import com.qmth.cqb.paper.model.ExtractConfig;
|
|
|
|
+import com.qmth.cqb.paper.model.Paper;
|
|
|
|
+import com.qmth.cqb.paper.model.PaperDetail;
|
|
|
|
+import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
|
|
+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;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ * @author chenken
|
|
|
|
+ * @date 2017年4月14日 下午6:07:55
|
|
|
|
+ * @company QMTH
|
|
|
|
+ * @description ExtractConfigServiceImpl.java
|
|
|
|
+ */
|
|
|
|
+@Service("extractConfigService")
|
|
|
|
+public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExtractConfigRepo extractConfigRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailRepo paperDetailRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperService paperService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperRepo paperRepo;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ExtractConfig findConfig(ExtractConfig condition) {
|
|
|
|
+ if(condition.getExamId()==null){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(condition.getCourseCode())){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ ExtractConfig tempConfig = extractConfigRepo.findOne(Example.of(condition));
|
|
|
|
+ return tempConfig;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saveExtractConfig(ExtractConfig extractConfig) {
|
|
|
|
+ List<ExamPaper> examPapers = extractConfig.getExamPaperList();
|
|
|
|
+ for(int i=0;i<examPapers.size();i++){
|
|
|
|
+ ExamPaper examPaper = examPapers.get(i);
|
|
|
|
+ Paper paper = examPaper.getPaper();
|
|
|
|
+ paper = paperRepo.findOne(paper.getId());
|
|
|
|
+ examPaper.setPaper(paper);
|
|
|
|
+ }
|
|
|
|
+ extractConfigRepo.save(extractConfig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> randomPaper(String extractConfigId,Long examId, String courseCode,String groupCode) {
|
|
|
|
+ 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){
|
|
|
|
+ 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()));
|
|
|
|
+ }
|
|
|
|
+ paperMap.put("paperDto", paperDto);
|
|
|
|
+ paperMap.put("msg","success");
|
|
|
|
+ return paperMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据设定好的几率取出一套试卷
|
|
|
|
+ * @param examPaperList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private ExamPaper getExamPaperByProbability(List<ExamPaper> examPaperList){
|
|
|
|
+ if(examPaperList == null || examPaperList.size() == 0) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ double sum = 0.0;
|
|
|
|
+ for (int i = 0;i<examPaperList.size();i++) {
|
|
|
|
+ sum += examPaperList.get(i).getWeight();
|
|
|
|
+ }
|
|
|
|
+ //得到权重总和
|
|
|
|
+ int boundary = Integer.valueOf(Math.rint(sum)+"");
|
|
|
|
+ // 从1开始
|
|
|
|
+ Integer rand = new Random().nextInt(boundary) + 1;
|
|
|
|
+ for (int i = 0;i<examPaperList.size();i++) {
|
|
|
|
+ rand -= Integer.valueOf(Math.rint(examPaperList.get(i).getWeight())+"");
|
|
|
|
+ // 选中
|
|
|
|
+ if (rand <= 0) {
|
|
|
|
+ return examPaperList.get(i);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+}
|