<?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.newstaff.mapper.TTnNewMapper">

    <resultMap type="TTnNew" id="TTnNewResult">
        <result property="newId"    column="new_id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="name"    column="name"    />
        <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="planStatus"    column="plan_status"    />
        <result property="planYear"    column="plan_year"    />
        <result property="startdate"    column="startdate"    />
        <result property="enddate"    column="enddate"    />
        <result property="mentorStaffId"    column="mentor_staff_id"    />
        <result property="planType"    column="plan_type"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
        <result property="staffName"    column="staffName"    />
        <result property="mentorStaffName"    column="mentorStaffName"    />
    </resultMap>

    <sql id="selectTTnNewVo">
        select d.new_id, d.staff_id,u.name as staffName,u2.name as mentorStaffName, d.name, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.plan_status, d.plan_year, d.startdate, d.enddate, d.mentor_staff_id, d.plan_type, d.remarks ,s.dept_name from t_tn_new d
      left join sys_dept s on s.dept_id = d.dept_id
      left join t_staffmgr u on d.staff_id = u.staffid and u.del_flag = 0
      left join t_staffmgr u2 on d.mentor_staff_id = u2.staffid and u2.del_flag = 0
    </sql>

    <select id="selectTTnNewList" parameterType="TTnNew" resultMap="TTnNewResult">
        <include refid="selectTTnNewVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="planStatus != null "> and plan_status = #{planStatus}</if>
            <if test="startdate != null "> and startdate = #{startdate}</if>
            <if test="enddate != null "> and enddate = #{enddate}</if>
            <if test="planType != null "> and plan_type = #{planType}</if>
            <if test="planYear != null "> and TO_CHAR(startdate,'yyyy') = #{planYear}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTTnNewById" parameterType="Long" resultMap="TTnNewResult">
        <include refid="selectTTnNewVo"/>
        where new_id = #{newId}
    </select>

    <insert id="insertTTnNew" parameterType="TTnNew">
        <selectKey keyProperty="newId" resultType="long" order="BEFORE">
            SELECT seq_t_tn_new.NEXTVAL as newId FROM DUAL
        </selectKey>
        insert into t_tn_new
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="newId != null">new_id,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="name != null">name,</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="planStatus != null">plan_status,</if>
            <if test="planYear != null">plan_year,</if>
            <if test="startdate != null">startdate,</if>
            <if test="enddate != null">enddate,</if>
            <if test="mentorStaffId != null">mentor_staff_id,</if>
            <if test="planType != null">plan_type,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="newId != null">#{newId},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="name != null">#{name},</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="planStatus != null">#{planStatus},</if>
            <if test="planYear != null">#{planYear},</if>
            <if test="startdate != null">#{startdate},</if>
            <if test="enddate != null">#{enddate},</if>
            <if test="mentorStaffId != null">#{mentorStaffId},</if>
            <if test="planType != null">#{planType},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTTnNew" parameterType="TTnNew">
        update t_tn_new
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="name != null">name = #{name},</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="planStatus != null">plan_status = #{planStatus},</if>
            <if test="planYear != null">plan_year = #{planYear},</if>
            <if test="startdate != null">startdate = #{startdate},</if>
            <if test="enddate != null">enddate = #{enddate},</if>
            <if test="mentorStaffId != null">mentor_staff_id = #{mentorStaffId},</if>
            <if test="planType != null">plan_type = #{planType},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where new_id = #{newId}
    </update>

    <update id="deleteTTnNewById" parameterType="Long">
        update t_tn_new set del_flag = 2 where new_id = #{newId}
    </update>

    <update id="deleteTTnNewByIds" parameterType="String">
        update t_tn_new set del_flag = 2 where new_id in
        <foreach item="newId" collection="array" open="(" separator="," close=")">
            #{newId}
        </foreach>
    </update>

</mapper>
