<?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.xinelu.manage.mapper.trainingitemdirectory.TrainingItemDirectoryMapper">

    <resultMap type="TrainingItemDirectory" id="TrainingItemDirectoryResult">
        <result property="id" column="id"/>
        <result property="trainingItemId" column="training_item_id"/>
        <result property="itemDirectoryName" column="item_directory_name"/>
        <result property="itemDirectoryCode" column="item_directory_code"/>
        <result property="itemDirectoryTitle" column="item_directory_title"/>
        <result property="itemDirectoryUrl" column="item_directory_url"/>
        <result property="itemDirectoryVideoDuration" column="item_directory_video_duration"/>
        <result property="itemDirectoryIntroduce" column="item_directory_introduce"/>
        <result property="itemDirectorySort" column="item_directory_sort"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectTrainingItemDirectoryVo">
        select id,
               training_item_id,
               item_directory_name,
               item_directory_code,
               item_directory_title,
               item_directory_url,
               item_directory_video_duration,
               item_directory_introduce,
               item_directory_sort,
               create_by,
               create_time,
               update_by,
               update_time
        from training_item_directory
    </sql>

    <select id="selectTrainingItemDirectoryList" parameterType="TrainingItemDirectory"
            resultMap="TrainingItemDirectoryResult">
        <include refid="selectTrainingItemDirectoryVo"/>
        <where>
            <if test="trainingItemId != null ">
                and training_item_id = #{trainingItemId}
            </if>
            <if test="itemDirectoryName != null  and itemDirectoryName != ''">
                and item_directory_name like concat('%', #{itemDirectoryName}, '%')
            </if>
            <if test="itemDirectoryCode != null  and itemDirectoryCode != ''">
                and item_directory_code = #{itemDirectoryCode}
            </if>
            <if test="itemDirectoryTitle != null  and itemDirectoryTitle != ''">
                and item_directory_title = #{itemDirectoryTitle}
            </if>
            <if test="itemDirectoryUrl != null  and itemDirectoryUrl != ''">
                and item_directory_url = #{itemDirectoryUrl}
            </if>
            <if test="itemDirectoryIntroduce != null  and itemDirectoryIntroduce != ''">
                and item_directory_introduce = #{itemDirectoryIntroduce}
            </if>
            <if test="itemDirectorySort != null ">
                and item_directory_sort = #{itemDirectorySort}
            </if>
        </where>
    </select>

    <select id="selectTrainingItemDirectoryById" parameterType="Long"
            resultMap="TrainingItemDirectoryResult">
        <include refid="selectTrainingItemDirectoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrainingItemDirectory" parameterType="TrainingItemDirectory" useGeneratedKeys="true"
            keyProperty="id">
        insert into training_item_directory
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="trainingItemId != null">training_item_id,
            </if>
            <if test="itemDirectoryName != null">item_directory_name,
            </if>
            <if test="itemDirectoryCode != null">item_directory_code,
            </if>
            <if test="itemDirectoryTitle != null">item_directory_title,
            </if>
            <if test="itemDirectoryUrl != null">item_directory_url,
            </if>
            <if test="itemDirectoryVideoDuration != null">item_directory_video_duration,
            </if>
            <if test="itemDirectoryIntroduce != null">item_directory_introduce,
            </if>
            <if test="itemDirectorySort != null">item_directory_sort,
            </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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="trainingItemId != null">#{trainingItemId},
            </if>
            <if test="itemDirectoryName != null">#{itemDirectoryName},
            </if>
            <if test="itemDirectoryCode != null">#{itemDirectoryCode},
            </if>
            <if test="itemDirectoryTitle != null">#{itemDirectoryTitle},
            </if>
            <if test="itemDirectoryUrl != null">#{itemDirectoryUrl},
            </if>
            <if test="itemDirectoryVideoDuration != null">#{itemDirectoryVideoDuration},
            </if>
            <if test="itemDirectoryIntroduce != null">#{itemDirectoryIntroduce},
            </if>
            <if test="itemDirectorySort != null">#{itemDirectorySort},
            </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>
        </trim>
    </insert>

    <update id="updateTrainingItemDirectory" parameterType="TrainingItemDirectory">
        update training_item_directory
        <trim prefix="SET" suffixOverrides=",">
            <if test="trainingItemId != null">training_item_id =
                #{trainingItemId},
            </if>
            <if test="itemDirectoryName != null">item_directory_name =
                #{itemDirectoryName},
            </if>
            <if test="itemDirectoryCode != null">item_directory_code =
                #{itemDirectoryCode},
            </if>
            <if test="itemDirectoryTitle != null">item_directory_title =
                #{itemDirectoryTitle},
            </if>
            <if test="itemDirectoryUrl != null">item_directory_url =
                #{itemDirectoryUrl},
            </if>
            <if test="itemDirectoryVideoDuration != null">item_directory_video_duration =
                #{itemDirectoryVideoDuration},
            </if>
            <if test="itemDirectoryIntroduce != null">item_directory_introduce =
                #{itemDirectoryIntroduce},
            </if>
            <if test="itemDirectorySort != null">item_directory_sort =
                #{itemDirectorySort},
            </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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrainingItemDirectoryById" parameterType="Long">
        delete
        from training_item_directory
        where id = #{id}
    </delete>

    <delete id="deleteTrainingItemDirectoryByIds" parameterType="String">
        delete from training_item_directory where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <insert id="insertTrainingItemDirectoryList">
        insert into training_item_directory(
        training_item_id,
        item_directory_name,
        item_directory_code,
        item_directory_title,
        item_directory_url,
        item_directory_video_duration,
        item_directory_introduce,
        item_directory_sort
        )
        VALUES
        <foreach collection="list" item="trainingItemDirectoryList" index="index" separator=",">
            (
            #{trainingItemDirectoryList.trainingItemId},
            #{trainingItemDirectoryList.itemDirectoryName},
            #{trainingItemDirectoryList.itemDirectoryCode},
            #{trainingItemDirectoryList.itemDirectoryTitle},
            #{trainingItemDirectoryList.itemDirectoryUrl},
            #{trainingItemDirectoryList.itemDirectoryVideoDuration},
            #{trainingItemDirectoryList.itemDirectoryIntroduce},
            #{trainingItemDirectoryList.itemDirectorySort}
            )
        </foreach>
    </insert>
</mapper>
