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

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

@@ -10,9 +10,18 @@ package cn.com.qmth.examcloud.core.print.repository;
 import cn.com.qmth.examcloud.core.print.entity.ObjectiveQuestionStructure;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
 
 @Repository
 public interface ObjectiveQuestionStructureRepository extends JpaRepository<ObjectiveQuestionStructure, Long>, JpaSpecificationExecutor<ObjectiveQuestionStructure> {
 
+    @Transactional
+    @Modifying
+    @Query("DELETE FROM ObjectiveQuestionStructure WHERE examId=:examId AND paperId=:paperId")
+    int deleteByPaperId(@Param("examId") Long examId, @Param("paperId") String paperId);
+
 }

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

@@ -10,9 +10,18 @@ package cn.com.qmth.examcloud.core.print.repository;
 import cn.com.qmth.examcloud.core.print.entity.SubjectiveQuestionStructure;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
 
 @Repository
 public interface SubjectiveQuestionStructureRepository extends JpaRepository<SubjectiveQuestionStructure, Long>, JpaSpecificationExecutor<SubjectiveQuestionStructure> {
 
+    @Transactional
+    @Modifying
+    @Query("DELETE FROM SubjectiveQuestionStructure WHERE examId=:examId AND paperId=:paperId")
+    int deleteByPaperId(@Param("examId") Long examId, @Param("paperId") String paperId);
+
 }

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

@@ -83,7 +83,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         Check.isNull(coursePaper.getCourseId(), "课程ID不能为空!");
         Check.isEmpty(coursePaper.getCourseCode(), "课程代码不能为空!");
         Check.isEmpty(coursePaper.getCourseName(), "课程名称不能为空!");
-        Check.isNull(coursePaper.getPaperId(), "试卷ID不能为空!");
+        Check.isEmpty(coursePaper.getPaperId(), "试卷ID不能为空!");
         Check.isEmpty(coursePaper.getPaperName(), "试卷名称不能为空!");
         Check.isNull(coursePaper.getPaperP(), "试卷页数不能为空!");
         Check.isBlank(coursePaper.getPaperFileUrl(), "试卷文件地址不能为空!");
@@ -97,6 +97,9 @@ public class CoursePaperServiceImpl implements CoursePaperService {
             oldCoursePaper.setPaperFileUrl(coursePaper.getPaperFileUrl());
             oldCoursePaper.setAnswerFileUrl(coursePaper.getAnswerFileUrl());
             coursePaperRepository.save(oldCoursePaper);
+
+            //更新试卷试题结构
+            questionStructureService.savePaperQuestionStructure(coursePaper.getExamId(), coursePaper.getPaperId());
             return;
         }
         //否则新增

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

@@ -7,6 +7,9 @@
 
 package cn.com.qmth.examcloud.core.print.service.impl;
 
+import cn.com.qmth.examcloud.core.print.common.utils.Check;
+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.repository.ObjectiveQuestionStructureRepository;
 import cn.com.qmth.examcloud.core.print.repository.SubjectiveQuestionStructureRepository;
 import cn.com.qmth.examcloud.core.print.service.CommonService;
@@ -18,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.validation.constraints.NotNull;
+import java.util.List;
 
 /**
  * @author: fengdesheng
@@ -35,8 +39,27 @@ public class QuestionStructureServiceImpl implements QuestionStructureService {
 
     @Override
     public void savePaperQuestionStructure(@NotNull Long examId, @NotNull String paperId) {
+        Check.isNull(examId, "考试ID不能为空!");
+        Check.isEmpty(paperId, "试卷ID不能为空!");
+
+        //从题库端获取试卷的试题结构信息
         PaperQuestionStructureInfo info = commonService.findStructureByPaperId(paperId);
-        //todo
+
+        //先清理旧数据
+        objectiveQuestionStructureRepository.deleteByPaperId(examId, paperId);
+        subjectiveQuestionStructureRepository.deleteByPaperId(examId, paperId);
+
+        //保存客观题数据
+        List<ObjectiveQuestionStructure> objectives = info.getObjectives();
+        if (objectives != null && !objectives.isEmpty()) {
+            objectiveQuestionStructureRepository.save(info.getObjectives());
+        }
+
+        //保存主观题数据
+        List<SubjectiveQuestionStructure> subjectives = info.getSubjectives();
+        if (subjectives != null && !subjectives.isEmpty()) {
+            subjectiveQuestionStructureRepository.save(info.getSubjectives());
+        }
     }
 
 }