From 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期三, 14 五月 2025 15:50:57 +0800 Subject: [PATCH] bug:学员有状态不能修改问题 --- src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 44 insertions(+), 5 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 8eb7a39..e0a83e9 100644 --- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java +++ b/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)), @@ -207,15 +216,18 @@ vm.setDepartmentIds(examPaperDepartmentService.getByExamPaperId(examPaper.getId()) .stream().map(ExamPaperDepartment::getDepartmentId).toArray(Integer[]::new)); List<ExamPaperUser> examPaperUsers = examPaperUserService.getByExamPaperId(examPaper.getId()); - Integer[][] userIds = new Integer[examPaperUsers.size()][2]; + List<Integer> userIds = new ArrayList(); + List<String> userNames = new ArrayList(); for (int i = 0; i < examPaperUsers.size(); i++) { User user = userService.getUserById(examPaperUsers.get(i).getUserId()); if (ObjectUtils.isNotEmpty(user)) { - Integer[] userId = {user.getUserLevel(), examPaperUsers.get(i).getUserId()}; - userIds[i] = userId; + Integer userId = examPaperUsers.get(i).getUserId(); + userIds.add(userId); + userNames.add(user.getRealName()); } } - vm.setUserId(userIds); + vm.setUserIds(userIds); + vm.setUserNames(userNames); return vm; } @@ -262,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) { @@ -520,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<>(); //澶氶�� -- Gitblit v1.8.0