|
@@ -2,10 +2,11 @@ package cn.com.qmth.examcloud.core.questions.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
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.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -29,14 +30,12 @@ import cn.com.qmth.examcloud.core.basic.api.response.GetUserResp;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.Model;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.enums.PaperStructType;
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.enums.QuestionDifficulty;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.PaperStructRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.PropertyRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.RandomPaperQuestionRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.RandomPaperRepo;
|
|
|
-import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailStruct;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.PaperStruct;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.Property;
|
|
@@ -47,6 +46,7 @@ import cn.com.qmth.examcloud.core.questions.dao.entity.dto.CoursePropertyNumberD
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PaperDetailUnitStructDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.PaperStructService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.CreateDefaultPaperParam;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperDetailUnitDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperQuestionViewQuery;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.QuestionDto;
|
|
@@ -59,7 +59,12 @@ import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuest
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionCountInfo;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionInfo;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.cache.RandomPaperCache;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.util.PaperUtil;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionGroup;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionStructureWrapper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionUnitWrapper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.QuestionType;
|
|
|
import cn.com.qmth.examcloud.support.CacheConstants;
|
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
@@ -245,8 +250,8 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
|
|
|
@Override
|
|
|
public StructInfo getPaperQuestionViewInfo(PaperQuestionViewQuery query) {
|
|
|
- String structId=query.getStructId();
|
|
|
- List<String> paperIds=query.getPaperIds();
|
|
|
+ String structId = query.getStructId();
|
|
|
+ List<String> paperIds = query.getPaperIds();
|
|
|
if (StringUtils.isBlank(structId)) {
|
|
|
throw new StatusException("structId不能为空");
|
|
|
}
|
|
@@ -287,6 +292,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
cd.setDetailNumber(detailNumber);
|
|
|
cd.setDs(ds);
|
|
|
cd.setSqinfo(sqinfo);
|
|
|
+ cd.setUnitScore(ds.getScore());
|
|
|
for (CoursePropertyNumberDto cp : ds.getCoursePropertyNumberDtos()) {
|
|
|
if (!cp.getDisable()) {
|
|
|
cd.setCp(cp);
|
|
@@ -313,6 +319,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
sqinfo.setDetailName(ds.getName());
|
|
|
cd.setDetailNumber(detailNumber);
|
|
|
cd.setSqinfo(sqinfo);
|
|
|
+ cd.setUnitScore(ds.getScore());
|
|
|
int index = 0;
|
|
|
for (PaperDetailUnitStructDto us : ds.getUnitStructs()) {
|
|
|
index++;
|
|
@@ -363,13 +370,13 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
ret.setValid(false);
|
|
|
}
|
|
|
for (RandomPaperQuestionDto dto : si.getHardInfo().getQuestionInfo()) {
|
|
|
- dto.setQuestionIds(new ArrayList<>());
|
|
|
+ dto.setQuestionDtos(new ArrayList<>());
|
|
|
}
|
|
|
for (RandomPaperQuestionDto dto : si.getMediumInfo().getQuestionInfo()) {
|
|
|
- dto.setQuestionIds(new ArrayList<>());
|
|
|
+ dto.setQuestionDtos(new ArrayList<>());
|
|
|
}
|
|
|
for (RandomPaperQuestionDto dto : si.getEasyInfo().getQuestionInfo()) {
|
|
|
- dto.setQuestionIds(new ArrayList<>());
|
|
|
+ dto.setQuestionDtos(new ArrayList<>());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -437,15 +444,15 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
} else {
|
|
|
if (checkExactQuesType(cd.getUs().getQuesNames(), cd.getUs().getQuestionType(), cd.getPub(),
|
|
|
cd.getDifficulty(), q)) {
|
|
|
- rq.getQuestionIds().add(q.getId());
|
|
|
+ rq.getQuestionDtos().add(q);
|
|
|
cd.getUsedQuesIds().add(q.getId());
|
|
|
it.remove();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- si.setCount(si.getCount() + rq.getQuestionIds().size());
|
|
|
- if (si.getValid() && cd.getNeedCount() > rq.getQuestionIds().size()) {
|
|
|
+ si.setCount(si.getCount() + rq.getQuestionDtos().size());
|
|
|
+ if (si.getValid() && cd.getNeedCount() > rq.getQuestionDtos().size()) {
|
|
|
si.setValid(false);
|
|
|
si.setInvalidMsg(getExactErrmsg(cd.getIndex(), cd.getDetailNumber(), cd.getPub(), cd.getDifficulty()));
|
|
|
}
|
|
@@ -514,15 +521,15 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
it.remove();
|
|
|
} else {
|
|
|
if (checkBlueQuesType(cd.getDs().getQuesNames(), cd.getDs().getQuestionType(), rq.getKey(), q)) {
|
|
|
- rq.getQuestionIds().add(q.getId());
|
|
|
+ rq.getQuestionDtos().add(q);
|
|
|
cd.getUsedQuesIds().add(q.getId());
|
|
|
it.remove();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- si.setCount(si.getCount() + rq.getQuestionIds().size());
|
|
|
- if (si.getValid() && cd.getNeedCount() > rq.getQuestionIds().size()) {
|
|
|
+ si.setCount(si.getCount() + rq.getQuestionDtos().size());
|
|
|
+ if (si.getValid() && cd.getNeedCount() > rq.getQuestionDtos().size()) {
|
|
|
si.setValid(false);
|
|
|
si.setInvalidMsg(getBlueErrmsg(cd.getDetailNumber(), cd.getCp().getPropertyParentId(),
|
|
|
cd.getCp().getPropertyId(), cd.getPub(), cd.getDifficulty()));
|
|
@@ -587,7 +594,11 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
|
|
|
private List<PaperDetailUnitDto> findUnitPaperId(String paperId) {
|
|
|
Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("paper.$id").is(new ObjectId(paperId)));
|
|
|
+ if(paperId.length()>24) {
|
|
|
+ query.addCriteria(Criteria.where("paper.$id").is(paperId));
|
|
|
+ }else {
|
|
|
+ query.addCriteria(Criteria.where("paper.$id").is(new ObjectId(paperId)));
|
|
|
+ }
|
|
|
List<PaperDetailUnitDto> units = this.mongoTemplate.find(query, PaperDetailUnitDto.class, "paperDetailUnit");
|
|
|
return units;
|
|
|
}
|
|
@@ -700,15 +711,58 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
}
|
|
|
|
|
|
private void addRqs(List<RandomPaperQuestion> rqs, RandomPaperQuestionDto dto, RandomPaper e) {
|
|
|
- if (CollectionUtils.isNotEmpty(dto.getQuestionIds())) {
|
|
|
- RandomPaperQuestion rq = new RandomPaperQuestion();
|
|
|
- rqs.add(rq);
|
|
|
- rq.setCourseId(e.getCourseId());
|
|
|
- rq.setKey(dto.getDetailNumber() + "-" + dto.getKey());
|
|
|
- rq.setQuestionIds(dto.getQuestionIds());
|
|
|
- rq.setRandomPaperId(e.getId());
|
|
|
- rq.setRootOrgId(e.getRootOrgId());
|
|
|
+ if (CollectionUtils.isNotEmpty(dto.getQuestionDtos())) {
|
|
|
+ for (QuestionDto qdto : dto.getQuestionDtos()) {
|
|
|
+ RandomPaperQuestion rq = new RandomPaperQuestion();
|
|
|
+ rqs.add(rq);
|
|
|
+ rq.setCourseId(e.getCourseId());
|
|
|
+ rq.setKey(dto.getDetailNumber() + "-" + dto.getKey());
|
|
|
+ rq.setQuestionId(qdto.getId());
|
|
|
+ rq.setRandomPaperId(e.getId());
|
|
|
+ rq.setRootOrgId(e.getRootOrgId());
|
|
|
+ rq.setScore(dto.getUnitScore());
|
|
|
+ rq.setQuestionType(qdto.getQuestionType());
|
|
|
+ rq.setAnswerType(qdto.getAnswerType());
|
|
|
+ if (CollectionUtils.isNotEmpty(qdto.getQuesOptions())) {
|
|
|
+ rq.setOptionCount(qdto.getQuesOptions().size());
|
|
|
+ }
|
|
|
+ if (QuesStructType.NESTED_ANSWER_QUESTION.equals(rq.getQuestionType())
|
|
|
+ && CollectionUtils.isNotEmpty(qdto.getSubQuestions())) {
|
|
|
+ List<RandomPaperQuestion> subQuestion = new ArrayList<>();
|
|
|
+ List<Double> subScores = getSubScoreList(rq.getScore(), qdto.getSubQuestions().size());
|
|
|
+ int i = 0;
|
|
|
+ for (QuestionDto subQd : qdto.getSubQuestions()) {
|
|
|
+ RandomPaperQuestion subrq = new RandomPaperQuestion();
|
|
|
+ subQuestion.add(subrq);
|
|
|
+ subrq.setCourseId(e.getCourseId());
|
|
|
+ subrq.setScore(subScores.get(i));
|
|
|
+ i++;
|
|
|
+ subrq.setQuestionType(subQd.getQuestionType());
|
|
|
+ subrq.setAnswerType(subQd.getAnswerType());
|
|
|
+ if (CollectionUtils.isNotEmpty(subQd.getQuesOptions())) {
|
|
|
+ subrq.setOptionCount(subQd.getQuesOptions().size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Double> getSubScoreList(double totalScore, int count) {
|
|
|
+ List<Double> scoreList = new ArrayList<>();
|
|
|
+ if (count > 0) {
|
|
|
+ int baseScore = (int) (totalScore / count);
|
|
|
+ double leftScore = totalScore;
|
|
|
+ for (int i = 0; i < count; i++) {
|
|
|
+ scoreList.add((double) baseScore);
|
|
|
+ leftScore -= baseScore;
|
|
|
+ }
|
|
|
+ if (leftScore > 0) {
|
|
|
+ scoreList.set(count - 1, baseScore + leftScore);
|
|
|
+ }
|
|
|
+ return scoreList;
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -729,12 +783,215 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DefaultPaper getRandomPaper(String randomPaperId) {
|
|
|
- RandomPaperCache rp=getByCache(randomPaperId);
|
|
|
- PaperStruct ps=paperStructService.getByCache(rp.getPaperStructId());
|
|
|
+ public DefaultPaper getRandomPaper(String randomPaperId, Integer playTime) {
|
|
|
+ RandomPaperCache rp = getByCache(randomPaperId);
|
|
|
+ PaperStruct ps = paperStructService.getByCache(rp.getPaperStructId());
|
|
|
+ CreateDefaultPaperParam param=new CreateDefaultPaperParam();
|
|
|
+ param.setFullyObjective(true);
|
|
|
+ param.setRp(rp);
|
|
|
+ DefaultPaper paper = new DefaultPaper();
|
|
|
+ paper.setName(rp.getName());
|
|
|
+ List<DefaultQuestionGroup> details = new ArrayList<>();
|
|
|
+ paper.setQuestionGroupList(details);
|
|
|
+ if (PaperStructType.BLUEPRINT.equals(ps.getPaperStrucType())) {
|
|
|
+ if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
|
|
|
+ int detailNumber = 0;
|
|
|
+ for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
|
|
|
+ DefaultQuestionGroup detail = new DefaultQuestionGroup();
|
|
|
+ detail.setGroupName(ds.getName());
|
|
|
+ detail.setGroupScore(ds.getTotalScore());
|
|
|
+ List<DefaultQuestionStructureWrapper> units = new ArrayList<>();
|
|
|
+ detail.setQuestionWrapperList(units);
|
|
|
+ detailNumber++;
|
|
|
+ param.setUnits(units);
|
|
|
+ param.setDetailNumber(detailNumber);
|
|
|
+ for (CoursePropertyNumberDto cp : ds.getCoursePropertyNumberDtos()) {
|
|
|
+ if (!cp.getDisable()) {
|
|
|
+ param.setCp(cp);
|
|
|
+ createUnitByBlueProp(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (PaperStructType.EXACT.equals(ps.getPaperStrucType())) {
|
|
|
+ if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
|
|
|
+ int detailNumber = 0;
|
|
|
+ for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
|
|
|
+ DefaultQuestionGroup detail = new DefaultQuestionGroup();
|
|
|
+ detail.setGroupName(ds.getName());
|
|
|
+ detail.setGroupScore(ds.getTotalScore());
|
|
|
+ List<DefaultQuestionStructureWrapper> units = new ArrayList<>();
|
|
|
+ detail.setQuestionWrapperList(units);
|
|
|
+ detailNumber++;
|
|
|
+ param.setUnits(units);
|
|
|
+ param.setDetailNumber(detailNumber);
|
|
|
+ int index = 0;
|
|
|
+ for (PaperDetailUnitStructDto us : ds.getUnitStructs()) {
|
|
|
+ index++;
|
|
|
+ param.setIndex(index);
|
|
|
+ param.setUs(us);
|
|
|
+ createUnitByExact(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ paper.setFullyObjective(param.getFullyObjective());
|
|
|
+ return paper;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createUnitByExact(CreateDefaultPaperParam param) {
|
|
|
+ PaperDetailUnitStructDto us = param.getUs();
|
|
|
+ if (us.getNoPublicDifficulty() > 0) {
|
|
|
+ param.setUnitCount(us.getNoPublicDifficulty());
|
|
|
+ String key=param.getDetailNumber()+"-"+param.getIndex() + "-" + false + "-" + QuestionDifficulty.HARD.getName();
|
|
|
+ param.setKey(key);
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (us.getPublicDifficulty() > 0) {
|
|
|
+ param.setUnitCount(us.getPublicDifficulty());
|
|
|
+ String key=param.getDetailNumber()+"-"+param.getIndex() + "-" + true + "-" + QuestionDifficulty.HARD.getName();
|
|
|
+ param.setKey(key);
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (us.getNoPublicMedium() > 0) {
|
|
|
+ param.setUnitCount(us.getNoPublicMedium());
|
|
|
+ String key=param.getDetailNumber()+"-"+param.getIndex() + "-" + false + "-" + QuestionDifficulty.MEDIUM.getName();
|
|
|
+ param.setKey(key);
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (us.getPublicMedium() > 0) {
|
|
|
+ param.setUnitCount(us.getPublicMedium());
|
|
|
+ String key=param.getDetailNumber()+"-"+param.getIndex() + "-" + true + "-" + QuestionDifficulty.MEDIUM.getName();
|
|
|
+ param.setKey(key);
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (us.getNoPublicSimple() > 0) {
|
|
|
+ param.setUnitCount(us.getNoPublicSimple());
|
|
|
+ String key=param.getDetailNumber()+"-"+param.getIndex() + "-" + false + "-" + QuestionDifficulty.EASY.getName();
|
|
|
+ param.setKey(key);
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (us.getPublicSimple() > 0) {
|
|
|
+ param.setUnitCount(us.getPublicSimple());
|
|
|
+ String key=param.getDetailNumber()+"-"+param.getIndex() + "-" + true + "-" + QuestionDifficulty.EASY.getName();
|
|
|
+ param.setKey(key);
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createUnitByBlueProp(CreateDefaultPaperParam param) {
|
|
|
+ CoursePropertyNumberDto cp = param.getCp();
|
|
|
+ if (cp.getNoPublicDifficulty() > 0) {
|
|
|
+ String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
|
|
|
+ cp.getPropertyId(), false, QuestionDifficulty.HARD.getName());
|
|
|
+ param.setKey(key);
|
|
|
+ param.setUnitCount(cp.getNoPublicDifficulty());
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (cp.getPublicDifficulty() > 0) {
|
|
|
+ String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
|
|
|
+ cp.getPropertyId(), true, QuestionDifficulty.HARD.getName());
|
|
|
+ param.setKey(key);
|
|
|
+ param.setUnitCount(cp.getPublicDifficulty());
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cp.getNoPublicMedium() > 0) {
|
|
|
+ String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
|
|
|
+ cp.getPropertyId(), false, QuestionDifficulty.MEDIUM.getName());
|
|
|
+ param.setKey(key);
|
|
|
+ param.setUnitCount(cp.getNoPublicMedium());
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (cp.getPublicMedium() > 0) {
|
|
|
+ String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
|
|
|
+ cp.getPropertyId(), true, QuestionDifficulty.MEDIUM.getName());
|
|
|
+ param.setKey(key);
|
|
|
+ param.setUnitCount(cp.getPublicMedium());
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (cp.getNoPublicSimple() > 0) {
|
|
|
+ String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
|
|
|
+ cp.getPropertyId(), false, QuestionDifficulty.EASY.getName());
|
|
|
+ param.setKey(key);
|
|
|
+ param.setUnitCount(cp.getNoPublicSimple());
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ if (cp.getPublicSimple() > 0) {
|
|
|
+ String key = param.getDetailNumber() + "-" + bulidPropertyGroupByBlueStruct(cp.getPropertyParentId(),
|
|
|
+ cp.getPropertyId(), true, QuestionDifficulty.EASY.getName());
|
|
|
+ param.setKey(key);
|
|
|
+ param.setUnitCount(cp.getPublicSimple());
|
|
|
+ createUnit(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createUnit(CreateDefaultPaperParam param) {
|
|
|
+ List<RandomPaperQuestion> rpqs = param.getRp().getRpqs().get(param.getKey());
|
|
|
+ Collections.shuffle(rpqs);
|
|
|
+ for (int i = 0; i < param.getUnitCount(); i++) {
|
|
|
+ RandomPaperQuestion rpq = rpqs.get(i);
|
|
|
+ DefaultQuestionStructureWrapper qw = new DefaultQuestionStructureWrapper();
|
|
|
+ qw.setLimitedPlayTimes(param.getPlayTime());
|
|
|
+ qw.setPlayedTimes(0);
|
|
|
+ qw.setQuestionId(rpq.getQuestionId());
|
|
|
+ qw.setQuestionScore(rpq.getScore());
|
|
|
+ List<DefaultQuestionUnitWrapper> qList = new ArrayList<>();
|
|
|
+ qw.setQuestionUnitWrapperList(qList);
|
|
|
+ if (QuesStructType.NESTED_ANSWER_QUESTION.equals(rpq.getQuestionType())) {
|
|
|
+ for (RandomPaperQuestion sub : rpq.getSubQuestions()) {
|
|
|
+ DefaultQuestionUnitWrapper q = new DefaultQuestionUnitWrapper();
|
|
|
+ qList.add(q);
|
|
|
+ q.setAnswerType(sub.getAnswerType());
|
|
|
+ q.setOptionPermutation(getOption(sub.getOptionCount()));
|
|
|
+ q.setQuestionScore(sub.getScore());
|
|
|
+ q.setQuestionType(getByOldType(sub.getQuestionType()));
|
|
|
+ if(!PaperUtil.isObjecttive(sub.getQuestionType())) {
|
|
|
+ param.setFullyObjective(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DefaultQuestionUnitWrapper q = new DefaultQuestionUnitWrapper();
|
|
|
+ qList.add(q);
|
|
|
+ q.setAnswerType(rpq.getAnswerType());
|
|
|
+ q.setOptionPermutation(getOption(rpq.getOptionCount()));
|
|
|
+ q.setQuestionScore(rpq.getScore());
|
|
|
+ q.setQuestionType(getByOldType(rpq.getQuestionType()));
|
|
|
+ if(!PaperUtil.isObjecttive(rpq.getQuestionType())) {
|
|
|
+ param.setFullyObjective(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private QuestionType getByOldType(QuesStructType quesStructType) {
|
|
|
+ if (quesStructType == QuesStructType.BOOL_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.TRUE_OR_FALSE;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.FILL_BLANK_QUESTION) {
|
|
|
+ return QuestionType.FILL_UP;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.MULTIPLE_CHOICE;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.SINGLE_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.SINGLE_CHOICE;
|
|
|
+ }
|
|
|
+ if (quesStructType == QuesStructType.TEXT_ANSWER_QUESTION) {
|
|
|
+ return QuestionType.ESSAY;
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private Integer[] getOption(Integer count) {
|
|
|
+ Integer[] ret = new Integer[count];
|
|
|
+ for (int i = 0; i < count; i++) {
|
|
|
+ ret[i] = i;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
private RandomPaperCache getByCache(String id) {
|
|
|
String key = CacheConstants.CACHE_Q_RANDOM_PAPER + id;
|
|
|
RandomPaperCache rp = redisClient.get(key, RandomPaperCache.class, cacheTimeOut);
|
|
@@ -744,13 +1001,21 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
if (e == null) {
|
|
|
throw new StatusException("未找到随机模板:" + id);
|
|
|
}
|
|
|
+ rp.setName(e.getName());
|
|
|
rp.setPaperStructId(e.getPaperStructId());
|
|
|
List<RandomPaperQuestion> rpqs = randomPaperQuestionRepo.findByRandomPaperId(id);
|
|
|
if (CollectionUtils.isEmpty(rpqs)) {
|
|
|
throw new StatusException("随机模板试题库为空:" + id);
|
|
|
}
|
|
|
- Map<String, RandomPaperQuestion> map = rpqs.stream()
|
|
|
- .collect(Collectors.toMap(RandomPaperQuestion::getKey, account -> account, (key1, key2) -> key2));
|
|
|
+ Map<String, List<RandomPaperQuestion>> map = new HashMap<>();
|
|
|
+ for (RandomPaperQuestion rpq : rpqs) {
|
|
|
+ List<RandomPaperQuestion> list = map.get(rpq.getKey());
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ map.put(rpq.getKey(), list);
|
|
|
+ }
|
|
|
+ list.add(rpq);
|
|
|
+ }
|
|
|
rp.setRpqs(map);
|
|
|
redisClient.set(key, rp, cacheTimeOut);
|
|
|
}
|