deason 6 年之前
父節點
當前提交
7fbcb16706

+ 14 - 8
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/enums/BackupGroupType.java

@@ -12,22 +12,28 @@ package cn.com.qmth.examcloud.core.print.enums;
  */
 public enum BackupGroupType {
 
-    LEARNING_CENTER("学习中心"),
+    LEARN_CENTER("学习中心"),
 
     EXAM_SITE("考点");
 
-    private String name;
+    private String title;
 
-    BackupGroupType(String name) {
-        this.name = name;
+    BackupGroupType(String title) {
+        this.title = title;
     }
 
-    public String getName() {
-        return name;
+    public static boolean isLeanCenter(BackupGroupType type) {
+        if (type == null) {
+            return false;
+        }
+        if (LEARN_CENTER.name().equals(type.name())) {
+            return true;
+        }
+        return false;
     }
 
-    public void setName(String name) {
-        this.name = name;
+    public String getTitle() {
+        return title;
     }
 
 }

+ 31 - 6
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/StatisticService.java

@@ -40,11 +40,6 @@ public interface StatisticService {
      */
     PaperQuestionStructureInfo findStructureByPaperId(Long examId, String paperId);
 
-    /**
-     * 获取考试的人科次(考生的数量)
-     */
-    int findExamTotalStudent(Long orgId, Long examId);
-
     /**
      * 获取某考试的课程和试卷类型列表
      */
@@ -53,11 +48,41 @@ public interface StatisticService {
     /**
      * 获取考试的课程数量
      */
-    int parseExamTotalCourse(List<ExamPaperTypeRelation> coursePaperTypes);
+    int countExamTotalCourse(List<ExamPaperTypeRelation> coursePaperTypes);
 
     /**
      * 获取考试的试卷袋列表
      */
     List<String> findExamPackageCodes(Long orgId, Long examId);
 
+    /**
+     * 获取考试的考点列表
+     */
+    List<String> findExamSites(Long examId);
+
+    /**
+     * 获取考试的学习中心列表
+     */
+    List<Long> findExamLearnCenters(Long examId);
+
+    /**
+     * 通过考试获取考生的数量(人科次)
+     */
+    int countExamTotalStudent(Long examId);
+
+    /**
+     * 通过试卷袋编号获取考生的数量
+     */
+    int countExamTotalStudentByPackageCode(Long examId, String packageCode);
+
+    /**
+     * 通过学习中心获取考生的数量
+     */
+    int countExamTotalStudentByLearnCenter(Long examId, Long learnCenterId);
+
+    /**
+     * 通过考点获取考生的数量
+     */
+    int countExamTotalStudentBySite(Long examId, String site);
+
 }

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

@@ -12,6 +12,7 @@ import cn.com.qmth.examcloud.core.print.common.utils.Check;
 import cn.com.qmth.examcloud.core.print.entity.PrintingProject;
 import cn.com.qmth.examcloud.core.print.entity.ProjectBackupSetting;
 import cn.com.qmth.examcloud.core.print.entity.ProjectStatistic;
+import cn.com.qmth.examcloud.core.print.enums.BackupGroupType;
 import cn.com.qmth.examcloud.core.print.repository.ProjectBackupSettingRepository;
 import cn.com.qmth.examcloud.core.print.repository.ProjectStatisticRepository;
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
@@ -116,10 +117,10 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
             ProjectBackupSetting backupSetting = projectBackupSettingRepository.findByProjectId(project.getProjectId());
 
             //人科次(考生的数量)
-            final int totalStudent = statisticService.findExamTotalStudent(project.getOrgId(), project.getExamId());
+            final int totalStudent = statisticService.countExamTotalStudent(project.getExamId());
 
             //课程数量(课程代码的数量)
-            final int totalCourse = statisticService.parseExamTotalCourse(coursePaperTypes);
+            final int totalCourse = statisticService.countExamTotalCourse(coursePaperTypes);
 
             //试卷数量(课程代码 + 试卷类型的数量)
             final int totalPaper = coursePaperTypes.size();
@@ -134,7 +135,7 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
             final int normalA4 = totalPkg * 4;
 
             //备份-A3数量(每袋冗余数 + 单独备份袋数)
-            final int backupA3 = this.parseBackupA3(backupSetting);
+            final int backupA3 = this.parseBackupA3(backupSetting, packageCodes, project.getExamId());
 
             //备份-A4数量(试卷袋数 * 2)
             final int backupA4 = totalPkg * 2;
@@ -165,7 +166,7 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
         return sumPaperA3 + (totalStudent * 2);
     }
 
-    private int parseBackupA3(ProjectBackupSetting backupSetting) {
+    private int parseBackupA3(ProjectBackupSetting backupSetting, List<String> packageCodes, Long examId) {
         if (backupSetting == null) {
             return 0;
         }
@@ -178,15 +179,55 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
 
         if (backupSetting.getNeedEachPkg()) {
             //备份A3 = ∑n 试卷袋(X考生 * P%备份比例) * 2
-
+            int eachTotal = 0;
+            for (String packageCode : packageCodes) {
+                eachTotal += statisticService.countExamTotalStudentByPackageCode(examId, packageCode);
+            }
+            sumA3 += (eachTotal * 2);
         }
 
         if (backupSetting.getNeedAlonePkg()) {
             //备份A3 = ∑n 学习中心或考点(X考生 * P%备份比例) * 2
+            int aloneTotal = 0;
+
+            if (BackupGroupType.isLeanCenter(backupSetting.getGroupType())) {
+                //备份比例:高于最大取最大;低于最小则取最小
+                Double percent = backupSetting.getEachPkgPercent();
+                if (percent > backupSetting.getEachPkgMax()) {
+                    percent = backupSetting.getEachPkgMax();
+                }
+                if (percent < backupSetting.getEachPkgMin()) {
+                    percent = backupSetting.getEachPkgMin();
+                }
+
+                //计算每个学习中心的备份数
+                List<Long> learnCenters = statisticService.findExamLearnCenters(examId);
+                for (Long learnCenterId : learnCenters) {
+                    int count = statisticService.countExamTotalStudentByLearnCenter(examId, learnCenterId);
+                    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) {
+                    int count = statisticService.countExamTotalStudentBySite(examId, siteId);
+                    aloneTotal += Math.ceil((count * percent) / 100);
+                }
+            }
 
+            sumA3 += (aloneTotal * 2);
         }
 
-        return 0;
+        return sumA3;
     }
 
 }

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

@@ -16,8 +16,10 @@ import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
 import cn.com.qmth.examcloud.examwork.api.bean.ExamPaperTypeRelation;
 import cn.com.qmth.examcloud.examwork.api.request.CountExamStudentReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamCoursePaperTypeListReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamOrgListReq;
 import cn.com.qmth.examcloud.examwork.api.response.CountExamStudentResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamCoursePaperTypeListResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamOrgListResp;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -88,14 +90,6 @@ public class StatisticServiceImpl implements StatisticService {
         return info;
     }
 
-    @Override
-    public int findExamTotalStudent(Long orgId, Long examId) {
-        CountExamStudentReq req = new CountExamStudentReq();
-        req.setExamId(examId);
-        CountExamStudentResp resp = examCloudService.countExamStudent(req);
-        return resp.getCount().intValue();
-    }
-
     public List<ExamPaperTypeRelation> findExamCourseAndPaperTypes(Long orgId, Long examId) {
         //获取某考试的课程和试卷类型列表
         List<ExamPaperTypeRelation> coursePaperTypes = new ArrayList<>();
@@ -121,7 +115,7 @@ public class StatisticServiceImpl implements StatisticService {
     }
 
     @Override
-    public int parseExamTotalCourse(List<ExamPaperTypeRelation> coursePaperTypes) {
+    public int countExamTotalCourse(List<ExamPaperTypeRelation> coursePaperTypes) {
         //获取实际课程数量
         Set<Long> ids = new HashSet<>();
         for (ExamPaperTypeRelation relation : coursePaperTypes) {
@@ -136,4 +130,86 @@ public class StatisticServiceImpl implements StatisticService {
         return Lists.newArrayList("abc");
     }
 
+    @Override
+    public List<String> findExamSites(Long examId) {
+        List<String> sites = new ArrayList<>();
+        GetExamOrgListReq req = new GetExamOrgListReq();
+        req.setExamId(examId);
+        Long start = 0L;
+        while (true) {
+            req.setStart(start);
+            GetExamOrgListResp resp = examCloudService.getExamOrgList(req);
+            List<Long> list = resp.getOrgIdList();
+            if (list == null || list.isEmpty()) {
+                break;
+            }
+            //sites.addAll(list);
+            if (start.equals(resp.getNext())) {
+                break;
+            } else {
+                start = resp.getNext();
+            }
+        }
+        return sites;
+    }
+
+    @Override
+    public List<Long> findExamLearnCenters(Long examId) {
+        List<Long> ids = new ArrayList<>();
+        GetExamOrgListReq req = new GetExamOrgListReq();
+        req.setExamId(examId);
+        Long start = 0L;
+        while (true) {
+            req.setStart(start);
+            GetExamOrgListResp resp = examCloudService.getExamOrgList(req);
+            List<Long> list = resp.getOrgIdList();
+            if (list == null || list.isEmpty()) {
+                break;
+            }
+            ids.addAll(list);
+            if (start.equals(resp.getNext())) {
+                break;
+            } else {
+                start = resp.getNext();
+            }
+        }
+        return ids;
+    }
+
+    @Override
+    public int countExamTotalStudent(Long examId) {
+        CountExamStudentReq req = new CountExamStudentReq();
+        req.setExamId(examId);
+        return this.countExamTotalStudent(req);
+    }
+
+    @Override
+    public int countExamTotalStudentByPackageCode(Long examId, String packageCode) {
+        CountExamStudentReq req = new CountExamStudentReq();
+        req.setExamId(examId);
+        //todo
+        return this.countExamTotalStudent(req);
+    }
+
+    @Override
+    public int countExamTotalStudentByLearnCenter(Long examId, Long learnCenterId) {
+        CountExamStudentReq req = new CountExamStudentReq();
+        req.setExamId(examId);
+        req.setOrgId(learnCenterId);
+        return this.countExamTotalStudent(req);
+    }
+
+    @Override
+    public int countExamTotalStudentBySite(Long examId, String site) {
+        CountExamStudentReq req = new CountExamStudentReq();
+        req.setExamId(examId);
+        req.setExamSite(site);
+        return this.countExamTotalStudent(req);
+    }
+
+    private int countExamTotalStudent(CountExamStudentReq req) {
+        CountExamStudentResp resp = examCloudService.countExamStudent(req);
+        return resp.getCount().intValue();
+    }
+
 }