|
|
|
@ -5,6 +5,8 @@ import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.sztzjy.financial_bigdata.config.Constant;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.*;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.stu_dto.StuTheoryTestDto;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.StuErrorMapper;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.StuTheoryExamMapper;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.SysObjectiveQuestionMapper;
|
|
|
|
|
import com.sztzjy.financial_bigdata.service.stu.ITheoryTestService;
|
|
|
|
@ -12,10 +14,7 @@ import com.sztzjy.financial_bigdata.util.PageUtil;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class TheoryTestServiceImpl implements ITheoryTestService {
|
|
|
|
@ -23,6 +22,9 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
|
|
|
|
|
StuTheoryExamMapper theoryExamMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
SysObjectiveQuestionMapper objectiveQuestionMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
StuErrorMapper errorMapper;
|
|
|
|
|
|
|
|
|
|
//开始考试 1 先查询考试时间最近的一堂考试 判断是否超过2小时 如果没超过 根据理论考试表中的题目ID和答案进行回显
|
|
|
|
|
// 如果超过了两小时 定时方法算分将数据保存到理论考试表和理论记录表中 如果根据userid查询理论记录表中数据未null 则需要创建
|
|
|
|
|
// 之前没有进行考试 从客观题库表中查询 35道单选,每题2分,5道多选每题4分,10道判断每题1分 并将id保存至理论考试表中
|
|
|
|
@ -30,35 +32,183 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
|
|
|
|
|
public List<SysObjectiveQuestion> startTheoryTest(String userId) {
|
|
|
|
|
StuTheoryExamExample example = new StuTheoryExamExample();
|
|
|
|
|
example.createCriteria().andUserIdEqualTo(userId);
|
|
|
|
|
List<StuTheoryExam> stuTheoryExams = theoryExamMapper.selectByExample(example);
|
|
|
|
|
if(stuTheoryExams.isEmpty()){
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList= objectiveQuestionMapper.selectRandomObjective100();
|
|
|
|
|
List<String> singleIdList=new ArrayList<>();
|
|
|
|
|
List<String> manyIdList=new ArrayList<>();
|
|
|
|
|
List<String> judgeIdList=new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < objectiveQuestionList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionList.get(i);
|
|
|
|
|
String objectiveId = objectiveQuestion.getObjectiveId();
|
|
|
|
|
if(Constant.OBJECTIVE_TYPE_SINGLE.equals(objectiveQuestion.getType())){
|
|
|
|
|
singleIdList.add(objectiveId);
|
|
|
|
|
}else if(Constant.OBJECTIVE_TYPE_Many.equals(objectiveQuestion.getType())){
|
|
|
|
|
manyIdList.add(objectiveId);
|
|
|
|
|
}else {
|
|
|
|
|
judgeIdList.add(objectiveId);
|
|
|
|
|
example.setOrderByClause("exam_time DESC");
|
|
|
|
|
List<StuTheoryExamWithBLOBs> stuTheoryExams = theoryExamMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
if (stuTheoryExams.isEmpty()) { //之前没有进行考试
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList = GenerateTest(userId);
|
|
|
|
|
return objectiveQuestionList;
|
|
|
|
|
} else { //根据考试时间排序 查询最近的一条
|
|
|
|
|
StuTheoryExamWithBLOBs stuTheoryExam = stuTheoryExams.get(0);
|
|
|
|
|
Date currentTime = new Date();
|
|
|
|
|
Date twoHoursAgo = new Date(currentTime.getTime() - (2 * 60 * 60 * 1000)); // 当前时间减去两个小时
|
|
|
|
|
if (stuTheoryExam.getExamTime().before(twoHoursAgo)) { //已超出两个小时 从新生成新试卷
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList = GenerateTest(userId);
|
|
|
|
|
return objectiveQuestionList;
|
|
|
|
|
} else { //在两个小时内 返回最近的一条试卷
|
|
|
|
|
List<SysObjectiveQuestion> returnQuestionList=new ArrayList();
|
|
|
|
|
String singleIds = stuTheoryExam.getSingleIds();
|
|
|
|
|
String multipleIds = stuTheoryExam.getMultipleIds();
|
|
|
|
|
String judgeIds = stuTheoryExam.getJudgeIds();
|
|
|
|
|
List<String> singleIdList = Arrays.asList(singleIds);
|
|
|
|
|
for (int i = 0; i < singleIdList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(singleIdList.get(i));
|
|
|
|
|
returnQuestionList.add(objectiveQuestion);
|
|
|
|
|
}
|
|
|
|
|
List<String> multipleIdList = Arrays.asList(multipleIds);
|
|
|
|
|
for (int i = 0; i < multipleIdList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(multipleIdList.get(i));
|
|
|
|
|
returnQuestionList.add(objectiveQuestion);
|
|
|
|
|
}
|
|
|
|
|
List<String> judgeIdList = Arrays.asList(judgeIds);
|
|
|
|
|
for (int i = 0; i < judgeIdList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(judgeIdList.get(i));
|
|
|
|
|
returnQuestionList.add(objectiveQuestion);
|
|
|
|
|
}
|
|
|
|
|
return returnQuestionList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//随机生成100分题目
|
|
|
|
|
public List<SysObjectiveQuestion> GenerateTest(String userId) {
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList = objectiveQuestionMapper.selectRandomObjective100();
|
|
|
|
|
List<String> singleIdList = new ArrayList<>();
|
|
|
|
|
List<String> manyIdList = new ArrayList<>();
|
|
|
|
|
List<String> judgeIdList = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < objectiveQuestionList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionList.get(i);
|
|
|
|
|
String objectiveId = objectiveQuestion.getObjectiveId();
|
|
|
|
|
if (Constant.OBJECTIVE_TYPE_SINGLE.equals(objectiveQuestion.getType())) {
|
|
|
|
|
singleIdList.add(objectiveId);
|
|
|
|
|
} else if (Constant.OBJECTIVE_TYPE_Many.equals(objectiveQuestion.getType())) {
|
|
|
|
|
manyIdList.add(objectiveId);
|
|
|
|
|
} else {
|
|
|
|
|
judgeIdList.add(objectiveId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
StuTheoryExamWithBLOBs stuTheoryExam = new StuTheoryExamWithBLOBs();
|
|
|
|
|
stuTheoryExam.setTheoryExamId(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
stuTheoryExam.setUserId(userId);
|
|
|
|
|
stuTheoryExam.setExamTime(new Date());
|
|
|
|
|
stuTheoryExam.setExamDuration(120);
|
|
|
|
|
stuTheoryExam.setAnswered(false);
|
|
|
|
|
stuTheoryExam.setSingleIds(String.valueOf(singleIdList));
|
|
|
|
|
stuTheoryExam.setMultipleIds(String.valueOf(manyIdList));
|
|
|
|
|
stuTheoryExam.setJudgeIds(String.valueOf(judgeIdList));
|
|
|
|
|
theoryExamMapper.insert(stuTheoryExam);
|
|
|
|
|
return objectiveQuestionList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int endTheoryTest(StuTheoryTestDto theoryTestDto) {
|
|
|
|
|
StuTheoryExamExample example = new StuTheoryExamExample();
|
|
|
|
|
example.createCriteria().andUserIdEqualTo(theoryTestDto.getUserId());
|
|
|
|
|
example.setOrderByClause("exam_time DESC");
|
|
|
|
|
List<StuTheoryExamWithBLOBs> stuTheoryExams = theoryExamMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
StuTheoryExamWithBLOBs stuTheoryExam= stuTheoryExams.get(0);
|
|
|
|
|
stuTheoryExam.setExamDuration(theoryTestDto.getExamDuration());
|
|
|
|
|
stuTheoryExam.setScore(theoryTestDto.getScore());
|
|
|
|
|
stuTheoryExam.setAccuracy(theoryTestDto.getAccuracy());
|
|
|
|
|
ArrayList<String> list = new ArrayList<>();
|
|
|
|
|
list.addAll(theoryTestDto.getSingleErrorIds());
|
|
|
|
|
list.addAll(theoryTestDto.getMultipleErrorIds());
|
|
|
|
|
list.addAll(theoryTestDto.getJudgeErrorIds());
|
|
|
|
|
stuTheoryExam.setErrorIds(list.toString());
|
|
|
|
|
stuTheoryExam.setAnswered(true);
|
|
|
|
|
int i = theoryExamMapper.updateByPrimaryKey(stuTheoryExam);
|
|
|
|
|
|
|
|
|
|
//更新错题集
|
|
|
|
|
StuErrorExample errorExample = new StuErrorExample();
|
|
|
|
|
errorExample.createCriteria().andUserIdEqualTo(theoryTestDto.getUserId());
|
|
|
|
|
List<StuErrorWithBLOBs> stuErrors = errorMapper.selectByExampleWithBLOBs(errorExample);
|
|
|
|
|
if(stuErrors.isEmpty()){
|
|
|
|
|
StuErrorWithBLOBs stuError = new StuErrorWithBLOBs();
|
|
|
|
|
stuError.setErrorId(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
stuError.setUserId(theoryTestDto.getUserId());
|
|
|
|
|
stuError.setSingleIds(String.valueOf(theoryTestDto.getSingleErrorIds()));
|
|
|
|
|
stuError.setMultipleIds(String.valueOf(theoryTestDto.getMultipleErrorIds()));
|
|
|
|
|
stuError.setJudgeIds(String.valueOf(theoryTestDto.getJudgeErrorIds()));
|
|
|
|
|
errorMapper.insert(stuError);
|
|
|
|
|
}else {
|
|
|
|
|
StuErrorWithBLOBs stuError = stuErrors.get(0);
|
|
|
|
|
if(!stuError.getSingleIds().isEmpty()){
|
|
|
|
|
List<String> stringList = Arrays.asList(stuError.getSingleIds());
|
|
|
|
|
List<String> singleErrorIds = theoryTestDto.getSingleErrorIds();
|
|
|
|
|
|
|
|
|
|
List<String> combinedList = new ArrayList<>(stringList);
|
|
|
|
|
combinedList.addAll(singleErrorIds);
|
|
|
|
|
Set<String> uniqueSet = new HashSet<>(combinedList);
|
|
|
|
|
List<String> uniqueList = new ArrayList<>(uniqueSet);
|
|
|
|
|
stuError.setSingleIds(String.valueOf(uniqueList));
|
|
|
|
|
}else {
|
|
|
|
|
stuError.setSingleIds(String.valueOf(theoryTestDto.getSingleErrorIds()));
|
|
|
|
|
}
|
|
|
|
|
if(!stuError.getMultipleIds().isEmpty()){
|
|
|
|
|
List<String> stringList = Arrays.asList(stuError.getMultipleIds());
|
|
|
|
|
List<String> multipleErrorIds = theoryTestDto.getMultipleErrorIds();
|
|
|
|
|
|
|
|
|
|
List<String> combinedList = new ArrayList<>(stringList);
|
|
|
|
|
combinedList.addAll(multipleErrorIds);
|
|
|
|
|
Set<String> uniqueSet = new HashSet<>(combinedList);
|
|
|
|
|
List<String> uniqueList = new ArrayList<>(uniqueSet);
|
|
|
|
|
stuError.setMultipleIds(String.valueOf(uniqueList));
|
|
|
|
|
}else {
|
|
|
|
|
stuError.setMultipleIds(String.valueOf(theoryTestDto.getMultipleErrorIds()));
|
|
|
|
|
}
|
|
|
|
|
if(!stuError.getJudgeIds().isEmpty()){
|
|
|
|
|
List<String> stringList = Arrays.asList(stuError.getJudgeIds());
|
|
|
|
|
List<String> judgeErrorIds = theoryTestDto.getJudgeErrorIds();
|
|
|
|
|
List<String> combinedList = new ArrayList<>(stringList);
|
|
|
|
|
combinedList.addAll(judgeErrorIds);
|
|
|
|
|
Set<String> uniqueSet = new HashSet<>(combinedList);
|
|
|
|
|
List<String> uniqueList = new ArrayList<>(uniqueSet);
|
|
|
|
|
stuError.setJudgeIds(String.valueOf(uniqueList));
|
|
|
|
|
}else {
|
|
|
|
|
stuError.setJudgeIds(String.valueOf(theoryTestDto.getJudgeErrorIds()));
|
|
|
|
|
}
|
|
|
|
|
errorMapper.updateByPrimaryKey(stuError);
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SysObjectiveQuestion> selectErrors(String userId) {
|
|
|
|
|
StuErrorExample example = new StuErrorExample();
|
|
|
|
|
example.createCriteria().andUserIdEqualTo(userId);
|
|
|
|
|
List<StuErrorWithBLOBs> stuErrors = errorMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
if(stuErrors.isEmpty()){
|
|
|
|
|
return null;
|
|
|
|
|
}else {
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList=new ArrayList<>();
|
|
|
|
|
StuErrorWithBLOBs stuError = stuErrors.get(0);
|
|
|
|
|
String singleIds = stuError.getSingleIds();
|
|
|
|
|
if(!singleIds.isEmpty()){
|
|
|
|
|
List<String> singleIdList = Arrays.asList(singleIds);
|
|
|
|
|
for (int i = 0; i < singleIdList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(singleIdList.get(i));
|
|
|
|
|
objectiveQuestionList.add(objectiveQuestion);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String multipleIds = stuError.getMultipleIds();
|
|
|
|
|
if(!multipleIds.isEmpty()){
|
|
|
|
|
List<String> stringList = Arrays.asList(multipleIds);
|
|
|
|
|
for (int i = 0; i < stringList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(stringList.get(i));
|
|
|
|
|
objectiveQuestionList.add(objectiveQuestion);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String judgeIds = stuError.getJudgeIds();
|
|
|
|
|
if(!judgeIds.isEmpty()){
|
|
|
|
|
List<String> stringList = Arrays.asList(judgeIds);
|
|
|
|
|
for (int i = 0; i < stringList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(stringList.get(i));
|
|
|
|
|
objectiveQuestionList.add(objectiveQuestion);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
StuTheoryExamWithBLOBs stuTheoryExam = new StuTheoryExamWithBLOBs();
|
|
|
|
|
stuTheoryExam.setTheoryExamId(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
stuTheoryExam.setUserId(userId);
|
|
|
|
|
stuTheoryExam.setExamTime(new Date());
|
|
|
|
|
stuTheoryExam.setExamDuration(120);
|
|
|
|
|
stuTheoryExam.setAnswered(false);
|
|
|
|
|
stuTheoryExam.setSingleIds(String.valueOf(singleIdList));
|
|
|
|
|
stuTheoryExam.setMultipleIds(String.valueOf(manyIdList));
|
|
|
|
|
stuTheoryExam.setJudgeIds(String.valueOf(judgeIdList));
|
|
|
|
|
theoryExamMapper.insert(stuTheoryExam);
|
|
|
|
|
return objectiveQuestionList;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|