From e3158205b083b760618ae4f7b17d183b3a40c963 Mon Sep 17 00:00:00 2001 From: caolin <1149034574@qq.com> Date: Tue, 12 Sep 2023 13:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E7=82=B9=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/dto/TestQuestionTypeDto.java | 23 ++-- .../service/impl/TdQuestionServiceImpl.java | 100 ++++++++++-------- .../resources/mapper/TdQuestionMapper.xml | 6 ++ 3 files changed, 79 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/jwl/driver/server/dto/TestQuestionTypeDto.java b/src/main/java/com/jwl/driver/server/dto/TestQuestionTypeDto.java index c779ecd..04f596a 100644 --- a/src/main/java/com/jwl/driver/server/dto/TestQuestionTypeDto.java +++ b/src/main/java/com/jwl/driver/server/dto/TestQuestionTypeDto.java @@ -6,6 +6,7 @@ import lombok.experimental.Accessors; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import java.util.List; /** * @author 曹林 @@ -18,10 +19,20 @@ public class TestQuestionTypeDto { //科目 private String subject; - //判断题 - private Integer judgeNum; - //单选题 - private Integer radioNum; - //多选题 - private Integer multipleChoiceNum; + + private List chapterList; + + @Data + @Accessors(chain = true) + public static class TestOfChapter { + //章节 + private String chapter; + //判断题 + private Integer judgeNum; + //单选题 + private Integer radioNum; + //多选题 + private Integer multipleChoiceNum; + } + } diff --git a/src/main/java/com/jwl/driver/server/service/impl/TdQuestionServiceImpl.java b/src/main/java/com/jwl/driver/server/service/impl/TdQuestionServiceImpl.java index ca93024..606e0f0 100644 --- a/src/main/java/com/jwl/driver/server/service/impl/TdQuestionServiceImpl.java +++ b/src/main/java/com/jwl/driver/server/service/impl/TdQuestionServiceImpl.java @@ -110,24 +110,36 @@ public class TdQuestionServiceImpl extends ServiceImpl optional = testQuestionTypeDtos.stream().filter(s -> StrUtil.equals(s.getSubject(), queryDto.getSubject())).findFirst(); if (optional.isPresent()) { TestQuestionTypeDto testQuestionTypeDto = optional.get(); - //判断题 - if (Objects.nonNull(testQuestionTypeDto.getJudgeNum()) && testQuestionTypeDto.getJudgeNum() > 0) { - queryDto.setType(Constants.QUESTION_TYPE_ONE) - .setNum(testQuestionTypeDto.getJudgeNum()); - resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto)); + List chapterList = testQuestionTypeDto.getChapterList(); + if (CollectionUtil.isEmpty(chapterList)){ + return resultList; } - //单选 - if (Objects.nonNull(testQuestionTypeDto.getRadioNum()) && testQuestionTypeDto.getRadioNum() > 0) { - queryDto.setType(Constants.QUESTION_TYPE_TWO) - .setNum(testQuestionTypeDto.getRadioNum()); - resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto)); + for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) { + //判断题 + if (Objects.nonNull(testOfChapter.getJudgeNum()) && testOfChapter.getJudgeNum() > 0) { + queryDto.setType(Constants.QUESTION_TYPE_ONE) + .setChapter(testOfChapter.getChapter()) + .setNum(testOfChapter.getJudgeNum()); + resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto)); + } } - - //多选 - if (Objects.nonNull(testQuestionTypeDto.getMultipleChoiceNum()) && testQuestionTypeDto.getMultipleChoiceNum() > 0) { - queryDto.setType(Constants.QUESTION_TYPE_THREE) - .setNum(testQuestionTypeDto.getMultipleChoiceNum()); - resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto)); + for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) { + //单选 + if (Objects.nonNull(testOfChapter.getRadioNum()) && testOfChapter.getRadioNum() > 0) { + queryDto.setType(Constants.QUESTION_TYPE_TWO) + .setChapter(testOfChapter.getChapter()) + .setNum(testOfChapter.getRadioNum()); + resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto)); + } + } + for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) { + //多选 + if (Objects.nonNull(testOfChapter.getMultipleChoiceNum()) && testOfChapter.getMultipleChoiceNum() > 0) { + queryDto.setType(Constants.QUESTION_TYPE_THREE) + .setChapter(testOfChapter.getChapter()) + .setNum(testOfChapter.getMultipleChoiceNum()); + resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto)); + } } } questionOptionHandler(resultList); @@ -151,24 +163,36 @@ public class TdQuestionServiceImpl extends ServiceImpl optional = testQuestionTypeDtos.stream().filter(s -> StrUtil.equals(s.getSubject(), queryDto.getSubject())).findFirst(); if (optional.isPresent()) { TestQuestionTypeDto testQuestionTypeDto = optional.get(); - //判断题 - if (Objects.nonNull(testQuestionTypeDto.getJudgeNum()) && testQuestionTypeDto.getJudgeNum() > 0) { - queryDto.setType(Constants.QUESTION_TYPE_ONE) - .setNum(testQuestionTypeDto.getJudgeNum()); - resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto)); + List chapterList = testQuestionTypeDto.getChapterList(); + if (CollectionUtil.isEmpty(chapterList)){ + return resultList; } - //单选 - if (Objects.nonNull(testQuestionTypeDto.getRadioNum()) && testQuestionTypeDto.getRadioNum() > 0) { - queryDto.setType(Constants.QUESTION_TYPE_TWO) - .setNum(testQuestionTypeDto.getRadioNum()); - resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto)); + for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) { + //判断题 + if (Objects.nonNull(testOfChapter.getJudgeNum()) && testOfChapter.getJudgeNum() > 0) { + queryDto.setType(Constants.QUESTION_TYPE_ONE) + .setChapter(testOfChapter.getChapter()) + .setNum(testOfChapter.getJudgeNum()); + resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto)); + } } - - //多选 - if (Objects.nonNull(testQuestionTypeDto.getMultipleChoiceNum()) && testQuestionTypeDto.getMultipleChoiceNum() > 0) { - queryDto.setType(Constants.QUESTION_TYPE_THREE) - .setNum(testQuestionTypeDto.getMultipleChoiceNum()); - resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto)); + for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) { + //单选 + if (Objects.nonNull(testOfChapter.getRadioNum()) && testOfChapter.getRadioNum() > 0) { + queryDto.setType(Constants.QUESTION_TYPE_TWO) + .setChapter(testOfChapter.getChapter()) + .setNum(testOfChapter.getRadioNum()); + resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto)); + } + } + for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) { + //多选 + if (Objects.nonNull(testOfChapter.getMultipleChoiceNum()) && testOfChapter.getMultipleChoiceNum() > 0) { + queryDto.setType(Constants.QUESTION_TYPE_THREE) + .setChapter(testOfChapter.getChapter()) + .setNum(testOfChapter.getMultipleChoiceNum()); + resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto)); + } } } return resultList; @@ -312,18 +336,6 @@ public class TdQuestionServiceImpl extends ServiceImpl testQuestionTypeDtos = new ArrayList<>(); - TestQuestionTypeDto dto1 = new TestQuestionTypeDto() - .setSubject("1") - .setJudgeNum(40) - .setRadioNum(60) - .setMultipleChoiceNum(0); - TestQuestionTypeDto dto2 = new TestQuestionTypeDto() - .setSubject("4") - .setJudgeNum(20) - .setRadioNum(20) - .setMultipleChoiceNum(10); - testQuestionTypeDtos.add(dto1); - testQuestionTypeDtos.add(dto2); String jsonString = JSONArray.toJSONString(testQuestionTypeDtos); System.out.println(jsonString); diff --git a/src/main/resources/mapper/TdQuestionMapper.xml b/src/main/resources/mapper/TdQuestionMapper.xml index b1025a3..781601b 100644 --- a/src/main/resources/mapper/TdQuestionMapper.xml +++ b/src/main/resources/mapper/TdQuestionMapper.xml @@ -143,6 +143,9 @@ and tq.TYPE = #{queryDto.type} + + and tq.CHAPTER = #{queryDto.chapter} + order by rand() limit ${queryDto.num}; @@ -273,6 +276,9 @@ and tq.TYPE = #{queryDto.type} + + and tq.CHAPTER = #{queryDto.chapter} + order by rand() limit ${queryDto.num};