|
@@ -20,8 +20,6 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -48,7 +46,7 @@ public class TrainingExamPaperServiceImpl extends ServiceImpl<ExamPaperDao, Exam
|
|
|
public static final Long ZERO= 0L;
|
|
|
|
|
|
@Override
|
|
|
- public R saveOrUpdate(TrainingPaperVo vo) {
|
|
|
+ public R questionCheck(TrainingPaperVo vo) {
|
|
|
// 固定题目
|
|
|
List<PaperSubjectAssignDo> paperSubjectAssignDos = vo.getPapersubjectassigndos();
|
|
|
// 随机题目
|
|
@@ -56,35 +54,44 @@ public class TrainingExamPaperServiceImpl extends ServiceImpl<ExamPaperDao, Exam
|
|
|
logger.info("固定题目信息: {}", paperSubjectAssignDos);
|
|
|
logger.info("随机题目信息: {}", paperSubjectAutoDos);
|
|
|
// 当随机题目不为空时
|
|
|
- if (paperSubjectAutoDos != null && !paperSubjectAutoDos.isEmpty()) {
|
|
|
- // 存放考题类型和所需要的题目数量
|
|
|
- Map<String, Long> subjectTypeAndNum = paperSubjectAutoDos.stream().collect(Collectors.groupingBy(info -> info.getSubjecttype(), Collectors.counting()));
|
|
|
- if (paperSubjectAssignDos != null && !paperSubjectAssignDos.isEmpty()) {
|
|
|
- Map<String, Long> collect = paperSubjectAssignDos.stream().collect(Collectors.groupingBy(info -> info.getSubjecttype(), Collectors.counting()));
|
|
|
- collect.forEach((key, value) -> subjectTypeAndNum.merge(key, value,(prev, one) -> prev + one ));
|
|
|
- }
|
|
|
- // 获取课程Id
|
|
|
- List<String> courseThemeId = paperSubjectAutoDos.stream().map(PaperSubjectAutoDo::getCoursethemeid).collect(Collectors.toList());
|
|
|
- // 获取随机题目中课程主题的所有题目信息
|
|
|
- List<SubjectDo> subjectDoList = subjectDao.selectInfoByCourseIds(courseThemeId);
|
|
|
- // 获取所有课程主题下 各类型题目的数量
|
|
|
- Map<String, Long> subjectMap = subjectDoList.stream().collect(Collectors.groupingBy(info -> info.getSubjecttype(), Collectors.counting()));
|
|
|
-
|
|
|
- for (Map.Entry<String, Long> entry : subjectTypeAndNum.entrySet()) {
|
|
|
- String k = entry.getKey();
|
|
|
- Long v = entry.getValue();
|
|
|
- if (v > subjectMap.getOrDefault(k, ZERO)) {
|
|
|
- return R.errorWithMsg("题目数量不够");
|
|
|
- }
|
|
|
- }
|
|
|
+ if (paperSubjectAutoDos == null || paperSubjectAutoDos.isEmpty()) {
|
|
|
+ return R.saveOk();
|
|
|
+ }
|
|
|
+ // 存放考题类型和所需要的题目数量
|
|
|
+ Map<String, Long> subjectTypeAndNum = paperSubjectAutoDos.stream().collect(Collectors.groupingBy(info -> info.getSubjecttype(), Collectors.counting()));
|
|
|
+ if (paperSubjectAssignDos != null && !paperSubjectAssignDos.isEmpty()) {
|
|
|
+ Map<String, Long> collect = paperSubjectAssignDos.stream().collect(Collectors.groupingBy(info -> info.getSubjecttype(), Collectors.counting()));
|
|
|
+ collect.forEach((key, value) -> subjectTypeAndNum.merge(key, value, (prev, one) -> prev + one));
|
|
|
+ }
|
|
|
+ // 获取课程Id
|
|
|
+ List<String> courseThemeId = paperSubjectAutoDos.stream().map(PaperSubjectAutoDo::getCoursethemeid).collect(Collectors.toList());
|
|
|
+ // 获取随机题目中课程主题的所有题目信息
|
|
|
+ List<SubjectDo> subjectDoList = subjectDao.selectInfoByCourseIds(courseThemeId);
|
|
|
+ // 获取所有课程主题下 各类型题目的数量
|
|
|
+ Map<String, Long> subjectMap = subjectDoList.stream().collect(Collectors.groupingBy(info -> info.getSubjecttype(), Collectors.counting()));
|
|
|
|
|
|
- // 校验题目数量是否足够
|
|
|
- String courseThemeName = questionCheck(paperSubjectAssignDos, paperSubjectAutoDos, subjectDoList);
|
|
|
- if (StringUtils.isNotBlank(courseThemeName)) {
|
|
|
- R.errorWithMsg(courseThemeName + "的题目数不够");
|
|
|
+ for (Map.Entry<String, Long> entry : subjectTypeAndNum.entrySet()) {
|
|
|
+ String k = entry.getKey();
|
|
|
+ Long v = entry.getValue();
|
|
|
+ if (v > subjectMap.getOrDefault(k, ZERO)) {
|
|
|
+ return R.errorWithMsg("题目数量不够");
|
|
|
}
|
|
|
}
|
|
|
+ // 校验题目数量是否足够
|
|
|
+ String courseThemeName = questionCheck(paperSubjectAssignDos, paperSubjectAutoDos, subjectDoList);
|
|
|
+ if (StringUtils.isNotBlank(courseThemeName)) {
|
|
|
+ R.errorWithMsg(courseThemeName + "的题目数不够");
|
|
|
+ }
|
|
|
+ return R.saveOk();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R saveorupdate(TrainingPaperVo vo) {
|
|
|
logger.info("开始保存试卷信息和题目");
|
|
|
+ // 固定题目
|
|
|
+ List<PaperSubjectAssignDo> paperSubjectAssignDos = vo.getPapersubjectassigndos();
|
|
|
+ // 随机题目
|
|
|
+ List<PaperSubjectAutoDo> paperSubjectAutoDos = vo.getPapersubjectautodos();
|
|
|
ExamPaperDo examPaperDo = new ExamPaperDo();
|
|
|
BeanUtils.copyProperties(vo, examPaperDo);
|
|
|
this.saveOrUpdate(examPaperDo);
|