考试生成试卷题目跟上一次考试不一样
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.peanut.modules.common.service.impl;
|
package com.peanut.modules.common.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@@ -149,6 +151,7 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
|||||||
return R.error("存在正在考试,请结束再试");
|
return R.error("存在正在考试,请结束再试");
|
||||||
}
|
}
|
||||||
List<ClassCourse> courseList = new ArrayList<>();
|
List<ClassCourse> courseList = new ArrayList<>();
|
||||||
|
List<String> historySubjectList = new ArrayList<>();
|
||||||
int examTime = 45;//考试持续时间
|
int examTime = 45;//考试持续时间
|
||||||
int stotal = 60;//单选题总数
|
int stotal = 60;//单选题总数
|
||||||
int mtotal = 40;//多选题总数
|
int mtotal = 40;//多选题总数
|
||||||
@@ -173,6 +176,17 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
|||||||
classCourse.setCourseId((Integer) params.get("relationId"));
|
classCourse.setCourseId((Integer) params.get("relationId"));
|
||||||
courseList.add(classCourse);
|
courseList.add(classCourse);
|
||||||
}
|
}
|
||||||
|
//查询上次考试得问题,生成问题时,去重
|
||||||
|
List<ClassExamUser> historyList = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
|
||||||
|
.eq(ClassExamUser::getUserId,ShiroUtils.getUId()).eq(ClassExamUser::getScoreSuccess,1)
|
||||||
|
.eq(ClassExamUser::getRelationId,params.get("relationId").toString()).orderByDesc(ClassExamUser::getStartTime));
|
||||||
|
if (historyList.size() > 0) {
|
||||||
|
ClassExamUser lastExamUser = historyList.get(0);
|
||||||
|
JSONArray subjectList = JSONUtil.parseArray(lastExamUser.getSubject());
|
||||||
|
for (Object o : subjectList){
|
||||||
|
historySubjectList.add(((Map)o).get("id").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
List<Map<String,Object>> resultList = new ArrayList<>();
|
List<Map<String,Object>> resultList = new ArrayList<>();
|
||||||
List<String> answerList = new ArrayList<>();
|
List<String> answerList = new ArrayList<>();
|
||||||
List<Map<String,Object>> sList = new ArrayList<>();
|
List<Map<String,Object>> sList = new ArrayList<>();
|
||||||
@@ -183,12 +197,11 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
|||||||
for (ClassCourse classCourse:courseList){
|
for (ClassCourse classCourse:courseList){
|
||||||
CourseEntity course = courseDao.selectById(classCourse.getCourseId());
|
CourseEntity course = courseDao.selectById(classCourse.getCourseId());
|
||||||
//单选
|
//单选
|
||||||
List<Map<String,Object>> singleList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper<ClassExamSubject>()
|
List<Map<String,Object>> singleList = classExamSubjectDao.selectMaps(new LambdaQueryWrapper<ClassExamSubject>()
|
||||||
.selectAs(ClassExamSubject::getId,"id")
|
.select(ClassExamSubject::getId,ClassExamSubject::getType,ClassExamSubject::getContent)
|
||||||
.selectAs(ClassExamSubject::getType,"type")
|
|
||||||
.selectAs(ClassExamSubject::getContent,"content")
|
|
||||||
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
|
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
|
||||||
.eq(ClassExamSubject::getType,0));
|
.eq(ClassExamSubject::getType,0)
|
||||||
|
.notIn(ClassExamSubject::getId,historySubjectList));
|
||||||
Collections.shuffle(singleList);//打乱顺序
|
Collections.shuffle(singleList);//打乱顺序
|
||||||
try {
|
try {
|
||||||
if (sList.size()+snum>stotal){
|
if (sList.size()+snum>stotal){
|
||||||
@@ -200,12 +213,11 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
|||||||
return R.error(course.getTitle()+"-单选题数量不足");
|
return R.error(course.getTitle()+"-单选题数量不足");
|
||||||
}
|
}
|
||||||
//多选
|
//多选
|
||||||
List<Map<String,Object>> mulList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper<ClassExamSubject>()
|
List<Map<String,Object>> mulList = classExamSubjectDao.selectMaps(new LambdaQueryWrapper<ClassExamSubject>()
|
||||||
.selectAs(ClassExamSubject::getId,"id")
|
.select(ClassExamSubject::getId,ClassExamSubject::getType,ClassExamSubject::getContent)
|
||||||
.selectAs(ClassExamSubject::getType,"type")
|
|
||||||
.selectAs(ClassExamSubject::getContent,"content")
|
|
||||||
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
|
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
|
||||||
.eq(ClassExamSubject::getType,1));
|
.eq(ClassExamSubject::getType,1)
|
||||||
|
.notIn(ClassExamSubject::getId,historySubjectList));
|
||||||
Collections.shuffle(mulList);//打乱顺序
|
Collections.shuffle(mulList);//打乱顺序
|
||||||
try {
|
try {
|
||||||
if (mList.size()+mnum>mtotal){
|
if (mList.size()+mnum>mtotal){
|
||||||
@@ -224,10 +236,8 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
|||||||
if (resultList.size()>0){
|
if (resultList.size()>0){
|
||||||
for (Map<String,Object> subject:resultList) {
|
for (Map<String,Object> subject:resultList) {
|
||||||
answerList.add("");//预留答案位置
|
answerList.add("");//预留答案位置
|
||||||
List<Map<String,Object>> options = classExamOptionDao.selectMaps(new MPJLambdaWrapper<ClassExamOption>()
|
List<Map<String,Object>> options = classExamOptionDao.selectMaps(new LambdaQueryWrapper<ClassExamOption>()
|
||||||
.selectAs(ClassExamOption::getId,"id")
|
.select(ClassExamOption::getId,ClassExamOption::getContent,ClassExamOption::getRightWrong)
|
||||||
.selectAs(ClassExamOption::getContent,"content")
|
|
||||||
.selectAs(ClassExamOption::getRightWrong,"rightWrong")
|
|
||||||
.eq(ClassExamOption::getSubjectId,subject.get("id")));
|
.eq(ClassExamOption::getSubjectId,subject.get("id")));
|
||||||
Collections.shuffle(options);//打乱顺序
|
Collections.shuffle(options);//打乱顺序
|
||||||
subject.put("options",options);
|
subject.put("options",options);
|
||||||
|
|||||||
Reference in New Issue
Block a user