<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fs.course.mapper.FsUserCourseVideoMapper">

    <resultMap type="FsUserCourseVideo" id="FsUserCourseVideoResult">
        <result property="videoId"    column="video_id"    />
        <result property="fileId"    column="file_id"    />
        <result property="title"    column="title"    />
        <result property="description"    column="description"    />
        <result property="videoUrl"    column="video_url"    />
        <result property="thumbnail"    column="thumbnail"    />
        <result property="duration"    column="duration"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="talentId"    column="talent_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="status"    column="status"    />
        <result property="courseSort"    column="course_sort"    />
        <result property="fileName"    column="file_name"    />
        <result property="isDel"    column="is_del"    />
        <result property="questionBankId"    column="question_bank_id"    />
        <result property="lineOne"    column="line_one"    />
        <result property="lineTwo"    column="line_two"    />
        <result property="lineThree"    column="line_three"    />
        <result property="uploadType"    column="upload_type"    />
        <result property="redPacketMoney"    column="red_packet_money"    />
        <result property="fileSize"    column="file_size"    />
        <result property="fileKey"    column="file_key"    />
        <result property="round"    column="round"    />
        <result property="packageJson"    column="package_json"    />
        <result property="isTranscode"    column="is_transcode"    />
        <result property="transcodeFileKey"    column="transcode_file_key"    />
    </resultMap>

    <sql id="selectFsUserCourseVideoVo">
        select video_id,line_one,package_json,is_transcode,transcode_file_key,file_size,file_key,round,red_packet_money,line_two,upload_type,line_three, file_id,file_name,is_del, title, description, video_url, thumbnail, duration, update_time, create_time, talent_id, course_id, status, course_sort, question_bank_id from fs_user_course_video
    </sql>

    <select id="selectFsUserCourseVideoList" parameterType="FsUserCourseVideo" resultMap="FsUserCourseVideoResult">
        <include refid="selectFsUserCourseVideoVo"/>
        <where>
            <if test="fileId != null  and fileId != ''"> and file_id = #{fileId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="videoUrl != null  and videoUrl != ''"> and video_url = #{videoUrl}</if>
            <if test="thumbnail != null  and thumbnail != ''"> and thumbnail = #{thumbnail}</if>
            <if test="duration != null "> and duration = #{duration}</if>
            <if test="talentId != null "> and talent_id = #{talentId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="courseSort != null "> and course_sort = #{courseSort}</if>
            <if test="questionBankId != null "> and question_bank_id = #{questionBankId}</if>
        </where>
    </select>

    <select id="selectFsUserCourseVideoByVideoId" parameterType="Long" resultMap="FsUserCourseVideoResult">
        <include refid="selectFsUserCourseVideoVo"/>
        where video_id = #{videoId}
    </select>

    <insert id="insertFsUserCourseVideo" parameterType="FsUserCourseVideo" useGeneratedKeys="true" keyProperty="videoId">
        insert into fs_user_course_video
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileId != null">file_id,</if>
            <if test="title != null">title,</if>
            <if test="description != null">description,</if>
            <if test="videoUrl != null">video_url,</if>
            <if test="thumbnail != null">thumbnail,</if>
            <if test="duration != null">duration,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="talentId != null">talent_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="status != null">status,</if>
            <if test="courseSort != null">course_sort,</if>
            <if test="fileName != null">file_name,</if>
            <if test="isDel != null">is_del,</if>
            <if test="questionBankId != null">question_bank_id,</if>
            <if test="lineOne != null">line_one,</if>
            <if test="lineTwo != null">line_two,</if>
            <if test="lineThree != null">line_three,</if>
            <if test="uploadType != null">upload_type,</if>
            <if test="redPacketMoney != null">red_packet_money,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="fileKey != null">file_key,</if>
            <if test="round != null">round,</if>
            <if test="packageJson != null">package_json,</if>
            <if test="isTranscode != null">is_transcode,</if>
            <if test="transcodeFileKey != null">transcode_file_key,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileId != null">#{fileId},</if>
            <if test="title != null">#{title},</if>
            <if test="description != null">#{description},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
            <if test="thumbnail != null">#{thumbnail},</if>
            <if test="duration != null">#{duration},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="talentId != null">#{talentId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="status != null">#{status},</if>
            <if test="courseSort != null">#{courseSort},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="questionBankId != null">#{questionBankId},</if>
            <if test="lineOne != null">#{lineOne},</if>
            <if test="lineTwo != null">#{lineTwo},</if>
            <if test="lineThree != null">#{lineThree},</if>
            <if test="uploadType != null">#{uploadType},</if>
            <if test="redPacketMoney != null">#{redPacketMoney},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="fileKey != null">#{fileKey},</if>
            <if test="round != null">#{round},</if>
            <if test="packageJson != null">#{packageJson},</if>
            <if test="isTranscode != null">#{isTranscode},</if>
            <if test="transcodeFileKey != null">#{transcodeFileKey},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseVideo" parameterType="FsUserCourseVideo">
        update fs_user_course_video
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileId != null">file_id = #{fileId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="description != null">description = #{description},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if>
            <if test="thumbnail != null">thumbnail = #{thumbnail},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="talentId != null">talent_id = #{talentId},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="courseSort != null">course_sort = #{courseSort},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="questionBankId != null">question_bank_id = #{questionBankId},</if>
            <if test="lineOne != null">line_one = #{lineOne},</if>
            <if test="lineTwo != null">line_two = #{lineTwo},</if>
            <if test="lineThree != null">line_three = #{lineThree},</if>
            <if test="uploadType != null">upload_type = #{uploadType},</if>
            <if test="redPacketMoney != null">red_packet_money = #{redPacketMoney},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="fileKey != null">file_key = #{fileKey},</if>
            <if test="round != null">round = #{round},</if>
            <if test="packageJson != null">package_json = #{packageJson},</if>
            <if test="isTranscode != null">is_transcode = #{isTranscode},</if>
            <if test="transcodeFileKey != null">transcode_file_key = #{transcodeFileKey},</if>
        </trim>
        where video_id = #{videoId}
    </update>

    <update id="deleteFsUserCourseVideoByVideoId" parameterType="String">
        update fs_user_course_video set is_del = 1 where video_id = #{videoId}
    </update>

    <update id="deleteFsUserCourseVideoByVideoIds" parameterType="String">
        update fs_user_course_video set is_del = 1 where video_id in
        <foreach item="videoId" collection="array" open="(" separator="," close=")">
            #{videoId}
        </foreach>
    </update>

    <select id="selectFsUserCourseVideoPageList" resultType="FsUserCourseVideoPageListVO">
        SELECT
        DISTINCT video.video_id,
            video.title,
            video.description,
            video.video_url,
            video.thumbnail,
            video.duration,
            video.create_time,
            video.course_id,
            video.STATUS,
            video.course_sort,
        course.course_name
        FROM `fs_user_course_video` video
        left join fs_user_course_period_days fcpd on fcpd.video_id = video.video_id
        left join fs_user_course_period fcp on fcp.period_id = fcpd.period_id
        LEFT JOIN fs_user_course course ON video.course_id = course.course_id
        where course.is_del = 0
        AND FIND_IN_SET(#{companyId}, fcp.company_id)
        <if test="periodId != null and periodId !='' ">
            AND fcpd.period_id = #{periodId}
        </if>
        <if test="keyword != null and keyword !='' ">
            AND video.title LIKE concat('%',#{keyword},'%')
        </if>
        order by video.course_sort
    </select>

</mapper>
