package com.fs.course.mapper;

import java.util.List;
import com.fs.course.domain.FsUserCourseStudyLog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 课程用户学习日志Mapper接口
 *
 * @author fs
 * @date 2024-05-15
 */
public interface FsUserCourseStudyLogMapper
{
    /**
     * 查询课程用户学习日志
     *
     * @param logId 课程用户学习日志主键
     * @return 课程用户学习日志
     */
    public FsUserCourseStudyLog selectFsUserCourseStudyLogByLogId(String logId);

    /**
     * 查询课程用户学习日志列表
     *
     * @param fsUserCourseStudyLog 课程用户学习日志
     * @return 课程用户学习日志集合
     */
    public List<FsUserCourseStudyLog> selectFsUserCourseStudyLogList(FsUserCourseStudyLog fsUserCourseStudyLog);

    /**
     * 新增课程用户学习日志
     *
     * @param fsUserCourseStudyLog 课程用户学习日志
     * @return 结果
     */
    public int insertFsUserCourseStudyLog(FsUserCourseStudyLog fsUserCourseStudyLog);

    /**
     * 修改课程用户学习日志
     *
     * @param fsUserCourseStudyLog 课程用户学习日志
     * @return 结果
     */
    public int updateFsUserCourseStudyLog(FsUserCourseStudyLog fsUserCourseStudyLog);

    /**
     * 删除课程用户学习日志
     *
     * @param logId 课程用户学习日志主键
     * @return 结果
     */
    public int deleteFsUserCourseStudyLogByLogId(String logId);

    /**
     * 批量删除课程用户学习日志
     *
     * @param logIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsUserCourseStudyLogByLogIds(String[] logIds);


    @Select("select * from fs_user_course_study_log where study_id = #{studyId} order by create_time desc limit 1")
    FsUserCourseStudyLog selectFsUserCourseStudyLogByStudyId(Long studyId);

    @Select("select * from fs_user_course_study_log where user_id = #{userId} and video_id = #{videoId} order by create_time desc limit 1")
    FsUserCourseStudyLog selectFsUserCourseStudyLogByUser(@Param("userId") Long userId, @Param("videoId") Long videoId);

    @Select("select * from fs_user_course_study_log where user_id = #{userId} and course_id = #{courseId} order by create_time desc limit 1")
    FsUserCourseStudyLog selectFsUserCourseStudyLogByCourse(@Param("userId") Long userId, @Param("courseId") Long courseId);

    @Select("select * from fs_user_course_study_log where user_id = #{userId} and video_id = #{videoId} ")
    FsUserCourseStudyLog selectFsUserCourseStudyLogByVideo(@Param("userId")Long userId, @Param("videoId")Long videoId);

    @Select("select count(0) from fs_user_course_study_log where user_id = #{userId} and course_id = #{courseId} and status = 1 ")
    Long selectStudyLogFinishCount(@Param("courseId") Long courseId,@Param("userId") Long userId);
}
