deason 6 gadi atpakaļ
vecāks
revīzija
e21ea0535c

+ 1 - 1
examcloud-core-print-dao/src/main/resources/db-schema.sql

@@ -27,7 +27,7 @@ CREATE TABLE ec_prt_course_paper (
   paper_p         int(11)             DEFAULT NULL,
   paper_pdf_url   varchar(255)        DEFAULT NULL,
   PRIMARY KEY (id),
-  UNIQUE KEY INDEX_PRT_COURSE_PAPER_03 (paper_id),
+  UNIQUE KEY INDEX_PRT_COURSE_PAPER_03 (examId, paper_id),
   KEY INDEX_PRT_COURSE_PAPER_01 (org_id),
   KEY INDEX_PRT_COURSE_PAPER_02 (exam_id)
 )

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

@@ -150,7 +150,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         //保存或更新试卷试题结构
         examQuestionStructureService.savePaperQuestionStructure(coursePaper.getExamId(), coursePaper.getPaperId());
 
-        //如果当前考试课程"只有一种试卷类型"且"未分配试卷",则默认分配该试卷
+        //如果当前考试课程"只有一种试卷类型"且"未分配试卷",则默认分配一次该试卷,已分配过则跳过分配
         SearchBuilder searches = new SearchBuilder()
                 .eq("orgId", coursePaper.getOrgId())
                 .eq("examId", coursePaper.getExamId())
@@ -161,21 +161,32 @@ public class CoursePaperServiceImpl implements CoursePaperService {
             return;
         }
 
+        if (statistics.size() == 1) {
+            //只有一种试卷类型,则默认分配
+            CourseStatistic statistic = statistics.get(0);
+            if (PaperStatus.已有.getIndex() != statistic.getPaperStatus()) {
+                statistic.setCoursePaper(coursePaper);
+                statistic.setPaperStatus(PaperStatus.已有.getIndex());
+                courseStatisticRepository.save(statistic);
+            }
+            return;
+        }
+
+        List<CourseStatistic> updateStatistics = new ArrayList<>();
         for (CourseStatistic statistic : statistics) {
             if (PaperStatus.已有.getIndex() == statistic.getPaperStatus()) {
                 //跳过已分配的
                 continue;
             }
-            if (statistics.size() == 1) {
-                //只有一种试卷类型,则默认分配
-                statistic.setCoursePaper(coursePaper);
-                statistic.setPaperStatus(PaperStatus.已有.getIndex());
-                break;
-            }
             //否则,分配状态改为"未指定"
             statistic.setPaperStatus(PaperStatus.未指定.getIndex());
+            updateStatistics.add(statistic);
+        }
+
+        //批量更新
+        if (updateStatistics.size() > 0) {
+            courseStatisticRepository.save(updateStatistics);
         }
-        courseStatisticRepository.save(statistics);
     }
 
     @Transactional

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

@@ -113,13 +113,16 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         Check.isNull(req.getExamId(), "考试ID不能为空!");
 
         //待刷新的课程列表
-        List<ExamCourseInfo> examCourses = null;
+        List<ExamCourseInfo> examCourses;
 
+        boolean needClear = false;//是否清除多余课程
         List<CourseStatisticRefreshReq.Course> courses = req.getCourses();
         if (courses == null || courses.size() == 0) {
             //未选择课程时,则统计当前考试下的所有课程
             examCourses = statisticService.findExamCourseAndPaperTypes(req.getOrgId(), req.getExamId());
+            needClear = true;
         } else {
+            //否则,统计已选择的课程
             examCourses = new ArrayList<>();
             for (CourseStatisticRefreshReq.Course course : courses) {
                 if (course.getCourseId() == null || StringUtils.isBlank(course.getPaperType())) {
@@ -131,7 +134,7 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
 
         //获取当前考试下已有的课程统计信息
         Map<String, CourseStatistic> oldCourseStatisticMaps = this.getCourseStatisticMaps(req.getOrgId(), req.getExamId());
-        this.syncCourseStatistics(examCourses, oldCourseStatisticMaps);
+        this.syncCourseStatistics(examCourses, oldCourseStatisticMaps, needClear);
     }
 
     @Override
@@ -151,11 +154,11 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
             //获取某考试的课程和试卷类型列表
             List<ExamCourseInfo> examCourses = statisticService.findExamCourseAndPaperTypes(exam.getOrgId(), exam.getExamId());
 
-            this.syncCourseStatistics(examCourses, oldCourseStatisticMaps);
+            this.syncCourseStatistics(examCourses, oldCourseStatisticMaps, true);
         }
     }
 
-    private void syncCourseStatistics(List<ExamCourseInfo> examCourses, Map<String, CourseStatistic> oldCourseStatisticMaps) {
+    private void syncCourseStatistics(List<ExamCourseInfo> examCourses, Map<String, CourseStatistic> oldCourseStatisticMaps, boolean needClear) {
         if (examCourses == null || examCourses.isEmpty()) {
             return;
         }
@@ -192,7 +195,7 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         }
 
         //清除已不存在的考试课程
-        if (oldCourseStatisticMaps.size() > 0) {
+        if (needClear && oldCourseStatisticMaps.size() > 0) {
             courseStatisticRepository.delete(oldCourseStatisticMaps.values());
         }
     }

+ 42 - 28
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/PrintingProjectStatisticServiceImpl.java

@@ -32,7 +32,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
 
@@ -138,11 +140,14 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
             //常规-A4数量(试卷袋数 * 4)
             final int normalA4 = totalPkg * 4;
 
+            //统计备份A3、A4数
+            Map<String, Integer> backupMaps = this.parseBackupA3A4(backupSetting, packageCodes, project.getExamId());
+
             //备份-A3数量(每袋冗余数 + 单独备份袋数)
-            final int backupA3 = this.parseBackupA3(backupSetting, packageCodes, project.getExamId());
+            final int backupA3 = backupMaps.get("backupA3");
 
             //备份-A4数量(试卷袋数 * 2)
-            final int backupA4 = totalPkg * 2;
+            final int backupA4 = backupMaps.get("backupA4");
 
             statistic.setTotalStudent(totalStudent);
             statistic.setTotalCourse(totalCourse);
@@ -170,40 +175,56 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
         return sumPaperA3 + (totalStudent * 2);
     }
 
-    private int parseBackupA3(ProjectBackupSetting backupSetting, List<String> packageCodes, Long examId) {
+    private Map<String, Integer> parseBackupA3A4(ProjectBackupSetting backupSetting, List<String> packageCodes, Long examId) {
+        Map<String, Integer> backupMaps = new HashMap<>();
+        backupMaps.put("backupA3", 0);
+        backupMaps.put("backupA4", 0);
+
         if (backupSetting == null) {
-            return 0;
+            return backupMaps;
         }
 
         if (!backupSetting.getNeedEachPkg() && !backupSetting.getNeedAlonePkg()) {
-            return 0;
+            return backupMaps;
         }
 
-        int sumA3 = 0;
+        int backupA3 = 0, backupA4 = 0;
 
         if (backupSetting.getNeedEachPkg()) {
             //备份A3 = ∑n 试卷袋(X考生 * P%备份比例) * 2
             int eachTotal = 0;
+
+            Double percent = backupSetting.getEachPkgPercent();//备份比例:高于最大取最大;低于最小则取最小
+            if (percent > backupSetting.getEachPkgMax()) {
+                percent = backupSetting.getEachPkgMax();
+            }
+            if (percent < backupSetting.getEachPkgMin()) {
+                percent = backupSetting.getEachPkgMin();
+            }
+
             for (String packageCode : packageCodes) {
-                eachTotal += statisticService.countExamTotalStudentByPackageCode(examId, packageCode);
+                int count = statisticService.countExamTotalStudentByPackageCode(examId, packageCode);
+                eachTotal += Math.ceil((count * percent) / 100);
             }
-            sumA3 += (eachTotal * 2);
+            backupA3 += (eachTotal * 2);
         }
 
         if (backupSetting.getNeedAlonePkg()) {
+            //备份-A4数量:只有单独备份袋设置才计算,默认不用算
+            backupA4 = packageCodes.size() * 2;
+
             //备份A3 = ∑n 学习中心或考点(X考生 * P%备份比例) * 2
             int aloneTotal = 0;
 
-            if (BackupGroupType.isLeanCenter(backupSetting.getGroupType())) {
-                //备份比例:高于最大取最大;低于最小则取最小
-                Double percent = backupSetting.getAlonePkgPercent();
-                if (percent > backupSetting.getAlonePkgMax()) {
-                    percent = backupSetting.getAlonePkgMin();
-                }
-                if (percent < backupSetting.getAlonePkgMin()) {
-                    percent = backupSetting.getAlonePkgMin();
-                }
+            Double percent = backupSetting.getAlonePkgPercent();//备份比例:高于最大取最大;低于最小则取最小
+            if (percent > backupSetting.getAlonePkgMax()) {
+                percent = backupSetting.getAlonePkgMax();
+            }
+            if (percent < backupSetting.getAlonePkgMin()) {
+                percent = backupSetting.getAlonePkgMin();
+            }
 
+            if (BackupGroupType.isLeanCenter(backupSetting.getGroupType())) {
                 //计算每个学习中心的备份数
                 List<Long> learnCenters = statisticService.findExamLearnCenters(examId);
                 for (Long learnCenterId : learnCenters) {
@@ -211,15 +232,6 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
                     aloneTotal += Math.ceil((count * percent) / 100);
                 }
             } else {
-                //备份比例:高于最大取最大;低于最小则取最小
-                Double percent = backupSetting.getAlonePkgPercent();
-                if (percent > backupSetting.getAlonePkgMax()) {
-                    percent = backupSetting.getAlonePkgMax();
-                }
-                if (percent < backupSetting.getAlonePkgMin()) {
-                    percent = backupSetting.getAlonePkgMin();
-                }
-
                 //计算每个考点的备份数
                 List<String> siteIds = statisticService.findExamSites(examId);
                 for (String siteId : siteIds) {
@@ -228,10 +240,12 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
                 }
             }
 
-            sumA3 += (aloneTotal * 2);
+            backupA3 += (aloneTotal * 2);
         }
 
-        return sumA3;
+        backupMaps.put("backupA3", backupA3);
+        backupMaps.put("backupA4", backupA4);
+        return backupMaps;
     }
 
 }