xiangpei
2025-05-14 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403
src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
@@ -121,6 +121,7 @@
        String frameTextContentStr = JsonUtil.toJsonStr(frameTextContentList);
        ExamPaper examPaper;
        Integer[] userIds = examPaperEditRequestVM.getUserIds();
        if (actionEnum == ActionEnum.ADD) {
            examPaper = modelMapper.map(examPaperEditRequestVM, ExamPaper.class);
            TextContent frameTextContent = new TextContent(frameTextContentStr, now);
@@ -138,7 +139,10 @@
            TextContent frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId());
            frameTextContent.setContent(frameTextContentStr);
            textContentService.updateByIdFilter(frameTextContent);
            examPaperEditRequestVM.setScore(null);
            examPaperEditRequestVM.setUserIds(null);
            modelMapper.map(examPaperEditRequestVM, examPaper);
            examPaperEditRequestVM.setUserIds(userIds);
            examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM);
            examPaperMapper.updateByPrimaryKeySelective(examPaper);
            //批量修改
@@ -154,6 +158,9 @@
    @Override
    public ExamPaperEditRequestVO examPaperToVM(Integer id) {
        ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(id);
        if (Objects.isNull(examPaper)) {
            throw new RuntimeException("该考试已被删除,无法查看");
        }
        ExamPaperEditRequestVO vm = modelMapper.map(examPaper, ExamPaperEditRequestVO.class);
        vm.setLevel(examPaper.getGradeLevel());
        vm.setMenuIds(examPaper.getUserIds());
@@ -167,6 +174,7 @@
            throw new RuntimeException("该试卷没有题目");
        }
        List<Question> questions = questionMapper.selectByIds(questionIds);
        //单选数量
        Integer singleChoice = questions.stream().filter(e -> e.getQuestionType() == 1).collect(Collectors.toList()).size();
        //多选数量
@@ -182,6 +190,7 @@
            List<ExamQuestionVO> questionItemsVM = t.getQuestionItems().stream().map(i -> {
                        Question question = questions.stream().filter(q -> q.getId().equals(i.getId())).findFirst().get();
                        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)),
@@ -265,10 +274,36 @@
            if(userDepartments.size() != 0){
                Department byId = departmentService.getById(userDepartments.get(0).getDepartmentId());
                e.setDepartmentName(byId.getName());
                e.setDeptId(byId.getId());
            }
            return e;
        }).collect(Collectors.toList());
        return paperExcel;
    }
    @Override
    public List<PaperExcelVO> getRandomPaperExcelById(Integer id) {
        List<PaperExcelVO> paperExcel = examPaperMapper.getRandomPaperExcelById(id);
        // 如果某考生存在多个部门,每个部门都加一遍数据
        List<PaperExcelVO> needAdd = new ArrayList<>();
        List<PaperExcelVO> needRemove = new ArrayList<>();
        paperExcel = paperExcel.stream().map(e->{
            e.setPaperScore(ExamUtil.scoreToVM(Integer.parseInt(e.getPaperScore())));
            e.setUserScore(ExamUtil.scoreToVM(Integer.parseInt(e.getUserScore())));
            List<Department> userDepartments = userDepartmentMapper.selectDeptByUserId(Integer.parseInt(e.getUserId()));
            for (Department dept : userDepartments) {
                PaperExcelVO vo = new PaperExcelVO();
                BeanUtils.copyProperties(e, vo);
                vo.setDepartmentName(dept.getName());
                vo.setDeptId(dept.getId());
                needAdd.add(vo);
                needRemove.add(e);
            }
            return e;
        }).collect(Collectors.toList());
        paperExcel.removeAll(needRemove);
        paperExcel.addAll(needAdd);
        return paperExcel.stream().filter(e -> Objects.nonNull(e.getDeptId())).collect(Collectors.toList());
    }
    private void examPaperFromVM(ExamPaperEditRequestVM examPaperEditRequestVM, ExamPaper examPaper, List<ExamPaperTitleItemVM> titleItemsVM) {
@@ -523,9 +558,10 @@
        Integer order = 0;
        for (QuestionTypeVM questionTypeVM : questionTypeVMList) {
            List<Integer> questions = questionSubjectService.getSubject(questionTypeVM.getSubjectId())
            List<Integer> questions = questionSubjectService.getSubjectBySubjectIds(examPaperEditRequestVM.getSubjectId())
                    .stream().map(QuestionSubject::getQuestionId).collect(Collectors.toList());
            List<Question> list = questionService.selectByIds(questions);
            // List<Question> list = questionService.getAll();
            Map<Integer, Integer> multiple = new HashMap<>();
            //多选