deason 6 år sedan
förälder
incheckning
c0a6607d38

+ 3 - 3
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/entity/ExamQuestionStructure.java

@@ -30,7 +30,7 @@ public class ExamQuestionStructure implements Serializable {
     private Integer boolQuestionTotal;
 
     public Integer getSingleChoiceTotal() {
-        return singleChoiceTotal;
+        return singleChoiceTotal != null ? singleChoiceTotal : 0;
     }
 
     public void setSingleChoiceTotal(Integer singleChoiceTotal) {
@@ -38,7 +38,7 @@ public class ExamQuestionStructure implements Serializable {
     }
 
     public Integer getMultipleChoiceTotal() {
-        return multipleChoiceTotal;
+        return multipleChoiceTotal != null ? multipleChoiceTotal : 0;
     }
 
     public void setMultipleChoiceTotal(Integer multipleChoiceTotal) {
@@ -46,7 +46,7 @@ public class ExamQuestionStructure implements Serializable {
     }
 
     public Integer getBoolQuestionTotal() {
-        return boolQuestionTotal;
+        return boolQuestionTotal != null ? boolQuestionTotal : 0;
     }
 
     public void setBoolQuestionTotal(Integer boolQuestionTotal) {

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

@@ -65,7 +65,7 @@ public class ObjectiveQuestionStructure extends IdEntity {
     /**
      * 小题分数
      */
-    @Excel(name = "分数", orderNum = "8")
+    @Excel(name = "小题分数", orderNum = "8")
     private Double unitScore;
     /**
      * 标准答案
@@ -74,7 +74,7 @@ public class ObjectiveQuestionStructure extends IdEntity {
     @Column(length = 50)
     private String answer;
     /**
-     * 题类型
+     * 题类型
      *
      * @See QuesStructType.java
      */

+ 3 - 3
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/ExamStructureServiceImpl.java

@@ -162,15 +162,15 @@ public class ExamStructureServiceImpl implements ExamStructureService {
         //ExamQuestionStructure questionStructure = new JsonMapper().fromJson(entity.getStruct(), ExamQuestionStructure.class);
 
         //校验考试结构中单选题、多选题、判断题的数量
-        /*long singleChoiceSize = objectiveQuestionStructureRepository.countByExamIdAndPaperIdAndQuestionType(examId, paperId, QuesStructType.SINGLE_ANSWER_QUESTION.name());
+        /*long singleChoiceSize = objectiveQuestionStructureRepository.countByExamIdAndPaperIdAndQuestionType(examId, paperId, QuesStructType.SINGLE_ANSWER_QUESTION.getTitle());
         if (singleChoiceSize > questionStructure.getSingleChoiceTotal()) {
             throw new StatusException(PRT_CODE_500, String.format("考试结构中%s题数量小于试卷题目数量,需重新设置!", QuesStructType.SINGLE_ANSWER_QUESTION.getTitle()));
         }
-        long multipleChoiceSize = objectiveQuestionStructureRepository.countByExamIdAndPaperIdAndQuestionType(examId, paperId, QuesStructType.MULTIPLE_ANSWER_QUESTION.name());
+        long multipleChoiceSize = objectiveQuestionStructureRepository.countByExamIdAndPaperIdAndQuestionType(examId, paperId, QuesStructType.MULTIPLE_ANSWER_QUESTION.getTitle());
         if (multipleChoiceSize > questionStructure.getMultipleChoiceTotal()) {
             throw new StatusException(PRT_CODE_500, String.format("考试结构中%s题数量小于试卷题目数量,需重新设置!", QuesStructType.MULTIPLE_ANSWER_QUESTION.getTitle()));
         }
-        long boolQuestionSize = objectiveQuestionStructureRepository.countByExamIdAndPaperIdAndQuestionType(examId, paperId, QuesStructType.BOOL_ANSWER_QUESTION.name());
+        long boolQuestionSize = objectiveQuestionStructureRepository.countByExamIdAndPaperIdAndQuestionType(examId, paperId, QuesStructType.BOOL_ANSWER_QUESTION.getTitle());
         if (boolQuestionSize > questionStructure.getBoolQuestionTotal()) {
             throw new StatusException(PRT_CODE_500, String.format("考试结构中%s题数量小于试卷题目数量,需重新设置!", QuesStructType.BOOL_ANSWER_QUESTION.getTitle()));
         }*/

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

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

+ 15 - 0
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/CoursePaperServiceTest.java

@@ -8,7 +8,9 @@
 package cn.com.qmth.examcloud.core.print.test;
 
 import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
+import cn.com.qmth.examcloud.core.print.entity.ObjectiveQuestionStructure;
 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.StatisticService;
 import cn.com.qmth.examcloud.core.print.service.bean.coursepaper.ExportAllReq;
 import cn.com.qmth.examcloud.core.print.service.bean.coursepaper.ExportBatchReq;
@@ -17,12 +19,15 @@ import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.File;
+import java.util.List;
 
 /**
  * @author: fengdesheng
  * @since: 2018/11/08
  */
 public class CoursePaperServiceTest extends BaseTest {
+    @Autowired
+    private ExamQuestionStructureService examQuestionStructureService;
     @Autowired
     private CoursePaperService coursePaperService;
     @Autowired
@@ -84,4 +89,14 @@ public class CoursePaperServiceTest extends BaseTest {
         }
     }
 
+    @Test
+    public void dd() {
+        final String paperId = "5bbc422def8fce44c27cfecf";
+        List<ObjectiveQuestionStructure> objectives = examQuestionStructureService.getObjectiveQuestionStructureList(orgId, examId, paperId, paperType);
+        System.out.println(jsonMapper.toJson(objectives));
+
+        //List<SubjectiveQuestionStructure> subjectives = examQuestionStructureService.getSubjectiveQuestionStructureList(orgId, examId, paperId, paperType);
+        //System.out.println(jsonMapper.toJson(subjectives));
+    }
+
 }