| | |
| | | package com.mindskip.xzs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.mindskip.xzs.base.RestResponse; |
| | | 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.QuestionContentVO; |
| | | import com.mindskip.xzs.domain.vo.QuestionVO; |
| | | import com.mindskip.xzs.repository.QuestionMapper; |
| | | import com.mindskip.xzs.repository.SubjectMapper; |
| | | import com.mindskip.xzs.service.QuestionService; |
| | | import com.mindskip.xzs.service.QuestionSubjectService; |
| | | import com.mindskip.xzs.service.SubjectService; |
| | | import com.mindskip.xzs.service.TextContentService; |
| | | import com.mindskip.xzs.utility.DateTimeUtil; |
| | | import com.mindskip.xzs.utility.JsonUtil; |
| | | import com.mindskip.xzs.utility.ModelMapperSingle; |
| | | import com.mindskip.xzs.utility.ExamUtil; |
| | | import com.mindskip.xzs.utility.*; |
| | | import com.mindskip.xzs.viewmodel.admin.education.SubjectPageRequestVM; |
| | | import com.mindskip.xzs.viewmodel.admin.question.ExamQuestionVO; |
| | | import com.mindskip.xzs.viewmodel.admin.question.QuestionEditItemVM; |
| | | import com.mindskip.xzs.viewmodel.admin.question.QuestionEditRequestVM; |
| | | import com.mindskip.xzs.viewmodel.admin.question.QuestionPageRequestVM; |
| | | import com.github.pagehelper.PageHelper; |
| | | 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.QuestionExportVO; |
| | | import com.mindskip.xzs.vo.QuestionImportVO; |
| | | 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.StringUtils; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | } |
| | | |
| | | @Override |
| | | public QuestionEditRequestVM getQuestionEditRequestVM(Integer questionId) { |
| | | public ExamQuestionVO getQuestionEditRequestVM(Integer questionId) { |
| | | //题目映射 |
| | | Question question = questionMapper.selectByPrimaryKey(questionId); |
| | | List<QuestionSubject> list = questionSubjectService.getQuestion(questionId).stream().map(e->{ |
| | |
| | | e.setSubName(subjectMapper.page(subject).get(0).getName()); |
| | | return e; |
| | | }).collect(Collectors.toList()); |
| | | QuestionEditRequestVM questionEditRequestVM = getQuestionEditRequestVM(question); |
| | | ExamQuestionVO questionEditRequestVM = getQuestionEditRequestVM(question); |
| | | questionEditRequestVM.setQuestionSubjects(list); |
| | | return questionEditRequestVM; |
| | | } |
| | | |
| | | @Override |
| | | public QuestionEditRequestVM getQuestionEditRequestVM(Question question) { |
| | | public ExamQuestionVO getQuestionEditRequestVM(Question question) { |
| | | //题目映射 |
| | | TextContent questionInfoTextContent = textContentService.selectById(question.getInfoTextContentId()); |
| | | QuestionObject questionObject = JsonUtil.toJsonObject(questionInfoTextContent.getContent(), QuestionObject.class); |
| | | QuestionEditRequestVM questionEditRequestVM = modelMapper.map(question, QuestionEditRequestVM.class); |
| | | ExamQuestionVO questionEditRequestVM = modelMapper.map(question, ExamQuestionVO.class); |
| | | questionEditRequestVM.setTitle(questionObject.getTitleContent()); |
| | | |
| | | //答案 |
| | |
| | | return questionSubjectService.removes(list.toArray(new Integer[list.size()])); |
| | | } |
| | | |
| | | @Override |
| | | public List<Question> getAll() { |
| | | return questionMapper.getAll(); |
| | | } |
| | | |
| | | @Override |
| | | public List<Question> selectByIds(List<Integer> ids) { |
| | | return questionMapper.selectByIds(ids); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<QuestionImportVO> export(QuestionExportVO query) { |
| | | return questionMapper.export(query); |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<QuestionPageStudentResponseVM> selectQuestion(QuestionPageStudentRequestVM model) { |
| | | return PageHelper.startPage(model.getPageIndex(), model.getPageSize(), "id desc").doSelectPageInfo(() -> |
| | | questionMapper.selectQuestion(model).stream().peek( |
| | | q -> q.setShortTitle(HtmlUtil.clear(q.getShortTitle())) |
| | | ).collect(Collectors.toList()) |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse selectContentById(Integer id) { |
| | | QuestionVO questionVO = questionMapper.selectContentById(id); |
| | | jsonQuestion(questionVO); |
| | | if (QuestionTypeEnum.MultipleChoice.getCode().equals(questionVO.getQuestionType())) { |
| | | // 多选题需要返回答案数量,学员选中对应数量才查询答案 |
| | | if (StringUtils.hasText(questionVO.getCorrect())) { |
| | | questionVO.setAnswerNum(questionVO.getCorrect().split(",").length); |
| | | } |
| | | } |
| | | questionVO.setContentJson(""); |
| | | questionVO.setCorrect(""); |
| | | questionVO.getContent().setCorrect(""); |
| | | questionVO.getContent().setAnalyze(""); |
| | | return RestResponse.ok(questionVO); |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse getAnswer(Integer id) { |
| | | QuestionVO questionVO = questionMapper.getAnswer(id); |
| | | if (Objects.nonNull(questionVO) && StringUtils.hasText(questionVO.getCorrect())) { |
| | | QuestionContentVO vo = JSON.parseObject(questionVO.getContentJson(), QuestionContentVO.class); |
| | | vo.setQuestionItemObjects(null); |
| | | vo.setTitleContent(null); |
| | | vo.setCorrect(questionVO.getCorrect()); |
| | | return RestResponse.ok(vo); |
| | | } |
| | | return RestResponse.ok(null); |
| | | } |
| | | |
| | | /** |
| | | * 处理题目内容JSON |
| | | * |
| | | * @param vo |
| | | */ |
| | | public void jsonQuestion(QuestionVO vo) { |
| | | if (StringUtils.hasText(vo.getContentJson())) { |
| | | QuestionContentVO questionContent = JSON.parseObject(vo.getContentJson(), QuestionContentVO.class); |
| | | vo.setContent(questionContent); |
| | | } |
| | | } |
| | | } |