diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java index 9e24f28e..160a43e8 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassExamServiceImpl.java @@ -1,6 +1,8 @@ package com.peanut.modules.common.service.impl; import cn.hutool.core.date.DateUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -149,6 +151,7 @@ public class ClassExamServiceImpl extends ServiceImpl i return R.error("存在正在考试,请结束再试"); } List courseList = new ArrayList<>(); + List historySubjectList = new ArrayList<>(); int examTime = 45;//考试持续时间 int stotal = 60;//单选题总数 int mtotal = 40;//多选题总数 @@ -173,6 +176,17 @@ public class ClassExamServiceImpl extends ServiceImpl i classCourse.setCourseId((Integer) params.get("relationId")); courseList.add(classCourse); } + //查询上次考试得问题,生成问题时,去重 + List historyList = classExamUserDao.selectList(new LambdaQueryWrapper() + .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> resultList = new ArrayList<>(); List answerList = new ArrayList<>(); List> sList = new ArrayList<>(); @@ -183,12 +197,11 @@ public class ClassExamServiceImpl extends ServiceImpl i for (ClassCourse classCourse:courseList){ CourseEntity course = courseDao.selectById(classCourse.getCourseId()); //单选 - List> singleList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper() - .selectAs(ClassExamSubject::getId,"id") - .selectAs(ClassExamSubject::getType,"type") - .selectAs(ClassExamSubject::getContent,"content") + List> singleList = classExamSubjectDao.selectMaps(new LambdaQueryWrapper() + .select(ClassExamSubject::getId,ClassExamSubject::getType,ClassExamSubject::getContent) .eq(ClassExamSubject::getCourseId,classCourse.getCourseId()) - .eq(ClassExamSubject::getType,0)); + .eq(ClassExamSubject::getType,0) + .notIn(ClassExamSubject::getId,historySubjectList)); Collections.shuffle(singleList);//打乱顺序 try { if (sList.size()+snum>stotal){ @@ -200,12 +213,11 @@ public class ClassExamServiceImpl extends ServiceImpl i return R.error(course.getTitle()+"-单选题数量不足"); } //多选 - List> mulList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper() - .selectAs(ClassExamSubject::getId,"id") - .selectAs(ClassExamSubject::getType,"type") - .selectAs(ClassExamSubject::getContent,"content") + List> mulList = classExamSubjectDao.selectMaps(new LambdaQueryWrapper() + .select(ClassExamSubject::getId,ClassExamSubject::getType,ClassExamSubject::getContent) .eq(ClassExamSubject::getCourseId,classCourse.getCourseId()) - .eq(ClassExamSubject::getType,1)); + .eq(ClassExamSubject::getType,1) + .notIn(ClassExamSubject::getId,historySubjectList)); Collections.shuffle(mulList);//打乱顺序 try { if (mList.size()+mnum>mtotal){ @@ -224,10 +236,8 @@ public class ClassExamServiceImpl extends ServiceImpl i if (resultList.size()>0){ for (Map subject:resultList) { answerList.add("");//预留答案位置 - List> options = classExamOptionDao.selectMaps(new MPJLambdaWrapper() - .selectAs(ClassExamOption::getId,"id") - .selectAs(ClassExamOption::getContent,"content") - .selectAs(ClassExamOption::getRightWrong,"rightWrong") + List> options = classExamOptionDao.selectMaps(new LambdaQueryWrapper() + .select(ClassExamOption::getId,ClassExamOption::getContent,ClassExamOption::getRightWrong) .eq(ClassExamOption::getSubjectId,subject.get("id"))); Collections.shuffle(options);//打乱顺序 subject.put("options",options);