From c9d04bc519b73f7fc4841c34e2f15fca9db7aad2 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期五, 31 五月 2024 14:08:30 +0800 Subject: [PATCH] 重构:service、mapper plus化,xml删除多余sql --- src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java | 35 ++++++++++++++++------------------- 1 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java index 7776dc5..c213d8d 100644 --- a/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java +++ b/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()); } + + } -- Gitblit v1.8.0