deason 6 年之前
父節點
當前提交
016edb6633

+ 1 - 1
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/repository/ExamStructureRepository.java

@@ -19,7 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
 @Repository
 public interface ExamStructureRepository extends JpaRepository<ExamStructure, Long>, JpaSpecificationExecutor<ExamStructure> {
 
-    ExamStructure findByExamIdAndOrgId(Long examId, Long orgId);
+    ExamStructure findByOrgIdAndExamId(Long orgId, Long examId);
 
     @Transactional
     @Modifying

+ 2 - 0
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/repository/ObjectiveQuestionStructureRepository.java

@@ -24,4 +24,6 @@ public interface ObjectiveQuestionStructureRepository extends JpaRepository<Obje
     @Query("DELETE FROM ObjectiveQuestionStructure WHERE examId=:examId AND paperId=:paperId")
     int deleteByExamIdAndPaperId(@Param("examId") Long examId, @Param("paperId") String paperId);
 
+    long countByExamIdAndPaperIdAndQuestionType(Long examId, String paperId, String questionType);
+
 }

+ 7 - 4
examcloud-core-print-provider/src/main/java/cn/com/qmth/examcloud/core/print/api/controller/CoursePaperController.java

@@ -10,6 +10,7 @@ package cn.com.qmth.examcloud.core.print.api.controller;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.print.common.Result;
 import cn.com.qmth.examcloud.core.print.service.CoursePaperService;
+import cn.com.qmth.examcloud.core.print.service.ExamStructureService;
 import cn.com.qmth.examcloud.core.print.service.bean.coursepaper.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -34,6 +35,8 @@ import static cn.com.qmth.examcloud.core.print.common.Result.success;
 public class CoursePaperController extends ControllerSupport {
     @Autowired
     private CoursePaperService coursePaperService;
+    @Autowired
+    private ExamStructureService examStructureService;
 
     @PostMapping("/list")
     @ApiOperation(value = "获取课程试卷列表")
@@ -61,10 +64,10 @@ public class CoursePaperController extends ControllerSupport {
         return coursePaperService.getPaperTotalByOrgIdAndExamId(orgId, examId);
     }
 
-    @PostMapping("/check/structure/{examId}/{paperId}")
-    @ApiOperation(value = "校验考试结构")
-    public Result checkPaperStructure(@PathVariable Long examId, @PathVariable String paperId) {
-        coursePaperService.checkPaperStructure(examId, paperId);
+    @PostMapping("/check/structure/{orgId}/{examId}/{paperId}")
+    @ApiOperation(value = "校验考试试卷结构")
+    public Result checkPaperStructure(@PathVariable Long orgId, @PathVariable Long examId, @PathVariable String paperId) {
+        examStructureService.checkExamStructure(orgId, examId, paperId);
         return success();
     }
 

+ 0 - 5
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/CoursePaperService.java

@@ -52,11 +52,6 @@ public interface CoursePaperService {
      */
     CoursePaperTotalInfo getPaperTotalByOrgIdAndExamId(Long orgId, Long examId);
 
-    /**
-     * 校验考试结构
-     */
-    void checkPaperStructure(Long examId, String paperId);
-
     /**
      * 批量导出(导出试卷、答案、试卷结构等文件)
      * 机考数据包(暂不支持)

+ 5 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/ExamStructureService.java

@@ -34,6 +34,11 @@ public interface ExamStructureService {
      */
     void saveExamStructure(ExamStructureInfo info);
 
+    /**
+     * 校验考试试卷结构
+     */
+    void checkExamStructure(Long orgId, Long examId, String paperId);
+
     /**
      * 删除某个考试结构信息
      */

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

@@ -240,15 +240,6 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         return new CoursePaperTotalInfo();
     }
 
-    @Override
-    public void checkPaperStructure(Long examId, String paperId) {
-        Check.isNull(examId, "考试ID不能为空!");
-        Check.isEmpty(paperId, "试卷ID不能为空!");
-
-        //todo
-        throw new RuntimeException();
-    }
-
     @Override
     public File exportBatchCoursePaper(ExportBatchReq req) {
         Check.isNull(req, "参数不能为空!");

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

@@ -8,15 +8,16 @@
 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.Constants;
 import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
 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.common.utils.JsonMapper;
 import cn.com.qmth.examcloud.core.print.entity.ExamQuestionStructure;
 import cn.com.qmth.examcloud.core.print.entity.ExamStructure;
 import cn.com.qmth.examcloud.core.print.enums.ExamType;
 import cn.com.qmth.examcloud.core.print.repository.ExamStructureRepository;
+import cn.com.qmth.examcloud.core.print.repository.ObjectiveQuestionStructureRepository;
 import cn.com.qmth.examcloud.core.print.service.ExamStructureService;
 import cn.com.qmth.examcloud.core.print.service.bean.examstructure.ExamStructureConvert;
 import cn.com.qmth.examcloud.core.print.service.bean.examstructure.ExamStructureInfo;
@@ -30,6 +31,8 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
+
 /**
  * @author: fengdesheng
  * @since: 2018/10/17
@@ -41,6 +44,8 @@ public class ExamStructureServiceImpl implements ExamStructureService {
     private static final Logger log = LoggerFactory.getLogger(ExamStructureServiceImpl.class);
     @Autowired
     private ExamStructureRepository examStructureRepository;
+    @Autowired
+    private ObjectiveQuestionStructureRepository objectiveQuestionStructureRepository;
 
     @Override
     public Page<ExamStructureInfo> getExamStructureList(ExamStructureQuery query) {
@@ -66,7 +71,7 @@ public class ExamStructureServiceImpl implements ExamStructureService {
         Check.isNull(query, "查询参数不能为空!");
         Check.isEmpty(query.getOrgId(), "学校ID不能为空!");
         Check.isEmpty(query.getExamId(), "考试ID不能为空!");
-        ExamStructure entity = examStructureRepository.findByExamIdAndOrgId(query.getExamId(), query.getOrgId());
+        ExamStructure entity = examStructureRepository.findByOrgIdAndExamId(query.getOrgId(), query.getExamId());
         if (entity == null) {
             return null;
         }
@@ -91,6 +96,39 @@ public class ExamStructureServiceImpl implements ExamStructureService {
         examStructureRepository.save(entity);
     }
 
+    @Override
+    public void checkExamStructure(Long orgId, Long examId, String paperId) {
+        Check.isNull(orgId, "学校ID不能为空!");
+        Check.isNull(examId, "考试ID不能为空!");
+        Check.isEmpty(paperId, "试卷ID不能为空!");
+
+        ExamStructure entity = examStructureRepository.findByOrgIdAndExamId(orgId, examId);
+        if (entity == null) {
+            throw new StatusException(PRT_CODE_500, "当前考试尚未创建考试结构!");
+        }
+
+        //考试结构设置的客观题数量
+        ExamQuestionStructure questionStructure = new JsonMapper().fromJson(entity.getStruct(), ExamQuestionStructure.class);
+
+        //校验考试结构中的单选题数量
+        /*long singleChoiceSize = objectiveQuestionStructureRepository.countByExamIdAndPaperIdAndQuestionType(examId, paperId, QuesStructType.SINGLE_ANSWER_QUESTION.name());
+        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());
+        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());
+        if (boolQuestionSize > questionStructure.getBoolQuestionTotal()) {
+            throw new StatusException(PRT_CODE_500, String.format("考试结构中%s题数量小于试卷题目数量,需重新设置!", QuesStructType.BOOL_ANSWER_QUESTION.getTitle()));
+        }*/
+    }
+
     @Override
     public void deleteExamStructure(Long[] ids) {
         if (ids == null || ids.length == 0) {
@@ -116,14 +154,14 @@ public class ExamStructureServiceImpl implements ExamStructureService {
         Check.isNull(info.getExamId(), "新考试ID不能为空!");
         Check.isBlank(info.getNewExamName(), "新考试名称不能为空!");
 
-        ExamStructure newStructure = examStructureRepository.findByExamIdAndOrgId(info.getNewExamId(), info.getNewOrgId());
+        ExamStructure newStructure = examStructureRepository.findByOrgIdAndExamId(info.getNewOrgId(), info.getNewExamId());
         if (newStructure != null) {
-            throw new StatusException(Constants.PRT_CODE_500, "新学校考试下已有结构信息,不可复用!");
+            throw new StatusException(PRT_CODE_500, "新学校考试下已有结构信息,不可复用!");
         }
 
-        ExamStructure oldStructure = examStructureRepository.findByExamIdAndOrgId(info.getExamId(), info.getOrgId());
+        ExamStructure oldStructure = examStructureRepository.findByOrgIdAndExamId(info.getOrgId(), info.getExamId());
         if (oldStructure == null) {
-            throw new StatusException(Constants.PRT_CODE_500, "原结构信息不存在!");
+            throw new StatusException(PRT_CODE_500, "原结构信息不存在!");
         }
 
         newStructure = new ExamStructure();

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

@@ -34,10 +34,10 @@ import java.util.List;
 public class QuestionStructureServiceImpl implements QuestionStructureService {
     private static final Logger log = LoggerFactory.getLogger(QuestionStructureServiceImpl.class);
     @Autowired
-    private SubjectiveQuestionStructureRepository subjectiveQuestionStructureRepository;
-    @Autowired
     private ObjectiveQuestionStructureRepository objectiveQuestionStructureRepository;
     @Autowired
+    private SubjectiveQuestionStructureRepository subjectiveQuestionStructureRepository;
+    @Autowired
     private CommonService commonService;
 
     @Override

+ 1 - 1
examcloud-core-print-starter/src/main/resources/security-exclusions.conf

@@ -37,7 +37,7 @@
 [${$rmp.ctrl.print}/course/paper][/allot/{courseStatisticId}/{coursePaperId}][POST]
 [${$rmp.ctrl.print}/course/paper][/allot/all/{orgId}/{examId}][POST]
 [${$rmp.ctrl.print}/course/paper][/total/{orgId}/{examId}][POST]
-[${$rmp.ctrl.print}/course/paper][/check/structure/{examId}/{paperId}][POST]
+[${$rmp.ctrl.print}/course/paper][/check/structure/{orgId}/{examId}/{paperId}][POST]
 [${$rmp.ctrl.print}/course/paper][/export/batch][GET]
 [${$rmp.ctrl.print}/course/paper][/export/all][GET]