|
@@ -221,45 +221,64 @@ public class CoursePaperServiceImpl implements CoursePaperService {
|
|
|
//查询所有未指定试卷的考试课程
|
|
|
SearchBuilder searches = new SearchBuilder()
|
|
|
.eq("orgId", orgId)
|
|
|
- .eq("examId", examId)
|
|
|
- .eq("paperStatus", PaperStatus.未指定.getIndex());
|
|
|
+ .eq("examId", examId);
|
|
|
|
|
|
Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
|
|
|
- List<CourseStatistic> statistics = courseStatisticRepository.findAll(spec);
|
|
|
- if (statistics == null || statistics.isEmpty()) {
|
|
|
+ List<CourseStatistic> courseStatistics = courseStatisticRepository.findAll(spec);
|
|
|
+ if (courseStatistics == null || courseStatistics.isEmpty()) {
|
|
|
log.warn("No course paper need to allot.");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
//反馈信息
|
|
|
StringBuilder errors = new StringBuilder();
|
|
|
|
|
|
//获取考试课程下的试卷列表
|
|
|
List<CoursePaper> coursePapers = this.getCoursePapers(orgId, examId);
|
|
|
|
|
|
- //按课程封装试卷列表 Map<courseId, List<CoursePaper>>
|
|
|
- Map<Long, List<CoursePaper>> maps = new HashMap<>();
|
|
|
+ //按课程封装课程试卷列表 Map<courseId, List<CoursePaper>>
|
|
|
+ Map<Long, List<CoursePaper>> paperMaps = new HashMap<>();
|
|
|
for (CoursePaper coursePaper : coursePapers) {
|
|
|
- List<CoursePaper> papers = maps.get(coursePaper.getCourseId());
|
|
|
- if (papers == null) {
|
|
|
- papers = new ArrayList<>();
|
|
|
- maps.put(coursePaper.getCourseId(), papers);
|
|
|
+ List<CoursePaper> list = paperMaps.get(coursePaper.getCourseId());
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ paperMaps.put(coursePaper.getCourseId(), list);
|
|
|
+ }
|
|
|
+ list.add(coursePaper);
|
|
|
+ }
|
|
|
+
|
|
|
+ //按课程封装课程统计列表 Map<courseId, List<CourseStatistic>>
|
|
|
+ Map<Long, List<CourseStatistic>> courseMaps = new HashMap<>();
|
|
|
+ for (CourseStatistic statistic : courseStatistics) {
|
|
|
+ List<CourseStatistic> list = courseMaps.get(statistic.getCourseId());
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ courseMaps.put(statistic.getCourseId(), list);
|
|
|
}
|
|
|
- papers.add(coursePaper);
|
|
|
+ list.add(statistic);
|
|
|
}
|
|
|
|
|
|
- //按课程随机指定试卷
|
|
|
+ //按课程指定试卷
|
|
|
List<CourseStatistic> needUpdateStatistics = new ArrayList<>();
|
|
|
- for (CourseStatistic statistic : statistics) {
|
|
|
- List<CoursePaper> papers = maps.get(statistic.getCourseId());
|
|
|
- if (papers == null || papers.isEmpty()) {
|
|
|
- errors.append(String.format("《%s(%s)》", statistic.getCourseName(), statistic.getCourseCode()));
|
|
|
+ for (Map.Entry<Long, List<CourseStatistic>> entry : courseMaps.entrySet()) {
|
|
|
+ List<CoursePaper> papers = paperMaps.get(entry.getKey());
|
|
|
+ List<CourseStatistic> statistics = entry.getValue();
|
|
|
+ if (papers == null || papers.size() < statistics.size()) {
|
|
|
+ //当题库传输过来的试卷数量不足时,会提示试卷数不足的课程名称(代码)
|
|
|
+ errors.append(String.format("《%s(%s)》", statistics.get(0).getCourseName(), statistics.get(0).getCourseCode()));
|
|
|
continue;
|
|
|
}
|
|
|
- Collections.shuffle(papers);
|
|
|
- statistic.setCoursePaper(papers.get(0));
|
|
|
- statistic.setPaperStatus(PaperStatus.已有.getIndex());
|
|
|
- needUpdateStatistics.add(statistic);
|
|
|
+
|
|
|
+ //当题库传输过来的试卷数量≥需求时,每种试卷类型随机分配
|
|
|
+ for (CourseStatistic statistic : statistics) {
|
|
|
+ if (PaperStatus.已有.getIndex() == statistic.getPaperStatus()) {
|
|
|
+ //跳过已分配的
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Collections.shuffle(papers);
|
|
|
+ statistic.setCoursePaper(papers.get(0));
|
|
|
+ statistic.setPaperStatus(PaperStatus.已有.getIndex());
|
|
|
+ needUpdateStatistics.add(statistic);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//批量更新
|