新增错题集展示、结束考试功能

newBigdata
yz 11 months ago
parent 00b2bbe913
commit 2c6a529e1b

@ -24,5 +24,7 @@ public class Constant {
public static final String OBJECTIVE_TYPE_SINGLE= "single";
public static final String OBJECTIVE_TYPE_Many= "many";
public static final String OBJECTIVE_TYPE_JUDGE= "judge";
//xcj
private String aaa="aaa";
}

@ -3,21 +3,19 @@ package com.sztzjy.financial_bigdata.controller.stu;
import com.sztzjy.financial_bigdata.annotation.AnonymousAccess;
import com.sztzjy.financial_bigdata.entity.SysObjectiveQuestion;
import com.sztzjy.financial_bigdata.entity.stu_dto.StuTheoryTestDto;
import com.sztzjy.financial_bigdata.service.stu.ITheoryTestService;
import com.sztzjy.financial_bigdata.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@Api(tags = "理论考试")
@Api(tags = "理论考试、错题集功能")
@RequestMapping("api/stu/theoryTestController")
public class TheoryTestController {
@Autowired
@ -33,7 +31,32 @@ public class TheoryTestController {
}
//结束考试
@GetMapping("endTheoryTest")
@ApiOperation("结束考试 学生自动点击交卷、前端检查时间到了也发送请求")
@AnonymousAccess
public ResultEntity endTheoryTest(@RequestBody StuTheoryTestDto theoryTestDto) {
int flag=theoryTestService.endTheoryTest(theoryTestDto);
if(theoryTestDto.getExamDuration()>120){
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "提交试卷超时");
}
if(flag==1){
return new ResultEntity<>(HttpStatus.OK, "提交试卷成功");
}else {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "提交试卷失败");
}
}
//错题集展示
@GetMapping("selectErrors")
@ApiOperation("错题集展示")
public ResultEntity<List<SysObjectiveQuestion>> selectErrors(@RequestParam String userId){
List<SysObjectiveQuestion> list=theoryTestService.selectErrors(userId);
if(list==null){
return new ResultEntity<>(HttpStatus.OK, "没有错题",null);
}
return new ResultEntity<>(HttpStatus.OK, "错题集展示成功",list);
}
//移除错题集
//考试记录查询
//考试记录详情查询

@ -57,12 +57,13 @@ public class UserController {
@PostMapping("/login")
@ApiOperation("登录接口")
@AnonymousAccess
public ResultEntity login(@RequestParam String passwordEncode,
@RequestParam String userName,
@RequestParam(required = false) String TOKEN) throws Exception {
JwtUser jwtUser;
String passWord = RsaUtil.decryptByPrivateKey(passwordEncode);
if (StringUtils.isNotBlank(TOKEN)) {
if (StringUtils.isBlank(TOKEN)) {
// 1、子系统直接登录
StuUserExample stuUserExample = new StuUserExample();
stuUserExample.createCriteria().andUsernameEqualTo(userName).andPasswordEqualTo(passWord);

@ -0,0 +1,45 @@
package com.sztzjy.financial_bigdata.entity.stu_dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.List;
@Data
@NoArgsConstructor
public class StuTheoryTestDto {
@ApiModelProperty("用户id")
private String userId;
@ApiModelProperty("考试用时、分钟")
private Integer examDuration;
@ApiModelProperty("得分")
BigDecimal score;
@ApiModelProperty("正确率")
BigDecimal accuracy;
@ApiModelProperty("是否打完")
Boolean answered;
@ApiModelProperty("单选题学生答案集合")
List<String> singleStuAnswer;
@ApiModelProperty("多选题学生答案集合 ABC AB")
List<String> multipleStuAnswer;
@ApiModelProperty("判断题学生答案集合true false")
List<String> judgeStuAnswer;
@ApiModelProperty("单选错误题目id集合")
List<String> singleErrorIds;
@ApiModelProperty("多选错误题目id集合")
List<String> multipleErrorIds;
@ApiModelProperty("判断错误题目id集合")
List<String> judgeErrorIds;
}

@ -4,8 +4,10 @@ import com.sztzjy.financial_bigdata.entity.StuError;
import com.sztzjy.financial_bigdata.entity.StuErrorExample;
import com.sztzjy.financial_bigdata.entity.StuErrorWithBLOBs;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface StuErrorMapper {
long countByExample(StuErrorExample example);

@ -1,9 +1,14 @@
package com.sztzjy.financial_bigdata.service.stu;
import com.sztzjy.financial_bigdata.entity.SysObjectiveQuestion;
import com.sztzjy.financial_bigdata.entity.stu_dto.StuTheoryTestDto;
import java.util.List;
public interface ITheoryTestService {
List<SysObjectiveQuestion> startTheoryTest(String userId);
int endTheoryTest(StuTheoryTestDto theoryTestDto);
List<SysObjectiveQuestion> selectErrors(String userId);
}

@ -128,6 +128,7 @@ public class ExerciseServiceImpl implements IExerciseService {
}else{
progress=progress.add(BigDecimal.valueOf(1));
}
bloBs.setProgress(progress);
int i = trainingMapper.updateByPrimaryKey(bloBs);
return i==1;
}

@ -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,20 +32,59 @@ 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<>();
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())){
if (Constant.OBJECTIVE_TYPE_SINGLE.equals(objectiveQuestion.getType())) {
singleIdList.add(objectiveId);
}else if(Constant.OBJECTIVE_TYPE_Many.equals(objectiveQuestion.getType())){
} else if (Constant.OBJECTIVE_TYPE_Many.equals(objectiveQuestion.getType())) {
manyIdList.add(objectiveId);
}else {
} else {
judgeIdList.add(objectiveId);
}
}
@ -59,6 +100,115 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
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);
}
}
return objectiveQuestionList;
}
}
}

@ -398,7 +398,7 @@
school_id = #{schoolId,jdbcType=VARCHAR}
where objective_id = #{objectiveId,jdbcType=VARCHAR}
</update>
<select id="selectRandomObjective" parameterType="map" resultMap="SysObjectiveQuestion">
<select id="selectRandomObjective" parameterType="map" resultMap="BaseResultMap">
SELECT * FROM sys_objective_question
WHERE chapter_id #{chapterId,jdbcType=VARCHAR}
ORDER BY RAND()
@ -406,28 +406,36 @@
</select>
<select id="selectRandomObjective100" resultType="com.sztzjy.financial_bigdata.entity.SysObjectiveQuestion">
<select id="selectRandomObjective100" resultMap="BaseResultMap">
<choose>
<when test="type = 'single' and inputType = '1'">
SELECT
*
FROM
sys_objective_question
WHERE
(type = 'single' AND inputType = '1' AND rownum = 35)
UNION
rownum &lt;= 35
</when>
<when test="type = 'many' and inputType = '1'">
SELECT
*
FROM
sys_objective_question
WHERE
(type = 'many' AND inputType = '1' AND rownum = 5)
UNION
rownum &lt;= 5
</when>
<when test="type = 'judge' and inputType = '1'">
SELECT
*
FROM
sys_objective_question
WHERE
(type = 'judge' AND inputType = '1' AND rownum = 10)
rownum &lt;= 10
</when>
</choose>
ORDER BY
RAND()
</select>
</mapper>
Loading…
Cancel
Save