From 6d05f0dc6e96ead24bb7e035e16f18031b1ede78 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期五, 17 五月 2024 11:35:26 +0800
Subject: [PATCH] feat:看题新增查询条件
---
src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java | 84 +++++++++++++++++++++++++++++-------------
1 files changed, 58 insertions(+), 26 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 15957bc..f0d9dc0 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
@@ -1,37 +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.PaperExcelVO;
+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.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;
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;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -45,6 +42,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;
@@ -60,9 +58,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;
@@ -128,6 +127,7 @@
examPaper.setCreateTime(now);
examPaper.setCreateUser(user.getId());
examPaper.setDeleted(false);
+ examPaper.setUserIds(examPaperEditRequestVM.getMenuIds());
examPaperFromVM(examPaperEditRequestVM, examPaper, titleItemsVM);
examPaperMapper.insertSelective(examPaper);
@@ -150,16 +150,20 @@
}
@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()
.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();
@@ -170,11 +174,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)),
@@ -182,7 +187,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;
@@ -202,8 +207,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;
@@ -216,8 +224,8 @@
@Override
- public Integer selectAllCount() {
- return examPaperMapper.selectAllCount();
+ public Integer selectAllCount(List<Integer> deptIds) {
+ return examPaperMapper.selectAllCount(deptIds);
}
@Override
@@ -358,6 +366,7 @@
int remainingScore = totalScore;
for (int i = 0; i < quantity - 1; i++) {
+ // 濡傛灉棰樻暟閲忚秴杩囦簡棰樺簱鏁伴噺锛屾姤閿�
if (i >= scoresMap.size()) {
throw new QuestionException();
}
@@ -516,14 +525,14 @@
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() * 2;
selectRandomScores(multiple, multipleMap, questionTypeVM.getMultipleChoice(), multipleSource);
//鍒ゆ柇
- List<Question> collect1 = list.stream().filter(e -> e.getQuestionType().equals(QuestionTypeEnum.TrueFalse.getCode())).collect(Collectors.toList());
+ 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;
@@ -533,7 +542,7 @@
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);
@@ -596,4 +605,27 @@
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
+ public List<ExamPaper> list(List<Integer> deptIds) {
+ return examPaperMapper.list(deptIds);
+ }
}
--
Gitblit v1.8.0