<?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.project.training.mapper.TTrainingNonMapper">
    
    <resultMap type="TTrainingNon" id="TTrainingNonResult">
        <result property="id"    column="id"    />
        <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="remarks"    column="remarks"    />
        <result property="trainingDate"    column="training_date"    />
        <result property="staffId"    column="staff_id"    />
        <result property="trainingId"    column="training_id"    />
        <result property="trainingStaff"    column="training_staff"    />
        <result property="isNew"    column="is_new"    />
        <result property="name"    column="name"    />
        <result property="staffName"    column="staffName"    />
    </resultMap>

    <sql id="selectTTrainingNonVo">
        select d.id, d.del_flag, t.name, m.name as staffName, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.training_date, d.staff_id, d.training_id, d.training_staff, d.is_new from t_training_non d
        left join t_staffmgr t on t.staffid = d.staff_id
        left join t_staffmgr m on m.staffid = d.training_staff
    </sql>

    <select id="selectTTrainingNonList" parameterType="TTrainingNon" resultMap="TTrainingNonResult">
        <include refid="selectTTrainingNonVo"/>
        <where>
            <if test="staffId != null  and staffId != ''"> and staff_id = #{staffId}</if>
            <if test="trainingId != null "> and training_id = #{trainingId}</if>
            <if test="isNew != null  and isNew != ''"> and is_new = #{isNew}</if>
            and d.del_flag = 0
        </where>
    </select>
    
    <select id="selectTTrainingNonById" parameterType="Long" resultMap="TTrainingNonResult">
        select *  from t_training_non
        where id = #{id}
    </select>
        
    <insert id="insertTTrainingNon" parameterType="TTrainingNon">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_training_non.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_training_non
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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="remarks != null">remarks,</if>
            <if test="trainingDate != null">training_date,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="trainingId != null">training_id,</if>
            <if test="trainingStaff != null">training_staff,</if>
            <if test="isNew != null">is_new,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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="remarks != null">#{remarks},</if>
            <if test="trainingDate != null">#{trainingDate},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="trainingId != null">#{trainingId},</if>
            <if test="trainingStaff != null">#{trainingStaff},</if>
            <if test="isNew != null">#{isNew},</if>
         </trim>
    </insert>

    <update id="updateTTrainingNon" parameterType="TTrainingNon">
        update t_training_non
        <trim prefix="SET" suffixOverrides=",">
            <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="remarks != null">remarks = #{remarks},</if>
            <if test="trainingDate != null">training_date = #{trainingDate},</if>
            <if test="trainingDate == null">training_date = NULL,</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="staffId == null">staff_id = NULL,</if>
            <if test="trainingId != null">training_id = #{trainingId},</if>
            <if test="trainingStaff != null">training_staff = #{trainingStaff},</if>
            <if test="isNew != null">is_new = #{isNew},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTTrainingNonById" parameterType="Long">
        update t_training_non set del_flag = 2 where id = #{id}
    </update>

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