package com.ruoyi.hezhi.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.hezhi.domain.TbTypeCourse;
import com.ruoyi.hezhi.mapper.TbTypeCourseMapper;
import com.ruoyi.hezhi.service.ITbTypeCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 类型课程关联Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@Service
public class TbTypeCourseServiceImpl implements ITbTypeCourseService
{
    @Autowired
    private TbTypeCourseMapper tbTypeCourseMapper;

    /**
     * 查询类型课程关联
     *
     * @param typeCourseId 类型课程关联主键
     * @return 类型课程关联
     */
    @Override
    public TbTypeCourse selectTbTypeCourseByTypeCourseId(Long typeCourseId)
    {
        return tbTypeCourseMapper.selectTbTypeCourseByTypeCourseId(typeCourseId);
    }

    /**
     * 查询类型课程关联列表
     *
     * @param tbTypeCourse 类型课程关联
     * @return 类型课程关联
     */
    @Override
    public List<TbTypeCourse> selectTbTypeCourseList(TbTypeCourse tbTypeCourse)
    {
        return tbTypeCourseMapper.selectTbTypeCourseList(tbTypeCourse);
    }

    /**
     * 新增类型课程关联
     *
     * @param tbTypeCourse 类型课程关联
     * @return 结果
     */
    @Override
    public int insertTbTypeCourse(TbTypeCourse tbTypeCourse)
    {
        tbTypeCourse.setCreateTime(DateUtils.getNowDate());
        return tbTypeCourseMapper.insertTbTypeCourse(tbTypeCourse);
    }

    /**
     * 修改类型课程关联
     *
     * @param tbTypeCourse 类型课程关联
     * @return 结果
     */
    @Override
    public int updateTbTypeCourse(TbTypeCourse tbTypeCourse)
    {
        tbTypeCourse.setUpdateTime(DateUtils.getNowDate());
        return tbTypeCourseMapper.updateTbTypeCourse(tbTypeCourse);
    }

    /**
     * 批量删除类型课程关联
     *
     * @param typeCourseIds 需要删除的类型课程关联主键
     * @return 结果
     */
    @Override
    public int deleteTbTypeCourseByTypeCourseIds(Long[] typeCourseIds)
    {
        return tbTypeCourseMapper.deleteTbTypeCourseByTypeCourseIds(typeCourseIds);
    }

    /**
     * 删除类型课程关联信息
     *
     * @param typeCourseId 类型课程关联主键
     * @return 结果
     */
    @Override
    public int deleteTbTypeCourseByTypeCourseId(Long typeCourseId)
    {
        return tbTypeCourseMapper.deleteTbTypeCourseByTypeCourseId(typeCourseId);
    }

    /**
     * 根据课程ID删除类型课程关联信息
     *
     * @param courseId 课程ID
     * @return 结果
     */
    @Override
    public int deleteTbTypeCourseByCourseId(Long courseId) {
        return tbTypeCourseMapper.deleteTbTypeCourseByCourseId(courseId);
    }

    /**
     * 批量新增类型课程关联
     *
     * @param classIds 分类组
     * @param courseId 课程ID
     * @return 结果
     */
    @Override
    public int batchInsertTbTypeCourse(Long[] classIds, Long courseId) {
        ArrayList<TbTypeCourse> arrayList = new ArrayList<>();
        for (Long classId : classIds) {
            TbTypeCourse tbTypeCourse = new TbTypeCourse();
            tbTypeCourse.setCourseId(courseId);
            tbTypeCourse.setCaseTypeId(classId);
            arrayList.add(tbTypeCourse);
        }
        return tbTypeCourseMapper.batchInsertTbTypeCourse(arrayList);
    }
}
