|
@@ -10,6 +10,7 @@ import com.ruoyi.enums.PaperType;
|
|
|
import com.ruoyi.ie.domain.AMarjorPlan;
|
|
import com.ruoyi.ie.domain.AMarjorPlan;
|
|
|
import com.ruoyi.ie.service.IAMarjorPlanService;
|
|
import com.ruoyi.ie.service.IAMarjorPlanService;
|
|
|
import com.ruoyi.learn.domain.*;
|
|
import com.ruoyi.learn.domain.*;
|
|
|
|
|
+import com.ruoyi.learn.mapper.LearnAnswerMapper;
|
|
|
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;
|
|
@@ -20,16 +21,16 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.validation.ValidationException;
|
|
import javax.validation.ValidationException;
|
|
|
-import java.util.Calendar;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 考试服务
|
|
* 考试服务
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
public class ExamService {
|
|
public class ExamService {
|
|
|
|
|
+ private final LearnAnswerMapper learnAnswerMapper;
|
|
|
|
|
+ private final LearnExamineeMapper learnExamineeMapper;
|
|
|
private Set<PaperType> paperTypeSet = Sets.newHashSet(PaperType.Real, PaperType.Custom, PaperType.Test);
|
|
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;
|
|
@@ -38,13 +39,15 @@ public class ExamService {
|
|
|
private final PaperService paperService;
|
|
private final PaperService paperService;
|
|
|
private final IAMarjorPlanService marjorPlanService;
|
|
private final IAMarjorPlanService marjorPlanService;
|
|
|
|
|
|
|
|
- public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService) {
|
|
|
|
|
|
|
+ public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService, LearnAnswerMapper learnAnswerMapper, LearnExamineeMapper learnExamineeMapper) {
|
|
|
this.paperMapper = paperMapper;
|
|
this.paperMapper = paperMapper;
|
|
|
this.knowledgeTreeMapper = knowledgeTreeMapper;
|
|
this.knowledgeTreeMapper = knowledgeTreeMapper;
|
|
|
this.examineeMapper = examineeMapper;
|
|
this.examineeMapper = examineeMapper;
|
|
|
this.learnPaperService = learnPaperService;
|
|
this.learnPaperService = learnPaperService;
|
|
|
this.paperService = paperService;
|
|
this.paperService = paperService;
|
|
|
this.marjorPlanService = marjorPlanService;
|
|
this.marjorPlanService = marjorPlanService;
|
|
|
|
|
+ this.learnAnswerMapper = learnAnswerMapper;
|
|
|
|
|
+ this.learnExamineeMapper = learnExamineeMapper;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -64,6 +67,23 @@ public class ExamService {
|
|
|
throw new RuntimeException("错误类型: " + paperType);
|
|
throw new RuntimeException("错误类型: " + paperType);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public AnswerSheet loadExaminee(Long examineeId) {
|
|
|
|
|
+ LearnExaminee examinee = examineeMapper.selectLearnExamineeByExamineeId(examineeId);
|
|
|
|
|
+ if(ExamineeStatus.Exam.getVal().equals(examinee.getState())) {
|
|
|
|
|
+ throw new RuntimeException("考试中,不能提取答案");
|
|
|
|
|
+ }
|
|
|
|
|
+ LearnAnswer aCond = new LearnAnswer();
|
|
|
|
|
+ aCond.setExamineeId(examineeId);
|
|
|
|
|
+ Map<Long, LearnAnswer> answerMap = learnAnswerMapper.selectLearnAnswerList(aCond).stream().collect(Collectors.toMap(LearnAnswer::getQuestionId, t -> t));
|
|
|
|
|
+ LearnPaper learnPaper = learnPaperService.selectLearnPaperById(examinee.getPaperId());
|
|
|
|
|
+ List<PaperVO.QuestionSeq> questionList = paperService.loadPaperQuestions(examinee.getPaperId(), answerMap, true);
|
|
|
|
|
+ AnswerSheet answerSheet = buildAnswerSheet(learnPaper, examinee);
|
|
|
|
|
+ answerSheet.setTotalCount(questionList.size());
|
|
|
|
|
+ answerSheet.setWrongCount(examinee.getWrongCount());
|
|
|
|
|
+ answerSheet.setQuestions(questionList);
|
|
|
|
|
+ return answerSheet;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 临时保存
|
|
* 临时保存
|
|
|
*/
|
|
*/
|
|
@@ -73,10 +93,61 @@ public class ExamService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 交卷
|
|
* 交卷
|
|
|
- * @param answer
|
|
|
|
|
|
|
+ * @param answerSheet
|
|
|
*/
|
|
*/
|
|
|
- public void commitAnswerSheet(AnswerSheet answer) {
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void commitAnswerSheet(AnswerSheet answerSheet) {
|
|
|
|
|
+ LearnAnswer aCond = new LearnAnswer();
|
|
|
|
|
+ aCond.setExamineeId(answerSheet.getExamineeId());
|
|
|
|
|
+ Map<Long, LearnAnswer> answerMap = learnAnswerMapper.selectLearnAnswerList(aCond).stream().collect(Collectors.toMap(LearnAnswer::getQuestionId, t -> t));
|
|
|
|
|
+ Map<Long, PaperVO.QuestionSeq> questionMap = paperService.loadPaperQuestions(answerSheet.getPaperId(), answerMap, true).stream().collect(Collectors.toMap(PaperVO.QuestionSeq::getId, t -> t));
|
|
|
|
|
+
|
|
|
|
|
+ List<LearnAnswer> addList = Lists.newArrayList();
|
|
|
|
|
+ List<LearnAnswer> updateList = Lists.newArrayList();
|
|
|
|
|
+ Integer wrongCount = 0;
|
|
|
|
|
+ for(PaperVO.QuestionSeq question : answerSheet.getQuestions()) {
|
|
|
|
|
+ LearnAnswer answer = new LearnAnswer();
|
|
|
|
|
+ PaperVO.QuestionSeq exist = questionMap.remove(question.getId());
|
|
|
|
|
+ if(null == exist) {
|
|
|
|
|
+ answer.setExamineeId(answerSheet.getExamineeId());
|
|
|
|
|
+ answer.setStudentId(SecurityUtils.getUserId());
|
|
|
|
|
+ answer.setQuestionId(question.getId());
|
|
|
|
|
+ answer.setSeq(question.getSeq());
|
|
|
|
|
+ answer.setKnowledgeId(answerSheet.getKnowledgeId());
|
|
|
|
|
+ addList.add(answer);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ answer.setAnswerId(answerMap.get(question.getId()).getAnswerId());
|
|
|
|
|
+ updateList.add(answer);
|
|
|
|
|
+ }
|
|
|
|
|
+ answer.setAnswer(StringUtils.join(question.getAnswers(), ","));
|
|
|
|
|
+ answer.setState(question.getState());
|
|
|
|
|
+ if(!answer.getState().equals(1L)) {
|
|
|
|
|
+ wrongCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(addList.size() > 0) {
|
|
|
|
|
+ addList.stream().forEach(t -> {
|
|
|
|
|
+ learnAnswerMapper.insertLearnAnswer(t);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ if(updateList.size() > 0) {
|
|
|
|
|
+ updateList.stream().forEach(t -> {
|
|
|
|
|
+ learnAnswerMapper.updateLearnAnswer(t);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ LearnExaminee upExaminee = new LearnExaminee();
|
|
|
|
|
+ upExaminee.setExamineeId(answerSheet.getExamineeId());
|
|
|
|
|
+ upExaminee.setDuration(answerSheet.getDuration());
|
|
|
|
|
+ upExaminee.setEndTime(new Date());
|
|
|
|
|
+ upExaminee.setState(ExamineeStatus.Commit.getVal());
|
|
|
|
|
+ upExaminee.setWrongCount(wrongCount);
|
|
|
|
|
+ learnExamineeMapper.updateLearnExaminee(upExaminee);
|
|
|
|
|
|
|
|
|
|
+ // 关闭试卷
|
|
|
|
|
+ LearnPaper up = new LearnPaper();
|
|
|
|
|
+ up.setId(answerSheet.getPaperId());
|
|
|
|
|
+ up.setStatus(PaperStatus.Valid.getVal());
|
|
|
|
|
+ paperMapper.updateLearnPaper(up);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private AnswerSheet openExaminee(PaperType paperType, Long paperId, Long studentId) {
|
|
private AnswerSheet openExaminee(PaperType paperType, Long paperId, Long studentId) {
|
|
@@ -93,6 +164,7 @@ public class ExamService {
|
|
|
} else {
|
|
} else {
|
|
|
learnExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
learnExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
|
learnExaminee.setBeginTime(new Date());
|
|
learnExaminee.setBeginTime(new Date());
|
|
|
|
|
+ learnExaminee.setDuration(0L);
|
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
|
}
|
|
}
|
|
|
return buildAnswerSheet(paper, learnExaminee);
|
|
return buildAnswerSheet(paper, learnExaminee);
|
|
@@ -118,9 +190,10 @@ public class ExamService {
|
|
|
throw new ValidationException("专业id无效");
|
|
throw new ValidationException("专业id无效");
|
|
|
}
|
|
}
|
|
|
LearnPaper paper = getBestPaper(plan, existPaperIdSet);
|
|
LearnPaper paper = getBestPaper(plan, existPaperIdSet);
|
|
|
- examinee.setPaperKey(PaperType.Simulated.name() + "_" + paper.getId());
|
|
|
|
|
|
|
+ examinee.setPaperKey(paper.getId().toString());
|
|
|
examinee.setState(ExamineeStatus.Exam.getVal());
|
|
examinee.setState(ExamineeStatus.Exam.getVal());
|
|
|
examinee.setBeginTime(new Date());
|
|
examinee.setBeginTime(new Date());
|
|
|
|
|
+ examinee.setDuration(0L);
|
|
|
examineeMapper.insertLearnExaminee(examinee);
|
|
examineeMapper.insertLearnExaminee(examinee);
|
|
|
return buildAnswerSheet(paper, examinee);
|
|
return buildAnswerSheet(paper, examinee);
|
|
|
}
|
|
}
|
|
@@ -144,10 +217,18 @@ public class ExamService {
|
|
|
learnExaminee.setStudentId(studentId);
|
|
learnExaminee.setStudentId(studentId);
|
|
|
learnExaminee.setPaperId(existPaper.getId());
|
|
learnExaminee.setPaperId(existPaper.getId());
|
|
|
learnExaminee.setPaperType(PaperType.Practice.getVal());
|
|
learnExaminee.setPaperType(PaperType.Practice.getVal());
|
|
|
|
|
+ learnExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
|
List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(learnExaminee);
|
|
List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(learnExaminee);
|
|
|
if (CollectionUtils.isNotEmpty(examineeList)) {
|
|
if (CollectionUtils.isNotEmpty(examineeList)) {
|
|
|
LearnExaminee examinee = examineeList.get(0);
|
|
LearnExaminee examinee = examineeList.get(0);
|
|
|
- return buildAnswerSheet(existPaper, examinee);
|
|
|
|
|
|
|
+ LearnAnswer aCond = new LearnAnswer();
|
|
|
|
|
+ aCond.setExamineeId(examinee.getExamineeId());
|
|
|
|
|
+ Map<Long, LearnAnswer> answerMap = learnAnswerMapper.selectLearnAnswerList(aCond).stream().collect(Collectors.toMap(LearnAnswer::getQuestionId, t -> t));
|
|
|
|
|
+ List<PaperVO.QuestionSeq> questionList = paperService.loadPaperQuestions(examinee.getPaperId(), answerMap, false);
|
|
|
|
|
+ AnswerSheet answerSheet = buildAnswerSheet(existPaper, examinee);
|
|
|
|
|
+ answerSheet.setQuestions(questionList);
|
|
|
|
|
+ answerSheet.setKnowledgeId(existPaper.getRelateId());
|
|
|
|
|
+ return answerSheet;
|
|
|
}
|
|
}
|
|
|
// 关闭试卷
|
|
// 关闭试卷
|
|
|
LearnPaper up = new LearnPaper();
|
|
LearnPaper up = new LearnPaper();
|
|
@@ -168,16 +249,22 @@ public class ExamService {
|
|
|
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"));
|
|
|
|
|
+ paper.setRelateId(knowledgeId);
|
|
|
paperService.savePaper(paper, pqList);
|
|
paperService.savePaper(paper, pqList);
|
|
|
|
|
|
|
|
LearnExaminee learnExaminee = new LearnExaminee();
|
|
LearnExaminee learnExaminee = new LearnExaminee();
|
|
|
learnExaminee.setStudentId(studentId);
|
|
learnExaminee.setStudentId(studentId);
|
|
|
learnExaminee.setPaperType(PaperType.Practice.getVal());
|
|
learnExaminee.setPaperType(PaperType.Practice.getVal());
|
|
|
learnExaminee.setPaperId(paper.getId());
|
|
learnExaminee.setPaperId(paper.getId());
|
|
|
|
|
+ learnExaminee.setPaperKey(String.valueOf(knowledgeId));
|
|
|
learnExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
learnExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
|
learnExaminee.setBeginTime(new Date());
|
|
learnExaminee.setBeginTime(new Date());
|
|
|
|
|
+ learnExaminee.setDuration(0L);
|
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
examineeMapper.insertLearnExaminee(learnExaminee);
|
|
|
- return buildAnswerSheet(paper, learnExaminee);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ AnswerSheet answerSheet = buildAnswerSheet(paper, learnExaminee);
|
|
|
|
|
+ answerSheet.setKnowledgeId(paper.getRelateId());
|
|
|
|
|
+ return answerSheet;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private LearnPaper getBestPaper(AMarjorPlan plan, Set<Long> existPaperIdSet) {
|
|
private LearnPaper getBestPaper(AMarjorPlan plan, Set<Long> existPaperIdSet) {
|