package com.fs.course.mapper;

import java.util.List;

import com.fs.common.annotation.DataSource;
import com.fs.common.enums.DataSourceType;
import com.fs.course.domain.FsUserCourse;
import com.fs.course.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * 课程Mapper接口
 *
 * @author fs
 * @date 2024-05-15
 */
@Repository
public interface FsUserCourseMapper
{
    /**
     * 查询课程
     *
     * @param courseId 课程主键
     * @return 课程
     */
    public FsUserCourse selectFsUserCourseByCourseId(Long courseId);


    @Update("update fs_user_course set views=views+1 where course_id=#{courseId}")
    int updateViews(Long courseId);


    @DataSource(DataSourceType.SLAVE)
    @Select("select course_id ,project   from fs_user_course where is_del = 0 and is_private = 1")
    List<FsUserCourse> selectFsUserCourseAllCourse();

    @Select("select course_id,course_name,description,img_url,second_img secondImg,views from fs_user_course where " +
            " is_private = 0 and is_del = 0 and is_show = 1 and is_tui = 1  order by sort,course_id")
    List<FsUserCourseVideoAppletVO> selectFsUserCourseVideoApplet();

    @Select("select video_id,title,course_id,video_url,SEC_TO_TIME(duration) as total_duration," +
            "thumbnail videoImgUrl,description videoDescription,video_url videoUrl,question_bank_id questionBankId " +
            " from fs_user_course_video where course_id = #{courseId} and is_del = 0 order by course_sort,video_id")
    List<FsUserCourseVideoAppletVO.FsUserCourseVideo> selectFsUserCourseVideoAppletByCourseId(@Param("courseId") Long courseId);
}
