|
|
@@ -1,8 +1,10 @@
|
|
|
package com.ruoyi.web.service;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.alibaba.fastjson2.util.DateUtils;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Sets;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.enums.ExamineeStatus;
|
|
|
import com.ruoyi.enums.PaperStatus;
|
|
|
@@ -10,11 +12,9 @@ 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.mapper.LearnAnswerMapper;
|
|
|
-import com.ruoyi.learn.mapper.LearnExamineeMapper;
|
|
|
-import com.ruoyi.learn.mapper.LearnKnowledgeTreeMapper;
|
|
|
-import com.ruoyi.learn.mapper.LearnPaperMapper;
|
|
|
+import com.ruoyi.learn.mapper.*;
|
|
|
import com.ruoyi.learn.service.ILearnPaperService;
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -31,6 +31,7 @@ import java.util.stream.Collectors;
|
|
|
public class ExamService {
|
|
|
private final LearnAnswerMapper learnAnswerMapper;
|
|
|
private final LearnExamineeMapper learnExamineeMapper;
|
|
|
+ private final LearnStudentMapper learnStudentMapper;
|
|
|
private Set<PaperType> paperTypeSet = Sets.newHashSet(PaperType.Real, PaperType.Custom, PaperType.Test);
|
|
|
private final LearnPaperMapper paperMapper;
|
|
|
private final LearnKnowledgeTreeMapper knowledgeTreeMapper;
|
|
|
@@ -38,8 +39,9 @@ public class ExamService {
|
|
|
private final ILearnPaperService learnPaperService;
|
|
|
private final PaperService paperService;
|
|
|
private final IAMarjorPlanService marjorPlanService;
|
|
|
+ private final ISysUserService sysUserService;
|
|
|
|
|
|
- public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService, LearnAnswerMapper learnAnswerMapper, LearnExamineeMapper learnExamineeMapper) {
|
|
|
+ public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService, LearnAnswerMapper learnAnswerMapper, LearnExamineeMapper learnExamineeMapper, ISysUserService sysUserService, LearnStudentMapper learnStudentMapper) {
|
|
|
this.paperMapper = paperMapper;
|
|
|
this.knowledgeTreeMapper = knowledgeTreeMapper;
|
|
|
this.examineeMapper = examineeMapper;
|
|
|
@@ -48,6 +50,8 @@ public class ExamService {
|
|
|
this.marjorPlanService = marjorPlanService;
|
|
|
this.learnAnswerMapper = learnAnswerMapper;
|
|
|
this.learnExamineeMapper = learnExamineeMapper;
|
|
|
+ this.sysUserService = sysUserService;
|
|
|
+ this.learnStudentMapper = learnStudentMapper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -55,28 +59,46 @@ public class ExamService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public AnswerSheet openExaminee(PaperType paperType, Long relatedId) {
|
|
|
+ public AnswerSheet openExaminee(boolean directed, PaperType paperType, Long relatedId) {
|
|
|
if(paperTypeSet.contains(paperType)) {
|
|
|
return openExaminee(paperType, relatedId, SecurityUtils.getUserId());
|
|
|
- } else if(PaperType.Practice.equals(paperType)) { // TODO 先连接学生的定向信息
|
|
|
- return openExaminee(relatedId, SecurityUtils.getUserId(), "");
|
|
|
+ } else if(PaperType.Practice.equals(paperType)) {
|
|
|
+ return openExaminee(relatedId, SecurityUtils.getUserId(), getDirectedKey(directed));
|
|
|
} else if(PaperType.Simulated.equals(paperType)) {
|
|
|
- Integer cnt = 3;
|
|
|
- return openExaminee(SecurityUtils.getUserId(), cnt);
|
|
|
+ SysUser exist = sysUserService.selectUserById(SecurityUtils.getUserId());
|
|
|
+ return openExaminee(relatedId, exist);
|
|
|
}
|
|
|
throw new RuntimeException("错误类型: " + paperType);
|
|
|
}
|
|
|
|
|
|
- public AnswerSheet loadExaminee(Long examineeId) {
|
|
|
+ private String getDirectedKey(boolean directed) {
|
|
|
+ if(!directed) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ LearnStudent ls = learnStudentMapper.selectLearnStudentByStudentId(SecurityUtils.getUserId());
|
|
|
+ return StringUtils.trimToEmpty(ls.getDirectKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ public AnswerSheet loadExaminee(Long examineeId, Boolean examContinue) {
|
|
|
LearnExaminee examinee = examineeMapper.selectLearnExamineeByExamineeId(examineeId);
|
|
|
- if(ExamineeStatus.Exam.getVal().equals(examinee.getState())) {
|
|
|
+ if(examContinue) {
|
|
|
+ if(ExamineeStatus.Sign.getVal().equals(examinee.getState())) {
|
|
|
+ LearnExaminee upExaminee = new LearnExaminee();
|
|
|
+ upExaminee.setExamineeId(examineeId);
|
|
|
+ upExaminee.setBeginTime(new Date());
|
|
|
+ upExaminee.setState(ExamineeStatus.Exam.getVal());
|
|
|
+ examineeMapper.updateLearnExaminee(upExaminee);
|
|
|
+ } else if(!ExamineeStatus.Exam.getVal().equals(examinee.getState())) {
|
|
|
+ throw new RuntimeException("已考完的卷不能继续做");
|
|
|
+ }
|
|
|
+ } else 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);
|
|
|
+ List<PaperVO.QuestionSeq> questionList = paperService.loadPaperQuestions(examinee.getPaperId(), answerMap, !examContinue);
|
|
|
AnswerSheet answerSheet = buildAnswerSheet(learnPaper, examinee);
|
|
|
answerSheet.setTotalCount(questionList.size());
|
|
|
answerSheet.setWrongCount(examinee.getWrongCount());
|
|
|
@@ -170,29 +192,33 @@ public class ExamService {
|
|
|
return buildAnswerSheet(paper, learnExaminee);
|
|
|
}
|
|
|
|
|
|
- private AnswerSheet openExaminee(Long planId, Integer maxCount) {
|
|
|
+ private AnswerSheet openExaminee(Long planId, SysUser sysUser) {
|
|
|
+ AMarjorPlan plan = marjorPlanService.selectAMarjorPlanById(planId);
|
|
|
+ if(null == plan) {
|
|
|
+ throw new ValidationException("专业id无效");
|
|
|
+ }
|
|
|
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())) {
|
|
|
+ if((ExamineeStatus.Exam.getVal().equals(e.getState()) || ExamineeStatus.Sign.getVal().equals(e.getState())) && e.getPaperKey().equals(planId.toString())) {
|
|
|
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无效");
|
|
|
+ if(existPaperIdSet.size() >= sysUser.getEvalCount()) {
|
|
|
+ throw new ValidationException("超过最大次数限制" + sysUser.getEvalCount() );
|
|
|
}
|
|
|
+ SysUser upUser = new SysUser();
|
|
|
+ upUser.setUserId(sysUser.getUserId());
|
|
|
+ upUser.setEvalCount(sysUser.getEvalCount() - 1);
|
|
|
+ sysUserService.updateUserProfile(upUser);
|
|
|
+
|
|
|
LearnPaper paper = getBestPaper(plan, existPaperIdSet);
|
|
|
examinee.setPaperKey(paper.getId().toString());
|
|
|
- examinee.setState(ExamineeStatus.Exam.getVal());
|
|
|
- examinee.setBeginTime(new Date());
|
|
|
+ examinee.setState(ExamineeStatus.Sign.getVal());
|
|
|
examinee.setDuration(0L);
|
|
|
examineeMapper.insertLearnExaminee(examinee);
|
|
|
return buildAnswerSheet(paper, examinee);
|
|
|
@@ -295,6 +321,9 @@ public class ExamService {
|
|
|
answerSheet.setPaperId(examinee.getPaperId());
|
|
|
answerSheet.setName(paper.getPaperName());
|
|
|
answerSheet.setBeginTime(examinee.getBeginTime());
|
|
|
+ if(StringUtils.isNotBlank(paper.getConditions())) {
|
|
|
+ answerSheet.setConditions(JSONObject.parseObject(paper.getConditions(), AnswerSheet.PaperCond.class));
|
|
|
+ }
|
|
|
answerSheet.setScoringType("1");
|
|
|
answerSheet.setMode(0L);
|
|
|
answerSheet.setState(examinee.getState());
|