From 83d35846e9f000a76376160a465f57c01981eec3 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 15:52:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=AF=95=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ClassExamServiceImpl.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) 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 b5d81848..a9e54659 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 @@ -114,18 +114,21 @@ public class ClassExamServiceImpl extends ServiceImpl i courseWrapper.eq(ClassEntity::getId,params.get("classId")); courseWrapper.selectAll(ClassCourse.class); List courseList = classCourseDao.selectList(courseWrapper); - List resultList = new ArrayList<>(); - List sList = new ArrayList<>(); - List mList = new ArrayList<>(); + List> resultList = new ArrayList<>(); + List> sList = new ArrayList<>(); + List> mList = new ArrayList<>(); if (courseList.size() > 0) { - int stotal = 50;//单选题总数 - int mtotal = 50;//多选题总数 + int stotal = 10;//单选题总数 + int mtotal = 10;//多选题总数 int snum = (int)Math.floor(stotal/courseList.size()); int mnum = (int)Math.floor(mtotal/courseList.size()); for (ClassCourse classCourse:courseList){ CourseEntity course = courseDao.selectById(classCourse.getCourseId()); //单选 - List singleList = classExamSubjectDao.selectList(new LambdaQueryWrapper() + List> singleList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper() + .selectAs(ClassExamSubject::getId,"id") + .selectAs(ClassExamSubject::getType,"type") + .selectAs(ClassExamSubject::getContent,"content") .eq(ClassExamSubject::getCourseId,classCourse.getCourseId()) .eq(ClassExamSubject::getType,0)); Collections.shuffle(singleList);//打乱顺序 @@ -139,7 +142,10 @@ public class ClassExamServiceImpl extends ServiceImpl i return R.error(course.getTitle()+"-单选题数量不足"); } //多选 - List mulList = classExamSubjectDao.selectList(new LambdaQueryWrapper() + List> mulList = classExamSubjectDao.selectMaps(new MPJLambdaWrapper() + .selectAs(ClassExamSubject::getId,"id") + .selectAs(ClassExamSubject::getType,"type") + .selectAs(ClassExamSubject::getContent,"content") .eq(ClassExamSubject::getCourseId,classCourse.getCourseId()) .eq(ClassExamSubject::getType,1)); Collections.shuffle(mulList);//打乱顺序 @@ -158,11 +164,14 @@ public class ClassExamServiceImpl extends ServiceImpl i resultList.addAll(mList); //拼装选项 if (resultList.size()>0){ - for (ClassExamSubject subject:resultList) { - List options = classExamOptionDao.selectList( - new LambdaQueryWrapper().eq(ClassExamOption::getSubjectId,subject.getId())); + for (Map subject:resultList) { + List> options = classExamOptionDao.selectMaps(new MPJLambdaWrapper() + .selectAs(ClassExamOption::getId,"id") + .selectAs(ClassExamOption::getContent,"content") + .selectAs(ClassExamOption::getRightWrong,"rightWrong") + .eq(ClassExamOption::getSubjectId,subject.get("id"))); Collections.shuffle(options);//打乱顺序 - subject.setOptions(options); + subject.put("options",options); } } ClassExamUser classExamUser = new ClassExamUser();