package com.ruoyi.project.training.elearn.service.impl;

import java.util.List;

import com.ruoyi.project.training.elearn.domain.TElExamRepo;
import com.ruoyi.project.training.elearn.mapper.TElExamRepoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.training.elearn.mapper.TElExamMapper;
import com.ruoyi.project.training.elearn.domain.TElExam;
import com.ruoyi.project.training.elearn.service.ITElExamService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 考试Service业务层处理
 *
 * @author ssy
 * @date 2024-05-29
 */
@Service
public class TElExamServiceImpl implements ITElExamService
{
    @Resource
    private TElExamMapper tElExamMapper;
    @Resource
    private TElExamRepoMapper tElExamRepoMapper;
    /**
     * 查询考试
     *
     * @param examId 考试ID
     * @return 考试
     */
    @Override
    public TElExam selectTElExamById(Long examId)
    {
        TElExam tElExam = tElExamMapper.selectTElExamById(examId);
        TElExamRepo quey = new TElExamRepo();
        quey.setExamId(examId);
        List<TElExamRepo> list = tElExamRepoMapper.selectTElExamRepoList(quey);
        tElExam.setRepoList(list);
        return tElExam;
    }

    /**
     * 查询考试列表
     *
     * @param tElExam 考试
     * @return 考试
     */
    @Override
    public List<TElExam> selectTElExamList(TElExam tElExam)
    {
        return tElExamMapper.selectTElExamList(tElExam);
    }

    /**
     * 新增考试
     *
     * @param tElExam 考试
     * @return 结果
     */
    @Override
    @Transactional
    public int insertTElExam(TElExam tElExam)
    {
        tElExamMapper.insertTElExam(tElExam);
        List<TElExamRepo> list = tElExam.getRepoList();
        for (TElExamRepo t: list
             ) {
            t.setExamId(tElExam.getExamId());
            tElExamRepoMapper.insertTElExamRepo(t);
        }
        return 1;
    }

    /**
     * 修改考试
     *
     * @param tElExam 考试
     * @return 结果
     */
    @Override
    @Transactional
    public int updateTElExam(TElExam tElExam)
    {
        tElExamMapper.updateTElExam(tElExam);
        //删除库

        tElExamRepoMapper.deleteTElExamRepoByExamId(tElExam.getExamId());

        List<TElExamRepo> list = tElExam.getRepoList();
        for (TElExamRepo t: list
        ) {
            t.setExamId(tElExam.getExamId());
            tElExamRepoMapper.insertTElExamRepo(t);
        }

        return 1;
    }

    /**
     * 批量删除考试
     *
     * @param examIds 需要删除的考试ID
     * @return 结果
     */
    @Override
    public int deleteTElExamByIds(Long[] examIds)
    {
        return tElExamMapper.deleteTElExamByIds(examIds);
    }

    /**
     * 删除考试信息
     *
     * @param examId 考试ID
     * @return 结果
     */
    @Override
    public int deleteTElExamById(Long examId)
    {
        return tElExamMapper.deleteTElExamById(examId);
    }
}
