<?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.TTnFirstplanMapper">

    <resultMap type="TTnFirstplan" id="TTnFirstplanResult">
        <result property="id"    column="id"    />
        <result property="newId"    column="new_id"    />
        <result property="courseCode"    column="course_code"    />
        <result property="topic"    column="topic"    />
        <result property="content"    column="content"    />
        <result property="courseDay"    column="course_day"    />
        <result property="courseHour"    column="course_hour"    />
        <result property="courseType"    column="course_type"    />
        <result property="trainer"    column="trainer"    />
        <result property="courseDate"    column="course_date"    />
        <result property="assess"    column="assess"    />
        <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" />
        <result property="planStatus"    column="plan_status"    />

    </resultMap>

    <sql id="selectTTnFirstplanVo">
        select d.id, d.new_id,d.plan_status, d.course_code, d.topic, d.content, d.course_day, d.course_hour, d.course_type, d.trainer, d.course_date, d.assess, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_tn_firstplan d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTnFirstplanList" parameterType="TTnFirstplan" resultMap="TTnFirstplanResult">
        <include refid="selectTTnFirstplanVo"/>
        <where>
            <if test="newId != null "> and new_id = #{newId}</if>
            <if test="courseCode != null  and courseCode != ''"> and course_code = #{courseCode}</if>
            <if test="topic != null  and topic != ''"> and topic = #{topic}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="courseDay != null "> and course_day = #{courseDay}</if>
            <if test="courseHour != null "> and course_hour = #{courseHour}</if>
            <if test="courseType != null  and courseType != ''"> and course_type = #{courseType}</if>
            <if test="trainer != null  and trainer != ''"> and trainer = #{trainer}</if>
            <if test="courseDate != null "> and course_date = #{courseDate}</if>
            <if test="planStatus != null "> and plan_status = #{planStatus}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.course_day
    </select>

    <select id="selectTTnFirstplanListByNewId" parameterType="TTnFirstplan" resultMap="TTnFirstplanResult">
        <include refid="selectTTnFirstplanVo"/>
        <where>
            <if test="newId != null "> and new_id = #{newId}</if>
            <if test="courseCode != null  and courseCode != ''"> and course_code = #{courseCode}</if>
            <if test="topic != null  and topic != ''"> and topic = #{topic}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="courseDay != null "> and course_day = #{courseDay}</if>
            <if test="courseHour != null "> and course_hour = #{courseHour}</if>
            <if test="courseType != null  and courseType != ''"> and course_type = #{courseType}</if>
            <if test="trainer != null  and trainer != ''"> and trainer = #{trainer}</if>
            <if test="courseDate != null "> and course_date = #{courseDate}</if>
            <if test="planStatus != null "> and plan_status = #{planStatus}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
    </select>

    <select id="selectTTnFirstplanById" parameterType="Long" resultMap="TTnFirstplanResult">
        <include refid="selectTTnFirstplanVo"/>
        where id = #{id}
    </select>

    <insert id="insertTTnFirstplan" parameterType="TTnFirstplan">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_tn_firstplan.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_tn_firstplan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="newId != null">new_id,</if>
            <if test="courseCode != null">course_code,</if>
            <if test="topic != null">topic,</if>
            <if test="content != null">content,</if>
            <if test="courseDay != null">course_day,</if>
            <if test="courseHour != null">course_hour,</if>
            <if test="courseType != null">course_type,</if>
            <if test="trainer != null">trainer,</if>
            <if test="courseDate != null">course_date,</if>
            <if test="assess != null">assess,</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="id != null">#{id},</if>
            <if test="newId != null">#{newId},</if>
            <if test="courseCode != null">#{courseCode},</if>
            <if test="topic != null">#{topic},</if>
            <if test="content != null">#{content},</if>
            <if test="courseDay != null">#{courseDay},</if>
            <if test="courseHour != null">#{courseHour},</if>
            <if test="courseType != null">#{courseType},</if>
            <if test="trainer != null">#{trainer},</if>
            <if test="courseDate != null">#{courseDate},</if>
            <if test="assess != null">#{assess},</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>

    <insert id="insertTTnFirstplanTmpl" parameterType="TTnFirstplanTmpl">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_tn_firstplan.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_tn_firstplan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="newId != null">new_id,</if>
            <if test="courseCode != null">course_code,</if>
            <if test="topic != null">topic,</if>
            <if test="content != null">content,</if>
            <if test="courseDay != null">course_day,</if>
            <if test="courseHour != null">course_hour,</if>
            <if test="courseType != null">course_type,</if>
            <if test="trainer != null">trainer,</if>
            <if test="courseDate != null">course_date,</if>
            <if test="assess != null">assess,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</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="id != null">#{id},</if>
            <if test="newId != null">#{newId},</if>
            <if test="courseCode != null">#{courseCode},</if>
            <if test="topic != null">#{topic},</if>
            <if test="content != null">#{content},</if>
            <if test="courseDay != null">#{courseDay},</if>
            <if test="courseHour != null">#{courseHour},</if>
            <if test="courseType != null">#{courseType},</if>
            <if test="trainer != null">#{trainer},</if>
            <if test="courseDate != null">#{courseDate},</if>
            <if test="assess != null">#{assess},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</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="updateTTnFirstplan" parameterType="TTnFirstplan">
        update t_tn_firstplan
        <trim prefix="SET" suffixOverrides=",">
            <if test="newId != null">new_id = #{newId},</if>
            <if test="courseCode != null">course_code = #{courseCode},</if>
            <if test="topic != null">topic = #{topic},</if>
            <if test="content != null">content = #{content},</if>
            <if test="courseDay != null">course_day = #{courseDay},</if>
            <if test="courseHour != null">course_hour = #{courseHour},</if>
            <if test="courseType != null">course_type = #{courseType},</if>
            <if test="trainer != null">trainer = #{trainer},</if>
            <if test="courseDate != null">course_date = #{courseDate},</if>
            <if test="assess != null">assess = #{assess},</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>
            <if test="planStatus != null">plan_status = #{planStatus},</if>

        </trim>
        where id = #{id}
    </update>

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

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


    <update id="batchStatusTTnFirstplanByids" parameterType="String">
        update t_tn_firstplan set plan_status = 1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
