deason 6 vuotta sitten
vanhempi
commit
e717ce9146

+ 13 - 0
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/entity/ObjectiveQuestionStructure.java

@@ -9,6 +9,7 @@ package cn.com.qmth.examcloud.core.print.entity;
 
 import cn.afterturn.easypoi.excel.annotation.Excel;
 import cn.com.qmth.examcloud.core.print.common.IdEntity;
+import cn.com.qmth.examcloud.core.print.enums.QuesStructType;
 
 import javax.persistence.*;
 
@@ -89,6 +90,18 @@ public class ObjectiveQuestionStructure extends IdEntity {
     @Transient
     private String paperType;
 
+    public ObjectiveQuestionStructure(QuesStructType questionType, int unitNum) {
+        this.questionType = questionType.getTitle();
+        this.sectionNum = questionType.getId();
+        this.unitNum = unitNum;
+        this.unitScore = 0D;
+        this.answer = "#";
+    }
+
+    public ObjectiveQuestionStructure() {
+
+    }
+
     public Long getExamId() {
         return examId;
     }

+ 10 - 10
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/enums/QuesStructType.java

@@ -8,14 +8,14 @@
 package cn.com.qmth.examcloud.core.print.enums;
 
 public enum QuesStructType {
-    SINGLE_ANSWER_QUESTION(1L, "单选", true, false),
-    MULTIPLE_ANSWER_QUESTION(2L, "多选", true, false),
-    BOOL_ANSWER_QUESTION(3L, "判断", true, false),
-    FILL_BLANK_QUESTION(4L, "填空", false, false),
-    TEXT_ANSWER_QUESTION(5L, "问答", false, false),
-    NESTED_ANSWER_QUESTION(6L, "套题", false, true);
-
-    private Long id;
+    SINGLE_ANSWER_QUESTION(1, "单选", true, false),
+    MULTIPLE_ANSWER_QUESTION(2, "多选", true, false),
+    BOOL_ANSWER_QUESTION(3, "判断", true, false),
+    FILL_BLANK_QUESTION(4, "填空", false, false),
+    TEXT_ANSWER_QUESTION(5, "问答", false, false),
+    NESTED_ANSWER_QUESTION(6, "套题", false, true);
+
+    private Integer id;
     private String title;
     private boolean objective;//是否是客观题
     private boolean combine;//是否是组合题
@@ -32,14 +32,14 @@ public enum QuesStructType {
         return null;
     }
 
-    QuesStructType(Long id, String title, boolean objective, boolean combine) {
+    QuesStructType(Integer id, String title, boolean objective, boolean combine) {
         this.id = id;
         this.title = title;
         this.objective = objective;
         this.combine = combine;
     }
 
-    public Long getId() {
+    public Integer getId() {
         return id;
     }
 

+ 1 - 1
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/ExamQuestionStructureService.java

@@ -31,7 +31,7 @@ public interface ExamQuestionStructureService {
     /**
      * 获取主观题结构
      */
-    List<SubjectiveQuestionStructure> getSubjectiveQuestionStructureList(Long examId, String paperId, String paperType);
+    List<SubjectiveQuestionStructure> getSubjectiveQuestionStructureList(Long orgId, Long examId, String paperId, String paperType);
 
     /**
      * 同步更新课程名称信息

+ 1 - 1
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CoursePaperServiceImpl.java

@@ -364,7 +364,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
                 allObjectives.addAll(objectives);
 
                 //主观题结构
-                List<SubjectiveQuestionStructure> subjectives = examQuestionStructureService.getSubjectiveQuestionStructureList(statistic.getExamId(), paper.getPaperId(), statistic.getPaperType());
+                List<SubjectiveQuestionStructure> subjectives = examQuestionStructureService.getSubjectiveQuestionStructureList(statistic.getOrgId(), statistic.getExamId(), paper.getPaperId(), statistic.getPaperType());
                 allSubjectives.addAll(subjectives);
             }
 

+ 76 - 37
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/QuestionStructureServiceImpl.java

@@ -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;
     }

+ 8 - 2
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/CoursePaperServiceTest.java

@@ -7,9 +7,11 @@
 
 package cn.com.qmth.examcloud.core.print.test;
 
+import cn.com.qmth.examcloud.core.print.common.utils.ExcelUtils;
 import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
 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.service.CoursePaperService;
 import cn.com.qmth.examcloud.core.print.service.ExamQuestionStructureService;
 import cn.com.qmth.examcloud.core.print.service.ExamStructureService;
@@ -111,9 +113,13 @@ public class CoursePaperServiceTest extends BaseTest {
         final String paperId = "5bbc422def8fce44c27cfecf";
         List<ObjectiveQuestionStructure> objectives = examQuestionStructureService.getObjectiveQuestionStructureList(orgId, examId, paperId, paperType);
         System.out.println(jsonMapper.toJson(objectives));
+        String objectiveFile = "C:/Users/deason/Desktop/客观题.xlsx";
+        ExcelUtils.exportExcel(ObjectiveQuestionStructure.class, objectives, new File(objectiveFile));
 
-        //List<SubjectiveQuestionStructure> subjectives = examQuestionStructureService.getSubjectiveQuestionStructureList(orgId, examId, paperId, paperType);
-        //System.out.println(jsonMapper.toJson(subjectives));
+        List<SubjectiveQuestionStructure> subjectives = examQuestionStructureService.getSubjectiveQuestionStructureList(orgId, examId, paperId, paperType);
+        System.out.println(jsonMapper.toJson(subjectives));
+        String subjectiveFile = "C:/Users/deason/Desktop/主观题.xlsx";
+        ExcelUtils.exportExcel(SubjectiveQuestionStructure.class, subjectives, new File(subjectiveFile));
     }
 
 }