deason 6 роки тому
батько
коміт
cbaada4573

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

@@ -12,6 +12,7 @@ import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
 import cn.com.qmth.examcloud.core.print.common.utils.Check;
 import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
 import cn.com.qmth.examcloud.core.print.entity.CourseStatistic;
+import cn.com.qmth.examcloud.core.print.enums.PaperStatus;
 import cn.com.qmth.examcloud.core.print.repository.CoursePaperRepository;
 import cn.com.qmth.examcloud.core.print.repository.CourseStatisticRepository;
 import cn.com.qmth.examcloud.core.print.service.CoursePaperService;
@@ -28,7 +29,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.File;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author: fengdesheng
@@ -93,12 +94,76 @@ public class CoursePaperServiceImpl implements CoursePaperService {
             return;
         }
         statistic.setCoursePaper(coursePaper);
+        statistic.setPaperStatus(PaperStatus.已有.getIndex());
         courseStatisticRepository.save(statistic);
     }
 
+    /**
+     * 选定学校和考试后,为该考试下的所有待分配课程随机分配试卷
+     * 当题库传输过来的试卷数量不足时,会提示试卷数不足的课程名称(代码)
+     * 当题库传输过来的试卷数量≥需求时,每种试卷类型随机分配
+     * 随机分配后的“课程代码+类型”其试卷状态变为"已有"
+     * 试卷状态:已有、无、待指定三种,显示为“待指定”时,点击时弹出试卷制定框
+     */
     @Override
     public void allotAllCoursePaper(Long orgId, Long examId) {
-        //todo
+        //查询所有未指定试卷的考试课程
+        SearchBuilder searches = new SearchBuilder()
+                .eq("orgId", orgId)
+                .eq("examId", examId)
+                .eq("paperStatus", PaperStatus.未指定.getIndex());
+
+        Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
+        List<CourseStatistic> statistics = courseStatisticRepository.findAll(spec);
+        if (statistics == null || statistics.isEmpty()) {
+            log.debug("No course paper need to allot.");
+            return;
+        }
+
+        //反馈信息
+        StringBuffer msg = new StringBuffer();
+
+        //获取考试课程下的试卷列表
+        List<CoursePaper> coursePapers = this.getCoursePapers(orgId, examId);
+
+        //按课程封装试卷列表
+        Map<Long, List<CoursePaper>> maps = new HashMap<>();
+        for (CoursePaper coursePaper : coursePapers) {
+            List<CoursePaper> papers = maps.get(coursePaper.getCourseId());
+            if (papers == null) {
+                papers = new ArrayList<>();
+                maps.put(coursePaper.getCourseId(), papers);
+            }
+            papers.add(coursePaper);
+        }
+
+        //按课程随机指定试卷
+        List<CourseStatistic> needUpdateStatistics = new ArrayList<>();
+        for (CourseStatistic statistic : statistics) {
+            List<CoursePaper> papers = maps.get(statistic.getCourseId());
+            if (papers == null || papers.isEmpty()) {
+                msg.append("课程《").append(statistic.getCourseName()).append("(").append(statistic.getCourseCode()).append(")》试卷数不足!").append("\n");
+                continue;
+            }
+            Collections.shuffle(papers);
+            statistic.setCoursePaper(papers.get(0));
+            statistic.setPaperStatus(PaperStatus.已有.getIndex());
+            needUpdateStatistics.add(statistic);
+        }
+
+        //批量更新
+        if (!needUpdateStatistics.isEmpty()) {
+            courseStatisticRepository.save(needUpdateStatistics);
+        }
+        log.debug(msg.toString());
+    }
+
+    private List<CoursePaper> getCoursePapers(Long orgId, Long examId) {
+        SearchBuilder searches = new SearchBuilder();
+        searches.eq("orgId", orgId);
+        searches.eq("examId", examId);
+        Specification<CoursePaper> spec = SpecUtils.buildSearchers(CoursePaper.class, searches.build());
+        return coursePaperRepository.findAll(spec);
     }
 
     @Override

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

@@ -42,7 +42,7 @@ import java.util.List;
 public class CourseStatisticServiceImpl implements CourseStatisticService {
     private static final Logger log = LoggerFactory.getLogger(CourseStatisticServiceImpl.class);
     @Autowired
-    private CourseStatisticRepository courseStatisticsRepository;
+    private CourseStatisticRepository courseStatisticRepository;
     @Autowired
     private PrintingProjectService printingProjectService;
     @Autowired
@@ -73,7 +73,7 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         OrderBuilder orders = new OrderBuilder().desc("id");
         //分页条件
         Pageable pageable = SpecUtils.buildPageable(query.getPageNo(), query.getPageSize(), orders.build());
-        Page<CourseStatistic> page = courseStatisticsRepository.findAll(spec, pageable);
+        Page<CourseStatistic> page = courseStatisticRepository.findAll(spec, pageable);
         return CourseStatisticConvert.ofPage(page);
     }
 
@@ -133,7 +133,7 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
                 .eq("courseId", info.getCourseId())
                 .eq("paperType", info.getPaperType());
         Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
-        long total = courseStatisticsRepository.count(spec);
+        long total = courseStatisticRepository.count(spec);
         if (total > 0) {
             return true;
         }
@@ -150,12 +150,12 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         statistic.setPaperType(info.getPaperType());
         statistic.setTotalStudent(info.getTotalStudent());
         statistic.setPaperStatus(PaperStatus.无.getIndex());
-        courseStatisticsRepository.save(statistic);
+        courseStatisticRepository.save(statistic);
     }
 
     private void syncTotalStudentByOrgExamCourse(ExamCourseInfo info) {
         //仅更新total_student字段
-        courseStatisticsRepository.updateTotalStudentByOrgExamCourse(info.getOrgId(), info.getExamId(), info.getCourseId(), info.getPaperType(), info.getTotalStudent());
+        courseStatisticRepository.updateTotalStudentByOrgExamCourse(info.getOrgId(), info.getExamId(), info.getCourseId(), info.getPaperType(), info.getTotalStudent());
     }
 
     @Override
@@ -163,7 +163,7 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         if (courseId == null || StringUtils.isBlank(courseName)) {
             return;
         }
-        courseStatisticsRepository.updateCourseNameByCourseId(courseId, courseName);
+        courseStatisticRepository.updateCourseNameByCourseId(courseId, courseName);
     }
 
 }

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

@@ -29,6 +29,10 @@ public class CoursePaperServiceTest extends BaseTest {
         Long courseStatisticId = 1L;
         Long coursePaperId = 1L;
         coursePaperService.allotCoursePaper(courseStatisticId, coursePaperId);
+
+        Long orgId = 7L;
+        Long examId = 60L;
+        //coursePaperService.allotAllCoursePaper(orgId, examId);
     }