| | |
| | | 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.mapper.ExamPaperMapper; |
| | | import com.ycl.jxkg.mapper.TaskExamMapper; |
| | |
| | | import com.ycl.jxkg.service.enums.ActionEnum; |
| | | import com.ycl.jxkg.utils.DateTimeUtil; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import com.ycl.jxkg.vo.admin.exam.ExamResponseVO; |
| | | import com.ycl.jxkg.vo.admin.task.TaskPageRequestVO; |
| | | import com.ycl.jxkg.vo.admin.task.TaskRequestVO; |
| | | 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 lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class TaskExamServiceImpl extends BaseServiceImpl<TaskExam> implements TaskExamService { |
| | | @RequiredArgsConstructor |
| | | public class TaskExamServiceImpl extends ServiceImpl<TaskExamMapper,TaskExam> implements TaskExamService { |
| | | |
| | | 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(TaskPageRequestVO requestVM) { |
| | |
| | | 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 old = taskExamMapper.selectByPrimaryKey(model.getId()); |
| | | TaskExam old = taskExamMapper.selectById(model.getId()); |
| | | if (Objects.isNull(old)) { |
| | | throw new RuntimeException("数据不存在"); |
| | | } |
| | | BeanUtils.copyProperties(taskExam, old); |
| | | TextContent textContent = textContentService.selectById(taskExam.getFrameTextContentId()); |
| | | 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(old); |
| | | textContentService.updateById(textContent); |
| | | taskExamMapper.updateById(old); |
| | | } |
| | | |
| | | //更新试卷的taskId |
| | |
| | | |
| | | @Override |
| | | public TaskRequestVO taskExamToVM(Integer id) { |
| | | TaskExam taskExam = taskExamMapper.selectByPrimaryKey(id); |
| | | TaskExam taskExam = taskExamMapper.selectById(id); |
| | | TaskRequestVO vo = new TaskRequestVO(); |
| | | BeanUtils.copyProperties(taskExam, vo); |
| | | TextContent textContent = textContentService.selectById(taskExam.getFrameTextContentId()); |
| | | TextContent textContent = textContentService.getById(taskExam.getFrameTextContentId()); |
| | | List<ExamResponseVO> examResponseVOS = JsonUtil.toJsonListObject(textContent.getContent(), TaskItemObject.class).stream().map(tk -> { |
| | | ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(tk.getExamPaperId()); |
| | | ExamPaper examPaper = examPaperMapper.selectById(tk.getExamPaperId()); |
| | | ExamResponseVO examResponseVO = new ExamResponseVO(); |
| | | BeanUtils.copyProperties(examPaper, examResponseVO); |
| | | examResponseVO.setCreateTime(DateTimeUtil.dateFormat(examPaper.getCreateTime())); |