fuliqi
2024-05-31 21a9aa320b3eeb072bcd7d3fa883587d57b6ccbb
src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java
@@ -1,5 +1,7 @@
package com.ycl.jxkg.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.jxkg.domain.TextContent;
import com.ycl.jxkg.domain.enums.ExamPaperTypeEnum;
import com.ycl.jxkg.domain.exam.ExamPaperQuestionItemObject;
@@ -27,6 +29,7 @@
import com.ycl.jxkg.domain.ExamPaper;
import com.ycl.jxkg.domain.Question;
import com.ycl.jxkg.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -36,26 +39,18 @@
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaper> implements ExamPaperService {
@RequiredArgsConstructor
public class ExamPaperServiceImpl extends ServiceImpl<ExamPaperMapper, ExamPaper> implements ExamPaperService {
    private final ExamPaperMapper examPaperMapper;
    private final QuestionMapper questionMapper;
    private final TextContentService textContentService;
    private final QuestionService questionService;
    private final SubjectService subjectService;
    @Autowired
    public ExamPaperServiceImpl(ExamPaperMapper examPaperMapper, QuestionMapper questionMapper, TextContentService textContentService, QuestionService questionService, SubjectService subjectService) {
        super(examPaperMapper);
        this.examPaperMapper = examPaperMapper;
        this.questionMapper = questionMapper;
        this.textContentService = textContentService;
        this.questionService = questionService;
        this.subjectService = subjectService;
    }
    @Override
@@ -92,31 +87,31 @@
            TextContent frameTextContent = new TextContent();
            frameTextContent.setContent(frameTextContentStr);
            frameTextContent.setCreateTime(now);
            textContentService.insertByFilter(frameTextContent);
            textContentService.save(frameTextContent);
            examPaper.setFrameTextContentId(frameTextContent.getId());
            examPaper.setCreateTime(now);
            examPaper.setCreateUser(user.getId());
            examPaper.setDeleted(false);
            examPaperFromVM(examPaperEditRequestVO, examPaper, titleItemsVM);
            examPaperMapper.insertSelective(examPaper);
            examPaperMapper.insert(examPaper);
        } else {
            examPaper = examPaperMapper.selectByPrimaryKey(examPaperEditRequestVO.getId());
            TextContent frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId());
            examPaper = examPaperMapper.selectById(examPaperEditRequestVO.getId());
            TextContent frameTextContent = textContentService.getById(examPaper.getFrameTextContentId());
            frameTextContent.setContent(frameTextContentStr);
            textContentService.updateByIdFilter(frameTextContent);
            textContentService.updateById(frameTextContent);
            examPaperFromVM(examPaperEditRequestVO, examPaper, titleItemsVM);
            examPaperMapper.updateByPrimaryKeySelective(examPaper);
            examPaperMapper.updateById(examPaper);
        }
        return examPaper;
    }
    @Override
    public ExamPaperEditRequestVO examPaperToVM(Integer id) {
        ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(id);
        ExamPaper examPaper = examPaperMapper.selectById(id);
        ExamPaperEditRequestVO vo = new ExamPaperEditRequestVO();
        BeanUtils.copyProperties(examPaper, vo);
        vo.setLevel(examPaper.getGradeLevel());
        TextContent frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId());
        TextContent frameTextContent = textContentService.getById(examPaper.getFrameTextContentId());
        List<ExamPaperTitleItemObject> examPaperTitleItemObjects = JsonUtil.toJsonListObject(frameTextContent.getContent(), ExamPaperTitleItemObject.class);
        List<Integer> questionIds = examPaperTitleItemObjects.stream()
                .flatMap(t -> t.getQuestionItems().stream()
@@ -202,4 +197,6 @@
            return titleItem;
        }).collect(Collectors.toList());
    }
}