|
@@ -7,11 +7,14 @@
|
|
|
|
|
|
package cn.com.qmth.examcloud.core.print.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.Check;
|
|
|
+import cn.com.qmth.examcloud.core.print.entity.ExamQuestionStructure;
|
|
|
import cn.com.qmth.examcloud.core.print.entity.ObjectiveQuestionStructure;
|
|
|
import cn.com.qmth.examcloud.core.print.entity.SubjectiveQuestionStructure;
|
|
|
+import cn.com.qmth.examcloud.core.print.enums.QuesStructType;
|
|
|
import cn.com.qmth.examcloud.core.print.repository.ObjectiveQuestionStructureRepository;
|
|
|
import cn.com.qmth.examcloud.core.print.repository.SubjectiveQuestionStructureRepository;
|
|
|
import cn.com.qmth.examcloud.core.print.service.ExamQuestionStructureService;
|
|
@@ -28,7 +31,12 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
+
|
|
|
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
|
|
|
|
|
|
/**
|
|
|
* @author: fengdesheng
|
|
@@ -93,20 +101,77 @@ public class QuestionStructureServiceImpl implements ExamQuestionStructureServic
|
|
|
.eq("paperId", paperId);
|
|
|
|
|
|
Specification<ObjectiveQuestionStructure> spec = SpecUtils.buildSearchers(ObjectiveQuestionStructure.class, searches.build());
|
|
|
- List<ObjectiveQuestionStructure> list = objectiveQuestionStructureRepository.findAll(spec);
|
|
|
- if (list == null || list.isEmpty()) {
|
|
|
+ List<ObjectiveQuestionStructure> objectives = objectiveQuestionStructureRepository.findAll(spec);
|
|
|
+ if (objectives == null || objectives.isEmpty()) {
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
|
|
|
//获取考试结构设置的客观题数量
|
|
|
ExamStructureInfo info = examStructureService.getExamStructure(orgId, examId);
|
|
|
+ if (info == null || info.getQuestionStructure() == null) {
|
|
|
+ throw new StatusException(PRT_CODE_500, "当前的考试结构设置不存在!");
|
|
|
+ }
|
|
|
|
|
|
- for (ObjectiveQuestionStructure structure : list) {
|
|
|
- structure.setPaperType(paperType);//补全信息
|
|
|
+ //按试题类型封装试题集合
|
|
|
+ Map<String, List<ObjectiveQuestionStructure>> structureMaps = new TreeMap<>();
|
|
|
+ ExamQuestionStructure questionStructure = info.getQuestionStructure();
|
|
|
+ for (ObjectiveQuestionStructure objective : objectives) {
|
|
|
+ objective.setPaperType(paperType);//补全信息
|
|
|
+ if (!structureMaps.containsKey(objective.getQuestionType())) {
|
|
|
+ structureMaps.put(objective.getQuestionType(), Lists.newArrayList());
|
|
|
+ }
|
|
|
+ List<ObjectiveQuestionStructure> list = structureMaps.get(objective.getQuestionType());
|
|
|
+ list.add(objective);
|
|
|
}
|
|
|
|
|
|
- //todo
|
|
|
- return list;
|
|
|
+ //补全阅卷时缺失的单选题
|
|
|
+ this.fillQuestionStructure(structureMaps, QuesStructType.SINGLE_ANSWER_QUESTION, questionStructure.getSingleChoiceTotal());
|
|
|
+
|
|
|
+ //补全阅卷时缺失的多选题
|
|
|
+ this.fillQuestionStructure(structureMaps, QuesStructType.MULTIPLE_ANSWER_QUESTION, questionStructure.getMultipleChoiceTotal());
|
|
|
+
|
|
|
+ //补全阅卷时缺失的判断题
|
|
|
+ this.fillQuestionStructure(structureMaps, QuesStructType.BOOL_ANSWER_QUESTION, questionStructure.getBoolQuestionTotal());
|
|
|
+
|
|
|
+ //返回所有客观题集合
|
|
|
+ List<ObjectiveQuestionStructure> allObjectives = new ArrayList<>();
|
|
|
+ for (String questionType : structureMaps.keySet()) {
|
|
|
+ allObjectives.addAll(structureMaps.get(questionType));
|
|
|
+ }
|
|
|
+ return allObjectives;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillQuestionStructure(Map<String, List<ObjectiveQuestionStructure>> structureMaps, QuesStructType quesStructType, final int total) {
|
|
|
+ List<ObjectiveQuestionStructure> objectives = structureMaps.get(quesStructType.getTitle());
|
|
|
+ final int size = objectives.size();
|
|
|
+
|
|
|
+ if (total == 0) {
|
|
|
+ //当前题型尚未定义试题数量,则置空当前集合
|
|
|
+ structureMaps.put(quesStructType.getTitle(), Lists.newArrayList());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (total < size) {
|
|
|
+ //当前题型定义的试题数量“小于”当前试卷该题型的数量,则移除多余的项
|
|
|
+ List<ObjectiveQuestionStructure> newList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < total; i++) {
|
|
|
+ newList.add(objectives.get(i));
|
|
|
+ }
|
|
|
+ structureMaps.put(quesStructType.getTitle(), newList);
|
|
|
+ } else if (total > size) {
|
|
|
+ //当前题型定义的试题数量“大于”当前试卷该题型的数量,则补全剩余的项
|
|
|
+ for (int i = (total - size); i < total; i++) {
|
|
|
+
|
|
|
+ ObjectiveQuestionStructure obj = new ObjectiveQuestionStructure();
|
|
|
+ obj.setUnitNum(size + i + 1);
|
|
|
+ obj.setUnitScore(0D);
|
|
|
+ obj.setAnswer("#");
|
|
|
+ objectives.add(obj);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //当前题型定义的试题数量“等于”当前试卷该题型的数量,则不用处理直接返回
|
|
|
+ //ignore
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -119,15 +184,15 @@ public class QuestionStructureServiceImpl implements ExamQuestionStructureServic
|
|
|
.eq("paperId", paperId);
|
|
|
|
|
|
Specification<SubjectiveQuestionStructure> spec = SpecUtils.buildSearchers(SubjectiveQuestionStructure.class, searches.build());
|
|
|
- List<SubjectiveQuestionStructure> list = subjectiveQuestionStructureRepository.findAll(spec);
|
|
|
- if (list == null || list.isEmpty()) {
|
|
|
+ List<SubjectiveQuestionStructure> subjectives = subjectiveQuestionStructureRepository.findAll(spec);
|
|
|
+ if (subjectives == null || subjectives.isEmpty()) {
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
|
|
|
- for (SubjectiveQuestionStructure structure : list) {
|
|
|
+ for (SubjectiveQuestionStructure structure : subjectives) {
|
|
|
structure.setPaperType(paperType);//补全信息
|
|
|
}
|
|
|
- return list;
|
|
|
+ return subjectives;
|
|
|
}
|
|
|
|
|
|
@Override
|