| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.domain.Question; |
| | | import com.ycl.jxkg.domain.TextContent; |
| | | import com.ycl.jxkg.domain.entity.Question; |
| | | import com.ycl.jxkg.domain.entity.TextContent; |
| | | import com.ycl.jxkg.domain.enums.QuestionStatusEnum; |
| | | import com.ycl.jxkg.domain.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.domain.question.QuestionItemObject; |
| | |
| | | import com.ycl.jxkg.utils.DateTimeUtil; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import com.ycl.jxkg.utils.ExamUtil; |
| | | import com.ycl.jxkg.vo.admin.question.QuestionEditItemVO; |
| | | import com.ycl.jxkg.vo.admin.question.QuestionEditRequestVO; |
| | | import com.ycl.jxkg.vo.admin.question.QuestionPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.question.QuestionEditItemVO; |
| | | import com.ycl.jxkg.domain.vo.admin.question.QuestionEditRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.question.QuestionPageRequestVO; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class QuestionServiceImpl extends BaseServiceImpl<Question> implements QuestionService { |
| | | @RequiredArgsConstructor |
| | | public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService { |
| | | |
| | | private final QuestionMapper questionMapper; |
| | | private final TextContentService textContentService; |
| | | private final SubjectService subjectService; |
| | | |
| | | @Autowired |
| | | public QuestionServiceImpl(QuestionMapper questionMapper, TextContentService textContentService, SubjectService subjectService) { |
| | | super(questionMapper); |
| | | this.textContentService = textContentService; |
| | | this.questionMapper = questionMapper; |
| | | this.subjectService = subjectService; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<Question> page(QuestionPageRequestVO requestVM) { |
| | |
| | | TextContent infoTextContent = new TextContent(); |
| | | infoTextContent.setCreateTime(now); |
| | | setQuestionInfoFromVM(infoTextContent, model); |
| | | textContentService.insertByFilter(infoTextContent); |
| | | textContentService.save(infoTextContent); |
| | | |
| | | Question question = new Question(); |
| | | question.setSubjectId(model.getSubjectId()); |
| | |
| | | question.setDifficult(model.getDifficult()); |
| | | question.setInfoTextContentId(infoTextContent.getId()); |
| | | question.setCreateUser(userId); |
| | | question.setDeleted(false); |
| | | questionMapper.insertSelective(question); |
| | | questionMapper.insert(question); |
| | | return question; |
| | | } |
| | | |
| | |
| | | @Transactional |
| | | public Question updateFullQuestion(QuestionEditRequestVO model) { |
| | | Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId()); |
| | | Question question = questionMapper.selectByPrimaryKey(model.getId()); |
| | | Question question = questionMapper.selectById(model.getId()); |
| | | question.setSubjectId(model.getSubjectId()); |
| | | question.setGradeLevel(gradeLevel); |
| | | question.setScore(ExamUtil.scoreFromVM(model.getScore())); |
| | | question.setDifficult(model.getDifficult()); |
| | | question.setCorrectFromVM(model.getCorrect(), model.getCorrectArray()); |
| | | questionMapper.updateByPrimaryKeySelective(question); |
| | | questionMapper.updateById(question); |
| | | |
| | | //题干、解析、选项等 更新 |
| | | TextContent infoTextContent = textContentService.selectById(question.getInfoTextContentId()); |
| | | TextContent infoTextContent = textContentService.getById(question.getInfoTextContentId()); |
| | | setQuestionInfoFromVM(infoTextContent, model); |
| | | textContentService.updateByIdFilter(infoTextContent); |
| | | textContentService.updateById(infoTextContent); |
| | | |
| | | return question; |
| | | } |
| | |
| | | @Override |
| | | public QuestionEditRequestVO getQuestionEditRequestVM(Integer questionId) { |
| | | //题目映射 |
| | | Question question = questionMapper.selectByPrimaryKey(questionId); |
| | | Question question = questionMapper.selectById(questionId); |
| | | return getQuestionEditRequestVM(question); |
| | | } |
| | | |
| | | @Override |
| | | public QuestionEditRequestVO getQuestionEditRequestVM(Question question) { |
| | | //题目映射 |
| | | TextContent questionInfoTextContent = textContentService.selectById(question.getInfoTextContentId()); |
| | | TextContent questionInfoTextContent = textContentService.getById(question.getInfoTextContentId()); |
| | | QuestionObject questionObject = JsonUtil.toJsonObject(questionInfoTextContent.getContent(), QuestionObject.class); |
| | | QuestionEditRequestVO questionEditRequestVO = new QuestionEditRequestVO(); |
| | | BeanUtils.copyProperties(question, questionEditRequestVO); |