浏览代码

fix:客观题导入加选项个数

caozixuan 1 年之前
父节点
当前提交
e10c6a241c

+ 14 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ObjectiveStructDto.java

@@ -39,12 +39,16 @@ public class ObjectiveStructDto {
     @ExcelColumn(name = "标准答案", index = 7, nullable = true)
     private String answer;
 
+    @ApiModelProperty(value = "选项个数")
+    @ExcelColumn(name = "选项个数", index = 8, nullable = true)
+    private Integer optionCount;
+
     @ApiModelProperty(value = "小题满分")
-    @ExcelColumn(name = "小题满分", index = 8, nullable = true)
+    @ExcelColumn(name = "小题满分", index = 9, nullable = true)
     private Double totalScore;
 
     @ApiModelProperty(value = "题型(1-单选,2-多选,3-判断)")
-    @ExcelColumn(name = "题型(1-单选,2-多选,3-判断)", index = 9, nullable = true)
+    @ExcelColumn(name = "题型(1-单选,2-多选,3-判断)", index = 10, nullable = true)
     private Integer questionType;
 
     @ApiModelProperty(value = "错误信息")
@@ -107,6 +111,14 @@ public class ObjectiveStructDto {
         this.answer = answer;
     }
 
+    public Integer getOptionCount() {
+        return optionCount;
+    }
+
+    public void setOptionCount(Integer optionCount) {
+        this.optionCount = optionCount;
+    }
+
     public Double getTotalScore() {
         return totalScore;
     }

+ 39 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -2352,6 +2352,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         // 题号重复校验
         // 导入的客观题题号集合
         Set<String> questionNumberCheckSet = new HashSet<>();
+        // 客观题选项个数在大题下一致性校验
+        Map<String, Integer> questionOptionCountMap = new HashMap<>();
         // 该试卷已存在的主观题题号集合
         Set<String> dbSubjectiveQuestionNumberSet = markQuestionService.list(
                         new QueryWrapper<MarkQuestion>().lambda().eq(MarkQuestion::getExamId, examId)
@@ -2374,6 +2376,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             Integer mainNumber = objectiveStructDto.getMainNumber();
             Integer subNumber = objectiveStructDto.getSubNumber();
             String answer = objectiveStructDto.getAnswer();
+            Integer optionCount = objectiveStructDto.getOptionCount();
             Double totalScore = objectiveStructDto.getTotalScore();
             Integer questionType = objectiveStructDto.getQuestionType();
             String errorMsg = objectiveStructDto.getErrorMsg();
@@ -2391,6 +2394,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 if (dbSubjectiveQuestionNumberSet.contains(questionNumberKey)) {
                     logicErrorList.add("该题号已存在主观题中");
                 }
+                String mainQuestionKey = paperNumber + SystemConstant.HYPHEN + mainNumber;
+                if (questionOptionCountMap.containsKey(mainQuestionKey)) {
+                    if (!Objects.equals(questionOptionCountMap.get(mainQuestionKey), optionCount)) {
+                        logicErrorList.add("选项个数和该大题中的其他小题不一致");
+                    }
+                } else {
+                    questionOptionCountMap.put(mainQuestionKey, optionCount);
+                }
             }
 
             // 2.校验课程编号,课程名称,试卷在考试下是否存在
@@ -2404,14 +2415,35 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     logicErrorList.add("试卷不存在");
                 }
             }
-            // 3.客观题答案必须是OptionsEnum中的编号
-            if (SystemConstant.strNotNull(answer)) {
-                for (String s : answer.split("")) {
-                    if (OptionsEnum.getByCode(s) == null) {
-                        logicErrorList.add("客观题答案必须是[A-Z]中的大写英文字母");
-                        break;
+            // 3.选项越界校验
+            List<String> optionScope = new ArrayList<>();
+            try {
+                for (int j = 1; j <= optionCount; j++) {
+                    String code = OptionsEnum.getCodeByIndex(j);
+                    optionScope.add(code);
+                }
+            } catch (Exception e) {
+                throw ExceptionResultEnum.ERROR.exception(logicErrorCommonNotice + "[选项个数]不能超过26");
+            }
+
+            // 答案选项越界校验
+            List<String> answerList = Arrays.asList(answer.split(""));
+            if (CollectionUtils.isNotEmpty(answerList)) {
+                for (String cell : answerList) {
+                    String outOfBoundsException = String.format("答案[%s]错误。答案只能从[%s]中选择", cell, String.join("", optionScope));
+                    try {
+                        OptionsEnum optionsEnum = OptionsEnum.getByCode(cell);
+                        int optionIndex = optionsEnum.getIndex();
+                        if (optionIndex > optionCount) {
+                            // 答案选项超出范围
+                            logicErrorList.add(outOfBoundsException);
+                        }
+                    } catch (Exception e) {
+                        logicErrorList.add(outOfBoundsException);
                     }
                 }
+            } else {
+                logicErrorList.add("答案必填");
             }
 
             // 4.判断答案是否符合题型
@@ -2452,6 +2484,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 markQuestion.setSubNumber(subNumber);
                 markQuestion.setMainTitle(mainTitle);
                 markQuestion.setAnswer(answer);
+                markQuestion.setOptionCount(optionCount);
                 markQuestion.setTotalScore(totalScore);
                 markQuestion.setObjectivePolicy(ObjectivePolicy.NONE);
                 markQuestion.setQuestionType(questionType);

二进制
distributed-print/src/main/resources/temps/objectiveStruct.xlsx