<?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.bccnew.mapper.TTsTrainerMapper">
    
    <resultMap type="TTsTrainer" id="TTsTrainerResult">
        <result property="trainerId"    column="trainer_id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="trainerName"    column="trainer_name"    />
        <result property="team"    column="team"    />
        <result property="post"    column="post"    />
        <result property="experience"    column="experience"    />
        <result property="apprenticePosition"    column="apprentice_position"    />
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTsTrainerVo">
        select d.trainer_id, d.staff_id, d.trainer_name, d.team, d.post, d.experience, d.apprentice_position, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_ts_trainer d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTsTrainerList" parameterType="TTsTrainer" resultMap="TTsTrainerResult">
        <include refid="selectTTsTrainerVo"/>
        <where>  
            <if test="staffId != null "> and staff_id = #{staffId}</if>
            <if test="trainerName != null  and trainerName != ''"> and trainer_name like concat(concat('%', #{trainerName}), '%')</if>
            <if test="team != null  and team != ''"> and team = #{team}</if>
            <if test="post != null  and post != ''"> and post = #{post}</if>
            <if test="experience != null  and experience != ''"> and experience = #{experience}</if>
            <if test="apprenticePosition != null  and apprenticePosition != ''"> and apprentice_position = #{apprenticePosition}</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 d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTTsTrainerById" parameterType="Long" resultMap="TTsTrainerResult">
        <include refid="selectTTsTrainerVo"/>
        where trainer_id = #{trainerId}
    </select>
        
    <insert id="insertTTsTrainer" parameterType="TTsTrainer">
        <selectKey keyProperty="trainerId" resultType="long" order="BEFORE">
            SELECT seq_t_ts_trainer.NEXTVAL as trainerId FROM DUAL
        </selectKey>
        insert into t_ts_trainer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="trainerId != null">trainer_id,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="trainerName != null">trainer_name,</if>
            <if test="team != null">team,</if>
            <if test="post != null">post,</if>
            <if test="experience != null">experience,</if>
            <if test="apprenticePosition != null">apprentice_position,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="trainerId != null">#{trainerId},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="trainerName != null">#{trainerName},</if>
            <if test="team != null">#{team},</if>
            <if test="post != null">#{post},</if>
            <if test="experience != null">#{experience},</if>
            <if test="apprenticePosition != null">#{apprenticePosition},</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>
         </trim>
    </insert>

    <update id="updateTTsTrainer" parameterType="TTsTrainer">
        update t_ts_trainer
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="trainerName != null">trainer_name = #{trainerName},</if>
            <if test="team != null">team = #{team},</if>
            <if test="post != null">post = #{post},</if>
            <if test="experience != null">experience = #{experience},</if>
            <if test="apprenticePosition != null">apprentice_position = #{apprenticePosition},</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>
        </trim>
        where trainer_id = #{trainerId}
    </update>

    <update id="deleteTTsTrainerById" parameterType="Long">
        update t_ts_trainer set del_flag = 2 where trainer_id = #{trainerId}
    </update>

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