|
@@ -2,49 +2,66 @@ package com.ruoyi.web.service;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.util.DateUtils;
|
|
import com.alibaba.fastjson2.util.DateUtils;
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.enums.ExamineeStatus;
|
|
import com.ruoyi.enums.ExamineeStatus;
|
|
|
import com.ruoyi.enums.PaperStatus;
|
|
import com.ruoyi.enums.PaperStatus;
|
|
|
import com.ruoyi.enums.PaperType;
|
|
import com.ruoyi.enums.PaperType;
|
|
|
|
|
+import com.ruoyi.ie.domain.AMarjorPlan;
|
|
|
|
|
+import com.ruoyi.ie.service.IAMarjorPlanService;
|
|
|
import com.ruoyi.learn.domain.*;
|
|
import com.ruoyi.learn.domain.*;
|
|
|
import com.ruoyi.learn.mapper.LearnExamineeMapper;
|
|
import com.ruoyi.learn.mapper.LearnExamineeMapper;
|
|
|
import com.ruoyi.learn.mapper.LearnKnowledgeTreeMapper;
|
|
import com.ruoyi.learn.mapper.LearnKnowledgeTreeMapper;
|
|
|
import com.ruoyi.learn.mapper.LearnPaperMapper;
|
|
import com.ruoyi.learn.mapper.LearnPaperMapper;
|
|
|
|
|
+import com.ruoyi.learn.service.ILearnPaperService;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import javax.validation.ValidationException;
|
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 考试服务
|
|
* 考试服务
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class ExamService {
|
|
public class ExamService {
|
|
|
|
|
+ private Set<PaperType> paperTypeSet = Sets.newHashSet(PaperType.Real, PaperType.Custom, PaperType.Test);
|
|
|
private final LearnPaperMapper paperMapper;
|
|
private final LearnPaperMapper paperMapper;
|
|
|
private final LearnKnowledgeTreeMapper knowledgeTreeMapper;
|
|
private final LearnKnowledgeTreeMapper knowledgeTreeMapper;
|
|
|
private final LearnExamineeMapper examineeMapper;
|
|
private final LearnExamineeMapper examineeMapper;
|
|
|
|
|
+ private final ILearnPaperService learnPaperService;
|
|
|
private final PaperService paperService;
|
|
private final PaperService paperService;
|
|
|
|
|
+ private final IAMarjorPlanService marjorPlanService;
|
|
|
|
|
|
|
|
- public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, PaperService paperService) {
|
|
|
|
|
|
|
+ public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService) {
|
|
|
this.paperMapper = paperMapper;
|
|
this.paperMapper = paperMapper;
|
|
|
this.knowledgeTreeMapper = knowledgeTreeMapper;
|
|
this.knowledgeTreeMapper = knowledgeTreeMapper;
|
|
|
this.examineeMapper = examineeMapper;
|
|
this.examineeMapper = examineeMapper;
|
|
|
|
|
+ this.learnPaperService = learnPaperService;
|
|
|
this.paperService = paperService;
|
|
this.paperService = paperService;
|
|
|
|
|
+ this.marjorPlanService = marjorPlanService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 开卷 (卷, 实时组卷)
|
|
* 开卷 (卷, 实时组卷)
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public AnswerSheet openExaminee(PaperType paperType, Long relatedId) {
|
|
public AnswerSheet openExaminee(PaperType paperType, Long relatedId) {
|
|
|
- if(PaperType.Practice.equals(paperType)) { // TODO 先连接学生的定向信息
|
|
|
|
|
|
|
+ if(paperTypeSet.contains(paperType)) {
|
|
|
|
|
+ return openExaminee(paperType, relatedId, SecurityUtils.getUserId());
|
|
|
|
|
+ } else if(PaperType.Practice.equals(paperType)) { // TODO 先连接学生的定向信息
|
|
|
return openExaminee(relatedId, SecurityUtils.getUserId(), "");
|
|
return openExaminee(relatedId, SecurityUtils.getUserId(), "");
|
|
|
|
|
+ } else if(PaperType.Simulated.equals(paperType)) {
|
|
|
|
|
+ Integer cnt = 3;
|
|
|
|
|
+ return openExaminee(SecurityUtils.getUserId(), cnt);
|
|
|
}
|
|
}
|
|
|
- return openExaminee(paperType, relatedId, SecurityUtils.getUserId(), "");
|
|
|
|
|
|
|
+ throw new RuntimeException("错误类型: " + paperType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -62,9 +79,7 @@ public class ExamService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public AnswerSheet openExaminee(PaperType paperType, Long paperId, Long studentId, String directKey) {
|
|
|
|
|
- AnswerSheet answerSheet = new AnswerSheet();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private AnswerSheet openExaminee(PaperType paperType, Long paperId, Long studentId) {
|
|
|
LearnPaper paper = paperMapper.selectLearnPaperById(paperId);
|
|
LearnPaper paper = paperMapper.selectLearnPaperById(paperId);
|
|
|
|
|
|
|
|
LearnExaminee learnExaminee = new LearnExaminee();
|
|
LearnExaminee learnExaminee = new LearnExaminee();
|
|
@@ -80,17 +95,41 @@ public class ExamService {
|
|
|
learnExaminee.setBeginTime(new Date());
|
|
learnExaminee.setBeginTime(new Date());
|
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
|
}
|
|
}
|
|
|
- return answerSheet;
|
|
|
|
|
|
|
+ return buildAnswerSheet(paper, learnExaminee);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private AnswerSheet openExaminee(Long planId, Integer maxCount) {
|
|
|
|
|
+ LearnExaminee examinee = new LearnExaminee();
|
|
|
|
|
+ examinee.setStudentId(SecurityUtils.getLoginUser().getUser().getUserId());
|
|
|
|
|
+ examinee.setPaperType(PaperType.Simulated.getVal());
|
|
|
|
|
+ List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(examinee);
|
|
|
|
|
+ Set<Long> existPaperIdSet = Sets.newHashSet();
|
|
|
|
|
+ for(LearnExaminee e : examineeList) {
|
|
|
|
|
+ if(ExamineeStatus.Exam.getVal().equals(e.getState())) {
|
|
|
|
|
+ return buildAnswerSheet(learnPaperService.selectLearnPaperById(e.getPaperId()), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ existPaperIdSet.add(e.getPaperId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if(existPaperIdSet.size() >= maxCount) {
|
|
|
|
|
+ throw new ValidationException("超过最大次数限制" + maxCount );
|
|
|
|
|
+ }
|
|
|
|
|
+ AMarjorPlan plan = marjorPlanService.selectAMarjorPlanById(planId);
|
|
|
|
|
+ if(null == plan) {
|
|
|
|
|
+ throw new ValidationException("专业id无效");
|
|
|
|
|
+ }
|
|
|
|
|
+ LearnPaper paper = getBestPaper(plan, existPaperIdSet);
|
|
|
|
|
+ examinee.setPaperKey(PaperType.Simulated.name() + "_" + paper.getId());
|
|
|
|
|
+ examinee.setState(ExamineeStatus.Exam.getVal());
|
|
|
|
|
+ examinee.setBeginTime(new Date());
|
|
|
|
|
+ examineeMapper.insertLearnExaminee(examinee);
|
|
|
|
|
+ return buildAnswerSheet(paper, examinee);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据知识点生成一次性练习卷并开始做题
|
|
* 根据知识点生成一次性练习卷并开始做题
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public AnswerSheet openExaminee(Long knowledgeId, Long studentId, String directKey) {
|
|
|
|
|
- AnswerSheet answerSheet = new AnswerSheet();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private AnswerSheet openExaminee(Long knowledgeId, Long studentId, String directKey) {
|
|
|
LearnKnowledgeTree knowledgeTree = knowledgeTreeMapper.selectLearnKnowledgeTreeById(knowledgeId);
|
|
LearnKnowledgeTree knowledgeTree = knowledgeTreeMapper.selectLearnKnowledgeTreeById(knowledgeId);
|
|
|
LearnPaper paper = new LearnPaper();
|
|
LearnPaper paper = new LearnPaper();
|
|
|
paper.setPaperType(PaperType.Practice.name());
|
|
paper.setPaperType(PaperType.Practice.name());
|
|
@@ -100,14 +139,15 @@ public class ExamService {
|
|
|
paper.setDirectKey(StringUtils.trimToEmpty(directKey));
|
|
paper.setDirectKey(StringUtils.trimToEmpty(directKey));
|
|
|
List<LearnPaper> paperList = paperMapper.selectLearnPaperList(paper);
|
|
List<LearnPaper> paperList = paperMapper.selectLearnPaperList(paper);
|
|
|
if (CollectionUtils.isNotEmpty(paperList)) { // 有未做完的
|
|
if (CollectionUtils.isNotEmpty(paperList)) { // 有未做完的
|
|
|
|
|
+ LearnPaper existPaper = paperList.get(0);
|
|
|
LearnExaminee learnExaminee = new LearnExaminee();
|
|
LearnExaminee learnExaminee = new LearnExaminee();
|
|
|
learnExaminee.setStudentId(studentId);
|
|
learnExaminee.setStudentId(studentId);
|
|
|
- learnExaminee.setPaperId(paperList.get(0).getId());
|
|
|
|
|
|
|
+ learnExaminee.setPaperId(existPaper.getId());
|
|
|
learnExaminee.setPaperType(PaperType.Practice.getVal());
|
|
learnExaminee.setPaperType(PaperType.Practice.getVal());
|
|
|
List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(learnExaminee);
|
|
List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(learnExaminee);
|
|
|
if (CollectionUtils.isNotEmpty(examineeList)) {
|
|
if (CollectionUtils.isNotEmpty(examineeList)) {
|
|
|
- examineeList.get(0);
|
|
|
|
|
- return answerSheet;
|
|
|
|
|
|
|
+ LearnExaminee examinee = examineeList.get(0);
|
|
|
|
|
+ return buildAnswerSheet(existPaper, examinee);
|
|
|
}
|
|
}
|
|
|
// 关闭试卷
|
|
// 关闭试卷
|
|
|
LearnPaper up = new LearnPaper();
|
|
LearnPaper up = new LearnPaper();
|
|
@@ -125,7 +165,6 @@ public class ExamService {
|
|
|
typeDefList.add(new TestPaperVO.TypeDef("判断题", "判断题", 10, 2));
|
|
typeDefList.add(new TestPaperVO.TypeDef("判断题", "判断题", 10, 2));
|
|
|
paperDef.setTypes(typeDefList);
|
|
paperDef.setTypes(typeDefList);
|
|
|
List<LearnPaperQuestion> pqList = paperService.getQuestions(studentId, paperDef);
|
|
List<LearnPaperQuestion> pqList = paperService.getQuestions(studentId, paperDef);
|
|
|
-
|
|
|
|
|
paper.setPaperSource(0);
|
|
paper.setPaperSource(0);
|
|
|
paper.setSubjectId(knowledgeTree.getSubjectId());
|
|
paper.setSubjectId(knowledgeTree.getSubjectId());
|
|
|
paper.setPaperName(studentId + "-" + knowledgeTree.getName() + "-" + DateUtils.format(new Date(), "yyyyMMddHHmmss"));
|
|
paper.setPaperName(studentId + "-" + knowledgeTree.getName() + "-" + DateUtils.format(new Date(), "yyyyMMddHHmmss"));
|
|
@@ -138,6 +177,42 @@ public class ExamService {
|
|
|
learnExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
learnExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
|
learnExaminee.setBeginTime(new Date());
|
|
learnExaminee.setBeginTime(new Date());
|
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
|
|
|
+ return buildAnswerSheet(paper, learnExaminee);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private LearnPaper getBestPaper(AMarjorPlan plan, Set<Long> existPaperIdSet) {
|
|
|
|
|
+ String groupName = StringUtils.trimToEmpty(plan.getMajorGroup());
|
|
|
|
|
+ LearnPaper paperCond = new LearnPaper();
|
|
|
|
|
+ paperCond.setPaperType(PaperType.Simulated.name());
|
|
|
|
|
+ for(int i = 3; i>0; i--) {
|
|
|
|
|
+ if(i == 3) {
|
|
|
|
|
+ paperCond.setDirectKey(plan.getUniversityId() + "_" + groupName + "_" + plan.getMajorName());
|
|
|
|
|
+ } else if(i == 2) {
|
|
|
|
|
+ paperCond.setDirectKey(plan.getUniversityId() + "_" + groupName);
|
|
|
|
|
+ } else if(StringUtils.isBlank(groupName)) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<LearnPaper> paperList = learnPaperService.selectLearnPaperList(paperCond);
|
|
|
|
|
+ for(LearnPaper paper : paperList) {
|
|
|
|
|
+ if(existPaperIdSet.add(paper.getId())) {
|
|
|
|
|
+ return paper;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new ValidationException("未初始化院校定向模拟题库: " + plan.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private AnswerSheet buildAnswerSheet(LearnPaper paper, LearnExaminee examinee) {
|
|
|
|
|
+ AnswerSheet answerSheet = new AnswerSheet();
|
|
|
|
|
+ answerSheet.setExamineeId(examinee.getExamineeId());
|
|
|
|
|
+ answerSheet.setPaperId(examinee.getPaperId());
|
|
|
|
|
+ answerSheet.setName(paper.getPaperName());
|
|
|
|
|
+ answerSheet.setBeginTime(examinee.getBeginTime());
|
|
|
|
|
+ answerSheet.setScoringType("1");
|
|
|
|
|
+ answerSheet.setMode(0L);
|
|
|
|
|
+ answerSheet.setState(examinee.getState());
|
|
|
|
|
+ answerSheet.setAllowAnswer(true);
|
|
|
|
|
+ answerSheet.setAllowScore(false);
|
|
|
return answerSheet;
|
|
return answerSheet;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|