From f70b376cd2b9a1d7f29b81b30231d30dd55351ad Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期四, 13 六月 2024 09:21:25 +0800 Subject: [PATCH] 删除examTemplate --- src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java | 183 +++++++++++++++++++++++++++++---------------- 1 files changed, 116 insertions(+), 67 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 ccefd50..b74394d 100644 --- a/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java +++ b/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java @@ -1,42 +1,42 @@ package com.ycl.jxkg.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ycl.jxkg.domain.entity.TextContent; -import com.ycl.jxkg.domain.enums.ExamPaperTypeEnum; -import com.ycl.jxkg.domain.exam.ExamPaperQuestionItemObject; -import com.ycl.jxkg.domain.exam.ExamPaperTitleItemObject; +import com.ycl.jxkg.context.WebContext; +import com.ycl.jxkg.domain.exam.PaperQuestion; +import com.ycl.jxkg.domain.exam.PaperQuestionDTO; +import com.ycl.jxkg.domain.form.ExamPaperForm; +import com.ycl.jxkg.domain.vo.admin.exam.ExamResponseVO; +import com.ycl.jxkg.enums.ExamPaperTypeEnum; import com.ycl.jxkg.domain.other.KeyValue; +import com.ycl.jxkg.enums.VisibilityEnum; import com.ycl.jxkg.mapper.ExamPaperMapper; import com.ycl.jxkg.mapper.QuestionMapper; import com.ycl.jxkg.service.ExamPaperService; import com.ycl.jxkg.service.QuestionService; import com.ycl.jxkg.service.SubjectService; import com.ycl.jxkg.service.TextContentService; -import com.ycl.jxkg.service.enums.ActionEnum; import com.ycl.jxkg.utils.DateTimeUtil; -import com.ycl.jxkg.utils.JsonUtil; -import com.ycl.jxkg.utils.ExamUtil; import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperEditRequestVO; import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperPageRequestVO; import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperTitleItemVO; -import com.ycl.jxkg.domain.vo.admin.question.QuestionEditRequestVO; import com.ycl.jxkg.domain.vo.student.dashboard.PaperFilter; import com.ycl.jxkg.domain.vo.student.dashboard.PaperInfo; import com.ycl.jxkg.domain.vo.student.exam.ExamPaperPageVO; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.ycl.jxkg.domain.entity.ExamPaper; -import com.ycl.jxkg.domain.entity.Question; -import com.ycl.jxkg.domain.entity.User; +import com.ycl.jxkg.utils.PageInfoHelper; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; 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.concurrent.atomic.AtomicInteger; +import java.util.Objects; import java.util.stream.Collectors; @Service @@ -48,19 +48,49 @@ private final TextContentService textContentService; private final QuestionService questionService; private final SubjectService subjectService; + private final WebContext webContext; @Override - public PageInfo<ExamPaper> page(ExamPaperPageRequestVO requestVM) { - return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> + @Transactional(rollbackFor = Exception.class) + public void addPaper(ExamPaperForm form) { + ExamPaper examPaper = ExamPaperForm.getEntityByForm(form,null); + examPaper.setContent(JSON.toJSONString(form.getQuestionList())); + baseMapper.insert(examPaper); + //TODO:闅忓簭璇曞嵎鐢熸垚棰樼洰 +// if(ExamPaperTypeEnum.RandomOrder.getCode().equals(form.getPaperType())){ +// List<PaperQuestionDTO> questionList = form.getQuestionList(); +// List<PaperQuestion> list = questionMapper.selectQuestion(); +// } + } + + @Override + public void updateExamPaper(ExamPaperForm form) { + ExamPaper entity = ExamPaperForm.getEntityByForm(form,null); + baseMapper.updateById(entity); + } + + @Override + public PageInfo<ExamResponseVO> page(ExamPaperPageRequestVO requestVM) { + PageInfo<ExamPaper> page = PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> examPaperMapper.page(requestVM)); + PageInfo<ExamResponseVO> pageVO = PageInfoHelper.copyMap(page, e -> { + ExamResponseVO vo = new ExamResponseVO(); + BeanUtils.copyProperties(e, vo); + vo.setVisibility(VisibilityEnum.valueOf(vo.getVisibility()).getCode() + ""); + vo.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime())); + vo.setQuestionList(JSONArray.parseArray(e.getContent(),PaperQuestionDTO.class)); + return vo; + }); + return pageVO; } - @Override - public PageInfo<ExamPaper> taskExamPage(ExamPaperPageRequestVO requestVM) { - return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> - examPaperMapper.taskExamPage(requestVM)); - } + +// @Override +// public PageInfo<ExamPaper> taskExamPage(ExamPaperPageRequestVO requestVM) { +// return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> +// examPaperMapper.taskExamPage(requestVM)); +// } @Override public PageInfo<ExamPaper> studentPage(ExamPaperPageVO requestVM) { @@ -69,44 +99,44 @@ } - @Override - @Transactional - public ExamPaper savePaperFromVM(ExamPaperEditRequestVO examPaperEditRequestVO, User user) { - ActionEnum actionEnum = (examPaperEditRequestVO.getId() == null) ? ActionEnum.ADD : ActionEnum.UPDATE; - Date now = new Date(); - List<ExamPaperTitleItemVO> titleItemsVM = examPaperEditRequestVO.getTitleItems(); - List<ExamPaperTitleItemObject> frameTextContentList = frameTextContentFromVM(titleItemsVM); - String frameTextContentStr = JsonUtil.toJsonStr(frameTextContentList); - - ExamPaper examPaper = new ExamPaper(); - BeanUtils.copyProperties(examPaperEditRequestVO, examPaper); - if (actionEnum == ActionEnum.ADD) { - TextContent frameTextContent = new TextContent(); - frameTextContent.setContent(frameTextContentStr); - frameTextContent.setCreateTime(now); - textContentService.save(frameTextContent); - examPaper.setCreateTime(now); - examPaper.setCreateUser(user.getId()); - examPaperFromVM(examPaperEditRequestVO, examPaper, titleItemsVM); - examPaperMapper.insert(examPaper); - } else { - examPaper = examPaperMapper.selectById(examPaperEditRequestVO.getId()); - //TODO:寰呭畬鎴� +// @Override +// @Transactional +// public ExamPaper savePaperFromVM(ExamPaperEditRequestVO examPaperEditRequestVO, User user) { +// ActionEnum actionEnum = (examPaperEditRequestVO.getId() == null) ? ActionEnum.ADD : ActionEnum.UPDATE; +// Date now = new Date(); +// List<ExamPaperTitleItemVO> titleItemsVM = examPaperEditRequestVO.getTitleItems(); +// List<ExamPaperTitleItemObject> frameTextContentList = frameTextContentFromVM(titleItemsVM); +// String frameTextContentStr = JsonUtil.toJsonStr(frameTextContentList); +// +// ExamPaper examPaper = new ExamPaper(); +// BeanUtils.copyProperties(examPaperEditRequestVO, examPaper); +// if (actionEnum == ActionEnum.ADD) { +// TextContent frameTextContent = new TextContent(); +// frameTextContent.setContent(frameTextContentStr); +// frameTextContent.setCreateTime(now); +// textContentService.save(frameTextContent); +// examPaper.setCreateTime(now); +// examPaper.setCreateUser(user.getId()); +// examPaperFromVM(examPaperEditRequestVO, examPaper, titleItemsVM); +// examPaperMapper.insert(examPaper); +// } else { +// examPaper = examPaperMapper.selectById(examPaperEditRequestVO.getId()); +// //TODO: // TextContent frameTextContent = textContentService.getById(examPaper.getFrameTextContentId()); // frameTextContent.setContent(frameTextContentStr); // textContentService.updateById(frameTextContent); - examPaperFromVM(examPaperEditRequestVO, examPaper, titleItemsVM); - examPaperMapper.updateById(examPaper); - } - return examPaper; - } +// examPaperFromVM(examPaperEditRequestVO, examPaper, titleItemsVM); +// examPaperMapper.updateById(examPaper); +// } +// return examPaper; +// } @Override public ExamPaperEditRequestVO examPaperToVM(Integer id) { ExamPaper examPaper = examPaperMapper.selectById(id); ExamPaperEditRequestVO vo = new ExamPaperEditRequestVO(); BeanUtils.copyProperties(examPaper, vo); - //TODO:寰呭畬鎴� + //TODO: // TextContent frameTextContent = textContentService.getById(examPaper.getFrameTextContentId()); // List<ExamPaperTitleItemObject> examPaperTitleItemObjects = JsonUtil.toJsonListObject(frameTextContent.getContent(), ExamPaperTitleItemObject.class); // List<Integer> questionIds = examPaperTitleItemObjects.stream() @@ -158,8 +188,10 @@ }).collect(Collectors.toList()); } + + private void examPaperFromVM(ExamPaperEditRequestVO examPaperEditRequestVO, ExamPaper examPaper, List<ExamPaperTitleItemVO> titleItemsVM) { - //TODO:寰呭畬鎴� + //TODO: // Integer gradeLevel = subjectService.levelBySubjectId(examPaperEditRequestVO.getSubjectId()); // Integer questionCount = titleItemsVM.stream() // .mapToInt(t -> t.getQuestionItems().size()).sum(); @@ -177,23 +209,40 @@ // } } - private List<ExamPaperTitleItemObject> frameTextContentFromVM(List<ExamPaperTitleItemVO> titleItems) { - AtomicInteger index = new AtomicInteger(1); - return titleItems.stream().map(t -> { - ExamPaperTitleItemObject titleItem = new ExamPaperTitleItemObject(); - BeanUtils.copyProperties(t, titleItem); - List<ExamPaperQuestionItemObject> questionItems = t.getQuestionItems().stream() - .map(q -> { - ExamPaperQuestionItemObject examPaperQuestionItemObject = new ExamPaperQuestionItemObject(); - BeanUtils.copyProperties(q, examPaperQuestionItemObject); - examPaperQuestionItemObject.setItemOrder(index.getAndIncrement()); - return examPaperQuestionItemObject; - }) - .collect(Collectors.toList()); - titleItem.setQuestionItems(questionItems); - return titleItem; - }).collect(Collectors.toList()); +// private List<ExamPaperTitleItemObject> frameTextContentFromVM(List<ExamPaperTitleItemVO> titleItems) { +// AtomicInteger index = new AtomicInteger(1); +// return titleItems.stream().map(t -> { +// ExamPaperTitleItemObject titleItem = new ExamPaperTitleItemObject(); +// BeanUtils.copyProperties(t, titleItem); +// List<ExamPaperQuestionItemObject> questionItems = t.getQuestionItems().stream() +// .map(q -> { +// ExamPaperQuestionItemObject examPaperQuestionItemObject = new ExamPaperQuestionItemObject(); +// BeanUtils.copyProperties(q, examPaperQuestionItemObject); +// examPaperQuestionItemObject.setItemOrder(index.getAndIncrement()); +// return examPaperQuestionItemObject; +// }) +// .collect(Collectors.toList()); +// titleItem.setQuestionItems(questionItems); +// return titleItem; +// }).collect(Collectors.toList()); +// } + + @Override + public List<ExamPaper> myExamPaper(Integer paperType) { + Integer userId = webContext.getCurrentUser().getId(); + List<ExamPaper> list = new LambdaQueryChainWrapper<>(baseMapper) + .select(ExamPaper::getId, ExamPaper::getName, ExamPaper::getVisibility) + .eq(ExamPaper::getCreateUser, userId) + .eq(Objects.nonNull(paperType), ExamPaper::getPaperType, paperType) + .or() + .eq(ExamPaper::getVisibility, VisibilityEnum.Public.getName()) + .eq(Objects.nonNull(paperType), ExamPaper::getPaperType, paperType) + .list(); + list.stream().forEach(item -> { + if (VisibilityEnum.Public.getName().equals(item.getVisibility())) { + item.setName(item.getName() + " (鍏紑)"); + } + }); + return list; } - - } -- Gitblit v1.8.0