<?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.yanzhu.manage.mapper.BusTrainingVideoUserMapper">
    
    <resultMap type="BusTrainingVideoUser" id="BusTrainingVideoUserResult">
        <result property="id"    column="id"    />
        <result property="comId"    column="com_id"    />
        <result property="comName"    column="com_name"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectName"    column="project_name"    />
        <result property="userId"    column="user_id"    />
        <result property="userNick"    column="user_nick"    />
        <result property="userName"    column="user_name"    />
        <result property="videoId"    column="video_id"    />
        <result property="trainTitle"    column="train_title"    />
        <result property="trainType"    column="train_type"    />
        <result property="trainLevel"    column="train_level"    />
        <result property="trainFilePath"    column="train_file_path"    />
        <result property="trainFileImage"    column="train_file_image"    />
        <result property="playStatus"    column="play_status"    />
        <result property="sortBy"    column="sort_by"    />
        <result property="isDel"    column="is_del"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBusTrainingVideoUserVo">
        select btvu.id, btvu.com_id, sd.dept_name as com_name, btvu.project_id, pi.project_name, btvu.user_id, su.nick_name as user_nick, su.user_name, btvu.video_id, btv.train_title,
        btv.train_type, btv.train_level, btv.train_file_path, btv.train_file_image,
        btvu.play_status, btvu.sort_by, btvu.is_del, btvu.create_by, btvu.create_time, btvu.update_by, btvu.update_time, btvu.remark from bus_training_video_user btvu
        left join bus_training_video btv on btv.id = btvu.video_id
        left join pro_project_info pi on pi.id = btvu.project_id
        left join sys_dept sd on sd.com_id = btvu.com_id
        left join sys_user su on su.user_id = btvu.user_id
    </sql>

    <select id="selectBusTrainingVideoUserList" parameterType="BusTrainingVideoUser" resultMap="BusTrainingVideoUserResult">
        <include refid="selectBusTrainingVideoUserVo"/>
        <where>
            btvu.is_del!=2
            <if test="comId != null "> and btvu.com_id = #{comId}</if>
            <if test="projectId != null "> and btvu.project_id = #{projectId}</if>
            <if test="activeComId != null "> and btvu.com_id = #{activeComId}</if>
            <if test="activeProjectId != null "> and btvu.project_id = #{activeProjectId}</if>
            <if test="projectName != null  and projectName != ''"> and pi.project_name like concat('%', #{projectName}, '%')</if>
            <if test="userName != null  and userName != ''"> and (su.nick_name like concat('%', #{userName}, '%') or su.user_name like concat('%', #{userName}, '%') )</if>
            <if test="userId != null "> and btvu.user_id = #{userId}</if>
            <if test="isDel != null "> and btvu.is_del = #{isDel}</if>
        </where>
        order by btvu.id desc
    </select>
    
    <select id="selectBusTrainingVideoUserById" parameterType="Long" resultMap="BusTrainingVideoUserResult">
        <include refid="selectBusTrainingVideoUserVo"/>
        where btvu.id = #{id}
    </select>
        
    <insert id="insertBusTrainingVideoUser" parameterType="BusTrainingVideoUser" useGeneratedKeys="true" keyProperty="id">
        insert into bus_training_video_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="comId != null">com_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="playStatus != null">play_status,</if>
            <if test="sortBy != null">sort_by,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="comId != null">#{comId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="playStatus != null">#{playStatus},</if>
            <if test="sortBy != null">#{sortBy},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBusTrainingVideoUser" parameterType="BusTrainingVideoUser">
        update bus_training_video_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="comId != null">com_id = #{comId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="playStatus != null">play_status = #{playStatus},</if>
            <if test="sortBy != null">sort_by = #{sortBy},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteBusTrainingVideoUserById" parameterType="Long">
        update bus_training_video_user set is_del=2 where id = #{id}
    </update>

    <update id="deleteBusTrainingVideoUserByIds" parameterType="String">
        update bus_training_video_user set is_del=2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>