<?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.srs.teacher.mapper.SysTeacherTrainingMapper">
    
    <resultMap type="SysTeacherTraining" id="SysTeacherTrainingResult">
        <result property="trainingId"    column="training_id"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="name"    column="name"    />
        <result property="organization"    column="organization"    />
        <result property="site"    column="site"    />
        <result property="startTime"    column="startTime"    />
        <result property="endTime"    column="endTime"    />
        <result property="hour"    column="hour"    />
        <result property="nature"    column="nature"    />
        <result property="level"    column="level"    />
    </resultMap>

    <sql id="selectSysTeacherTrainingVo">
        select training_id, teacher_id, name, organization, site, startTime, endTime, hour, nature, level from sys_teacher_training
    </sql>

    <select id="selectSysTeacherTrainingList" parameterType="SysTeacherTraining" resultMap="SysTeacherTrainingResult">
        <include refid="selectSysTeacherTrainingVo"/>
        <where>  
            <if test="teacherId != null "> and teacher_id = #{teacherId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="organization != null  and organization != ''"> and organization = #{organization}</if>
            <if test="site != null  and site != ''"> and site = #{site}</if>
            <if test="startTime != null  and startTime != ''"> and startTime = #{startTime}</if>
            <if test="endTime != null  and endTime != ''"> and endTime = #{endTime}</if>
            <if test="hour != null  and hour != ''"> and hour = #{hour}</if>
            <if test="nature != null  and nature != ''"> and nature = #{nature}</if>
            <if test="level != null  and level != ''"> and level = #{level}</if>
        </where>
    </select>
    
    <select id="selectSysTeacherTrainingByTrainingId" parameterType="Long" resultMap="SysTeacherTrainingResult">
        <include refid="selectSysTeacherTrainingVo"/>
        where training_id = #{trainingId}
    </select>
        
    <insert id="insertSysTeacherTraining" parameterType="SysTeacherTraining">
        insert into sys_teacher_training
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="trainingId != null">training_id,</if>
            <if test="teacherId != null">teacher_id,</if>
            <if test="name != null">name,</if>
            <if test="organization != null">organization,</if>
            <if test="site != null">site,</if>
            <if test="startTime != null">startTime,</if>
            <if test="endTime != null">endTime,</if>
            <if test="hour != null">hour,</if>
            <if test="nature != null">nature,</if>
            <if test="level != null">level,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="trainingId != null">#{trainingId},</if>
            <if test="teacherId != null">#{teacherId},</if>
            <if test="name != null">#{name},</if>
            <if test="organization != null">#{organization},</if>
            <if test="site != null">#{site},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="hour != null">#{hour},</if>
            <if test="nature != null">#{nature},</if>
            <if test="level != null">#{level},</if>
         </trim>
    </insert>

    <update id="updateSysTeacherTraining" parameterType="SysTeacherTraining">
        update sys_teacher_training
        <trim prefix="SET" suffixOverrides=",">
            <if test="teacherId != null">teacher_id = #{teacherId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="organization != null">organization = #{organization},</if>
            <if test="site != null">site = #{site},</if>
            <if test="startTime != null">startTime = #{startTime},</if>
            <if test="endTime != null">endTime = #{endTime},</if>
            <if test="hour != null">hour = #{hour},</if>
            <if test="nature != null">nature = #{nature},</if>
            <if test="level != null">level = #{level},</if>
        </trim>
        where training_id = #{trainingId}
    </update>

    <delete id="deleteSysTeacherTrainingByTrainingId" parameterType="Long">
        delete from sys_teacher_training where training_id = #{trainingId}
    </delete>

    <delete id="deleteSysTeacherTrainingByTrainingIds" parameterType="String">
        delete from sys_teacher_training where training_id in 
        <foreach item="trainingId" collection="array" open="(" separator="," close=")">
            #{trainingId}
        </foreach>
    </delete>
</mapper>