<?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.ruoyi.system.mapper.TdTrainMapper">
    
    <resultMap type="TdTrain" id="TdTrainResult">
        <result property="ID"    column="ID"    />
        <result property="USERNAME"    column="USERNAME"    />
        <result property="deptName"    column="DEPT_NAME"    />
        <result property="trainType"    column="TRAIN_TYPE"    />
        <result property="trainSubject"    column="TRAIN_SUBJECT"    />
        <result property="trainAddress"    column="TRAIN_ADDRESS"    />
        <result property="trainDate"    column="TRAIN_DATE"    />
        <result property="createStaffid"    column="CREATE_STAFFID"    />
        <result property="createDepartid"    column="CREATE_DEPARTID"    />
        <result property="createDate"    column="CREATE_DATE"    />
        <result property="updateDepartid"    column="UPDATE_DEPARTID"    />
        <result property="updateStaffid"    column="UPDATE_STAFFID"    />
        <result property="updateDate"    column="UPDATE_DATE"    />
        <result property="AREAID"    column="AREAID"    />
        <result property="FRAMEWORK"    column="FRAMEWORK"    />
        <result property="trainName"    column="TRAIN_NAME"    />
        <result property="trainState"    column="TRAIN_STATE"    />
        <result property="trainTimeend"    column="TRAIN_TIMEEND"    />
        <result property="PART"    column="PART"    />
        <result property="TRAININFO"    column="TRAININFO"    />
    </resultMap>

    <sql id="selectTdTrainVo">
        select ID, USERNAME, DEPT_NAME, TRAIN_TYPE, TRAIN_SUBJECT, TRAIN_ADDRESS, TRAIN_DATE, CREATE_STAFFID, CREATE_DEPARTID, CREATE_DATE, UPDATE_DEPARTID, UPDATE_STAFFID, UPDATE_DATE, AREAID, FRAMEWORK, TRAIN_NAME, TRAIN_STATE, TRAIN_TIMEEND, PART, TRAININFO from td_train
    </sql>

    <select id="selectTdTrainList" parameterType="TdTrain" resultMap="TdTrainResult">
        <include refid="selectTdTrainVo"/>
        <where>  
            <if test="USERNAME != null  and USERNAME != ''"> and USERNAME like concat('%', #{USERNAME}, '%')</if>
            <if test="deptName != null  and deptName != ''"> and DEPT_NAME like concat('%', #{deptName}, '%')</if>
            <if test="trainType != null  and trainType != ''"> and TRAIN_TYPE = #{trainType}</if>
            <if test="trainSubject != null  and trainSubject != ''"> and TRAIN_SUBJECT = #{trainSubject}</if>
            <if test="trainAddress != null  and trainAddress != ''"> and TRAIN_ADDRESS = #{trainAddress}</if>
            <if test="trainDate != null "> and TRAIN_DATE = #{trainDate}</if>
            <if test="createStaffid != null  and createStaffid != ''"> and CREATE_STAFFID = #{createStaffid}</if>
            <if test="createDepartid != null  and createDepartid != ''"> and CREATE_DEPARTID = #{createDepartid}</if>
            <if test="createDate != null "> and CREATE_DATE = #{createDate}</if>
            <if test="updateDepartid != null  and updateDepartid != ''"> and UPDATE_DEPARTID = #{updateDepartid}</if>
            <if test="updateStaffid != null  and updateStaffid != ''"> and UPDATE_STAFFID = #{updateStaffid}</if>
            <if test="updateDate != null "> and UPDATE_DATE = #{updateDate}</if>
            <if test="AREAID != null  and AREAID != ''"> and AREAID = #{AREAID}</if>
            <if test="FRAMEWORK != null  and FRAMEWORK != ''"> and FRAMEWORK = #{FRAMEWORK}</if>
            <if test="trainName != null  and trainName != ''"> and TRAIN_NAME like concat('%', #{trainName}, '%')</if>
            <if test="trainState != null "> and TRAIN_STATE = #{trainState}</if>
            <if test="trainTimeend != null "> and TRAIN_TIMEEND = #{trainTimeend}</if>
            <if test="PART != null  and PART != ''"> and PART = #{PART}</if>
            <if test="TRAININFO != null  and TRAININFO != ''"> and TRAININFO = #{TRAININFO}</if>
        </where>
        order by CREATE_DATE desc
    </select>
    
    <select id="selectTdTrainByID" parameterType="Long" resultMap="TdTrainResult">
        <include refid="selectTdTrainVo"/>
        where ID = #{ID}
    </select>
        
    <insert id="insertTdTrain" parameterType="TdTrain" useGeneratedKeys="true" keyProperty="ID">
        insert into td_train
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="USERNAME != null">USERNAME,</if>
            <if test="deptName != null">DEPT_NAME,</if>
            <if test="trainType != null">TRAIN_TYPE,</if>
            <if test="trainSubject != null">TRAIN_SUBJECT,</if>
            <if test="trainAddress != null">TRAIN_ADDRESS,</if>
            <if test="trainDate != null">TRAIN_DATE,</if>
            <if test="createStaffid != null">CREATE_STAFFID,</if>
            <if test="createDepartid != null">CREATE_DEPARTID,</if>
            <if test="createDate != null">CREATE_DATE,</if>
            <if test="updateDepartid != null">UPDATE_DEPARTID,</if>
            <if test="updateStaffid != null">UPDATE_STAFFID,</if>
            <if test="updateDate != null">UPDATE_DATE,</if>
            <if test="AREAID != null and AREAID != ''">AREAID,</if>
            <if test="FRAMEWORK != null">FRAMEWORK,</if>
            <if test="trainName != null">TRAIN_NAME,</if>
            <if test="trainState != null">TRAIN_STATE,</if>
            <if test="trainTimeend != null">TRAIN_TIMEEND,</if>
            <if test="PART != null">PART,</if>
            <if test="TRAININFO != null">TRAININFO,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="USERNAME != null">#{USERNAME},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="trainType != null">#{trainType},</if>
            <if test="trainSubject != null">#{trainSubject},</if>
            <if test="trainAddress != null">#{trainAddress},</if>
            <if test="trainDate != null">#{trainDate},</if>
            <if test="createStaffid != null">#{createStaffid},</if>
            <if test="createDepartid != null">#{createDepartid},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateDepartid != null">#{updateDepartid},</if>
            <if test="updateStaffid != null">#{updateStaffid},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="AREAID != null and AREAID != ''">#{AREAID},</if>
            <if test="FRAMEWORK != null">#{FRAMEWORK},</if>
            <if test="trainName != null">#{trainName},</if>
            <if test="trainState != null">#{trainState},</if>
            <if test="trainTimeend != null">#{trainTimeend},</if>
            <if test="PART != null">#{PART},</if>
            <if test="TRAININFO != null">#{TRAININFO},</if>
         </trim>
    </insert>

    <update id="updateTdTrain" parameterType="TdTrain">
        update td_train
        <trim prefix="SET" suffixOverrides=",">
            <if test="USERNAME != null">USERNAME = #{USERNAME},</if>
            <if test="deptName != null">DEPT_NAME = #{deptName},</if>
            <if test="trainType != null">TRAIN_TYPE = #{trainType},</if>
            <if test="trainSubject != null">TRAIN_SUBJECT = #{trainSubject},</if>
            <if test="trainAddress != null">TRAIN_ADDRESS = #{trainAddress},</if>
            <if test="trainDate != null">TRAIN_DATE = #{trainDate},</if>
            <if test="createStaffid != null">CREATE_STAFFID = #{createStaffid},</if>
            <if test="createDepartid != null">CREATE_DEPARTID = #{createDepartid},</if>
            <if test="createDate != null">CREATE_DATE = #{createDate},</if>
            <if test="updateDepartid != null">UPDATE_DEPARTID = #{updateDepartid},</if>
            <if test="updateStaffid != null">UPDATE_STAFFID = #{updateStaffid},</if>
            <if test="updateDate != null">UPDATE_DATE = #{updateDate},</if>
            <if test="AREAID != null and AREAID != ''">AREAID = #{AREAID},</if>
            <if test="FRAMEWORK != null">FRAMEWORK = #{FRAMEWORK},</if>
            <if test="trainName != null">TRAIN_NAME = #{trainName},</if>
            <if test="trainState != null">TRAIN_STATE = #{trainState},</if>
            <if test="trainTimeend != null">TRAIN_TIMEEND = #{trainTimeend},</if>
            <if test="PART != null">PART = #{PART},</if>
            <if test="TRAININFO != null">TRAININFO = #{TRAININFO},</if>
        </trim>
        where ID = #{ID}
    </update>

    <delete id="deleteTdTrainByID" parameterType="Long">
        delete from td_train where ID = #{ID}
    </delete>

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

</mapper>