diff --git a/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java b/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java index 6fe1738..dd8412f 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java +++ b/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java @@ -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"; + } diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java index 495a730..49edd95 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java @@ -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> selectErrors(@RequestParam String userId){ + List list=theoryTestService.selectErrors(userId); + if(list==null){ + return new ResultEntity<>(HttpStatus.OK, "没有错题",null); + } + return new ResultEntity<>(HttpStatus.OK, "错题集展示成功",list); + } + //移除错题集 //考试记录查询 //考试记录详情查询 diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java index f7e897e..c22f07d 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/UserController.java @@ -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); diff --git a/src/main/java/com/sztzjy/financial_bigdata/entity/stu_dto/StuTheoryTestDto.java b/src/main/java/com/sztzjy/financial_bigdata/entity/stu_dto/StuTheoryTestDto.java new file mode 100644 index 0000000..07828d8 --- /dev/null +++ b/src/main/java/com/sztzjy/financial_bigdata/entity/stu_dto/StuTheoryTestDto.java @@ -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 singleStuAnswer; + + @ApiModelProperty("多选题学生答案集合 ABC AB") + List multipleStuAnswer; + + @ApiModelProperty("判断题学生答案集合true false") + List judgeStuAnswer; + + @ApiModelProperty("单选错误题目id集合") + List singleErrorIds; + + @ApiModelProperty("多选错误题目id集合") + List multipleErrorIds; + + @ApiModelProperty("判断错误题目id集合") + List judgeErrorIds; +} diff --git a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuErrorMapper.java b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuErrorMapper.java index b5ae72d..8c71680 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/StuErrorMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/StuErrorMapper.java @@ -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); diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/ITheoryTestService.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/ITheoryTestService.java index 4b8762f..d913ef5 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/ITheoryTestService.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/ITheoryTestService.java @@ -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 startTheoryTest(String userId); + + int endTheoryTest(StuTheoryTestDto theoryTestDto); + + List selectErrors(String userId); } diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java index 8d0347c..7ffd57d 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java @@ -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; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java index d763d21..4249d74 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java @@ -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 startTheoryTest(String userId) { StuTheoryExamExample example = new StuTheoryExamExample(); example.createCriteria().andUserIdEqualTo(userId); - List stuTheoryExams = theoryExamMapper.selectByExample(example); - if(stuTheoryExams.isEmpty()){ - List objectiveQuestionList= objectiveQuestionMapper.selectRandomObjective100(); - List singleIdList=new ArrayList<>(); - List manyIdList=new ArrayList<>(); - List 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 stuTheoryExams = theoryExamMapper.selectByExampleWithBLOBs(example); + if (stuTheoryExams.isEmpty()) { //之前没有进行考试 + List 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 objectiveQuestionList = GenerateTest(userId); + return objectiveQuestionList; + } else { //在两个小时内 返回最近的一条试卷 + List returnQuestionList=new ArrayList(); + String singleIds = stuTheoryExam.getSingleIds(); + String multipleIds = stuTheoryExam.getMultipleIds(); + String judgeIds = stuTheoryExam.getJudgeIds(); + List singleIdList = Arrays.asList(singleIds); + for (int i = 0; i < singleIdList.size(); i++) { + SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(singleIdList.get(i)); + returnQuestionList.add(objectiveQuestion); + } + List multipleIdList = Arrays.asList(multipleIds); + for (int i = 0; i < multipleIdList.size(); i++) { + SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(multipleIdList.get(i)); + returnQuestionList.add(objectiveQuestion); + } + List 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 GenerateTest(String userId) { + List objectiveQuestionList = objectiveQuestionMapper.selectRandomObjective100(); + List singleIdList = new ArrayList<>(); + List manyIdList = new ArrayList<>(); + List 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 stuTheoryExams = theoryExamMapper.selectByExampleWithBLOBs(example); + StuTheoryExamWithBLOBs stuTheoryExam= stuTheoryExams.get(0); + stuTheoryExam.setExamDuration(theoryTestDto.getExamDuration()); + stuTheoryExam.setScore(theoryTestDto.getScore()); + stuTheoryExam.setAccuracy(theoryTestDto.getAccuracy()); + ArrayList 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 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 stringList = Arrays.asList(stuError.getSingleIds()); + List singleErrorIds = theoryTestDto.getSingleErrorIds(); + + List combinedList = new ArrayList<>(stringList); + combinedList.addAll(singleErrorIds); + Set uniqueSet = new HashSet<>(combinedList); + List uniqueList = new ArrayList<>(uniqueSet); + stuError.setSingleIds(String.valueOf(uniqueList)); + }else { + stuError.setSingleIds(String.valueOf(theoryTestDto.getSingleErrorIds())); + } + if(!stuError.getMultipleIds().isEmpty()){ + List stringList = Arrays.asList(stuError.getMultipleIds()); + List multipleErrorIds = theoryTestDto.getMultipleErrorIds(); + + List combinedList = new ArrayList<>(stringList); + combinedList.addAll(multipleErrorIds); + Set uniqueSet = new HashSet<>(combinedList); + List uniqueList = new ArrayList<>(uniqueSet); + stuError.setMultipleIds(String.valueOf(uniqueList)); + }else { + stuError.setMultipleIds(String.valueOf(theoryTestDto.getMultipleErrorIds())); + } + if(!stuError.getJudgeIds().isEmpty()){ + List stringList = Arrays.asList(stuError.getJudgeIds()); + List judgeErrorIds = theoryTestDto.getJudgeErrorIds(); + List combinedList = new ArrayList<>(stringList); + combinedList.addAll(judgeErrorIds); + Set uniqueSet = new HashSet<>(combinedList); + List uniqueList = new ArrayList<>(uniqueSet); + stuError.setJudgeIds(String.valueOf(uniqueList)); + }else { + stuError.setJudgeIds(String.valueOf(theoryTestDto.getJudgeErrorIds())); + } + errorMapper.updateByPrimaryKey(stuError); + } + return i; + } + + @Override + public List selectErrors(String userId) { + StuErrorExample example = new StuErrorExample(); + example.createCriteria().andUserIdEqualTo(userId); + List stuErrors = errorMapper.selectByExampleWithBLOBs(example); + if(stuErrors.isEmpty()){ + return null; + }else { + List objectiveQuestionList=new ArrayList<>(); + StuErrorWithBLOBs stuError = stuErrors.get(0); + String singleIds = stuError.getSingleIds(); + if(!singleIds.isEmpty()){ + List 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 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 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; } } diff --git a/src/main/resources/mapper/SysObjectiveQuestionMapper.xml b/src/main/resources/mapper/SysObjectiveQuestionMapper.xml index 4c7a242..328ad88 100644 --- a/src/main/resources/mapper/SysObjectiveQuestionMapper.xml +++ b/src/main/resources/mapper/SysObjectiveQuestionMapper.xml @@ -398,7 +398,7 @@ school_id = #{schoolId,jdbcType=VARCHAR} where objective_id = #{objectiveId,jdbcType=VARCHAR} - SELECT * FROM sys_objective_question WHERE chapter_id #{chapterId,jdbcType=VARCHAR} ORDER BY RAND() @@ -406,28 +406,36 @@ - + + + SELECT + * + FROM + sys_objective_question + WHERE + rownum <= 35 + + + SELECT + * + FROM + sys_objective_question + WHERE + rownum <= 5 + + + SELECT + * + FROM + sys_objective_question + WHERE + rownum <= 10 + + ORDER BY - RAND() + RAND() + + \ No newline at end of file