<?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.TTsYsplanContentMapper">
    
    <resultMap type="TTsYsplanContent" id="TTsYsplanContentResult">
        <result property="id"    column="id"    />
        <result property="pid"    column="pid"    />
        <result property="planDate"    column="plan_date"    />
        <result property="content"    column="content"    />
        <result property="courseDay"    column="course_day"    />
        <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="sortTmpl"    column="sort_tmpl"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTsYsplanContentVo">
        select d.id, d.pid, d.plan_date, d.content, d.course_day, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.sort_tmpl ,s.dept_name from t_ts_ysplan_content d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTsYsplanContentList" parameterType="TTsYsplanContent" resultMap="TTsYsplanContentResult">
        <include refid="selectTTsYsplanContentVo"/>
        <where>  
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="planDate != null "> and plan_date = #{planDate}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="courseDay != null  and courseDay != ''"> and course_day = #{courseDay}</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>
            <if test="sortTmpl != null "> and sort_tmpl = #{sortTmpl}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.sort_tmpl
    </select>
    
    <select id="selectTTsYsplanContentById" parameterType="Long" resultMap="TTsYsplanContentResult">
        <include refid="selectTTsYsplanContentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTTsYsplanContent" parameterType="TTsYsplanContent">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_ts_ysplan_content.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_ts_ysplan_content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="pid != null">pid,</if>
            <if test="planDate != null">plan_date,</if>
            <if test="content != null">content,</if>
            <if test="courseDay != null">course_day,</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>
            <if test="sortTmpl != null">sort_tmpl,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="pid != null">#{pid},</if>
            <if test="planDate != null">#{planDate},</if>
            <if test="content != null">#{content},</if>
            <if test="courseDay != null">#{courseDay},</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>
            <if test="sortTmpl != null">#{sortTmpl},</if>
         </trim>
    </insert>

    <update id="updateTTsYsplanContent" parameterType="TTsYsplanContent">
        update t_ts_ysplan_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="pid != null">pid = #{pid},</if>
            <if test="planDate != null">plan_date = #{planDate},</if>
            <if test="content != null">content = #{content},</if>
            <if test="courseDay != null">course_day = #{courseDay},</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="sortTmpl != null">sort_tmpl = #{sortTmpl},</if>
        </trim>
        where id = #{id}
    </update>

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

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