deason 6 жил өмнө
parent
commit
05892c5c61

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

@@ -7,6 +7,7 @@
 
 
 package cn.com.qmth.examcloud.core.print.service.impl;
 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.SearchBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
 import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
 import cn.com.qmth.examcloud.core.print.common.upyun.SystemProperty;
 import cn.com.qmth.examcloud.core.print.common.upyun.SystemProperty;
@@ -279,10 +280,12 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         List<CourseStatistic> courseStatistics = courseStatisticRepository.findAll(spec);
         List<CourseStatistic> courseStatistics = courseStatisticRepository.findAll(spec);
         if (courseStatistics == null || courseStatistics.isEmpty()) {
         if (courseStatistics == null || courseStatistics.isEmpty()) {
             log.warn("No course paper need to allot.");
             log.warn("No course paper need to allot.");
-            return;
+            String msg = String.format("当前考试下暂无需要分配的课程!");
+            throw new StatusException(SYS_CODE_500, msg);
         }
         }
+
         //反馈信息
         //反馈信息
-        StringBuilder errors = new StringBuilder();
+        Set<Long> errorCourses = new HashSet<>();
 
 
         //获取考试课程下的已转换PDF的试卷列表
         //获取考试课程下的已转换PDF的试卷列表
         List<CoursePaper> coursePapers = this.getCoursePapers(orgId, examId, true);
         List<CoursePaper> coursePapers = this.getCoursePapers(orgId, examId, true);
@@ -314,9 +317,11 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         for (Map.Entry<Long, List<CourseStatistic>> entry : courseMaps.entrySet()) {
         for (Map.Entry<Long, List<CourseStatistic>> entry : courseMaps.entrySet()) {
             List<CoursePaper> papers = paperMaps.get(entry.getKey());
             List<CoursePaper> papers = paperMaps.get(entry.getKey());
             List<CourseStatistic> statistics = entry.getValue();
             List<CourseStatistic> statistics = entry.getValue();
+
+            //当题库传输过来的试卷数量不足时,提示试卷数不足的课程
             if (papers == null || papers.size() < statistics.size()) {
             if (papers == null || papers.size() < statistics.size()) {
-                //当题库传输过来的试卷数量不足时,会提示试卷数不足的课程名称(代码)
-                errors.append(String.format("《%s(%s)》", statistics.get(0).getCourseName(), statistics.get(0).getCourseCode()));
+                //记录错误数
+                errorCourses.add(entry.getKey());
                 continue;
                 continue;
             }
             }
 
 
@@ -326,6 +331,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
                     //跳过已分配的
                     //跳过已分配的
                     continue;
                     continue;
                 }
                 }
+
                 Collections.shuffle(papers);
                 Collections.shuffle(papers);
                 statistic.setCoursePaper(papers.get(0));
                 statistic.setCoursePaper(papers.get(0));
                 statistic.setPaperStatus(PaperStatus.已有.getIndex());
                 statistic.setPaperStatus(PaperStatus.已有.getIndex());
@@ -339,10 +345,9 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         }
         }
 
 
         //试卷不足时,反馈给前端
         //试卷不足时,反馈给前端
-        if (errors.length() > 0) {
-            errors.append("等课程的试卷数不足!");
-            log.debug(errors.toString());
-            //throw new StatusException(SYS_CODE_500, errors.toString());
+        if (errorCourses.size() > 0) {
+            String msg = String.format("当前考试下共%s门课程,其中有%s门课程的试卷数不足!", courseMaps.size(), errorCourses.size());
+            throw new StatusException(SYS_CODE_500, msg);
         }
         }
     }
     }