|
@@ -1,629 +1,712 @@
|
|
-package com.qmth.cqb.paper.service.impl;
|
|
|
|
-
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Collections;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Iterator;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Random;
|
|
|
|
-import java.util.Set;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-import com.qmth.cqb.base.dao.CourseRepo;
|
|
|
|
-import com.qmth.cqb.base.model.Course;
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
-import org.nlpcn.commons.lang.util.StringUtil;
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.data.domain.Example;
|
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
|
-import org.springframework.data.domain.PageImpl;
|
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
|
-import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
-import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
-import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.util.Assert;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.core.ExamCourseDto;
|
|
|
|
-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;
|
|
|
|
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
-import cn.com.qmth.examcloud.common.util.GsonUtil;
|
|
|
|
-
|
|
|
|
-import com.qmth.cqb.paper.dao.ExportServiceManageRepo;
|
|
|
|
-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.dto.PageExamCourse;
|
|
|
|
-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.paper.rpc.ExamCourseClient;
|
|
|
|
-import com.qmth.cqb.paper.service.ExportStructureService;
|
|
|
|
-import com.qmth.cqb.paper.service.ExtractConfigService;
|
|
|
|
-import com.qmth.cqb.paper.service.PaperDetailUnitService;
|
|
|
|
-import com.qmth.cqb.paper.service.PaperService;
|
|
|
|
-import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
|
-import com.qmth.cqb.question.model.QuesOption;
|
|
|
|
-import com.qmth.cqb.question.model.Question;
|
|
|
|
-import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
|
-import com.qmth.cqb.utils.CommonUtils;
|
|
|
|
-import com.qmth.cqb.utils.enums.PaperType;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- *
|
|
|
|
- * @author chenken
|
|
|
|
- * @date 2017年4月14日 下午6:07:55
|
|
|
|
- * @company QMTH
|
|
|
|
- * @description 调卷规则service
|
|
|
|
- */
|
|
|
|
-@Service("extractConfigService")
|
|
|
|
-public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
|
-
|
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(ExtractConfigServiceImpl.class);
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ExtractConfigRepo extractConfigRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private PaperDetailRepo paperDetailRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private PaperDetailUnitService paperDetailUnitService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private PaperService paperService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private PaperRepo paperRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private QuesRepo quesRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ExportServiceManageRepo exportServiceManageRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ExportStructureService exportStructureService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ExamCourseClient examCourseClient;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private CourseRepo courseRepo;
|
|
|
|
-
|
|
|
|
- @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 Map<String, String> saveExtractConfig(ExtractConfig extractConfig,AccessUser accessUser) throws Exception {
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- Course course = courseRepo.findFirstByCodeAndOrgId(extractConfig.getCourseCode(),extractConfig.getOrgId());
|
|
|
|
- extractConfig.setCourse(course);
|
|
|
|
- return makePaperByConfig(extractConfig);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public ExtractConfig findConfigById(String id) {
|
|
|
|
- if(StringUtils.isBlank(id)){
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- return extractConfigRepo.findOne(id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Map<String, Object> extract(Long exam_id,String course_code,String group_code){
|
|
|
|
- Map<String, Object> returnMap = new HashMap<String,Object>();
|
|
|
|
- logger.info("调卷开始...");
|
|
|
|
- logger.info("开始根据examId:"+exam_id+"和courseCode:"+course_code+"获取调卷规则");
|
|
|
|
- ExtractConfig extractConfig = this.findConfig(new ExtractConfig(exam_id,course_code));
|
|
|
|
- if(extractConfig==null){
|
|
|
|
- logger.info("该考试和课程下调卷规则未制定,请先制定调卷规则,调卷程序退出");
|
|
|
|
- returnMap.put("errorMsg","该考试和课程下调卷规则未制定,请先制定调卷规则");
|
|
|
|
- return returnMap;
|
|
|
|
- }
|
|
|
|
- logger.info("根据调卷规则中设置的概率获取类型为"+group_code+"的试卷");
|
|
|
|
- Map<String,Paper> paperMap = this.getExamPaperByProbability(extractConfig.getExamPaperList());
|
|
|
|
- if(paperMap.isEmpty()){
|
|
|
|
- logger.info("该考试和课程下调卷规则中试卷不存在,请检查调卷规则,调卷程序退出");
|
|
|
|
- returnMap.put("errorMsg","该考试和课程下调卷规则中试卷不存在,请重新制定调卷规则");
|
|
|
|
- return returnMap;
|
|
|
|
- }
|
|
|
|
- Paper basePaper = paperMap.get(group_code);
|
|
|
|
- if(basePaper==null){
|
|
|
|
- logger.info("该考试和课程下调卷规则中该类型试卷不存在,请检查调卷规则,调卷程序退出");
|
|
|
|
- returnMap.put("errorMsg","该考试和课程下调卷规则中该类型试卷不存在,请重新制定调卷规则");
|
|
|
|
- return returnMap;
|
|
|
|
- }
|
|
|
|
- String basePaperId = basePaper.getId();
|
|
|
|
- logger.info("将原始试卷:"+basePaperId+"根据规则重新组卷");
|
|
|
|
- Paper newPaper = this.recombinationPaper(basePaper,
|
|
|
|
- extractConfig.getScrambling_the_question_order(),
|
|
|
|
- extractConfig.getScrambling_the_option_order());
|
|
|
|
- logger.info("根据新试卷 paperId:"+newPaper.getId()+"组装PaperDto后返回");
|
|
|
|
- PaperDto paperDto = getPaperDtoByPaper(newPaper);
|
|
|
|
- paperDto.setBasePaperId(basePaperId);
|
|
|
|
- paperDto.setAllQbjectiveQuestion(checkIsAllQbjectiveQuestion(basePaperId));
|
|
|
|
- returnMap.put("paperDto",paperDto);
|
|
|
|
- logger.info("调卷完成");
|
|
|
|
- return returnMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public boolean checkIsAllQbjectiveQuestion(String paperId) {
|
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
- for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
|
- Question question = paperDetailUnit.getQuestion();
|
|
|
|
- //填空或问答
|
|
|
|
- if(question.getQuestionType()==QuesStructType.FILL_BLANK_QUESTION
|
|
|
|
- ||question.getQuestionType()==QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- if(question.getQuestionType()==QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
|
- List<Question> subQuestions = question.getSubQuestions();
|
|
|
|
- for(Question subQuestion:subQuestions){
|
|
|
|
- if(subQuestion.getQuestionType()==QuesStructType.FILL_BLANK_QUESTION
|
|
|
|
- ||subQuestion.getQuestionType()==QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Map<String, String> makePaperByConfig(ExtractConfig extractConfig) {
|
|
|
|
- Map<String, String> finishedPaperIdMap = new HashMap<String, String>();
|
|
|
|
- if(extractConfig==null){
|
|
|
|
- throw new RuntimeException("调卷规则不存在");
|
|
|
|
- }
|
|
|
|
- //获得规则中设置的试卷
|
|
|
|
- Map<String,Paper> paperMap = this.getExamPaperByProbability(extractConfig.getExamPaperList());
|
|
|
|
- if(paperMap.isEmpty()){
|
|
|
|
- throw new RuntimeException("抽取试卷失败");
|
|
|
|
- }
|
|
|
|
- for (Map.Entry<String, Paper> entry : paperMap.entrySet()) {
|
|
|
|
- String key = entry.getKey();
|
|
|
|
- //根据原有试卷重新组卷得到新试卷
|
|
|
|
- Paper newPaper = this.recombinationPaper(entry.getValue(),
|
|
|
|
- extractConfig.getScrambling_the_question_order(),
|
|
|
|
- extractConfig.getScrambling_the_option_order());
|
|
|
|
- finishedPaperIdMap.put(key, newPaper.getId());
|
|
|
|
- }
|
|
|
|
- return finishedPaperIdMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 重组试卷,生成新的试卷
|
|
|
|
- * @param paper 选中的试卷
|
|
|
|
- * @param upSetQuestionOrder 小题乱序 1:乱序 0:不乱序
|
|
|
|
- * @param upSetOptionOrder 选项乱序 1:乱序 0:不乱序
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Paper recombinationPaper(Paper paper,int upSetQuestionOrder,int upSetOptionOrder){
|
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
- paper.setId(null);
|
|
|
|
- paper.setPaperType(PaperType.PREVIEW);//试卷类型为调卷规则预览卷
|
|
|
|
- Paper newPaper = paperRepo.save(paper);//重新保存成新的paper
|
|
|
|
- for(int i = 0;i<paperDetails.size();i++){
|
|
|
|
- PaperDetail paperDetail = paperDetails.get(i);
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitService.getUnitsByPaperDetail(paperDetail);
|
|
|
|
- paperDetail.setPaper(newPaper);//关联新Paper
|
|
|
|
- paperDetail.setId(null);
|
|
|
|
- PaperDetail newPaperDetail = paperDetailRepo.save(paperDetail);//保存新的paperDetail
|
|
|
|
- //小题乱序
|
|
|
|
- if(upSetQuestionOrder==1){
|
|
|
|
- Collections.shuffle(paperDetailUnits);//打乱小题List
|
|
|
|
- }
|
|
|
|
- for(int j = 0;j<paperDetailUnits.size();j++){
|
|
|
|
- //重新设置保存PaperDetailUnit
|
|
|
|
- PaperDetailUnit paperDetailUnit = paperDetailUnits.get(j);
|
|
|
|
- paperDetailUnit.setPaper(newPaper); //关联新Paper
|
|
|
|
- paperDetailUnit.setPaperDetail(newPaperDetail); //关联新paperDetail
|
|
|
|
- paperDetailUnit.setNumber(j+1); //重新设置序号
|
|
|
|
- reSavePaperDetailUtilAndQuestion(paperDetailUnit,upSetOptionOrder);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return newPaper;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 每个试卷类型取出一套试卷
|
|
|
|
- * {
|
|
|
|
- * A:Paper,
|
|
|
|
- * B:Paper
|
|
|
|
- * }
|
|
|
|
- * A是试卷类型 Paper是A类型下选定的试卷
|
|
|
|
- * @param examPaperList
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private Map<String,Paper> getExamPaperByProbability(List<ExamPaper> examPaperList){
|
|
|
|
- Map<String,Paper> paperByTypeMap = new HashMap<String,Paper>();
|
|
|
|
- if(examPaperList == null || examPaperList.size() == 0) {
|
|
|
|
- throw new RuntimeException("可供抽取的试卷集合为空,无法抽取试卷");
|
|
|
|
- }
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(examPaperMap!=null){
|
|
|
|
- Set<String> keys = examPaperMap.keySet();
|
|
|
|
- Iterator<String> it = keys.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- String key = it.next();
|
|
|
|
- Paper paper = this.getPaperByProbability(examPaperMap.get(key));
|
|
|
|
- //不能用原来的paper对象,否则examPaperList中的paper对象会被覆盖
|
|
|
|
- Paper newPaper =paperRepo.findOne(paper.getId());
|
|
|
|
- paperByTypeMap.put(key,newPaper);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return paperByTypeMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 根据设定几率取出一套试卷
|
|
|
|
- * @param examPaperList
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private Paper getPaperByProbability(List<ExamPaper> examPaperList){
|
|
|
|
- int sum = 0;
|
|
|
|
- for (int i = 0;i<examPaperList.size();i++) {
|
|
|
|
- sum += examPaperList.get(i).getWeight();
|
|
|
|
- }
|
|
|
|
- // 从1开始
|
|
|
|
- Integer rand = new Random().nextInt(sum) + 1;
|
|
|
|
- for (int i = 0;i<examPaperList.size();i++) {
|
|
|
|
- rand -= examPaperList.get(i).getWeight();
|
|
|
|
- // 选中
|
|
|
|
- if (rand <= 0) {
|
|
|
|
- return examPaperList.get(i).getPaper();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 重新设置并保存paperDetailUnit和question
|
|
|
|
- * @param paperDetailUnit
|
|
|
|
- * @param upSetOptionOrder
|
|
|
|
- */
|
|
|
|
- private void reSavePaperDetailUtilAndQuestion(PaperDetailUnit paperDetailUnit,Integer upSetOptionOrder){
|
|
|
|
- Question question = paperDetailUnit.getQuestion();
|
|
|
|
- //选项乱序
|
|
|
|
- if(upSetOptionOrder==1){
|
|
|
|
- //单选或多选
|
|
|
|
- if(question.getQuestionType()==QuesStructType.SINGLE_ANSWER_QUESTION||
|
|
|
|
- question.getQuestionType()==QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
|
- List<String> numberList = new ArrayList<String>();
|
|
|
|
- List<QuesOption> options = question.getQuesOptions();
|
|
|
|
- for(int k = 0;k<options.size();k++){
|
|
|
|
- QuesOption quesOption = options.get(k);
|
|
|
|
- numberList.add(quesOption.getNumber());
|
|
|
|
- }
|
|
|
|
- Collections.shuffle(numberList); //打乱number顺序
|
|
|
|
- paperDetailUnit.setOptionOrder(StringUtils.join(numberList.toArray(),","));//设置option顺序
|
|
|
|
- }
|
|
|
|
- //套题,套题下小题不乱序,选择题选项乱序
|
|
|
|
- if(question.getQuestionType()==QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
|
- List<Question> subQuestions = question.getSubQuestions();
|
|
|
|
- StringBuffer optionOrder = new StringBuffer();
|
|
|
|
- for(int m=0;m<subQuestions.size();m++){
|
|
|
|
- Question subQuestion = subQuestions.get(m);
|
|
|
|
- if(subQuestion.getQuestionType()==QuesStructType.SINGLE_ANSWER_QUESTION||
|
|
|
|
- subQuestion.getQuestionType()==QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
|
- List<String> numberList = new ArrayList<String>();
|
|
|
|
- List<QuesOption> options = subQuestion.getQuesOptions();
|
|
|
|
- for(int n = 0;n<options.size();n++){
|
|
|
|
- QuesOption quesOption = options.get(n);
|
|
|
|
- numberList.add(quesOption.getNumber());
|
|
|
|
- }
|
|
|
|
- Collections.shuffle(numberList); //打乱number顺序
|
|
|
|
- optionOrder.append(StringUtils.join(numberList.toArray(),",")).append(";");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- paperDetailUnit.setOptionOrder(optionOrder.toString()); //设置option顺序
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- paperDetailUnit.setId(null);
|
|
|
|
- paperDetailUnitRepo.save(paperDetailUnit);//保存新的paperDetailUnit
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<String> getExamPaperId(String courseCode,String orgId) {
|
|
|
|
- Assert.hasLength(courseCode,"courseCode不能为空");
|
|
|
|
- Assert.hasLength(orgId,"orgId不能为空");
|
|
|
|
- List<String> paperIdList = new ArrayList<String>();
|
|
|
|
- Query query = new Query();
|
|
|
|
- query.addCriteria(Criteria.where("courseCode").is(courseCode));
|
|
|
|
- query.addCriteria(Criteria.where("orgId").is(orgId));
|
|
|
|
- List<ExtractConfig> extractConfigList = this.mongoTemplate.find(query, ExtractConfig.class);
|
|
|
|
- for(ExtractConfig extractConfig:extractConfigList){
|
|
|
|
- List<ExamPaper> examPaperList = extractConfig.getExamPaperList();
|
|
|
|
- if(examPaperList!=null&&examPaperList.size()>0){
|
|
|
|
- for(ExamPaper examPaper:examPaperList){
|
|
|
|
- paperIdList.add(examPaper.getPaper().getId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return paperIdList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 根据paper得到PaperDto
|
|
|
|
- * @param paper
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private PaperDto getPaperDtoByPaper(Paper paper){
|
|
|
|
- PaperDto paperDto = BeanCopierUtil.copyProperties(paper, PaperDto.class);
|
|
|
|
- // 获取大题
|
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
- //大题根据number进行排序 PaperDetail 对象中有compareTo方法
|
|
|
|
- Collections.sort(paperDetails);
|
|
|
|
- List<PaperDetailDto> paperDetailDtos = BeanCopierUtil.copyPropertiesOfList(paperDetails, PaperDetailDto.class);
|
|
|
|
- paperDto.setPaperDetails(paperDetailDtos);
|
|
|
|
- // 封装小题
|
|
|
|
- for (int i = 0; i < paperDetailDtos.size(); i++) {
|
|
|
|
- //根据大题查出大题下面的小题
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetails.get(i));
|
|
|
|
- //小题根据number进行排序 perDetailUnit 对象中有compareTo方法
|
|
|
|
- Collections.sort(paperDetailUnits);
|
|
|
|
- //设置答案
|
|
|
|
- setAnswer(paperDetailUnits);
|
|
|
|
- List<PaperDetailUnitDto> paperDetailUnitDtos = BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitDto.class);
|
|
|
|
- for (int j = 0; j < paperDetailUnitDtos.size(); j++) {
|
|
|
|
- PaperDetailUnit paperDetailUnit = paperDetailUnits.get(j);
|
|
|
|
- if(paperDetailUnit==null||paperDetailUnit.getQuestion()==null){
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- PaperDetailUnitDto unitDto = paperDetailUnitDtos.get(j);
|
|
|
|
- /**
|
|
|
|
- * 此处不能传questionId,需要传paperDetailUnitId
|
|
|
|
- * 因为选项乱序在paperDetailUnit里
|
|
|
|
- * unitDto.setQuesId(paperDetailUnit.getQuestion().getId());
|
|
|
|
- */
|
|
|
|
- unitDto.setQuesId(paperDetailUnit.getId());
|
|
|
|
- String answer = paperDetailUnit.getQuestion().getQuesAnswer();
|
|
|
|
- if (StringUtils.isNotEmpty(answer)){
|
|
|
|
- unitDto.setAnswer(answer);
|
|
|
|
- }
|
|
|
|
- if (unitDto.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {// 假如是套题
|
|
|
|
- List<Question> subQuesList = paperDetailUnit.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);
|
|
|
|
- if(StringUtils.isNotEmpty(subQuesList.get(m).getQuesAnswer())){
|
|
|
|
- subQuesDtos.get(m).setQuesAnswer(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()));
|
|
|
|
- }
|
|
|
|
- return paperDto;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void setAnswer(List<PaperDetailUnit> paperDetailUnits) {
|
|
|
|
- for (PaperDetailUnit paperDetailUnit : paperDetailUnits) {
|
|
|
|
- if(paperDetailUnit==null||paperDetailUnit.getQuestion()==null){
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- String optionOrder = paperDetailUnit.getOptionOrder();
|
|
|
|
- Question question = paperDetailUnit.getQuestion();
|
|
|
|
- if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
- || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
- setAnswerUnit(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(";")){
|
|
|
|
- setAnswerUnit(subQuestion, optionOrder.split(";")[index]);
|
|
|
|
- }else{
|
|
|
|
- setAnswerUnit(subQuestion, "");
|
|
|
|
- }
|
|
|
|
- index++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void setAnswerUnit(Question question,String optionOrder){
|
|
|
|
- List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
|
- if(quesOptions == null || quesOptions.size() == 0){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if(StringUtils.isEmpty(optionOrder)){
|
|
|
|
- int j = 0;
|
|
|
|
- String answer = "";
|
|
|
|
- for(QuesOption quesOption : quesOptions){
|
|
|
|
- if(quesOption.getIsCorrect() == 1){
|
|
|
|
- answer += CommonUtils.getOptionNum(j);
|
|
|
|
- }
|
|
|
|
- j++;
|
|
|
|
- }
|
|
|
|
- question.setQuesAnswer(answer);
|
|
|
|
- }else{
|
|
|
|
- String [] order = optionOrder.split(",");
|
|
|
|
- String answer = "";
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- question.setQuesAnswer(answer);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 根据paperDetailUnitId抽取单个试题
|
|
|
|
- * 根据paperDetailUnitId中设置的option顺序对option排序
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public Map<String, Object> getQuestionById(String paperDetailUnitId) {
|
|
|
|
- String msg = "";
|
|
|
|
- Map<String, Object> quesMap = new HashMap<String, Object>();
|
|
|
|
- PaperDetailUnit paperDetailUnit = paperDetailUnitRepo.findOne(paperDetailUnitId);
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
- paperDetailUnits.add(paperDetailUnit);
|
|
|
|
- //设置答案
|
|
|
|
- setAnswer(paperDetailUnits);
|
|
|
|
- //重新对选择题option进行排序(多选、单选、套题下选择题)
|
|
|
|
- reorderChoicequestionOption(paperDetailUnit);
|
|
|
|
- Question ques = paperDetailUnit.getQuestion();
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(ques.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
- ||ques.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
|
- dto.setQuesAnswer(ques.getQuesAnswer());
|
|
|
|
- }
|
|
|
|
- msg = "success";
|
|
|
|
- quesMap.put("quesDto", dto);
|
|
|
|
- quesMap.put("msg", msg);
|
|
|
|
- return quesMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 重新对选择题option进行排序(多选、单选、套题下选择题)
|
|
|
|
- */
|
|
|
|
- private void reorderChoicequestionOption(PaperDetailUnit paperDetailUnit) {
|
|
|
|
- String optionOrder = paperDetailUnit.getOptionOrder();
|
|
|
|
- if (StringUtil.isNotBlank(optionOrder)) {
|
|
|
|
- Question question = paperDetailUnit.getQuestion();
|
|
|
|
- if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
- || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
- question.setQuesOptions(reorderOptionCore(question.getQuesOptions(), optionOrder));
|
|
|
|
- }
|
|
|
|
- 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) {
|
|
|
|
- subQuestion.setQuesOptions(reorderOptionCore(subQuestion.getQuesOptions(), optionOrder.split(";")[index]));
|
|
|
|
- index++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 对option排序
|
|
|
|
- * @param quesOptions
|
|
|
|
- * @param optionOrder
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private List<QuesOption> reorderOptionCore(List<QuesOption> quesOptions, String optionOrder) {
|
|
|
|
- List<QuesOption> newQuesOptions = new ArrayList<QuesOption>();
|
|
|
|
- if (StringUtil.isBlank(optionOrder) || quesOptions.isEmpty()) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- String[] optionOrderArr = optionOrder.split(",");
|
|
|
|
- for (int j = 0; j < optionOrderArr.length; j++) {
|
|
|
|
- for (int k = 0; k < quesOptions.size(); k++) {
|
|
|
|
- if (optionOrderArr[j].equals(quesOptions.get(k).getNumber())) {
|
|
|
|
- newQuesOptions.add(quesOptions.get(k));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- quesOptions = null;
|
|
|
|
- return newQuesOptions;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Page<ExtractConfig> findPageExtractConfig(int currentPage,int pageSize, Long examId, String courseNo) {
|
|
|
|
- String examCourseJson = examCourseClient.findPageExamCourse(examId,courseNo,currentPage,pageSize);
|
|
|
|
-
|
|
|
|
- PageExamCourse pageExamCourse = GsonUtil.getInstanceByJson(examCourseJson,PageExamCourse.class);
|
|
|
|
-
|
|
|
|
- List<ExamCourseDto> examCourseList = pageExamCourse.getContent();
|
|
|
|
- if(examCourseList.size()==0){
|
|
|
|
- throw new RuntimeException("考务系统无数据返回");
|
|
|
|
- }
|
|
|
|
- List<ExtractConfig> extractConfigs = new ArrayList<ExtractConfig>();
|
|
|
|
- for(ExamCourseDto examCourseDto:examCourseList){
|
|
|
|
- ExtractConfig condition = new ExtractConfig();
|
|
|
|
- condition.setExamId(examCourseDto.getExamId());
|
|
|
|
- condition.setCourseCode(examCourseDto.getCourseCode());
|
|
|
|
- ExtractConfig extractConfig = this.findConfig(condition);
|
|
|
|
- if(extractConfig==null){
|
|
|
|
- extractConfig = new ExtractConfig(examCourseDto);
|
|
|
|
- Course course = courseRepo.findFirstByCodeAndOrgId(examCourseDto.getCourseCode(),examCourseDto.getOrgId().toString());
|
|
|
|
- extractConfig.setCourse(course);
|
|
|
|
- }
|
|
|
|
- extractConfigs.add(extractConfig);
|
|
|
|
- }
|
|
|
|
- return new PageImpl<ExtractConfig>(extractConfigs,new PageRequest(currentPage,pageSize),pageExamCourse.getTotalElements());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+package com.qmth.cqb.paper.service.impl;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Random;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import com.qmth.cqb.base.dao.CourseRepo;
|
|
|
|
+import com.qmth.cqb.base.model.Course;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.nlpcn.commons.lang.util.StringUtil;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.core.ExamCourseDto;
|
|
|
|
+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;
|
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
+import cn.com.qmth.examcloud.common.util.GsonUtil;
|
|
|
|
+
|
|
|
|
+import com.qmth.cqb.paper.dao.AudioTimeConfigRepo;
|
|
|
|
+import com.qmth.cqb.paper.dao.ExportServiceManageRepo;
|
|
|
|
+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.dto.PageExamCourse;
|
|
|
|
+import com.qmth.cqb.paper.model.AudioTimeConfig;
|
|
|
|
+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.paper.rpc.ExamCourseClient;
|
|
|
|
+import com.qmth.cqb.paper.service.ExportStructureService;
|
|
|
|
+import com.qmth.cqb.paper.service.ExtractConfigService;
|
|
|
|
+import com.qmth.cqb.paper.service.PaperDetailUnitService;
|
|
|
|
+import com.qmth.cqb.paper.service.PaperService;
|
|
|
|
+import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
|
+import com.qmth.cqb.question.dao.QuestionAudioRepo;
|
|
|
|
+import com.qmth.cqb.question.model.QuesOption;
|
|
|
|
+import com.qmth.cqb.question.model.Question;
|
|
|
|
+import com.qmth.cqb.question.model.QuestionAudio;
|
|
|
|
+import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
|
+import com.qmth.cqb.utils.CommonUtils;
|
|
|
|
+import com.qmth.cqb.utils.enums.PaperType;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ * @author chenken
|
|
|
|
+ * @date 2017年4月14日 下午6:07:55
|
|
|
|
+ * @company QMTH
|
|
|
|
+ * @description 调卷规则service
|
|
|
|
+ */
|
|
|
|
+@Service("extractConfigService")
|
|
|
|
+public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
|
+
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ExtractConfigServiceImpl.class);
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExtractConfigRepo extractConfigRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailRepo paperDetailRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private AudioTimeConfigRepo audioTimeConfigRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperDetailUnitService paperDetailUnitService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperService paperService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperRepo paperRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private QuesRepo quesRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private QuestionAudioRepo questionAudioRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExportServiceManageRepo exportServiceManageRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExportStructureService exportStructureService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamCourseClient examCourseClient;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CourseRepo courseRepo;
|
|
|
|
+
|
|
|
|
+ @Value("${upyun.downloadUrl}")
|
|
|
|
+ private String downloadUrl;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @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 Map<String, String> saveExtractConfig(ExtractConfig extractConfig,AccessUser accessUser) throws Exception {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ Course course = courseRepo.findFirstByCodeAndOrgId(extractConfig.getCourseCode(),extractConfig.getOrgId());
|
|
|
|
+ extractConfig.setCourse(course);
|
|
|
|
+ return makePaperByConfig(extractConfig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ExtractConfig findConfigById(String id) {
|
|
|
|
+ if(StringUtils.isBlank(id)){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ return extractConfigRepo.findOne(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> extract(Long exam_id,String course_code,String group_code){
|
|
|
|
+ Map<String, Object> returnMap = new HashMap<String,Object>();
|
|
|
|
+ logger.info("调卷开始...");
|
|
|
|
+ logger.info("开始根据examId:"+exam_id+"和courseCode:"+course_code+"获取调卷规则");
|
|
|
|
+ ExtractConfig extractConfig = this.findConfig(new ExtractConfig(exam_id,course_code));
|
|
|
|
+ if(extractConfig==null){
|
|
|
|
+ logger.info("该考试和课程下调卷规则未制定,请先制定调卷规则,调卷程序退出");
|
|
|
|
+ returnMap.put("errorMsg","该考试和课程下调卷规则未制定,请先制定调卷规则");
|
|
|
|
+ return returnMap;
|
|
|
|
+ }
|
|
|
|
+ logger.info("根据调卷规则中设置的概率获取类型为"+group_code+"的试卷");
|
|
|
|
+ Map<String,Paper> paperMap = this.getExamPaperByProbability(extractConfig.getExamPaperList());
|
|
|
|
+ if(paperMap.isEmpty()){
|
|
|
|
+ logger.info("该考试和课程下调卷规则中试卷不存在,请检查调卷规则,调卷程序退出");
|
|
|
|
+ returnMap.put("errorMsg","该考试和课程下调卷规则中试卷不存在,请重新制定调卷规则");
|
|
|
|
+ return returnMap;
|
|
|
|
+ }
|
|
|
|
+ Paper basePaper = paperMap.get(group_code);
|
|
|
|
+ if(basePaper==null){
|
|
|
|
+ logger.info("该考试和课程下调卷规则中该类型试卷不存在,请检查调卷规则,调卷程序退出");
|
|
|
|
+ returnMap.put("errorMsg","该考试和课程下调卷规则中该类型试卷不存在,请重新制定调卷规则");
|
|
|
|
+ return returnMap;
|
|
|
|
+ }
|
|
|
|
+ String basePaperId = basePaper.getId();
|
|
|
|
+ logger.info("将原始试卷:"+basePaperId+"根据规则重新组卷");
|
|
|
|
+ Paper newPaper = this.recombinationPaper(basePaper,
|
|
|
|
+ extractConfig.getScrambling_the_question_order(),
|
|
|
|
+ extractConfig.getScrambling_the_option_order());
|
|
|
|
+ logger.info("根据新试卷 paperId:"+newPaper.getId()+"组装PaperDto后返回");
|
|
|
|
+ PaperDto paperDto = getPaperDtoByPaper(newPaper);
|
|
|
|
+ paperDto.setBasePaperId(basePaperId);
|
|
|
|
+ paperDto.setAllQbjectiveQuestion(checkIsAllQbjectiveQuestion(basePaperId));
|
|
|
|
+ returnMap.put("paperDto",paperDto);
|
|
|
|
+ logger.info("调卷完成");
|
|
|
|
+ return returnMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean checkIsAllQbjectiveQuestion(String paperId) {
|
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
|
+ //填空或问答
|
|
|
|
+ if(question.getQuestionType()==QuesStructType.FILL_BLANK_QUESTION
|
|
|
|
+ ||question.getQuestionType()==QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if(question.getQuestionType()==QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
|
+ List<Question> subQuestions = question.getSubQuestions();
|
|
|
|
+ for(Question subQuestion:subQuestions){
|
|
|
|
+ if(subQuestion.getQuestionType()==QuesStructType.FILL_BLANK_QUESTION
|
|
|
|
+ ||subQuestion.getQuestionType()==QuesStructType.TEXT_ANSWER_QUESTION){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, String> makePaperByConfig(ExtractConfig extractConfig) {
|
|
|
|
+ Map<String, String> finishedPaperIdMap = new HashMap<String, String>();
|
|
|
|
+ if(extractConfig==null){
|
|
|
|
+ throw new RuntimeException("调卷规则不存在");
|
|
|
|
+ }
|
|
|
|
+ //获得规则中设置的试卷
|
|
|
|
+ Map<String,Paper> paperMap = this.getExamPaperByProbability(extractConfig.getExamPaperList());
|
|
|
|
+ if(paperMap.isEmpty()){
|
|
|
|
+ throw new RuntimeException("抽取试卷失败");
|
|
|
|
+ }
|
|
|
|
+ for (Map.Entry<String, Paper> entry : paperMap.entrySet()) {
|
|
|
|
+ String key = entry.getKey();
|
|
|
|
+ //根据原有试卷重新组卷得到新试卷
|
|
|
|
+ Paper newPaper = this.recombinationPaper(entry.getValue(),
|
|
|
|
+ extractConfig.getScrambling_the_question_order(),
|
|
|
|
+ extractConfig.getScrambling_the_option_order());
|
|
|
|
+ finishedPaperIdMap.put(key, newPaper.getId());
|
|
|
|
+ }
|
|
|
|
+ return finishedPaperIdMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重组试卷,生成新的试卷
|
|
|
|
+ * @param paper 选中的试卷
|
|
|
|
+ * @param upSetQuestionOrder 小题乱序 1:乱序 0:不乱序
|
|
|
|
+ * @param upSetOptionOrder 选项乱序 1:乱序 0:不乱序
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Paper recombinationPaper(Paper paper,int upSetQuestionOrder,int upSetOptionOrder){
|
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
+ paper.setId(null);
|
|
|
|
+ paper.setPaperType(PaperType.PREVIEW);//试卷类型为调卷规则预览卷
|
|
|
|
+ Paper newPaper = paperRepo.save(paper);//重新保存成新的paper
|
|
|
|
+ for(int i = 0;i<paperDetails.size();i++){
|
|
|
|
+ PaperDetail paperDetail = paperDetails.get(i);
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitService.getUnitsByPaperDetail(paperDetail);
|
|
|
|
+ paperDetail.setPaper(newPaper);//关联新Paper
|
|
|
|
+ paperDetail.setId(null);
|
|
|
|
+ PaperDetail newPaperDetail = paperDetailRepo.save(paperDetail);//保存新的paperDetail
|
|
|
|
+ //小题乱序
|
|
|
|
+ if(upSetQuestionOrder==1){
|
|
|
|
+ Collections.shuffle(paperDetailUnits);//打乱小题List
|
|
|
|
+ }
|
|
|
|
+ for(int j = 0;j<paperDetailUnits.size();j++){
|
|
|
|
+ //重新设置保存PaperDetailUnit
|
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnits.get(j);
|
|
|
|
+ paperDetailUnit.setPaper(newPaper); //关联新Paper
|
|
|
|
+ paperDetailUnit.setPaperDetail(newPaperDetail); //关联新paperDetail
|
|
|
|
+ paperDetailUnit.setNumber(j+1); //重新设置序号
|
|
|
|
+ reSavePaperDetailUtilAndQuestion(paperDetailUnit,upSetOptionOrder);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return newPaper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 每个试卷类型取出一套试卷
|
|
|
|
+ * {
|
|
|
|
+ * A:Paper,
|
|
|
|
+ * B:Paper
|
|
|
|
+ * }
|
|
|
|
+ * A是试卷类型 Paper是A类型下选定的试卷
|
|
|
|
+ * @param examPaperList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Map<String,Paper> getExamPaperByProbability(List<ExamPaper> examPaperList){
|
|
|
|
+ Map<String,Paper> paperByTypeMap = new HashMap<String,Paper>();
|
|
|
|
+ if(examPaperList == null || examPaperList.size() == 0) {
|
|
|
|
+ throw new RuntimeException("可供抽取的试卷集合为空,无法抽取试卷");
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(examPaperMap!=null){
|
|
|
|
+ Set<String> keys = examPaperMap.keySet();
|
|
|
|
+ Iterator<String> it = keys.iterator();
|
|
|
|
+ while (it.hasNext()) {
|
|
|
|
+ String key = it.next();
|
|
|
|
+ Paper paper = this.getPaperByProbability(examPaperMap.get(key));
|
|
|
|
+ //不能用原来的paper对象,否则examPaperList中的paper对象会被覆盖
|
|
|
|
+ Paper newPaper =paperRepo.findOne(paper.getId());
|
|
|
|
+ paperByTypeMap.put(key,newPaper);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return paperByTypeMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据设定几率取出一套试卷
|
|
|
|
+ * @param examPaperList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Paper getPaperByProbability(List<ExamPaper> examPaperList){
|
|
|
|
+ int sum = 0;
|
|
|
|
+ for (int i = 0;i<examPaperList.size();i++) {
|
|
|
|
+ sum += examPaperList.get(i).getWeight();
|
|
|
|
+ }
|
|
|
|
+ // 从1开始
|
|
|
|
+ Integer rand = new Random().nextInt(sum) + 1;
|
|
|
|
+ for (int i = 0;i<examPaperList.size();i++) {
|
|
|
|
+ rand -= examPaperList.get(i).getWeight();
|
|
|
|
+ // 选中
|
|
|
|
+ if (rand <= 0) {
|
|
|
|
+ return examPaperList.get(i).getPaper();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重新设置并保存paperDetailUnit和question
|
|
|
|
+ * @param paperDetailUnit
|
|
|
|
+ * @param upSetOptionOrder
|
|
|
|
+ */
|
|
|
|
+ private void reSavePaperDetailUtilAndQuestion(PaperDetailUnit paperDetailUnit,Integer upSetOptionOrder){
|
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
|
+ //选项乱序
|
|
|
|
+ if(upSetOptionOrder==1){
|
|
|
|
+ //单选或多选
|
|
|
|
+ if(question.getQuestionType()==QuesStructType.SINGLE_ANSWER_QUESTION||
|
|
|
|
+ question.getQuestionType()==QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
|
+ List<String> numberList = new ArrayList<String>();
|
|
|
|
+ List<QuesOption> options = question.getQuesOptions();
|
|
|
|
+ for(int k = 0;k<options.size();k++){
|
|
|
|
+ QuesOption quesOption = options.get(k);
|
|
|
|
+ numberList.add(quesOption.getNumber());
|
|
|
|
+ }
|
|
|
|
+ Collections.shuffle(numberList); //打乱number顺序
|
|
|
|
+ paperDetailUnit.setOptionOrder(StringUtils.join(numberList.toArray(),","));//设置option顺序
|
|
|
|
+ }
|
|
|
|
+ //套题,套题下小题不乱序,选择题选项乱序
|
|
|
|
+ if(question.getQuestionType()==QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
|
+ List<Question> subQuestions = question.getSubQuestions();
|
|
|
|
+ StringBuffer optionOrder = new StringBuffer();
|
|
|
|
+ for(int m=0;m<subQuestions.size();m++){
|
|
|
|
+ Question subQuestion = subQuestions.get(m);
|
|
|
|
+ if(subQuestion.getQuestionType()==QuesStructType.SINGLE_ANSWER_QUESTION||
|
|
|
|
+ subQuestion.getQuestionType()==QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
|
+ List<String> numberList = new ArrayList<String>();
|
|
|
|
+ List<QuesOption> options = subQuestion.getQuesOptions();
|
|
|
|
+ for(int n = 0;n<options.size();n++){
|
|
|
|
+ QuesOption quesOption = options.get(n);
|
|
|
|
+ numberList.add(quesOption.getNumber());
|
|
|
|
+ }
|
|
|
|
+ Collections.shuffle(numberList); //打乱number顺序
|
|
|
|
+ optionOrder.append(StringUtils.join(numberList.toArray(),",")).append(";");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ paperDetailUnit.setOptionOrder(optionOrder.toString()); //设置option顺序
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ paperDetailUnit.setId(null);
|
|
|
|
+ paperDetailUnitRepo.save(paperDetailUnit);//保存新的paperDetailUnit
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<String> getExamPaperId(String courseCode,String orgId) {
|
|
|
|
+ Assert.hasLength(courseCode,"courseCode不能为空");
|
|
|
|
+ Assert.hasLength(orgId,"orgId不能为空");
|
|
|
|
+ List<String> paperIdList = new ArrayList<String>();
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ query.addCriteria(Criteria.where("courseCode").is(courseCode));
|
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(orgId));
|
|
|
|
+ List<ExtractConfig> extractConfigList = this.mongoTemplate.find(query, ExtractConfig.class);
|
|
|
|
+ for(ExtractConfig extractConfig:extractConfigList){
|
|
|
|
+ List<ExamPaper> examPaperList = extractConfig.getExamPaperList();
|
|
|
|
+ if(examPaperList!=null&&examPaperList.size()>0){
|
|
|
|
+ for(ExamPaper examPaper:examPaperList){
|
|
|
|
+ paperIdList.add(examPaper.getPaper().getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return paperIdList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据paper得到PaperDto
|
|
|
|
+ * @param paper
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private PaperDto getPaperDtoByPaper(Paper paper){
|
|
|
|
+ PaperDto paperDto = BeanCopierUtil.copyProperties(paper, PaperDto.class);
|
|
|
|
+ // 获取大题
|
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
+ //大题根据number进行排序 PaperDetail 对象中有compareTo方法
|
|
|
|
+ Collections.sort(paperDetails);
|
|
|
|
+ List<PaperDetailDto> paperDetailDtos = BeanCopierUtil.copyPropertiesOfList(paperDetails, PaperDetailDto.class);
|
|
|
|
+ paperDto.setPaperDetails(paperDetailDtos);
|
|
|
|
+ // 封装小题
|
|
|
|
+ for (int i = 0; i < paperDetailDtos.size(); i++) {
|
|
|
|
+ //根据大题查出大题下面的小题
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetails.get(i));
|
|
|
|
+ //小题根据number进行排序 perDetailUnit 对象中有compareTo方法
|
|
|
|
+ Collections.sort(paperDetailUnits);
|
|
|
|
+ //设置答案
|
|
|
|
+ setAnswer(paperDetailUnits);
|
|
|
|
+ List<PaperDetailUnitDto> paperDetailUnitDtos = BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitDto.class);
|
|
|
|
+ for (int j = 0; j < paperDetailUnitDtos.size(); j++) {
|
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnits.get(j);
|
|
|
|
+ if(paperDetailUnit==null||paperDetailUnit.getQuestion()==null){
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ PaperDetailUnitDto unitDto = paperDetailUnitDtos.get(j);
|
|
|
|
+ /**
|
|
|
|
+ * 此处不能传questionId,需要传paperDetailUnitId
|
|
|
|
+ * 因为选项乱序在paperDetailUnit里
|
|
|
|
+ * unitDto.setQuesId(paperDetailUnit.getQuestion().getId());
|
|
|
|
+ */
|
|
|
|
+ unitDto.setQuesId(paperDetailUnit.getId());
|
|
|
|
+ String answer = paperDetailUnit.getQuestion().getQuesAnswer();
|
|
|
|
+ if (StringUtils.isNotEmpty(answer)){
|
|
|
|
+ unitDto.setAnswer(answer);
|
|
|
|
+ }
|
|
|
|
+ if (unitDto.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {// 假如是套题
|
|
|
|
+ List<Question> subQuesList = paperDetailUnit.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);
|
|
|
|
+ if(StringUtils.isNotEmpty(subQuesList.get(m).getQuesAnswer())){
|
|
|
|
+ subQuesDtos.get(m).setQuesAnswer(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()));
|
|
|
|
+ }
|
|
|
|
+ return paperDto;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setAnswer(List<PaperDetailUnit> paperDetailUnits) {
|
|
|
|
+ for (PaperDetailUnit paperDetailUnit : paperDetailUnits) {
|
|
|
|
+ if(paperDetailUnit==null||paperDetailUnit.getQuestion()==null){
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ String optionOrder = paperDetailUnit.getOptionOrder();
|
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
+ || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
+ setAnswerUnit(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(";")){
|
|
|
|
+ setAnswerUnit(subQuestion, optionOrder.split(";")[index]);
|
|
|
|
+ }else{
|
|
|
|
+ setAnswerUnit(subQuestion, "");
|
|
|
|
+ }
|
|
|
|
+ index++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setAnswerUnit(Question question,String optionOrder){
|
|
|
|
+ List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
|
+ if(quesOptions == null || quesOptions.size() == 0){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isEmpty(optionOrder)){
|
|
|
|
+ int j = 0;
|
|
|
|
+ String answer = "";
|
|
|
|
+ for(QuesOption quesOption : quesOptions){
|
|
|
|
+ if(quesOption.getIsCorrect() == 1){
|
|
|
|
+ answer += CommonUtils.getOptionNum(j);
|
|
|
|
+ }
|
|
|
|
+ j++;
|
|
|
|
+ }
|
|
|
|
+ question.setQuesAnswer(answer);
|
|
|
|
+ }else{
|
|
|
|
+ String [] order = optionOrder.split(",");
|
|
|
|
+ String answer = "";
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ question.setQuesAnswer(answer);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据paperDetailUnitId抽取单个试题
|
|
|
|
+ * 根据paperDetailUnitId中设置的option顺序对option排序
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> getQuestionById(String paperDetailUnitId) {
|
|
|
|
+ String msg = "";
|
|
|
|
+ Map<String, Object> quesMap = new HashMap<String, Object>();
|
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnitRepo.findOne(paperDetailUnitId);
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
+ paperDetailUnits.add(paperDetailUnit);
|
|
|
|
+ //设置答案
|
|
|
|
+ setAnswer(paperDetailUnits);
|
|
|
|
+ //重新对选择题option进行排序(多选、单选、套题下选择题)
|
|
|
|
+ reorderChoicequestionOption(paperDetailUnit);
|
|
|
|
+ Question ques = paperDetailUnit.getQuestion();
|
|
|
|
+ QuestionDto dto = BeanCopierUtil.copyProperties(ques, QuestionDto.class);
|
|
|
|
+
|
|
|
|
+ dto.setQuesOptions(buildQuestionOptionDto(ques.getQuesOptions()));
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(ques.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
+ ||ques.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
|
+ dto.setQuesAnswer(ques.getQuesAnswer());
|
|
|
|
+ }
|
|
|
|
+ buildQuestionDto(dto,paperDetailUnit);
|
|
|
|
+ msg = "success";
|
|
|
|
+ quesMap.put("quesDto", dto);
|
|
|
|
+ quesMap.put("msg", msg);
|
|
|
|
+ return quesMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<QuesOptionDto> buildQuestionOptionDto(List<QuesOption> quesOptions) {
|
|
|
|
+ List<QuesOptionDto> optionDtos = new ArrayList<QuesOptionDto>();
|
|
|
|
+ for(QuesOption option:quesOptions){
|
|
|
|
+ QuesOptionDto optionDto = new QuesOptionDto();
|
|
|
|
+ optionDto.setNumber(option.getNumber());
|
|
|
|
+ optionDto.setOptionBody(option.getOptionBody());
|
|
|
|
+ optionDtos.add(optionDto);
|
|
|
|
+ }
|
|
|
|
+ return optionDtos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 1.给QuestionDto添加音频播放次数
|
|
|
|
+ * 2.给试题音频中有a标签添加url
|
|
|
|
+ * @param questionDto
|
|
|
|
+ */
|
|
|
|
+ private void buildQuestionDto(QuestionDto questionDto, PaperDetailUnit paperDetailUnit){
|
|
|
|
+ //判断questionDto是否含有音频,如果有添加音频播放次数
|
|
|
|
+ if(questionDto.getHasAudio() != null && questionDto.getHasAudio() == true){
|
|
|
|
+ AudioTimeConfig audioTimeConfig = audioTimeConfigRepo.findByPaperDetailUnit(paperDetailUnit);
|
|
|
|
+ if(audioTimeConfig != null && audioTimeConfig.getPlayTime() != null){
|
|
|
|
+ questionDto.setPlayTime(audioTimeConfig.getPlayTime());
|
|
|
|
+ }else {
|
|
|
|
+ questionDto.setPlayTime(null);
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ questionDto.setPlayTime(null);
|
|
|
|
+ }
|
|
|
|
+ //2.1 取到题干,给a标签添加url
|
|
|
|
+ String quesBody = questionDto.getQuesBody();
|
|
|
|
+ questionDto.setQuesBody(buildBody(quesBody, questionDto));
|
|
|
|
+ //2.2取到选项,给a标签添加url
|
|
|
|
+ List<QuesOptionDto> quesOptionDtoList = questionDto.getQuesOptions();
|
|
|
|
+ for(QuesOptionDto quesOptionDto:quesOptionDtoList){
|
|
|
|
+ quesOptionDto.setOptionBody(buildBody(quesOptionDto.getOptionBody(), questionDto));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //给题目和选项添加url
|
|
|
|
+ public String buildBody(String body,QuestionDto questionDto){
|
|
|
|
+ String[] bodys = body.split("<a");
|
|
|
|
+ if(bodys.length>1){
|
|
|
|
+ //取到文件名
|
|
|
|
+ String[] bodyStrings = bodys[1].split("\"");
|
|
|
|
+ String fileName = bodyStrings[1];
|
|
|
|
+ //获取url
|
|
|
|
+ QuestionAudio questionAudio = questionAudioRepo.findByQuestionIdAndFileName(questionDto.getId(), fileName);
|
|
|
|
+ String url = downloadUrl + questionAudio.getFileUrl();
|
|
|
|
+ //添加url
|
|
|
|
+ String[] queStrings = body.split("></a>");
|
|
|
|
+ String quesBody = queStrings[0] + " " + "url=\"" + url + "\"" + "></a>" + queStrings[1];
|
|
|
|
+ return quesBody;
|
|
|
|
+ }else {
|
|
|
|
+ return body;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重新对选择题option进行排序(多选、单选、套题下选择题)
|
|
|
|
+ */
|
|
|
|
+ private void reorderChoicequestionOption(PaperDetailUnit paperDetailUnit) {
|
|
|
|
+ String optionOrder = paperDetailUnit.getOptionOrder();
|
|
|
|
+ if (StringUtil.isNotBlank(optionOrder)) {
|
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
|
+ || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
|
+ question.setQuesOptions(reorderOptionCore(question.getQuesOptions(), optionOrder));
|
|
|
|
+ }
|
|
|
|
+ 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) {
|
|
|
|
+ subQuestion.setQuesOptions(reorderOptionCore(subQuestion.getQuesOptions(), optionOrder.split(";")[index]));
|
|
|
|
+ index++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 对option排序
|
|
|
|
+ * @param quesOptions
|
|
|
|
+ * @param optionOrder
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<QuesOption> reorderOptionCore(List<QuesOption> quesOptions, String optionOrder) {
|
|
|
|
+ List<QuesOption> newQuesOptions = new ArrayList<QuesOption>();
|
|
|
|
+ if (StringUtil.isBlank(optionOrder) || quesOptions.isEmpty()) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String[] optionOrderArr = optionOrder.split(",");
|
|
|
|
+ for (int j = 0; j < optionOrderArr.length; j++) {
|
|
|
|
+ for (int k = 0; k < quesOptions.size(); k++) {
|
|
|
|
+ if (optionOrderArr[j].equals(quesOptions.get(k).getNumber())) {
|
|
|
|
+ newQuesOptions.add(quesOptions.get(k));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ quesOptions = null;
|
|
|
|
+ return newQuesOptions;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Page<ExtractConfig> findPageExtractConfig(int currentPage,int pageSize, Long examId, String courseNo) {
|
|
|
|
+ String examCourseJson = examCourseClient.findPageExamCourse(examId,courseNo,currentPage,pageSize);
|
|
|
|
+
|
|
|
|
+ PageExamCourse pageExamCourse = GsonUtil.getInstanceByJson(examCourseJson,PageExamCourse.class);
|
|
|
|
+
|
|
|
|
+ List<ExamCourseDto> examCourseList = pageExamCourse.getContent();
|
|
|
|
+ if(examCourseList.size()==0){
|
|
|
|
+ throw new RuntimeException("考务系统无数据返回");
|
|
|
|
+ }
|
|
|
|
+ List<ExtractConfig> extractConfigs = new ArrayList<ExtractConfig>();
|
|
|
|
+ for(ExamCourseDto examCourseDto:examCourseList){
|
|
|
|
+ ExtractConfig condition = new ExtractConfig();
|
|
|
|
+ condition.setExamId(examCourseDto.getExamId());
|
|
|
|
+ condition.setCourseCode(examCourseDto.getCourseCode());
|
|
|
|
+ ExtractConfig extractConfig = this.findConfig(condition);
|
|
|
|
+ if(extractConfig==null){
|
|
|
|
+ extractConfig = new ExtractConfig(examCourseDto);
|
|
|
|
+ Course course = courseRepo.findFirstByCodeAndOrgId(examCourseDto.getCourseCode(),examCourseDto.getOrgId().toString());
|
|
|
|
+ extractConfig.setCourse(course);
|
|
|
|
+ }
|
|
|
|
+ extractConfigs.add(extractConfig);
|
|
|
|
+ }
|
|
|
|
+ return new PageImpl<ExtractConfig>(extractConfigs,new PageRequest(currentPage,pageSize),pageExamCourse.getTotalElements());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|