|
@@ -31,10 +31,7 @@ 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 java.util.*;
|
|
|
|
|
|
import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
|
|
|
|
|
@@ -60,6 +57,7 @@ public class QuestionStructureServiceImpl implements ExamQuestionStructureServic
|
|
|
Check.isEmpty(paperId, "试卷ID不能为空!");
|
|
|
|
|
|
//从题库端获取试卷的试题结构信息
|
|
|
+ //PaperServiceImpl --> findQuestionStructure(paperId)
|
|
|
ExamQuestionStructureInfo info = statisticService.findStructureByPaperId(examId, paperId);
|
|
|
if (info == null) {
|
|
|
log.warn("试卷试题结构不存在! paperId is " + paperId);
|
|
@@ -113,69 +111,110 @@ public class QuestionStructureServiceImpl implements ExamQuestionStructureServic
|
|
|
}
|
|
|
|
|
|
//按试题类型封装试题集合
|
|
|
- Map<String, List<ObjectiveQuestionStructure>> structureMaps = new TreeMap<>();
|
|
|
+ Map<String, List<ObjectiveQuestionStructure>> structureMaps = new HashMap<>();
|
|
|
ExamQuestionStructure questionStructure = info.getQuestionStructure();
|
|
|
for (ObjectiveQuestionStructure objective : objectives) {
|
|
|
- objective.setPaperType(paperType);//补全信息
|
|
|
- if (!structureMaps.containsKey(objective.getQuestionType())) {
|
|
|
- structureMaps.put(objective.getQuestionType(), Lists.newArrayList());
|
|
|
- }
|
|
|
+ objective.setPaperType(paperType);//补全试卷类型
|
|
|
List<ObjectiveQuestionStructure> list = structureMaps.get(objective.getQuestionType());
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ structureMaps.put(objective.getQuestionType(), list);
|
|
|
+ }
|
|
|
list.add(objective);
|
|
|
}
|
|
|
|
|
|
//补全阅卷时缺失的单选题
|
|
|
- this.fillQuestionStructure(structureMaps, QuesStructType.SINGLE_ANSWER_QUESTION, questionStructure.getSingleChoiceTotal());
|
|
|
+ int startNum = 1;
|
|
|
+ this.fillQuestionStructure(structureMaps, QuesStructType.SINGLE_ANSWER_QUESTION, questionStructure.getSingleChoiceTotal(), startNum);
|
|
|
|
|
|
//补全阅卷时缺失的多选题
|
|
|
- this.fillQuestionStructure(structureMaps, QuesStructType.MULTIPLE_ANSWER_QUESTION, questionStructure.getMultipleChoiceTotal());
|
|
|
+ startNum += questionStructure.getSingleChoiceTotal();
|
|
|
+ this.fillQuestionStructure(structureMaps, QuesStructType.MULTIPLE_ANSWER_QUESTION, questionStructure.getMultipleChoiceTotal(), startNum);
|
|
|
|
|
|
//补全阅卷时缺失的判断题
|
|
|
- this.fillQuestionStructure(structureMaps, QuesStructType.BOOL_ANSWER_QUESTION, questionStructure.getBoolQuestionTotal());
|
|
|
+ startNum += questionStructure.getMultipleChoiceTotal();
|
|
|
+ this.fillQuestionStructure(structureMaps, QuesStructType.BOOL_ANSWER_QUESTION, questionStructure.getBoolQuestionTotal(), startNum);
|
|
|
|
|
|
//返回所有客观题集合
|
|
|
List<ObjectiveQuestionStructure> allObjectives = new ArrayList<>();
|
|
|
for (String questionType : structureMaps.keySet()) {
|
|
|
allObjectives.addAll(structureMaps.get(questionType));
|
|
|
}
|
|
|
+
|
|
|
+ //按大题号和小题号排序
|
|
|
+ Collections.sort(allObjectives, (current, target) -> {
|
|
|
+ if (current.getUnitNum() > target.getUnitNum()) {
|
|
|
+ return 1;
|
|
|
+ } else if (current.getUnitNum() < target.getUnitNum()) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ });
|
|
|
+
|
|
|
return allObjectives;
|
|
|
}
|
|
|
|
|
|
- private void fillQuestionStructure(Map<String, List<ObjectiveQuestionStructure>> structureMaps, QuesStructType quesStructType, final int total) {
|
|
|
+ /**
|
|
|
+ * 补全客观题的阅卷纪录
|
|
|
+ *
|
|
|
+ * @See ExportPaperAbstractService --> fillObjectiveQuestions(...)
|
|
|
+ */
|
|
|
+ private void fillQuestionStructure(Map<String, List<ObjectiveQuestionStructure>> structureMaps, QuesStructType quesStructType, int limitSize, int startNum) {
|
|
|
List<ObjectiveQuestionStructure> objectives = structureMaps.get(quesStructType.getTitle());
|
|
|
- final int size = objectives.size();
|
|
|
+ if (objectives == null) {
|
|
|
+ objectives = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ final int currentSize = objectives.size();
|
|
|
|
|
|
- if (total == 0) {
|
|
|
- //当前题型尚未定义试题数量,则置空当前集合
|
|
|
- structureMaps.put(quesStructType.getTitle(), Lists.newArrayList());
|
|
|
+ if (limitSize == 0) {
|
|
|
+ //若当前题型尚未定义试题数量,则置空当前小题集合
|
|
|
+ objectives.clear();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (total < size) {
|
|
|
- //当前题型定义的试题数量“小于”当前试卷该题型的数量,则移除多余的项
|
|
|
- List<ObjectiveQuestionStructure> newList = new ArrayList<>();
|
|
|
- for (int i = 0; i < total; i++) {
|
|
|
- newList.add(objectives.get(i));
|
|
|
+ if (currentSize == 0) {
|
|
|
+ //若当前试卷该题型的数量为0,则设置默认小题集合
|
|
|
+ for (int i = 0; i < limitSize; i++) {
|
|
|
+ objectives.add(new ObjectiveQuestionStructure(quesStructType, startNum + 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);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (limitSize > currentSize) {
|
|
|
+ //若当前题型定义的试题数量“大于”当前试卷该题型的数量,则修正小题序号并补全剩余的小题
|
|
|
+ for (int i = 0; i < limitSize; i++) {
|
|
|
+ if (i < currentSize) {
|
|
|
+ ObjectiveQuestionStructure objective = objectives.get(i);
|
|
|
+ objective.setUnitNum(startNum + i);
|
|
|
+ } else {
|
|
|
+ objectives.add(new ObjectiveQuestionStructure(quesStructType, startNum + i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (limitSize < currentSize) {
|
|
|
+ //若当前题型定义的试题数量“小于”当前试卷该题型的数量,则修正小题序号并移除多余的小题
|
|
|
+ List<ObjectiveQuestionStructure> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < limitSize; i++) {
|
|
|
+ ObjectiveQuestionStructure objective = objectives.get(i);
|
|
|
+ objective.setUnitNum(startNum + i);
|
|
|
+ list.add(objective);
|
|
|
}
|
|
|
- } else {
|
|
|
- //当前题型定义的试题数量“等于”当前试卷该题型的数量,则不用处理直接返回
|
|
|
- //ignore
|
|
|
+ structureMaps.put(quesStructType.getTitle(), list);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前题型定义的试题数量“等于”当前试卷该题型的数量,则仅修正小题序号即可
|
|
|
+ for (int i = 0; i < limitSize; i++) {
|
|
|
+ ObjectiveQuestionStructure objective = objectives.get(i);
|
|
|
+ objective.setUnitNum(startNum + i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<SubjectiveQuestionStructure> getSubjectiveQuestionStructureList(Long examId, String paperId, String paperType) {
|
|
|
+ public List<SubjectiveQuestionStructure> getSubjectiveQuestionStructureList(Long orgId, Long examId, String paperId, String paperType) {
|
|
|
Check.isNull(examId, "考试ID不能为空!");
|
|
|
Check.isEmpty(paperId, "试卷ID不能为空!");
|
|
|
|
|
@@ -190,7 +229,7 @@ public class QuestionStructureServiceImpl implements ExamQuestionStructureServic
|
|
|
}
|
|
|
|
|
|
for (SubjectiveQuestionStructure structure : subjectives) {
|
|
|
- structure.setPaperType(paperType);//补全信息
|
|
|
+ structure.setPaperType(paperType);//补全试卷类型
|
|
|
}
|
|
|
return subjectives;
|
|
|
}
|