xiangpei
2024-05-31 c9d04bc519b73f7fc4841c34e2f15fca9db7aad2
src/main/java/com/ycl/jxkg/service/impl/TaskExamServiceImpl.java
@@ -1,5 +1,6 @@
package com.ycl.jxkg.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.jxkg.domain.ExamPaper;
import com.ycl.jxkg.domain.TaskExam;
import com.ycl.jxkg.domain.TextContent;
@@ -17,6 +18,7 @@
import com.ycl.jxkg.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;
@@ -28,19 +30,12 @@
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) {
@@ -70,17 +65,17 @@
                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()
@@ -95,8 +90,8 @@
                taskItemObject.setExamPaperName(p.getName());
                return taskItemObject;
            });
            textContentService.updateByIdFilter(textContent);
            taskExamMapper.updateByPrimaryKeySelective(old);
            textContentService.updateById(textContent);
            taskExamMapper.updateById(old);
        }
        //更新试卷的taskId
@@ -107,12 +102,12 @@
    @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()));