From cfc61445380851d621f4dd853fe62941f9c80207 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期四, 09 五月 2024 15:30:52 +0800 Subject: [PATCH] 部门管理员优化 --- src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java | 48 ++++++++++++++++++++++++++++-------------------- 1 files changed, 28 insertions(+), 20 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..2f54f3a 100644 --- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java +++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java @@ -18,10 +18,8 @@ import com.mindskip.xzs.utility.JsonUtil; import com.mindskip.xzs.utility.ModelMapperSingle; import com.mindskip.xzs.utility.ExamUtil; -import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVM; -import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperPageRequestVM; -import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperTitleItemVM; -import com.mindskip.xzs.viewmodel.admin.exam.QuestionTypeVM; +import com.mindskip.xzs.viewmodel.admin.exam.*; +import com.mindskip.xzs.viewmodel.admin.question.ExamQuestionVO; import com.mindskip.xzs.viewmodel.admin.question.QuestionEditRequestVM; import com.mindskip.xzs.viewmodel.student.dashboard.PaperFilter; import com.mindskip.xzs.viewmodel.student.dashboard.PaperInfo; @@ -32,6 +30,7 @@ import com.mindskip.xzs.domain.Question; import com.mindskip.xzs.domain.User; import org.modelmapper.ModelMapper; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -56,6 +55,8 @@ private final UserService userService; 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) { @@ -126,6 +127,7 @@ examPaper.setCreateTime(now); examPaper.setCreateUser(user.getId()); examPaper.setDeleted(false); + examPaper.setUserIds(examPaperEditRequestVM.getMenuIds()); examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM); examPaperMapper.insertSelective(examPaper); @@ -148,10 +150,11 @@ } @Override - public ExamPaperEditRequestVM examPaperToVM(Integer id) { + public ExamPaperEditRequestVO examPaperToVM(Integer id) { ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(id); - ExamPaperEditRequestVM vm = modelMapper.map(examPaper, ExamPaperEditRequestVM.class); + ExamPaperEditRequestVO vm = modelMapper.map(examPaper, ExamPaperEditRequestVO.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() @@ -168,11 +171,12 @@ Integer order = 0; Set<Integer> generatedNumbers = new HashSet<>(); Random random = new Random(); - List<ExamPaperTitleItemVM> examPaperTitleItemVMS = examPaperTitleItemObjects.stream().map(t -> { - ExamPaperTitleItemVM tTitleVM = modelMapper.map(t, ExamPaperTitleItemVM.class); - List<QuestionEditRequestVM> questionItemsVM = t.getQuestionItems().stream().map(i -> { + List<ExamPaperTitleItemVO> examPaperTitleItemVMS = examPaperTitleItemObjects.stream().map(t -> { + ExamPaperTitleItemVO tTitleVM = new ExamPaperTitleItemVO(); + BeanUtils.copyProperties(t, tTitleVM); + List<ExamQuestionVO> questionItemsVM = t.getQuestionItems().stream().map(i -> { Question question = questions.stream().filter(q -> q.getId().equals(i.getId())).findFirst().get(); - QuestionEditRequestVM questionEditRequestVM = questionService.getQuestionEditRequestVM(question); + ExamQuestionVO questionEditRequestVM = questionService.getQuestionEditRequestVM(question); questionEditRequestVM.setTitle("(" + QuestionTypeEnum.fromCode(questionEditRequestVM.getQuestionType()).getName() + ") " + questionEditRequestVM.getTitle()); questionEditRequestVM.setItemOrder(generateRandomNumber(questionEditRequestVM.getQuestionType() == 1 ? 0 : ((questionEditRequestVM.getQuestionType() == 2 ? singleChoice : multipleChoice + singleChoice)), questionEditRequestVM.getQuestionType() == 1 ? singleChoice : ((questionEditRequestVM.getQuestionType() == 2 ? multipleChoice + singleChoice : trueFalse + multipleChoice + singleChoice)), @@ -180,7 +184,7 @@ // questionEditRequestVM.setItemOrder(getRandomNumber(t.getQuestionItems().size() - 1, generatedNumbers, random)); return questionEditRequestVM; - }).sorted(Comparator.comparing(QuestionEditRequestVM::getItemOrder)) + }).sorted(Comparator.comparing(ExamQuestionVO::getItemOrder)) .collect(Collectors.toList()); tTitleVM.setQuestionItems(questionItemsVM); return tTitleVM; @@ -356,6 +360,7 @@ int remainingScore = totalScore; for (int i = 0; i < quantity - 1; i++) { + // 濡傛灉棰樻暟閲忚秴杩囦簡棰樺簱鏁伴噺锛屾姤閿� if (i >= scoresMap.size()) { throw new QuestionException(); } @@ -370,7 +375,6 @@ keys.remove(index); } } - if (!values.isEmpty()) { int index = random.nextInt(values.size()); int score = values.get(index); @@ -479,13 +483,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(100)) { throw new QuestionException(); } @@ -511,24 +519,24 @@ Map<Integer, Integer> multiple = new HashMap<>(); //澶氶�� Map<Integer, Integer> multipleMap = list.stream() - .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.MultipleChoice.getCode())) + .filter(e -> Objects.equals(QuestionTypeEnum.MultipleChoice.getCode(), e.getQuestionType())) .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 -> Objects.equals(e.getQuestionType(), 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); //鍗曢�夊垎鏁� Integer radioSource = questionTypeVM.getSingleChoice() * 4; //鍗曢�� Map<Integer, Integer> radioMap = list.stream() - .filter(e -> e.getQuestionType().equals(QuestionTypeEnum.SingleChoice.getCode())) + .filter(e -> Objects.equals(e.getQuestionType(), QuestionTypeEnum.SingleChoice.getCode())) .collect(Collectors.toMap(Question::getId, Question::getScore)); selectRandomScores(multiple, radioMap, questionTypeVM.getSingleChoice(), radioSource); -- Gitblit v1.8.0