|
@@ -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
|