deason 6 년 전
부모
커밋
f91119ac01

+ 21 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/StatisticService.java

@@ -10,6 +10,7 @@ package cn.com.qmth.examcloud.core.print.service;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamCourseInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.questionstructure.PaperQuestionStructureInfo;
+import cn.com.qmth.examcloud.examwork.api.bean.ExamPaperTypeRelation;
 
 import java.util.List;
 
@@ -39,4 +40,24 @@ public interface StatisticService {
      */
     PaperQuestionStructureInfo findStructureByPaperId(Long examId, String paperId);
 
+    /**
+     * 获取某考试的课程和试卷类型列表
+     */
+    List<ExamPaperTypeRelation> findExamCourseAndPaperTypes(Long orgId, Long examId);
+
+    /**
+     * 获取试卷袋列表
+     */
+    List<String> findExamPackageCodes(Long orgId, Long examId);
+
+    /**
+     * 获取人科次
+     */
+    int getTotalStudent(Long orgId, Long examId);
+
+    /**
+     * 获取课程数量
+     */
+    int getTotalCourse(List<ExamPaperTypeRelation> coursePaperTypes);
+
 }

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

@@ -12,19 +12,18 @@ 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.ProjectStatistic;
 import cn.com.qmth.examcloud.core.print.repository.ProjectStatisticRepository;
-import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
-import cn.com.qmth.examcloud.core.print.service.PrintingProjectService;
-import cn.com.qmth.examcloud.core.print.service.PrintingProjectStatisticService;
-import cn.com.qmth.examcloud.core.print.service.ProjectBackupSettingService;
+import cn.com.qmth.examcloud.core.print.service.*;
 import cn.com.qmth.examcloud.core.print.service.bean.printingproject.PrintingProjectLessInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.printingprojectstatistic.PrintingProjectStatisticConvert;
 import cn.com.qmth.examcloud.core.print.service.bean.printingprojectstatistic.PrintingProjectStatisticInfo;
+import cn.com.qmth.examcloud.examwork.api.bean.ExamPaperTypeRelation;
 import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
@@ -44,6 +43,8 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
     private CourseStatisticService courseStatisticService;
     @Autowired
     private ProjectBackupSettingService projectBackupSettingService;
+    @Autowired
+    private StatisticService statisticService;
 
     @Override
     public PrintingProjectStatisticInfo getPrintingProjectStatistic(Long orgId, Long examId) {
@@ -87,50 +88,55 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
             return;
         }
 
+        List<ProjectStatistic> statistics = new ArrayList<>();
         for (PrintingProjectLessInfo project : projects) {
             ProjectStatistic statistic = projectStatisticRepository.getProjectStatisticByProjectId(project.getProjectId());
             if (statistic == null) {
                 statistic = new ProjectStatistic();
                 statistic.setProjectId(project.getProjectId());
             }
-            //人科次
-            int totalStudent = this.calculateTotalStudent(project.getOrgId(), project.getExamId());
-
-            //课程数量
-            int totalCourse = this.calculateTotalCourse(project.getOrgId(), project.getExamId());
 
-            //试卷数量
-            int totalPaper = this.calculateTotalPaper(project.getOrgId(), project.getExamId());
+            //获取某考试的课程和试卷类型列表
+            List<ExamPaperTypeRelation> coursePaperTypes = statisticService.findExamCourseAndPaperTypes(project.getOrgId(), project.getExamId());
 
-            //试卷袋数量
-            int totalPkg = this.calculateTotalPkg(project.getOrgId(), project.getExamId());
+            //获取试卷袋列表
+            List<String> packageCodes = statisticService.findExamPackageCodes(project.getOrgId(), project.getExamId());
 
-            //常规-A3数量
+            //人科次(考生的数量)
+            final int totalStudent = statisticService.getTotalStudent(project.getOrgId(), project.getExamId());
 
-            //常规-A4数量
+            //课程数量(课程代码的数量)
+            final int totalCourse = statisticService.getTotalCourse(coursePaperTypes);
 
-            //projectBackupSettingService
-            //备份-A3数量
-
-            //备份-A4数量
-            //Double ceil = Math.ceil(getNormalA4() / 2.0);
-        }
-    }
+            //试卷数量(课程代码 + 试卷类型的数量)
+            final int totalPaper = coursePaperTypes.size();
 
-    private int calculateTotalStudent(Long orgId, Long examId) {
-        return 0;
-    }
+            //试卷袋数量
+            final int totalPkg = packageCodes.size();
 
-    private int calculateTotalCourse(Long orgId, Long examId) {
-        return 0;
-    }
+            //常规-A3数量(总试卷A3数 + 总答题卡A3数)
+            final int normalA3 = 0;//todo
 
-    private int calculateTotalPaper(Long orgId, Long examId) {
-        return 0;
-    }
+            //常规-A4数量(试卷袋数 * 4)
+            final int normalA4 = totalPkg * 4;
 
-    private int calculateTotalPkg(Long orgId, Long examId) {
-        return 0;
+            //备份-A3数量
+            final int backupA3 = 0;//todo
+
+            //备份-A4数量(试卷袋数 * 2)
+            final int backupA4 = totalPkg * 2;
+
+            statistic.setTotalStudent(totalStudent);
+            statistic.setTotalCourse(totalCourse);
+            statistic.setTotalPaper(totalPaper);
+            statistic.setTotalPkg(totalPkg);
+            statistic.setNormalA3(normalA3);
+            statistic.setNormalA4(normalA4);
+            statistic.setBackupA3(backupA3);
+            statistic.setBackupA4(backupA4);
+            statistics.add(statistic);
+        }
+        projectStatisticRepository.save(statistics);
     }
 
 }

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

@@ -13,6 +13,12 @@ import cn.com.qmth.examcloud.core.print.service.bean.common.ExamCourseInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.questionstructure.PaperQuestionStructureInfo;
 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.response.CountExamStudentResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamCoursePaperTypeListResp;
+import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -21,7 +27,10 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * @author: fengdesheng
@@ -79,4 +88,52 @@ public class StatisticServiceImpl implements StatisticService {
         return info;
     }
 
+    public List<ExamPaperTypeRelation> findExamCourseAndPaperTypes(Long orgId, Long examId) {
+        //获取某考试的课程和试卷类型列表
+        List<ExamPaperTypeRelation> coursePaperTypes = new ArrayList<>();
+        GetExamCoursePaperTypeListReq req = new GetExamCoursePaperTypeListReq();
+        req.setRootOrgId(orgId);
+        req.setExamId(examId);
+        Long start = 0L;
+        while (true) {
+            req.setStart(start);
+            GetExamCoursePaperTypeListResp resp = examCloudService.getExamCoursePaperTypeList(req);
+            List<ExamPaperTypeRelation> list = resp.getRelationList();
+            if (list == null || list.isEmpty()) {
+                break;
+            }
+            coursePaperTypes.addAll(list);
+            if (start.equals(resp.getNext())) {
+                break;
+            } else {
+                start = resp.getNext();
+            }
+        }
+        return coursePaperTypes;
+    }
+
+    @Override
+    public List<String> findExamPackageCodes(Long orgId, Long examId) {
+        //todo
+        return Lists.newArrayList("abc");
+    }
+
+    @Override
+    public int getTotalStudent(Long orgId, Long examId) {
+        CountExamStudentReq req = new CountExamStudentReq();
+        req.setExamId(examId);
+        CountExamStudentResp resp = examCloudService.countExamStudent(req);
+        return resp.getCount().intValue();
+    }
+
+    @Override
+    public int getTotalCourse(List<ExamPaperTypeRelation> coursePaperTypes) {
+        //获取实际课程数量
+        Set<Long> ids = new HashSet<>();
+        for (ExamPaperTypeRelation relation : coursePaperTypes) {
+            ids.add(relation.getCourseId());
+        }
+        return ids.size();
+    }
+
 }

+ 2 - 1
examcloud-core-print-starter/src/main/resources/logback-spring.xml

@@ -34,7 +34,7 @@
         </rollingPolicy>
     </appender>
 
-    <logger name="INTERFACE_LOGGER" level="DEBUG" additivity="false">
+    <logger name="INTERFACE_LOGGER" level="WARN" additivity="false">
         <appender-ref ref="INTERFACE_APPENDER"/>
         <appender-ref ref="STDOUT"/>
     </logger>
@@ -52,6 +52,7 @@
     <logger name="com.netflix.discovery" level="WARN"/>
     <logger name="springfox.documentation" level="WARN"/>
     <logger name="cn.afterturn.easypoi" level="WARN"/>
+    <logger name="com.netflix" level="WARN"/>
     <logger name="cn.com.qmth.examcloud.commons" level="INFO"/>
 
     <root level="DEBUG">

+ 4 - 4
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/ProjectStatisticServiceTest.java

@@ -30,10 +30,10 @@ public class ProjectStatisticServiceTest extends BaseTest {
 
     @Test
     public void initPrintingProjectStatisticTest() throws Exception {
-        Long orgId = 1L;
-        Long examId = 1L;
-        //printingProjectStatisticService.refreshPrintingProjectStatistic(orgId, examId);
-        printingProjectStatisticService.initAllPrintingProjectStatistic();
+        Long orgId = 27L;
+        Long examId = 70L;
+        printingProjectStatisticService.refreshPrintingProjectStatistic(orgId, examId);
+        //printingProjectStatisticService.initAllPrintingProjectStatistic();
     }
 
 }