From fe0a4c0495cf9f1a65343158c2a8c2d4a163e045 Mon Sep 17 00:00:00 2001 From: qirong <2032486488@qq.com> Date: 星期二, 28 十一月 2023 21:16:21 +0800 Subject: [PATCH] 优化查询 --- src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java index 9614957..2881df0 100644 --- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java +++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java @@ -57,6 +57,8 @@ private final UserDepartmentMapper userDepartmentMapper; private final DepartmentService departmentService; + + @Autowired public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamPaperSubjectService examPaperSubjectService, QuestionSubjectService questionSubjectService, ExamPaperUserService examPaperUserService, UserService userService, UserDepartmentMapper userDepartmentMapper, DepartmentService departmentService) { super(examPaperMapper); @@ -126,6 +128,7 @@ examPaper.setCreateTime(now); examPaper.setCreateUser(user.getId()); examPaper.setDeleted(false); + examPaper.setUserIds(examPaperEditRequestVM.getMenuIds()); examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM); examPaperMapper.insertSelective(examPaper); @@ -152,6 +155,7 @@ ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(id); ExamPaperEditRequestVM vm = modelMapper.map(examPaper, ExamPaperEditRequestVM.class); vm.setLevel(examPaper.getGradeLevel()); + vm.setMenuIds(examPaper.getUserIds()); TextContent frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId()); List<ExamPaperTitleItemObject> examPaperTitleItemObjects = JsonUtil.toJsonListObject(frameTextContent.getContent(), ExamPaperTitleItemObject.class); List<Integer> questionIds = examPaperTitleItemObjects.stream() @@ -370,7 +374,6 @@ keys.remove(index); } } - if (!values.isEmpty()) { int index = random.nextInt(values.size()); int score = values.get(index); @@ -479,13 +482,17 @@ * @param titleItemsVM title */ private void randomQuestionType(ExamPaperEditRequestVM examPaperEditRequestVM, List<ExamPaperTitleItemObject> frameTextContentList, List<ExamPaperTitleItemVM> titleItemsVM) throws QuestionException { + + //鍗曢�� Integer singleChoice = examPaperEditRequestVM.getQuestionTypeVMS().stream().mapToInt(QuestionTypeVM::getSingleChoice).sum(); //澶氶�� Integer multipleChoice = examPaperEditRequestVM.getQuestionTypeVMS().stream().mapToInt(QuestionTypeVM::getMultipleChoice).sum(); //鍒ゆ柇 Integer judgment = examPaperEditRequestVM.getQuestionTypeVMS().stream().mapToInt(QuestionTypeVM::getTrueFalse).sum(); - if ((singleChoice * 2 + multipleChoice * 2 + judgment * 2) != new Integer(20)) { + + + if ((singleChoice * 2 + multipleChoice * 2 + judgment * 2) != new Integer(10)) { throw new QuestionException(); } @@ -513,15 +520,15 @@ Map<Integer, Integer> multipleMap = list.stream() .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.MultipleChoice.getCode())) .collect(Collectors.toMap(Question::getId, Question::getScore)); - Integer multipleSource = questionTypeVM.getMultipleChoice() * 5; + Integer multipleSource = questionTypeVM.getMultipleChoice() * 2; selectRandomScores(multiple, multipleMap, questionTypeVM.getMultipleChoice(), multipleSource); //鍒ゆ柇 - Map<Integer, Integer> judgmentMap = list.stream() - .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.TrueFalse.getCode())) - .collect(Collectors.toMap(Question::getId, Question::getScore)); - Integer trueFalse = questionTypeVM.getTrueFalse() * 2; + List<Question> collect1 = list.stream().filter(e -> e.getQuestionType().equals(QuestionTypeEnum.TrueFalse.getCode())).collect(Collectors.toList()); + Map<Integer, Integer> judgmentMap = collect1.stream().collect(Collectors.toMap(Question::getId, Question::getScore)); + Integer trueFalse1 = questionTypeVM.getTrueFalse(); + Integer trueFalse = trueFalse1 * 2; selectRandomScores(multiple, judgmentMap, questionTypeVM.getTrueFalse(), trueFalse); //鍗曢�夊垎鏁� -- Gitblit v1.8.0