From 9a1c378ec5566a727efcb85120cdafd52c3ee9f1 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期四, 23 五月 2024 16:21:37 +0800 Subject: [PATCH] 在线练习增加练习模式、融合在线练题 --- src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java | 71 +++++++++++++++++++++++++++++------ 1 files changed, 59 insertions(+), 12 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 2f54f3a..e8584a5 100644 --- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java +++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java @@ -1,34 +1,34 @@ package com.mindskip.xzs.service.impl; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.mindskip.xzs.configuration.spring.exception.QuestionException; import com.mindskip.xzs.domain.*; -import com.mindskip.xzs.domain.TextContent; import com.mindskip.xzs.domain.enums.ExamPaperTypeEnum; import com.mindskip.xzs.domain.enums.QuestionTypeEnum; import com.mindskip.xzs.domain.exam.ExamPaperQuestionItemObject; import com.mindskip.xzs.domain.exam.ExamPaperTitleItemObject; import com.mindskip.xzs.domain.other.KeyValue; +import com.mindskip.xzs.domain.vo.ExamTemplatesVO; import com.mindskip.xzs.domain.vo.PaperExcelVO; +import com.mindskip.xzs.domain.vo.UserVO; +import com.mindskip.xzs.repository.ExamPaperAnswerMapper; import com.mindskip.xzs.repository.ExamPaperMapper; import com.mindskip.xzs.repository.QuestionMapper; import com.mindskip.xzs.repository.UserDepartmentMapper; import com.mindskip.xzs.service.*; import com.mindskip.xzs.service.enums.ActionEnum; import com.mindskip.xzs.utility.DateTimeUtil; +import com.mindskip.xzs.utility.ExamUtil; 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.*; 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; import com.mindskip.xzs.viewmodel.student.exam.ExamPaperPageVM; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.mindskip.xzs.domain.ExamPaper; -import com.mindskip.xzs.domain.Question; -import com.mindskip.xzs.domain.User; +import org.apache.commons.lang3.ObjectUtils; import org.modelmapper.ModelMapper; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -44,6 +44,7 @@ protected final static ModelMapper modelMapper = ModelMapperSingle.Instance(); private final ExamPaperMapper examPaperMapper; + private final ExamPaperAnswerMapper examPaperAnswerMapper; private final QuestionMapper questionMapper; private final TextContentService textContentService; private final QuestionService questionService; @@ -59,9 +60,10 @@ @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) { + public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, ExamPaperAnswerMapper examPaperAnswerMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamPaperSubjectService examPaperSubjectService, QuestionSubjectService questionSubjectService, ExamPaperUserService examPaperUserService, UserService userService, UserDepartmentMapper userDepartmentMapper, DepartmentService departmentService) { super(examPaperMapper); this.examPaperMapper = examPaperMapper; + this.examPaperAnswerMapper = examPaperAnswerMapper; this.questionMapper = questionMapper; this.textContentService = textContentService; this.questionService = questionService; @@ -161,6 +163,9 @@ .flatMap(t -> t.getQuestionItems().stream() .map(q -> q.getId())) .collect(Collectors.toList()); + if (ObjectUtils.isEmpty(questionIds)) { + throw new RuntimeException("璇ヨ瘯鍗锋病鏈夐鐩�"); + } List<Question> questions = questionMapper.selectByIds(questionIds); //鍗曢�夋暟閲� Integer singleChoice = questions.stream().filter(e -> e.getQuestionType() == 1).collect(Collectors.toList()).size(); @@ -204,8 +209,11 @@ List<ExamPaperUser> examPaperUsers = examPaperUserService.getByExamPaperId(examPaper.getId()); Integer[][] userIds = new Integer[examPaperUsers.size()][2]; for (int i = 0; i < examPaperUsers.size(); i++) { - Integer[] userId = {userService.getUserById(examPaperUsers.get(i).getUserId()).getUserLevel(), examPaperUsers.get(i).getUserId()}; - userIds[i] = userId; + User user = userService.getUserById(examPaperUsers.get(i).getUserId()); + if (ObjectUtils.isNotEmpty(user)) { + Integer[] userId = {user.getUserLevel(), examPaperUsers.get(i).getUserId()}; + userIds[i] = userId; + } } vm.setUserId(userIds); return vm; @@ -218,8 +226,8 @@ @Override - public Integer selectAllCount() { - return examPaperMapper.selectAllCount(); + public Integer selectAllCount(List<Integer> deptIds) { + return examPaperMapper.selectAllCount(deptIds); } @Override @@ -599,4 +607,43 @@ return randomNumber; } + + @Override + @Transactional + public void missExam(ExamPaperEditRequestVM model) { + // 淇敼鍘熸潵鐨勮瘯鍗锋椂闂� + if (ObjectUtils.isNotEmpty(model.getLimitDateTime())) { + ExamPaper examPaper = new ExamPaper(); + examPaper.setId(model.getExamPaperId()); + examPaper.setLimitStartTime(DateTimeUtil.parse(model.getLimitDateTime().get(0), DateTimeUtil.STANDER_FORMAT)); + examPaper.setLimitEndTime(DateTimeUtil.parse(model.getLimitDateTime().get(1), DateTimeUtil.STANDER_FORMAT)); + examPaperMapper.updateByPrimaryKeySelective(examPaper); + } + // 鏍规嵁鑰冭瘯id灏嗛�夋嫨鐨勮ˉ鑰冭�冪敓鐨勮�冭瘯鎴愮哗璁剧疆涓烘棤鏁� + examPaperAnswerMapper.setMissExam(model); + + // 琛ヨ�冩椂灏嗘病鏈夐�夋嫨鐨勫苟涓旀病鏈夊弬鍔犺繃鑰冭瘯鐨勮�冪敓澧炲姞涓�鏉¢浂鍒嗚�冭瘯璁板綍锛屽惁鍒欐病鏈夊弬鍔犺繃鑰冭瘯鐨勫嵆浣夸笉琚�夋嫨涔熷彲浠ュ弬鍔犺ˉ鑰� + examPaperAnswerMapper.insertDefault(model); + } + + @Override + @Transactional + public void missExamByTemplateId(ExamTemplatesVO model) { + List<Integer> id = examPaperMapper.getExamPaperByTemplateId(model); + model.setPaperIds(id); + // 鏍规嵁鑰冭瘯id灏嗛�夋嫨鐨勮ˉ鑰冭�冪敓鐨勮�冭瘯鎴愮哗璁剧疆涓烘棤鏁� + examPaperAnswerMapper.setMissExamByTemplate(model); + } + + @Override + public List<ExamPaper> list(List<Integer> deptIds) { + return examPaperMapper.list(deptIds); + } + + @Override + public PageInfo<UserVO> selectStudent(UserVO userVO, List<Integer> adminDeptIds) { + userVO.setDeptIds(ObjectUtils.isNotEmpty(userVO.getDeptIds()) ? userVO.getDeptIds() : adminDeptIds); + return PageHelper.startPage(userVO.getPageIndex(), userVO.getPageSize()).doSelectPageInfo(() -> + examPaperMapper.selectStudent(userVO)); + } } -- Gitblit v1.8.0