luohairen
2024-11-14 247cb86585a1d1894596ed18a6c93efecb992946
src/main/java/com/ycl/jxkg/service/impl/TaskExamServiceImpl.java
@@ -1,9 +1,10 @@
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;
@@ -12,13 +13,13 @@
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;
@@ -28,19 +29,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) {
@@ -61,7 +55,6 @@
            taskExam.setCreateUser(user.getId());
            taskExam.setCreateUserName(user.getUserName());
            taskExam.setCreateTime(now);
            taskExam.setDeleted(false);
            //保存任务结构
            TextContent textContent = textContentService.jsonConvertInsert(model.getPaperItems(), now, p -> {
@@ -70,17 +63,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 +88,8 @@
                taskItemObject.setExamPaperName(p.getName());
                return taskItemObject;
            });
            textContentService.updateByIdFilter(textContent);
            taskExamMapper.updateByPrimaryKeySelective(old);
            textContentService.updateById(textContent);
            taskExamMapper.updateById(old);
        }
        //更新试卷的taskId
@@ -107,12 +100,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()));