| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.mindskip.xzs.base.RestResponse; |
| | | import com.mindskip.xzs.domain.DeptQuestion; |
| | | import com.mindskip.xzs.domain.QuestionSubject; |
| | | import com.mindskip.xzs.domain.other.KeyValue; |
| | | import com.mindskip.xzs.domain.Question; |
| | |
| | | import com.mindskip.xzs.domain.enums.QuestionTypeEnum; |
| | | import com.mindskip.xzs.domain.question.QuestionItemObject; |
| | | import com.mindskip.xzs.domain.question.QuestionObject; |
| | | import com.mindskip.xzs.domain.vo.DeptQuestionVO; |
| | | import com.mindskip.xzs.domain.vo.QuestionContentVO; |
| | | import com.mindskip.xzs.domain.vo.QuestionVO; |
| | | import com.mindskip.xzs.repository.BaseMapper; |
| | | import com.mindskip.xzs.repository.DeptQuestionMapper; |
| | | import com.mindskip.xzs.repository.QuestionMapper; |
| | | import com.mindskip.xzs.repository.SubjectMapper; |
| | | import com.mindskip.xzs.service.QuestionService; |
| | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentRequestVM; |
| | | import com.mindskip.xzs.viewmodel.student.question.answer.QuestionPageStudentResponseVM; |
| | | import com.mindskip.xzs.vo.QuestionExportData; |
| | | import com.mindskip.xzs.vo.QuestionExportVO; |
| | | import com.mindskip.xzs.vo.QuestionImportVO; |
| | | import com.mindskip.xzs.vo.QuestionSubjectVO; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.modelmapper.ModelMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.Arrays; |
| | |
| | | private final SubjectService subjectService; |
| | | private final QuestionSubjectService questionSubjectService; |
| | | private final SubjectMapper subjectMapper; |
| | | private final DeptQuestionMapper deptQuestionMapper; |
| | | |
| | | @Autowired |
| | | public QuestionServiceImpl(QuestionMapper questionMapper, TextContentService textContentService, SubjectService subjectService, QuestionSubjectService questionSubjectService, SubjectMapper subjectMapper) { |
| | | super(questionMapper); |
| | | this.textContentService = textContentService; |
| | | public QuestionServiceImpl(BaseMapper<Question> baseMapper, QuestionMapper questionMapper, TextContentService textContentService, SubjectService subjectService, QuestionSubjectService questionSubjectService, SubjectMapper subjectMapper, DeptQuestionMapper deptQuestionMapper) { |
| | | super(baseMapper); |
| | | this.questionMapper = questionMapper; |
| | | this.textContentService = textContentService; |
| | | this.subjectService = subjectService; |
| | | this.questionSubjectService = questionSubjectService; |
| | | this.subjectMapper = subjectMapper; |
| | | this.deptQuestionMapper = deptQuestionMapper; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Transactional |
| | | public Question insertFullQuestion(QuestionEditRequestVM model, Integer userId) { |
| | | Date now = new Date(); |
| | | // Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId()); |
| | | |
| | | //题干、解析、选项等 插入 |
| | | // 题干、解析、选项等 插入 |
| | | TextContent infoTextContent = new TextContent(); |
| | | infoTextContent.setCreateTime(now); |
| | | setQuestionInfoFromVM(infoTextContent, model); |
| | | textContentService.insertByFilter(infoTextContent); |
| | | |
| | | // 题目插入 |
| | | Question question = new Question(); |
| | | // question.setSubjectId(model.getSubjectId()); |
| | | question.setGradeLevel(model.getGradeLevel()); |
| | | question.setCreateTime(now); |
| | | question.setQuestionType(model.getQuestionType()); |
| | |
| | | question.setDeleted(false); |
| | | questionMapper.insertSelective(question); |
| | | |
| | | // 题目所属部门插入 |
| | | if (! CollectionUtils.isEmpty(model.getDeptIds())) { |
| | | List<DeptQuestion> deptQuestions = model.getDeptIds().stream().map(deptId -> { |
| | | DeptQuestion deptQuestion = new DeptQuestion(); |
| | | deptQuestion.setQuestionId(question.getId()); |
| | | deptQuestion.setDeptId(deptId); |
| | | return deptQuestion; |
| | | }).collect(Collectors.toList()); |
| | | if (! CollectionUtils.isEmpty(model.getDeptIds())) { |
| | | deptQuestionMapper.add(deptQuestions); |
| | | } |
| | | } |
| | | |
| | | //批量添加 |
| | | List<QuestionSubject> list = Arrays.asList(model.getSubjectIds()).stream().map(e->{ |
| | | List<QuestionSubject> list = Arrays.asList(model.getSubjectIds()).stream().map(e -> { |
| | | QuestionSubject questionSubject = new QuestionSubject(); |
| | | questionSubject.setQuestionId(question.getId()); |
| | | questionSubject.setSubjectId(e); |
| | |
| | | @Override |
| | | @Transactional |
| | | public Question updateFullQuestion(QuestionEditRequestVM model) { |
| | | // Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId()); |
| | | |
| | | // 题目修改 |
| | | Question question = questionMapper.selectByPrimaryKey(model.getId()); |
| | | question.setSubjectId(model.getSubjectId()); |
| | | question.setGradeLevel(model.getGradeLevel()); |
| | |
| | | question.setCorrectFromVM(model.getCorrect(), model.getCorrectArray()); |
| | | questionMapper.updateByPrimaryKeySelective(question); |
| | | |
| | | // 处理题目所属部门 |
| | | deptQuestionMapper.remove(question.getId()); |
| | | List<DeptQuestion> deptQuestions = model.getDeptIds().stream().map(deptId -> { |
| | | DeptQuestion deptQuestion = new DeptQuestion(); |
| | | deptQuestion.setQuestionId(question.getId()); |
| | | deptQuestion.setDeptId(deptId); |
| | | return deptQuestion; |
| | | }).collect(Collectors.toList()); |
| | | if (! CollectionUtils.isEmpty(model.getDeptIds())) { |
| | | deptQuestionMapper.add(deptQuestions); |
| | | } |
| | | |
| | | //题干、解析、选项等 更新 |
| | | TextContent infoTextContent = textContentService.selectById(question.getInfoTextContentId()); |
| | | setQuestionInfoFromVM(infoTextContent, model); |
| | |
| | | |
| | | questionSubjectService.removeQuestionId(question.getId()); |
| | | //批量添加 |
| | | List<QuestionSubject> list = Arrays.asList(model.getSubjectIds()).stream().map(e->{ |
| | | List<QuestionSubject> list = Arrays.asList(model.getSubjectIds()).stream().map(e -> { |
| | | QuestionSubject questionSubject = new QuestionSubject(); |
| | | questionSubject.setQuestionId(question.getId()); |
| | | questionSubject.setSubjectId(e); |
| | |
| | | |
| | | @Override |
| | | public ExamQuestionVO getQuestionEditRequestVM(Integer questionId) { |
| | | //题目映射 |
| | | // 题目映射 |
| | | Question question = questionMapper.selectByPrimaryKey(questionId); |
| | | List<QuestionSubject> list = questionSubjectService.getQuestion(questionId).stream().map(e->{ |
| | | List<QuestionSubject> list = questionSubjectService.getQuestion(questionId).stream().map(e -> { |
| | | SubjectPageRequestVM subject = new SubjectPageRequestVM(); |
| | | subject.setId(e.getSubjectId()); |
| | | e.setSubName(subjectMapper.page(subject).get(0).getName()); |
| | |
| | | }).collect(Collectors.toList()); |
| | | ExamQuestionVO questionEditRequestVM = getQuestionEditRequestVM(question); |
| | | questionEditRequestVM.setQuestionSubjects(list); |
| | | // 查询题目所属部门 |
| | | List<Integer> deptIds = deptQuestionMapper.deptByQuestionId(questionId) |
| | | .stream().map(DeptQuestionVO::getDeptId).collect(Collectors.toList()); |
| | | questionEditRequestVM.setDeptIds(deptIds); |
| | | return questionEditRequestVM; |
| | | } |
| | | |
| | |
| | | question.setDeleted(true); |
| | | questionMapper.updateByPrimaryKeySelective(question); |
| | | List<Integer> list = questionSubjectService.getQuestion(id) |
| | | .stream().map(e->{ |
| | | .stream().map(e -> { |
| | | return e.getId(); |
| | | }).collect(Collectors.toList()); |
| | | return questionSubjectService.removes(list.toArray(new Integer[list.size()])); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<QuestionImportVO> exportData(QuestionExportVO query) { |
| | | return questionMapper.exportData(query); |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<QuestionPageStudentResponseVM> selectQuestion(QuestionPageStudentRequestVM model) { |
| | | return PageHelper.startPage(model.getPageIndex(), model.getPageSize(), "id desc").doSelectPageInfo(() -> |
| | | return PageHelper.startPage(model.getPageIndex(), model.getPageSize()).doSelectPageInfo(() -> |
| | | questionMapper.selectQuestion(model).stream().peek( |
| | | q -> q.setShortTitle(HtmlUtil.clear(q.getShortTitle())) |
| | | ).collect(Collectors.toList()) |
| | |
| | | return RestResponse.ok(null); |
| | | } |
| | | |
| | | @Override |
| | | public Integer countQuestionByTitle(String title) { |
| | | return questionMapper.countQuestionByTitle(title); |
| | | } |
| | | |
| | | @Override |
| | | public List<QuestionSubjectVO> countQuestionByTitleAndSubject(String title, Integer subjectId) { |
| | | return questionMapper.countQuestionByTitleAndSubject(title, subjectId); |
| | | } |
| | | |
| | | /** |
| | | * 处理题目内容JSON |
| | | * |