From 10e8e2dc9afe555c792a93e881a15ad86508fd80 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 09:04:10 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=80=83=E8=AF=95=E5=AD=A6=E5=91=98?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/ClassController.java | 6 +++ .../modules/common/entity/ClassExamUser.java | 2 +- .../common/service/ClassEntityService.java | 2 + .../service/impl/ClassEntityServiceImpl.java | 51 ++++++++++++++++--- .../service/impl/ClassExamServiceImpl.java | 2 +- 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/peanut/modules/common/controller/ClassController.java b/src/main/java/com/peanut/modules/common/controller/ClassController.java index 84f74db6..ba7a4917 100644 --- a/src/main/java/com/peanut/modules/common/controller/ClassController.java +++ b/src/main/java/com/peanut/modules/common/controller/ClassController.java @@ -318,4 +318,10 @@ public class ClassController { return R.ok().put("result",classEntityService.getUserScore(params)); } + //学员成绩列表 + @RequestMapping("/userScoreList") + public R userScoreList(@RequestBody Map params){ + return R.ok().put("result",classEntityService.userScoreList(params)); + } + } diff --git a/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java b/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java index 2562622a..78981cd3 100644 --- a/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java +++ b/src/main/java/com/peanut/modules/common/entity/ClassExamUser.java @@ -12,7 +12,7 @@ public class ClassExamUser { @TableId private Integer id; - private Integer examId; + private Integer classId; private Integer userId; diff --git a/src/main/java/com/peanut/modules/common/service/ClassEntityService.java b/src/main/java/com/peanut/modules/common/service/ClassEntityService.java index 4df99e86..643bd46e 100644 --- a/src/main/java/com/peanut/modules/common/service/ClassEntityService.java +++ b/src/main/java/com/peanut/modules/common/service/ClassEntityService.java @@ -85,4 +85,6 @@ public interface ClassEntityService extends IService { Map getUserScore(Map params); + List userScoreList(Map params); + } diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java index 9cd9a5ab..4b37c9d7 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java @@ -43,6 +43,8 @@ public class ClassEntityServiceImpl extends ServiceImpl params) { @@ -968,9 +970,13 @@ public class ClassEntityServiceImpl extends ServiceImpl questionReplys = classTaskAndQuesReplyDao.selectList(questionWrapper); if (questionReplys.size() > 0) { for (ClassTaskAndQuesReply reply : questionReplys) { @@ -986,7 +992,7 @@ public class ClassEntityServiceImpl extends ServiceImpl task0wrapper = new MPJLambdaWrapper<>(); task0wrapper.leftJoin(ClassTask.class,ClassTask::getId,ClassTaskAndQuesReply::getRelationId); task0wrapper.selectAll(ClassTaskAndQuesReply.class); - task0wrapper.eq(ClassTask::getClassId,params.get("classId")); + task0wrapper.eq(ClassTask::getClassId,classEntity.getId()); task0wrapper.eq(ClassTask::getType,"0"); task0wrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId()); List task0Replys = classTaskAndQuesReplyDao.selectList(task0wrapper); @@ -1004,7 +1010,7 @@ public class ClassEntityServiceImpl extends ServiceImpl task1wrapper = new MPJLambdaWrapper<>(); task1wrapper.leftJoin(ClassTask.class,ClassTask::getId,ClassTaskAndQuesReply::getRelationId); task1wrapper.selectAll(ClassTaskAndQuesReply.class); - task1wrapper.eq(ClassTask::getClassId,params.get("classId")); + task1wrapper.eq(ClassTask::getClassId,classEntity.getId()); task1wrapper.eq(ClassTask::getType,"1"); task1wrapper.eq(ClassTaskAndQuesReply::getUserId,ShiroUtils.getUId()); List task1Replys = classTaskAndQuesReplyDao.selectList(task1wrapper); @@ -1021,7 +1027,7 @@ public class ClassEntityServiceImpl extends ServiceImpl experiencewrapper = new MPJLambdaWrapper<>(); experiencewrapper.eq(ClassTask::getUserId,ShiroUtils.getUId()); - experiencewrapper.eq(ClassTask::getClassId,params.get("classId")); + experiencewrapper.eq(ClassTask::getClassId,classEntity.getId()); experiencewrapper.eq(ClassTask::getType,"2"); List experiences = classTaskDao.selectList(experiencewrapper); if (experiences.size() > 0) { @@ -1036,5 +1042,38 @@ public class ClassEntityServiceImpl extends ServiceImpl params) { + ClassEntity classEntity = this.getBaseMapper().selectById(params.get("classId").toString()); + ClassModel classModel = classModelDao.selectById(classEntity.getModelId()); + List classUsers = classUserDao.selectList(new LambdaQueryWrapper() + .eq(ClassUser::getClassId,classEntity.getId()).eq(ClassUser::getRole,"0")); + List> resultList = new ArrayList<>(); + if (classUsers.size() > 0){ + for (ClassUser classUser:classUsers){ + params.put("userId",classUser.getUserId()); + Map map = getUserScore(params); + map.put("user",myUserDao.selectById(classUser.getUserId())); + if (classModel.getIsExam()==1){ + List classExamUsers = classExamUserDao.selectList(new LambdaQueryWrapper() + .eq(ClassExamUser::getUserId,classUser.getUserId()) + .eq(ClassExamUser::getClassId,classEntity.getId())); + int examScore = 0; + for (ClassExamUser classExamUser:classExamUsers){ + if (classExamUser.getScore()>examScore){ + examScore = classExamUser.getScore(); + } + } + map.put("examScore",examScore); + } + //处理分数占比 + + + resultList.add(map); + } + } + return resultList; + } + } 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 57332e08..b4c9fca2 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 @@ -154,7 +154,7 @@ public class ClassExamServiceImpl extends ServiceImpl i } } ClassExamUser classExamUser = new ClassExamUser(); - classExamUser.setExamId(this.getBaseMapper().selectOne(new LambdaQueryWrapper().eq(ClassExam::getClassId,params.get("classId"))).getId()); + classExamUser.setClassId(Integer.parseInt(params.get("classId").toString())); classExamUser.setSubject(JSONUtil.toJsonStr(resultList)); classExamUser.setUserId(ShiroUtils.getUId()); classExamUserDao.insert(classExamUser); From 9eefe130218e1c930675f2f8da9cea031f8702dc Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 11:53:01 +0800 Subject: [PATCH 2/8] =?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 --- .../controller/ClassExamController.java | 74 +++++++++++++------ .../common/service/ClassExamService.java | 3 +- .../service/impl/ClassEntityServiceImpl.java | 74 ++++++++++++++++++- .../service/impl/ClassExamServiceImpl.java | 39 ++++++---- 4 files changed, 153 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/peanut/modules/common/controller/ClassExamController.java b/src/main/java/com/peanut/modules/common/controller/ClassExamController.java index 6700b33c..a6bd7167 100644 --- a/src/main/java/com/peanut/modules/common/controller/ClassExamController.java +++ b/src/main/java/com/peanut/modules/common/controller/ClassExamController.java @@ -39,13 +39,12 @@ public class ClassExamController { public R importSubject(@RequestParam("file") MultipartFile file, @RequestParam("courseId") int courseId) { int num = 0; try (InputStream fis = file.getInputStream()) { - List optionList = new ArrayList<>(); - Long time = System.currentTimeMillis(); + //解析数据 ExcelUtil example = new ExcelUtil(); example.processOneSheet(fis); - Long endtime = System.currentTimeMillis(); LinkedHashMap map = example.getRowContents(); Iterator> it = map.entrySet().iterator(); + //处理数据 int count = 0; while (it.hasNext()) { Map.Entry entry = it.next(); @@ -54,20 +53,54 @@ public class ClassExamController { count = Integer.parseInt(rowNo); // System.out.println(pos + ";" + entry.getValue()); } + List optionList = new ArrayList<>(); + //先校验数据 + StringBuffer sb = new StringBuffer(); + for (int i=2;i<=count;i++){ + //类型 + String type = map.containsKey("A"+i)?map.get("A"+i):""; + if (type.contains("单选")||type.contains("多选")){ + }else { + sb.append("第"+i+"行题目类型出错\n"); + } + String option1 = map.containsKey("C"+i)?map.get("C"+i):""; + if (StringUtils.isBlank(option1)){ + sb.append("第"+i+"行无选项1\n"); + } + String option2 = map.containsKey("D"+i)?map.get("D"+i):""; + if (StringUtils.isBlank(option2)){ + sb.append("第"+i+"行无选项2\n"); + } + String option3 = map.containsKey("E"+i)?map.get("E"+i):""; + if (StringUtils.isBlank(option3)){ + sb.append("第"+i+"行无选项3\n"); + } + String option4 = map.containsKey("F"+i)?map.get("F"+i):""; + if (StringUtils.isBlank(option4)){ + sb.append("第"+i+"行无选项4\n"); + } + String answer = map.containsKey("I"+i)?map.get("I"+i):""; + if (StringUtils.isBlank(answer)){ + sb.append("第"+i+"行无答案\n"); + } + //题目 + String content = map.containsKey("B"+i)?map.get("B"+i):""; + if (StringUtils.isBlank(content)) { + sb.append("第"+i+"行无题目\n"); + } + } + if (sb.length() > 0){ + throw new Exception(sb.toString()); + } for (int i=2;i<=count;i++){ ClassExamSubject subject = new ClassExamSubject(); subject.setCourseId(courseId); - //类型 - String type = map.containsKey("A"+i)?map.get("A"+i):""; - if (type.contains("单选")){ + if (map.get("A"+i).contains("单选")){ subject.setType(0); - }else if (type.contains("多选")){ + }else if (map.get("A"+i).contains("多选")){ subject.setType(1); - }else { - throw new Exception("第"+i+"题无题目类型"); } - //题目 - subject.setContent(map.containsKey("B"+i)?map.get("B"+i):""); + subject.setContent(map.get("B"+i)); //所属章节 subject.setChapter(map.containsKey("N"+i)?map.get("N"+i):""); //音视频序号 @@ -78,15 +111,15 @@ public class ClassExamController { subject.setCreateUser(map.containsKey("Q"+i)?map.get("Q"+i):""); classExamSubjectService.save(subject); num++; - insertOption(optionList,subject.getId(),map.containsKey("C"+i)?map.get("C"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); - insertOption(optionList,subject.getId(),map.containsKey("D"+i)?map.get("D"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); - insertOption(optionList,subject.getId(),map.containsKey("E"+i)?map.get("E"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); - insertOption(optionList,subject.getId(),map.containsKey("F"+i)?map.get("F"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); - insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); - insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.containsKey("I"+i)?map.get("I"+i):""); + //插入选项 + insertOption(optionList,subject.getId(),map.get("C"+i),map.get("I"+i)); + insertOption(optionList,subject.getId(),map.get("D"+i),map.get("I"+i)); + insertOption(optionList,subject.getId(),map.get("E"+i),map.get("I"+i)); + insertOption(optionList,subject.getId(),map.get("F"+i),map.get("I"+i)); + insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.get("I"+i)); + insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.get("I"+i)); } classExamOptionService.saveBatch(optionList); - System.out.println("解析数据" + count + "条;耗时" + (endtime - time) / 1000 + "秒"); } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); @@ -127,11 +160,10 @@ public class ClassExamController { return R.ok().put("page",classExamSubjectList); } - //考试题目列表 + //生成试卷 @RequestMapping("/generateExamPaper") public R generateExamPaper(@RequestBody Map params){ - Object examPaper = classExamService.generateExamPaper(params); - return R.ok().put("examPaper",examPaper); + return classExamService.generateExamPaper(params); } //提交考卷 diff --git a/src/main/java/com/peanut/modules/common/service/ClassExamService.java b/src/main/java/com/peanut/modules/common/service/ClassExamService.java index 862c48d9..ce036d49 100644 --- a/src/main/java/com/peanut/modules/common/service/ClassExamService.java +++ b/src/main/java/com/peanut/modules/common/service/ClassExamService.java @@ -2,6 +2,7 @@ package com.peanut.modules.common.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import com.peanut.common.utils.R; import com.peanut.modules.common.entity.ClassExam; import com.peanut.modules.common.entity.ClassExamOption; import com.peanut.modules.common.entity.ClassExamSubject; @@ -25,7 +26,7 @@ public interface ClassExamService extends IService { Page getClassExamSubjectList(Map params); - Object generateExamPaper(Map params); + R generateExamPaper(Map params); Object submitExamPaper(Map params); diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java index 4b37c9d7..d73ab832 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java @@ -45,6 +45,8 @@ public class ClassEntityServiceImpl extends ServiceImpl params) { @@ -1067,10 +1069,78 @@ public class ClassEntityServiceImpl extends ServiceImpl wrapper = new MPJLambdaWrapper(); + wrapper.leftJoin(ClassCourse.class,ClassCourse::getCourseId,CourseCatalogueChapterEntity::getCourseId); + wrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); + wrapper.eq(ClassModel::getId,classModel.getId()); + wrapper.ne(CourseCatalogueChapterEntity::getQuestions,""); + int count = courseCatalogueChapterDao.selectCount(wrapper); + BigDecimal totalScore = new BigDecimal(staticScore*count); + questionScore.divide(totalScore); + questionScore.multiply(new BigDecimal(classModel.getQuestionScore())); + questionScore = questionScore.setScale(2,RoundingMode.HALF_UP); + map.put("questionScore",questionScore); + userScore.add(questionScore); + } + if(classModel.getIsTask()==1){ + BigDecimal task0Score = new BigDecimal(map.get("task0Score").toString()); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.eq(ClassTask::getClassId,classEntity.getId()); + wrapper.eq(ClassTask::getType,"0"); + int count = classTaskDao.selectCount(wrapper); + BigDecimal totalScore = new BigDecimal(staticScore*count); + task0Score.divide(totalScore); + task0Score.multiply(new BigDecimal(classModel.getTaskScore())); + task0Score = task0Score.setScale(2,RoundingMode.HALF_UP); + map.put("task0Score",task0Score); + userScore.add(task0Score); + } + if(classModel.getIsMedicalcase()==1){ + BigDecimal task1Score = new BigDecimal(map.get("task1Score").toString()); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.eq(ClassTask::getClassId,classEntity.getId()); + wrapper.eq(ClassTask::getType,"1"); + int count = classTaskDao.selectCount(wrapper); + BigDecimal totalScore = new BigDecimal(staticScore*count); + task1Score.divide(totalScore); + task1Score.multiply(new BigDecimal(classModel.getMedicalcaseScore())); + task1Score = task1Score.setScale(2,RoundingMode.HALF_UP); + map.put("task1Score",task1Score); + userScore.add(task1Score); + } + if(classModel.getIsExperience()==1){ + BigDecimal experienceScore = new BigDecimal(map.get("experienceScore").toString()); + if (experienceScore.compareTo(new BigDecimal(classModel.getExperienceScore()))>-1){ + experienceScore = new BigDecimal(classModel.getExperienceScore()); + } + map.put("experienceScore",experienceScore); + userScore.add(experienceScore); + } + map.put("userScore",userScore); resultList.add(map); } + Collections.sort(resultList, new Comparator>() { + @Override + public int compare(Map m1, Map m2) { + if((double)(m2.get("userScore")) > (double)(m1.get("userScore"))){ + return 1; + }else { + return -1; + } + } + }); } return resultList; } 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 b4c9fca2..fa498c9e 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 @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.peanut.common.utils.R; import com.peanut.common.utils.ShiroUtils; import com.peanut.modules.common.dao.*; import com.peanut.modules.common.entity.*; @@ -27,6 +28,8 @@ public class ClassExamServiceImpl extends ServiceImpl i private ClassCourseDao classCourseDao; @Autowired private ClassExamUserDao classExamUserDao; + @Autowired + private CourseDao courseDao; @Override public void addClassExamSubject(ClassExamSubject classExamSubject) { @@ -104,7 +107,7 @@ public class ClassExamServiceImpl extends ServiceImpl i } @Override - public Object generateExamPaper(Map params) { + public R generateExamPaper(Map params) { MPJLambdaWrapper courseWrapper = new MPJLambdaWrapper<>(); courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId); @@ -119,26 +122,35 @@ public class ClassExamServiceImpl extends ServiceImpl i int mtotal = 50;//多选题总数 int snum = (int)Math.floor(stotal/courseList.size()); int mnum = (int)Math.floor(mtotal/courseList.size()); - for (ClassCourse course:courseList){ + for (ClassCourse classCourse:courseList){ + CourseEntity course = courseDao.selectById(classCourse.getCourseId()); //单选 List singleList = classExamSubjectDao.selectList(new LambdaQueryWrapper() - .eq(ClassExamSubject::getCourseId,course.getCourseId()) + .eq(ClassExamSubject::getCourseId,classCourse.getCourseId()) .eq(ClassExamSubject::getType,0)); Collections.shuffle(singleList);//打乱顺序 - if (sList.size()+snum>stotal){ - sList.addAll(singleList.subList(0,stotal-sList.size())); - }else { - sList.addAll(singleList.subList(0,snum)); + try { + if (sList.size()+snum>stotal){ + sList.addAll(singleList.subList(0,stotal-sList.size())); + }else { + sList.addAll(singleList.subList(0,snum)); + } + }catch (Exception e) { + return R.error(course.getTitle()+"-单选题数量不足"); } //多选 List mulList = classExamSubjectDao.selectList(new LambdaQueryWrapper() - .eq(ClassExamSubject::getCourseId,course.getCourseId()) + .eq(ClassExamSubject::getCourseId,classCourse.getCourseId()) .eq(ClassExamSubject::getType,1)); Collections.shuffle(mulList);//打乱顺序 - if (mList.size()+mnum>mtotal){ - mList.addAll(mulList.subList(0,mtotal-mList.size())); - }else { - mList.addAll(mulList.subList(0,mnum)); + try { + if (mList.size()+mnum>mtotal){ + mList.addAll(mulList.subList(0,mtotal-mList.size())); + }else { + mList.addAll(mulList.subList(0,mnum)); + } + }catch (Exception e) { + return R.error(course.getTitle()+"-多选题数量不足"); } } } @@ -158,7 +170,8 @@ public class ClassExamServiceImpl extends ServiceImpl i classExamUser.setSubject(JSONUtil.toJsonStr(resultList)); classExamUser.setUserId(ShiroUtils.getUId()); classExamUserDao.insert(classExamUser); - return resultList; + return R.ok().put("examPaper",resultList); + } @Override From 66fcf9a34de59767e0d7ccb72bcc9b79f713f0a9 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 13:08:41 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=8A=B1=E7=94=9F=E5=B8=81=E6=8D=A2?= =?UTF-8?q?=E6=88=90=E5=A4=A9=E5=8C=BB=E5=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peanut/modules/book/controller/BuyOrderController.java | 2 +- .../peanut/modules/master/controller/UserVipController.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java index 7381e636..3312a4ab 100644 --- a/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java +++ b/src/main/java/com/peanut/modules/book/controller/BuyOrderController.java @@ -306,7 +306,7 @@ public class BuyOrderController { addEbookToUser(buyOrderProductList, buyOrder, 0); addCourseToUser(buyOrder); } else { - return R.error(500, "花生币余额不足!"); + return R.error(500, "天医币余额不足!"); } } // 2. 微信支付,需要预支付 diff --git a/src/main/java/com/peanut/modules/master/controller/UserVipController.java b/src/main/java/com/peanut/modules/master/controller/UserVipController.java index 43efaa62..c915105a 100644 --- a/src/main/java/com/peanut/modules/master/controller/UserVipController.java +++ b/src/main/java/com/peanut/modules/master/controller/UserVipController.java @@ -85,7 +85,7 @@ public class UserVipController { return R.error("积分不足"); } }else { - return R.error("花生币不足"); + return R.error("天医币不足"); } } @@ -107,7 +107,7 @@ public class UserVipController { return R.error("积分不足"); } }else { - return R.error("花生币不足"); + return R.error("天医币不足"); } } From 256dec40ff9b2d9c5a1e8d62b2b1f3c5bcf8cac7 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 14:08:32 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/ClassController.java | 39 ++++++++++++++----- .../common/service/ClassEntityService.java | 4 +- .../service/impl/ClassEntityServiceImpl.java | 18 ++++++++- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/peanut/modules/common/controller/ClassController.java b/src/main/java/com/peanut/modules/common/controller/ClassController.java index ba7a4917..c0a29ddb 100644 --- a/src/main/java/com/peanut/modules/common/controller/ClassController.java +++ b/src/main/java/com/peanut/modules/common/controller/ClassController.java @@ -2,16 +2,16 @@ package com.peanut.modules.common.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.peanut.common.utils.R; -import com.peanut.modules.common.entity.ClassEntity; -import com.peanut.modules.common.entity.ClassModel; -import com.peanut.modules.common.entity.ClassTask; -import com.peanut.modules.common.entity.ClassTaskAndQuesReply; +import com.peanut.modules.common.entity.*; import com.peanut.modules.common.service.ClassEntityService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; + +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -33,6 +33,15 @@ public class ClassController { //新增班级模型 @RequestMapping("/addClassModel") public R addClassModel(@RequestBody ClassModel classModel){ + String[] courseIds = classModel.getCourseIds().split(","); + if(courseIds.length > 0){ + HashSet set = new HashSet<>(); + for (String courseId : courseIds) { + if (!set.add(courseId)){ + return R.error("课程不能重复"); + } + } + } int score = 0; if (classModel.getIsQuestion()==1){ score += classModel.getQuestionScore(); @@ -50,11 +59,7 @@ public class ClassController { score += classModel.getExamScore(); } if (score==100){ - if (classEntityService.addClassModel(classModel)){ - return R.ok(); - }else { - return R.error("保存出错"); - } + return classEntityService.addClassModel(classModel); }else { return R.error("请设置各模块占比总和为100"); } @@ -63,6 +68,15 @@ public class ClassController { //修改班级模型 @RequestMapping("/editClassModel") public R editClassModel(@RequestBody ClassModel classModel){ + String[] courseIds = classModel.getCourseIds().split(","); + if(courseIds.length > 0){ + HashSet set = new HashSet<>(); + for (String courseId : courseIds) { + if (!set.add(courseId)){ + return R.error("课程不能重复"); + } + } + } int score = 0; if (classModel.getIsQuestion()==1){ score += classModel.getQuestionScore(); @@ -86,6 +100,13 @@ public class ClassController { } } + //获取模型可选课程 + @RequestMapping("/getClassModelCourseList") + public R getClassModelCourseList(@RequestBody Map params){ + List courseList = classEntityService.getClassModelCourseList(params); + return R.ok().put("courseList",courseList); + } + //获取主任下的班级模型 @RequestMapping("/getClassModelByUserid") public R getClassModelByUserid(@RequestBody Map params){ diff --git a/src/main/java/com/peanut/modules/common/service/ClassEntityService.java b/src/main/java/com/peanut/modules/common/service/ClassEntityService.java index 643bd46e..84a37ccc 100644 --- a/src/main/java/com/peanut/modules/common/service/ClassEntityService.java +++ b/src/main/java/com/peanut/modules/common/service/ClassEntityService.java @@ -11,10 +11,12 @@ public interface ClassEntityService extends IService { Page getClassModelList(Map params); - boolean addClassModel(ClassModel classModel); + R addClassModel(ClassModel classModel); R editClassModel(ClassModel classModel); + List getClassModelCourseList(Map params); + List getClassModelByUserid(Map params); List> getClassByDirectorid(Map params); diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java index d73ab832..39f5ba08 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java @@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; @@ -66,7 +68,8 @@ public class ClassEntityServiceImpl extends ServiceImpl 0){ @@ -77,7 +80,7 @@ public class ClassEntityServiceImpl extends ServiceImpl getClassModelCourseList(Map params) { + MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); + wrapper.exists("select * from course_to_medicine where del_flag = 0 and course_id = t.id"); + wrapper.like(CourseEntity::getTitle,params.get("title")); + wrapper.selectAs(CourseEntity::getId,"id"); + wrapper.selectAs(CourseEntity::getTitle,"title"); + List list = courseDao.selectList(wrapper); + return list; + } + @Override public List getClassModelByUserid(Map params) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); From b190a88424cfeb36bc107015a33743288b1498e1 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 14:33:10 +0800 Subject: [PATCH 5/8] =?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 --- .../modules/common/controller/ClassExamController.java | 9 ++++++++- .../peanut/modules/common/service/ClassExamService.java | 2 ++ .../common/service/impl/ClassExamServiceImpl.java | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/peanut/modules/common/controller/ClassExamController.java b/src/main/java/com/peanut/modules/common/controller/ClassExamController.java index a6bd7167..7567a939 100644 --- a/src/main/java/com/peanut/modules/common/controller/ClassExamController.java +++ b/src/main/java/com/peanut/modules/common/controller/ClassExamController.java @@ -166,13 +166,20 @@ public class ClassExamController { return classExamService.generateExamPaper(params); } - //提交考卷 + //提交试卷 @RequestMapping("/submitExamPaper") public R submitExamPaper(@RequestBody Map params){ Object examPaper = classExamService.submitExamPaper(params); return R.ok().put("examPaper",examPaper); } + //试卷详情 + @RequestMapping("/getExamPaperInfo") + public R getExamPaperInfo(@RequestBody Map params){ + Object examPaper = classExamService.getExamPaperInfo(params); + return R.ok().put("examPaper",examPaper); + } + diff --git a/src/main/java/com/peanut/modules/common/service/ClassExamService.java b/src/main/java/com/peanut/modules/common/service/ClassExamService.java index ce036d49..d05f30fd 100644 --- a/src/main/java/com/peanut/modules/common/service/ClassExamService.java +++ b/src/main/java/com/peanut/modules/common/service/ClassExamService.java @@ -30,4 +30,6 @@ public interface ClassExamService extends IService { Object submitExamPaper(Map params); + Object getExamPaperInfo(Map params); + } 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 fa498c9e..b5d81848 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 @@ -217,4 +217,11 @@ public class ClassExamServiceImpl extends ServiceImpl i return classExamUser; } + @Override + public Object getExamPaperInfo(Map params) { + List classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper() + .eq(ClassExamUser::getClassId,params.get("classId")).eq(ClassExamUser::getUserId,params.get("userId"))); + return classExamUserList; + } + } From 83d35846e9f000a76376160a465f57c01981eec3 Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 15:52:23 +0800 Subject: [PATCH 6/8] =?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(); From 66e91fed7a31f4524dcc616b8e9ae5730246e93c Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 15:55:39 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=9C=AA=E5=BC=80=E7=8F=AD=E5=B0=8F=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/common/service/impl/ClassEntityServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java index 39f5ba08..6788c36d 100644 --- a/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java +++ b/src/main/java/com/peanut/modules/common/service/impl/ClassEntityServiceImpl.java @@ -548,6 +548,7 @@ public class ClassEntityServiceImpl extends ServiceImpl getClassNoUser() { MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); wrapper.selectAll(ClassEntity.class); + wrapper.eq(ClassEntity::getState,"0"); String classSql = "select 1 from ( select c.id from class c left join class_course cc on cc.model_id = c.model_id left join class_user cu on cu.class_id = c.id where c.del_flag = 0 and cc.del_flag = 0 and cu.del_flag = 0 and cu.user_id = "+ShiroUtils.getUId()+" ) s where s.id = t.id"; String courseSql = "select 1 from (select cc.model_id from class_course cc where cc.del_flag = 0 and cc.course_id in (select cc.course_id from class_course cc left join class_model cm on cm.id = cc.model_id left join class c on c.model_id = cm.id left join class_user cu on cu.class_id = c.id where cc.del_flag = 0 and cm.del_flag = 0 and c.del_flag = 0 and cu.del_flag = 0 and cu.user_id = "+ShiroUtils.getUId()+")) q where q.model_id = t.model_id"; wrapper.notExists(classSql); From e397ebc4705d39dd5e3f76583d30cd2b2cd5e85d Mon Sep 17 00:00:00 2001 From: wuchunlei Date: Fri, 30 Aug 2024 16:57:13 +0800 Subject: [PATCH 8/8] =?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 --- .../common/service/impl/ClassExamServiceImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 a9e54659..9be60687 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 @@ -118,8 +118,8 @@ public class ClassExamServiceImpl extends ServiceImpl i List> sList = new ArrayList<>(); List> mList = new ArrayList<>(); if (courseList.size() > 0) { - int stotal = 10;//单选题总数 - int mtotal = 10;//多选题总数 + int stotal = 5;//单选题总数 + int mtotal = 5;//多选题总数 int snum = (int)Math.floor(stotal/courseList.size()); int mnum = (int)Math.floor(mtotal/courseList.size()); for (ClassCourse classCourse:courseList){ @@ -179,7 +179,7 @@ public class ClassExamServiceImpl extends ServiceImpl i classExamUser.setSubject(JSONUtil.toJsonStr(resultList)); classExamUser.setUserId(ShiroUtils.getUId()); classExamUserDao.insert(classExamUser); - return R.ok().put("examPaper",resultList); + return R.ok().put("examPaper",resultList).put("id",classExamUser.getId()); } @@ -229,7 +229,9 @@ public class ClassExamServiceImpl extends ServiceImpl i @Override public Object getExamPaperInfo(Map params) { List classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper() - .eq(ClassExamUser::getClassId,params.get("classId")).eq(ClassExamUser::getUserId,params.get("userId"))); + .eq(ClassExamUser::getClassId,params.get("classId")) + .eq(ClassExamUser::getUserId,params.get("userId")) + .orderByDesc(ClassExamUser::getScore)); return classExamUserList; }