| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.ycl.jxkg.domain.ExamPaper; |
| | | import com.ycl.jxkg.domain.TaskExam; |
| | | import com.ycl.jxkg.domain.TextContent; |
| | | import com.ycl.jxkg.domain.User; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.domain.entity.ExamPaper; |
| | | import com.ycl.jxkg.domain.entity.TaskExam; |
| | | import com.ycl.jxkg.domain.entity.TextContent; |
| | | import com.ycl.jxkg.domain.entity.User; |
| | | import com.ycl.jxkg.domain.task.TaskItemObject; |
| | | import com.ycl.jxkg.repository.ExamPaperMapper; |
| | | import com.ycl.jxkg.repository.TaskExamMapper; |
| | | import com.ycl.jxkg.mapper.ExamPaperMapper; |
| | | import com.ycl.jxkg.mapper.TaskExamMapper; |
| | | import com.ycl.jxkg.service.TaskExamService; |
| | | import com.ycl.jxkg.service.TextContentService; |
| | | import com.ycl.jxkg.service.enums.ActionEnum; |
| | | import com.ycl.jxkg.utility.DateTimeUtil; |
| | | import com.ycl.jxkg.utility.JsonUtil; |
| | | import com.ycl.jxkg.utility.ModelMapperSingle; |
| | | import com.ycl.jxkg.viewmodel.admin.exam.ExamResponseVM; |
| | | import com.ycl.jxkg.viewmodel.admin.task.TaskPageRequestVM; |
| | | import com.ycl.jxkg.viewmodel.admin.task.TaskRequestVM; |
| | | import com.ycl.jxkg.utils.DateTimeUtil; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamResponseVO; |
| | | import com.ycl.jxkg.domain.vo.admin.task.TaskPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.task.TaskRequestVO; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import org.modelmapper.ModelMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class TaskExamServiceImpl extends BaseServiceImpl<TaskExam> implements TaskExamService { |
| | | @RequiredArgsConstructor |
| | | public class TaskExamServiceImpl extends ServiceImpl<TaskExamMapper,TaskExam> implements TaskExamService { |
| | | |
| | | protected final static ModelMapper modelMapper = ModelMapperSingle.Instance(); |
| | | private final TaskExamMapper taskExamMapper; |
| | | private final TextContentService textContentService; |
| | | private final ExamPaperMapper examPaperMapper; |
| | | |
| | | @Autowired |
| | | public TaskExamServiceImpl(TaskExamMapper taskExamMapper, TextContentService textContentService, ExamPaperMapper examPaperMapper) { |
| | | super(taskExamMapper); |
| | | this.taskExamMapper = taskExamMapper; |
| | | this.textContentService = textContentService; |
| | | this.examPaperMapper = examPaperMapper; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<TaskExam> page(TaskPageRequestVM requestVM) { |
| | | public PageInfo<TaskExam> page(TaskPageRequestVO requestVM) { |
| | | return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> |
| | | taskExamMapper.page(requestVM) |
| | | ); |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void edit(TaskRequestVM model, User user) { |
| | | public void edit(TaskRequestVO model, User user) { |
| | | ActionEnum actionEnum = (model.getId() == null) ? ActionEnum.ADD : ActionEnum.UPDATE; |
| | | TaskExam taskExam = null; |
| | | TaskExam taskExam = new TaskExam(); |
| | | |
| | | if (actionEnum == ActionEnum.ADD) { |
| | | BeanUtils.copyProperties(model, taskExam); |
| | | Date now = new Date(); |
| | | taskExam = modelMapper.map(model, TaskExam.class); |
| | | taskExam.setCreateUser(user.getId()); |
| | | taskExam.setCreateUserName(user.getUserName()); |
| | | taskExam.setCreateTime(now); |
| | | taskExam.setDeleted(false); |
| | | |
| | | //保存任务结构 |
| | | TextContent textContent = textContentService.jsonConvertInsert(model.getPaperItems(), now, p -> { |
| | |
| | | taskItemObject.setExamPaperName(p.getName()); |
| | | return taskItemObject; |
| | | }); |
| | | textContentService.insertByFilter(textContent); |
| | | textContentService.save(textContent); |
| | | taskExam.setFrameTextContentId(textContent.getId()); |
| | | taskExamMapper.insertSelective(taskExam); |
| | | taskExamMapper.insert(taskExam); |
| | | |
| | | } else { |
| | | taskExam = taskExamMapper.selectByPrimaryKey(model.getId()); |
| | | modelMapper.map(model, taskExam); |
| | | |
| | | TextContent textContent = textContentService.selectById(taskExam.getFrameTextContentId()); |
| | | TaskExam old = taskExamMapper.selectById(model.getId()); |
| | | if (Objects.isNull(old)) { |
| | | throw new RuntimeException("数据不存在"); |
| | | } |
| | | BeanUtils.copyProperties(taskExam, old); |
| | | TextContent textContent = textContentService.getById(taskExam.getFrameTextContentId()); |
| | | //清空试卷任务的试卷Id,后面会统一设置 |
| | | List<Integer> paperIds = JsonUtil.toJsonListObject(textContent.getContent(), TaskItemObject.class) |
| | | .stream() |
| | |
| | | taskItemObject.setExamPaperName(p.getName()); |
| | | return taskItemObject; |
| | | }); |
| | | textContentService.updateByIdFilter(textContent); |
| | | taskExamMapper.updateByPrimaryKeySelective(taskExam); |
| | | textContentService.updateById(textContent); |
| | | taskExamMapper.updateById(old); |
| | | } |
| | | |
| | | //更新试卷的taskId |
| | |
| | | } |
| | | |
| | | @Override |
| | | public TaskRequestVM taskExamToVM(Integer id) { |
| | | TaskExam taskExam = taskExamMapper.selectByPrimaryKey(id); |
| | | TaskRequestVM vm = modelMapper.map(taskExam, TaskRequestVM.class); |
| | | TextContent textContent = textContentService.selectById(taskExam.getFrameTextContentId()); |
| | | List<ExamResponseVM> examResponseVMS = JsonUtil.toJsonListObject(textContent.getContent(), TaskItemObject.class).stream().map(tk -> { |
| | | ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(tk.getExamPaperId()); |
| | | ExamResponseVM examResponseVM = modelMapper.map(examPaper, ExamResponseVM.class); |
| | | examResponseVM.setCreateTime(DateTimeUtil.dateFormat(examPaper.getCreateTime())); |
| | | return examResponseVM; |
| | | public TaskRequestVO taskExamToVM(Integer id) { |
| | | TaskExam taskExam = taskExamMapper.selectById(id); |
| | | TaskRequestVO vo = new TaskRequestVO(); |
| | | BeanUtils.copyProperties(taskExam, vo); |
| | | TextContent textContent = textContentService.getById(taskExam.getFrameTextContentId()); |
| | | List<ExamResponseVO> examResponseVOS = JsonUtil.toJsonListObject(textContent.getContent(), TaskItemObject.class).stream().map(tk -> { |
| | | ExamPaper examPaper = examPaperMapper.selectById(tk.getExamPaperId()); |
| | | ExamResponseVO examResponseVO = new ExamResponseVO(); |
| | | BeanUtils.copyProperties(examPaper, examResponseVO); |
| | | examResponseVO.setCreateTime(DateTimeUtil.dateFormat(examPaper.getCreateTime())); |
| | | return examResponseVO; |
| | | }).collect(Collectors.toList()); |
| | | vm.setPaperItems(examResponseVMS); |
| | | return vm; |
| | | vo.setPaperItems(examResponseVOS); |
| | | return vo; |
| | | } |
| | | |
| | | @Override |