| | |
| | | package com.mindskip.xzs.service.impl; |
| | | |
| | | import com.mindskip.xzs.domain.QuestionSubject; |
| | | import com.mindskip.xzs.domain.other.KeyValue; |
| | | import com.mindskip.xzs.domain.Question; |
| | | import com.mindskip.xzs.domain.TextContent; |
| | |
| | | import com.mindskip.xzs.domain.question.QuestionObject; |
| | | import com.mindskip.xzs.repository.QuestionMapper; |
| | | 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 org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | private final QuestionMapper questionMapper; |
| | | private final TextContentService textContentService; |
| | | private final SubjectService subjectService; |
| | | private final QuestionSubjectService questionSubjectService; |
| | | |
| | | @Autowired |
| | | public QuestionServiceImpl(QuestionMapper questionMapper, TextContentService textContentService, SubjectService subjectService) { |
| | | public QuestionServiceImpl(QuestionMapper questionMapper, TextContentService textContentService, SubjectService subjectService, QuestionSubjectService questionSubjectService) { |
| | | super(questionMapper); |
| | | this.textContentService = textContentService; |
| | | this.questionMapper = questionMapper; |
| | | this.subjectService = subjectService; |
| | | this.questionSubjectService = questionSubjectService; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Transactional |
| | | public Question insertFullQuestion(QuestionEditRequestVM model, Integer userId) { |
| | | Date now = new Date(); |
| | | Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId()); |
| | | // Integer gradeLevel = subjectService.levelBySubjectId(model.getSubjectId()); |
| | | |
| | | //题干、解析、选项等 插入 |
| | | TextContent infoTextContent = new TextContent(); |
| | |
| | | textContentService.insertByFilter(infoTextContent); |
| | | |
| | | Question question = new Question(); |
| | | question.setSubjectId(model.getSubjectId()); |
| | | question.setGradeLevel(gradeLevel); |
| | | // question.setSubjectId(model.getSubjectId()); |
| | | // question.setGradeLevel(gradeLevel); |
| | | question.setCreateTime(now); |
| | | question.setQuestionType(model.getQuestionType()); |
| | | question.setStatus(QuestionStatusEnum.OK.getCode()); |
| | |
| | | question.setCreateUser(userId); |
| | | question.setDeleted(false); |
| | | questionMapper.insertSelective(question); |
| | | |
| | | //批量添加 |
| | | List<QuestionSubject> list = Arrays.asList(model.getSubjectIds()).stream().map(e->{ |
| | | QuestionSubject questionSubject = new QuestionSubject(); |
| | | questionSubject.setQuestionId(question.getId()); |
| | | questionSubject.setSubjectId(e); |
| | | questionSubject.setDeleted(0); |
| | | return questionSubject; |
| | | }).collect(Collectors.toList()); |
| | | questionSubjectService.saves(list); |
| | | return question; |
| | | } |
| | | |
| | |
| | | TextContent infoTextContent = textContentService.selectById(question.getInfoTextContentId()); |
| | | setQuestionInfoFromVM(infoTextContent, model); |
| | | textContentService.updateByIdFilter(infoTextContent); |
| | | |
| | | questionSubjectService.removeQuestionId(question.getId()); |
| | | //批量添加 |
| | | List<QuestionSubject> list = Arrays.asList(model.getSubjectIds()).stream().map(e->{ |
| | | QuestionSubject questionSubject = new QuestionSubject(); |
| | | questionSubject.setQuestionId(question.getId()); |
| | | questionSubject.setSubjectId(e); |
| | | questionSubject.setDeleted(0); |
| | | return questionSubject; |
| | | }).collect(Collectors.toList()); |
| | | questionSubjectService.saves(list); |
| | | |
| | | return question; |
| | | } |
| | |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Integer remove(Integer id) { |
| | | Question question = questionMapper.selectByPrimaryKey(id); |
| | | question.setDeleted(true); |
| | | questionMapper.updateByPrimaryKeySelective(question); |
| | | List<Integer> list = questionSubjectService.getQuestion(id) |
| | | .stream().map(e->{ |
| | | return e.getId(); |
| | | }).collect(Collectors.toList()); |
| | | return questionSubjectService.removes(list.toArray(new Integer[list.size()])); |
| | | } |
| | | |
| | | |
| | | } |