|
@@ -1,175 +0,0 @@
|
|
|
-package com.qmth.cqb.paper.service;
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
-
|
|
|
-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 com.qmth.cqb.paper.dao.ExamPaperRepo;
|
|
|
-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.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.dao.QuesRepo;
|
|
|
-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;
|
|
|
-
|
|
|
-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.QuestionDto;
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.SubQuestionDto;
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
-
|
|
|
-@Service
|
|
|
-public class ExtractService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamPaperRepo examPaperRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperRepo paperRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExtractConfigRepo extractConfigRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperDetailRepo paperDetailRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperService paperService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- 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 examId
|
|
|
- * @param courseCode
|
|
|
- * @param groupCode
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Map<String, Object> randomPaper(Long examId, String courseCode, String groupCode) {
|
|
|
- String msg = "";
|
|
|
- List<Paper> papers = paperService.listExamPapers(examId, courseCode, groupCode);
|
|
|
- Map<String, Object> paperMap = new HashMap<String, Object>();
|
|
|
- if (papers.size() > 0) {
|
|
|
- papers.get(this.randomNumber(examId + courseCode + groupCode, papers.size()));
|
|
|
-
|
|
|
- } else {
|
|
|
- msg = "没有可用的抽取试卷,请检查";
|
|
|
- paperMap.put("msg", msg);
|
|
|
- return paperMap;
|
|
|
- }
|
|
|
- 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()));
|
|
|
- }
|
|
|
- msg = "success";
|
|
|
- paperMap.put("paperDto", paperDto);
|
|
|
- paperMap.put("msg", msg);
|
|
|
- return paperMap;
|
|
|
- }
|
|
|
-
|
|
|
- public ExtractConfig findConfig(long examId, String courseCode) {
|
|
|
- ExtractConfig tempConfig = new ExtractConfig();
|
|
|
- tempConfig.setExamId(examId);
|
|
|
- tempConfig.setCourseCode(courseCode);
|
|
|
- return extractConfigRepo.findOne(Example.of(tempConfig));
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Object> getQuestionById(String id) {
|
|
|
- String msg = "";
|
|
|
- Map<String, Object> quesMap = new HashMap<String, Object>();
|
|
|
- Question ques = questionRepo.findOne(id);
|
|
|
- QuestionDto dto = BeanCopierUtil.copyProperties(ques, QuestionDto.class);
|
|
|
- if (ques.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
- List<Question> subQuesList = ques.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(subQuesList.get(m).getQuesAnswer());
|
|
|
- subQuesDtos.get(m).setNumber(m + 1);
|
|
|
- dto.setSubQuestions(subQuesDtos);
|
|
|
- }
|
|
|
- }
|
|
|
- msg = "success";
|
|
|
- quesMap.put("quesDto", dto);
|
|
|
- quesMap.put("msg", msg);
|
|
|
- return quesMap;
|
|
|
- }
|
|
|
-}
|