|
|
|
@ -1,17 +1,15 @@
|
|
|
|
|
package com.sztzjy.financial_bigdata.service.stu.impl;
|
|
|
|
|
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.SysObjectiveQuestion;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.TeaExamManageWithBLOBs;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.*;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.stu_dto.StuCommitCaseExamDto;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.stu_dto.StuTheoryTestDto;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.SysObjectiveQuestionMapper;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.TeaExamManageMapper;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.*;
|
|
|
|
|
import com.sztzjy.financial_bigdata.service.stu.IExamService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class ExamServiceImpl implements IExamService {
|
|
|
|
@ -19,21 +17,68 @@ public class ExamServiceImpl implements IExamService {
|
|
|
|
|
TeaExamManageMapper examManageMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
SysObjectiveQuestionMapper objectiveQuestionMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
StuStudentExamMapper studentExamMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
SysCaseQuestionStepMapper stepMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
StuExamCaseMapper stuExamCaseMapper;
|
|
|
|
|
|
|
|
|
|
//如果学生考试表查询不到 则新增一条数据
|
|
|
|
|
//根据examManageId 查询该考试的题目idlist 再通过idlist查询题目信息进行返回
|
|
|
|
|
//先判断是否考试过 如果结束考试状态不为true 判断考试时间是否超过答题时间 超过时间则不允许答题、并回显考试内容\没超过时间 则重新答题
|
|
|
|
|
// 如果结束考试状态为true,则直接回显题目和考生的答题记录
|
|
|
|
|
@Override
|
|
|
|
|
public List<SysObjectiveQuestion> basicKnowledge(String examManageId, String userId) {
|
|
|
|
|
//查询
|
|
|
|
|
public List<SysObjectiveQuestion> basicKnowledge(String examManageId, String userId,String classId) {
|
|
|
|
|
//判断考试时间是否已经超过
|
|
|
|
|
TeaExamManageWithBLOBs teaExamManageWithBLOBs = examManageMapper.selectByPrimaryKey(examManageId);
|
|
|
|
|
if(teaExamManageWithBLOBs.getEndTime().before(new Date())){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询学生考试记录
|
|
|
|
|
StuStudentExamExample example = new StuStudentExamExample();
|
|
|
|
|
example.createCriteria().andUseridEqualTo(userId).andExamManageIdEqualTo(examManageId);
|
|
|
|
|
List<StuStudentExamWithBLOBs> stuStudentExams = studentExamMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
if(stuStudentExams==null || stuStudentExams.size()==0){
|
|
|
|
|
StuStudentExamWithBLOBs stuExam = new StuStudentExamWithBLOBs();
|
|
|
|
|
stuExam.setStudentExamId(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
stuExam.setExamManageId(examManageId);
|
|
|
|
|
stuExam.setUserid(userId);
|
|
|
|
|
stuExam.setClassId(classId);
|
|
|
|
|
stuExam.setStartTime(new Date());
|
|
|
|
|
studentExamMapper.insert(stuExam);
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList = GenerateExam(examManageId);
|
|
|
|
|
return objectiveQuestionList;
|
|
|
|
|
}else {
|
|
|
|
|
StuStudentExamWithBLOBs stuExam = stuStudentExams.get(0);
|
|
|
|
|
if("true".equals(stuExam.getExamEndStatus())){ //代表已经考完
|
|
|
|
|
return null;
|
|
|
|
|
}else { //先判断考试时间是否超时
|
|
|
|
|
// Date currentTime = new Date();
|
|
|
|
|
// Date twoHoursAgo = new Date(currentTime.getTime() - (2 * 60 * 60 * 1000)); // 当前时间减去两个小时
|
|
|
|
|
// if (stuExam.getStartTime().before(twoHoursAgo)) { //已超出两个小时 不允许交卷 并更新studentExam参数
|
|
|
|
|
// stuExam.setObjectiveScore(BigDecimal.ZERO);
|
|
|
|
|
// stuExam.setExamEndStatus("true");
|
|
|
|
|
// studentExamMapper.updateByPrimaryKeyWithBLOBs(stuExam);
|
|
|
|
|
// return null;
|
|
|
|
|
// }else { //没超过两个小时
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList = GenerateExam(examManageId);
|
|
|
|
|
return objectiveQuestionList;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SysObjectiveQuestion> GenerateExam(String examManageId){
|
|
|
|
|
TeaExamManageWithBLOBs teaExamManageWithBLOBs = examManageMapper.selectByPrimaryKey(examManageId);
|
|
|
|
|
String singleIds = teaExamManageWithBLOBs.getSingleIdlist();
|
|
|
|
|
String manyIds = teaExamManageWithBLOBs.getManyIdlist();
|
|
|
|
|
String judgeIds = teaExamManageWithBLOBs.getJudgeIdlist();
|
|
|
|
|
List<String> singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(", "));
|
|
|
|
|
List<String> manyIdList = Arrays.asList(manyIds.substring(1, manyIds.length() - 1).split(", "));
|
|
|
|
|
List<String> judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(", "));
|
|
|
|
|
List<String> singleIdList = Arrays.asList(singleIds.substring(0, singleIds.length() ).split(","));
|
|
|
|
|
List<String> manyIdList = Arrays.asList(manyIds.substring(0, manyIds.length()).split(","));
|
|
|
|
|
List<String> judgeIdList = Arrays.asList(judgeIds.substring(0, judgeIds.length()).split(","));
|
|
|
|
|
List<SysObjectiveQuestion> objectiveQuestionList=new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < singleIdList.size(); i++) {
|
|
|
|
|
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(singleIdList.get(i));
|
|
|
|
@ -50,8 +95,142 @@ public class ExamServiceImpl implements IExamService {
|
|
|
|
|
return objectiveQuestionList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//先判断是否提交过考试
|
|
|
|
|
@Override
|
|
|
|
|
public int commitExam(StuTheoryTestDto theoryTestDto) {
|
|
|
|
|
public int commitExam(StuTheoryTestDto theoryTestDto,String examManageId) {
|
|
|
|
|
String userId = theoryTestDto.getUserId();
|
|
|
|
|
StuStudentExamExample example = new StuStudentExamExample();
|
|
|
|
|
example.createCriteria().andUseridEqualTo(userId).andExamManageIdEqualTo(examManageId);
|
|
|
|
|
List<StuStudentExamWithBLOBs> stuStudentExams = studentExamMapper.selectByExampleWithBLOBs(example);
|
|
|
|
|
if(stuStudentExams==null){ //没有考试开始记录
|
|
|
|
|
return 0;
|
|
|
|
|
}else {
|
|
|
|
|
StuStudentExamWithBLOBs stuStudentExam = stuStudentExams.get(0);
|
|
|
|
|
String examEndStatus = stuStudentExam.getExamEndStatus();
|
|
|
|
|
if("true".equals(examEndStatus)){ //已提交过考试 不能重复提交
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
//未提交过考试 将客观题得分、总分 ids保存
|
|
|
|
|
stuStudentExam.setObjectiveScore(theoryTestDto.getScore());
|
|
|
|
|
if(stuStudentExam.getTotalScore()==null){
|
|
|
|
|
stuStudentExam.setTotalScore(theoryTestDto.getScore());
|
|
|
|
|
}else {
|
|
|
|
|
stuStudentExam.setTotalScore(stuStudentExam.getTotalScore().add(theoryTestDto.getScore()));
|
|
|
|
|
}
|
|
|
|
|
stuStudentExam.setSingleStuAnswerIds(String.valueOf(theoryTestDto.getSingleStuAnswer()));
|
|
|
|
|
stuStudentExam.setManyStuAnswerIds(String.valueOf(theoryTestDto.getMultipleStuAnswer()));
|
|
|
|
|
stuStudentExam.setJudgeStuAnswerIds(String.valueOf(theoryTestDto.getJudgeStuAnswer()));
|
|
|
|
|
stuStudentExam.setExamEndStatus("true");
|
|
|
|
|
studentExamMapper.updateByPrimaryKeyWithBLOBs(stuStudentExam);
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//案例开始答题
|
|
|
|
|
//先查询当前时间是否在考试时间之内
|
|
|
|
|
//在考试时间外 返回不在考试时间内
|
|
|
|
|
//考试时间内
|
|
|
|
|
//根据传递的caseid查询所有step数据(判断是否查询第一个案例数据 )
|
|
|
|
|
//根据casestepid、userid、exammanageid 查询该案例的数据 如果有 代表之前提交过 则替换返回的答案 没有 则返回上一步查询的数据 并设置答案为null
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SysCaseQuestionStep> startCase(String examManageId, String userId, String classId,String caseId) {
|
|
|
|
|
TeaExamManageWithBLOBs manage = examManageMapper.selectByPrimaryKey(examManageId);
|
|
|
|
|
Date endTime = manage.getEndTime();
|
|
|
|
|
if(endTime.before(new Date())){
|
|
|
|
|
return null;
|
|
|
|
|
}else {
|
|
|
|
|
String caseIdlist = manage.getCaseIdlist();
|
|
|
|
|
List<String> caseIdList = Arrays.asList(caseIdlist.split(", "));
|
|
|
|
|
SysCaseQuestionStepExample example = new SysCaseQuestionStepExample();
|
|
|
|
|
if(caseId.equals("first")){
|
|
|
|
|
String caseIdFirst = caseIdList.get(0);
|
|
|
|
|
//根据caseid 到casestep表中查询所有step
|
|
|
|
|
example.createCriteria().andCaseIdEqualTo(caseIdFirst);
|
|
|
|
|
List<SysCaseQuestionStep> stepList = stepMapper.selectByExample(example);
|
|
|
|
|
for (int i = 0; i < stepList.size(); i++) {
|
|
|
|
|
StuExamCaseExample stuExamCaseExample = new StuExamCaseExample();
|
|
|
|
|
stuExamCaseExample.createCriteria().andCaseStepIdEqualTo(stepList.get(i).getCaseStepId()).andUserIdEqualTo(userId).andExamManageIdEqualTo(examManageId);
|
|
|
|
|
List<StuExamCase> stuExamCases = stuExamCaseMapper.selectByExample(stuExamCaseExample);
|
|
|
|
|
if(stuExamCases==null || stuExamCases.size()==0){
|
|
|
|
|
stepList.get(i).setAnswer("");
|
|
|
|
|
stepList.get(i).setAnswerOriginal("");
|
|
|
|
|
continue;
|
|
|
|
|
}else {
|
|
|
|
|
stepList.get(i).setAnswerOriginal(stuExamCases.get(0).getStudentAnswer());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return stepList;
|
|
|
|
|
}else {
|
|
|
|
|
example.createCriteria().andCaseIdEqualTo(caseId);
|
|
|
|
|
List<SysCaseQuestionStep> stepList = stepMapper.selectByExample(example);
|
|
|
|
|
for (int i = 0; i < stepList.size(); i++) {
|
|
|
|
|
StuExamCaseExample stuExamCaseExample = new StuExamCaseExample();
|
|
|
|
|
stuExamCaseExample.createCriteria().andCaseStepIdEqualTo(stepList.get(i).getCaseStepId()).andUserIdEqualTo(userId).andExamManageIdEqualTo(examManageId);
|
|
|
|
|
List<StuExamCase> stuExamCases = stuExamCaseMapper.selectByExample(stuExamCaseExample);
|
|
|
|
|
if(stuExamCases==null || stuExamCases.size()==0){
|
|
|
|
|
stepList.get(i).setAnswer("");
|
|
|
|
|
stepList.get(i).setAnswerOriginal("");
|
|
|
|
|
continue;
|
|
|
|
|
}else {
|
|
|
|
|
stepList.get(i).setAnswerOriginal(stuExamCases.get(0).getStudentAnswer());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return stepList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//先根据commitCaseExamDto.caseStepId userid、examManageId查询stuExamCaseMapper表中是否有数据 有的话 表示该步骤已经提交
|
|
|
|
|
//没有数据 代表可以提交 根据caseStepId到案例题库表中查询答案 判断案例题库中的答案和dto中的答案是否相同
|
|
|
|
|
//如果相同 则新增一条学生考试案例表 并设置分数、基础信息、学生答案
|
|
|
|
|
//如果不同 则新增一条学生考试案例表 并设置分数、基础信息、学生答案
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean commitCaseExam(StuCommitCaseExamDto commitCaseExamDto) {
|
|
|
|
|
StuExamCaseExample example = new StuExamCaseExample();
|
|
|
|
|
example.createCriteria().andCaseStepIdEqualTo(commitCaseExamDto.getCaseStepId()).andUserIdEqualTo(commitCaseExamDto.getUserId()).andExamManageIdEqualTo(commitCaseExamDto.getExamManageId());
|
|
|
|
|
List<StuExamCase> stuExamCases = stuExamCaseMapper.selectByExample(example);
|
|
|
|
|
String caseStepId = commitCaseExamDto.getCaseStepId();
|
|
|
|
|
SysCaseQuestionStep sysCaseQuestionStep = stepMapper.selectByPrimaryKey(caseStepId);
|
|
|
|
|
if(stuExamCases==null || stuExamCases.size()==0){
|
|
|
|
|
StuExamCase stuExamCase = new StuExamCase();
|
|
|
|
|
stuExamCase.setCaseId(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
stuExamCase.setExamManageId(commitCaseExamDto.getExamManageId());
|
|
|
|
|
stuExamCase.setCaseId(commitCaseExamDto.getCaseId());
|
|
|
|
|
stuExamCase.setStudentAnswer(commitCaseExamDto.getStuAnswer());
|
|
|
|
|
stuExamCase.setCaseStepId(caseStepId);
|
|
|
|
|
stuExamCase.setUserId(commitCaseExamDto.getUserId());
|
|
|
|
|
if(sysCaseQuestionStep.getAnswerOriginal().equals(commitCaseExamDto.getStuAnswer())){
|
|
|
|
|
stuExamCase.setCaseScore(sysCaseQuestionStep.getScore());
|
|
|
|
|
}else {
|
|
|
|
|
stuExamCase.setCaseScore(BigDecimal.ZERO);
|
|
|
|
|
}
|
|
|
|
|
stuExamCaseMapper.insert(stuExamCase);
|
|
|
|
|
|
|
|
|
|
//设置stustudentexam中的案例题得分、总分、案例题结束状态
|
|
|
|
|
StuStudentExamExample stuStudentExamExample = new StuStudentExamExample();
|
|
|
|
|
stuStudentExamExample.createCriteria().andUseridEqualTo(commitCaseExamDto.getUserId()).andExamManageIdEqualTo(commitCaseExamDto.getExamManageId());
|
|
|
|
|
List<StuStudentExam> stuStudentExams = studentExamMapper.selectByExample(stuStudentExamExample);
|
|
|
|
|
if(stuStudentExams==null || stuStudentExams.size()==0){
|
|
|
|
|
return false;
|
|
|
|
|
}else {
|
|
|
|
|
StuStudentExam stuStudentExam = stuStudentExams.get(0);
|
|
|
|
|
if(stuStudentExam.getCaseScore()==null){ //案例题分数
|
|
|
|
|
stuStudentExam.setCaseScore(sysCaseQuestionStep.getScore());
|
|
|
|
|
}else {
|
|
|
|
|
stuStudentExam.setCaseScore(stuStudentExam.getCaseScore().add(sysCaseQuestionStep.getScore()));
|
|
|
|
|
}
|
|
|
|
|
if(stuStudentExam.getTotalScore()==null){ //总分
|
|
|
|
|
stuStudentExam.setTotalScore(sysCaseQuestionStep.getScore());
|
|
|
|
|
}else {
|
|
|
|
|
stuStudentExam.setTotalScore(stuStudentExam.getTotalScore().add(sysCaseQuestionStep.getScore()));
|
|
|
|
|
}
|
|
|
|
|
//平均正确率
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|