<?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.cpms.project.training.mapper.TTrainRosterMapper">

    <resultMap type="TTrainRoster" id="TTrainRosterResult">
        <result property="id"    column="id"    />
        <result property="topic"    column="topic"    />
        <result property="material"    column="material"    />
        <result property="trainer"    column="trainer"    />
        <result property="participants"    column="participants"    />
        <result property="trainStartDate"    column="train_start_date"    />
        <result property="trainEndDate"    column="train_end_date"    />
        <result property="trainDuration"    column="train_duration"    />
        <result property="teams"    column="teams"    />
        <result property="content"    column="content"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="nameList"    column="name_list"    />
        <result property="exportType"    column="export_type"    />
    </resultMap>

    <sql id="selectTTrainRosterVo">
        select id,name_list,export_type, topic, material, trainer, participants, train_start_date,train_end_date,train_duration, teams, content, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_train_roster
    </sql>

    <select id="selectTTrainRosterList" parameterType="TTrainRoster" resultMap="TTrainRosterResult">
        <include refid="selectTTrainRosterVo"/>
        <where>
            <if test="topic != null  and topic != ''"> and topic = #{topic}</if>
            <if test="material != null  and material != ''"> and material = #{material}</if>
            <if test="trainer != null  and trainer != ''"> and trainer = #{trainer}</if>
            <if test="participants != null  and participants != ''"> and participants = #{participants}</if>
            <if test="teams != null  and teams != ''"> and teams = #{teams}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        and del_flag = 0
        </where>
    </select>

    <select id="selectTTrainRosterById" parameterType="Long" resultMap="TTrainRosterResult">
        <include refid="selectTTrainRosterVo"/>
        where id = #{id}
    </select>

    <insert id="insertTTrainRoster" parameterType="TTrainRoster" useGeneratedKeys="true" keyProperty="id">
        insert into t_train_roster
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="topic != null and topic != ''">topic,</if>
            <if test="material != null and material != ''">material,</if>
            <if test="trainer != null and trainer != ''">trainer,</if>
            <if test="participants != null and participants != ''">participants,</if>
            <if test="trainEndDate != null">train_end_date,</if>
            <if test="trainStartDate != null">train_start_date,</if>
            <if test="trainDuration != null">train_duration,</if>
            <if test="teams != null and teams != ''">teams,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="nameList != null">name_list,</if>
            <if test="exportType != null">export_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="topic != null and topic != ''">#{topic},</if>
            <if test="material != null and material != ''">#{material},</if>
            <if test="trainer != null and trainer != ''">#{trainer},</if>
            <if test="participants != null and participants != ''">#{participants},</if>
            <if test="trainEndDate != null">#{trainEndDate},</if>
            <if test="trainStartDate != null">#{trainStartDate},</if>
            <if test="trainDuration != null">#{trainDuration},</if>
            <if test="teams != null and teams != ''">#{teams},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="nameList != null">#{nameList},</if>
            <if test="exportType != null">#{exportType},</if>
         </trim>
    </insert>

    <update id="updateTTrainRoster" parameterType="TTrainRoster">
        update t_train_roster
        <trim prefix="SET" suffixOverrides=",">
            <if test="topic != null and topic != ''">topic = #{topic},</if>
            <if test="material != null and material != ''">material = #{material},</if>
            <if test="trainer != null and trainer != ''">trainer = #{trainer},</if>
            <if test="participants != null and participants != ''">participants = #{participants},</if>
            <if test="trainEndDate != null">train_end_date=#{trainEndDate},</if>
            <if test="trainStartDate != null">train_start_date=#{trainStartDate},</if>
            <if test="trainDuration != null">train_duration=#{trainDuration},</if>
            <if test="teams != null and teams != ''">teams = #{teams},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="nameList != null">name_list = #{nameList},</if>
            <if test="exportType != null">export_type = #{exportType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTTrainRosterById" parameterType="Long">
        update t_train_roster set del_flag=1 where id = #{id}
    </delete>

    <delete id="deleteTTrainRosterByIds" parameterType="String">
        update t_train_roster set del_flag=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
