<?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.TTsFlplanMapper">
    
    <resultMap type="TTsFlplan" id="TTsFlplanResult">
        <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="detailPlan"    column="detail_plan"    />
        <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="planStatus"    column="plan_status"    />
        <result property="score1"    column="score_1"    />
        <result property="score2"    column="score_2"    />
        <result property="score3"    column="score_3"    />
        <result property="deptName" column="dept_name" />
        <result property="fileUrl" column="file_url" />
        <result property="fileName" column="file_name" />
        <result property="timer" column="timer" />
        <result property="timerNeed" column="timer_need" />
        <result property="sortTmpl"    column="sort_tmpl"    />
        <result property="planDate"    column="plan_date"    />
        <result property="planEndData"    column="plan_end_data"    />
        <result property="scorePass"    column="score_pass"    />
    </resultMap>

    <sql id="selectTTsFlplanVo">
        select c.pid,d.score_pass,c.plan_date,d.sort_tmpl,d.id, d.new_id, d.course_code, d.topic, c.content, c.course_day, d.course_hour, d.detail_plan, 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, d.plan_status, d.score_1, d.score_2, d.score_3 ,d.file_url,d.file_name,d.timer,d.timer_need,s.dept_name from t_ts_flplan d
      left join sys_dept s on s.dept_id = d.dept_id
      left join t_ts_flplan_content c on d.id=c.pid
    </sql>

    <select id="selectTTsFlplanList" parameterType="TTsFlplan" resultMap="TTsFlplanResult">
        <include refid="selectTTsFlplanVo"/>
        <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="detailPlan != null  and detailPlan != ''"> and detail_plan = #{detailPlan}</if>
            <if test="trainer != null  and trainer != ''"> and trainer = #{trainer}</if>
            <if test="courseDate != null "> and course_date = #{courseDate}</if>
            <if test="assess != null  and assess != ''"> and assess = #{assess}</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="planStatus != null "> and plan_status = #{planStatus}</if>
            <if test="score1 != null  and score1 != ''"> and score_1 = #{score1}</if>
            <if test="score2 != null  and score2 != ''"> and score_2 = #{score2}</if>
            <if test="score3 != null  and score3 != ''"> and score_3 = #{score3}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.sort_tmpl,c.sort_tmpl
    </select>
    
    <select id="selectTTsFlplanById" parameterType="Long" resultMap="TTsFlplanResult">
        select d.score_pass,d.plan_start_data,d.plan_end_data,d.sort_tmpl,d.id, d.new_id, d.course_code, d.topic, d.content, d.course_day, d.course_hour, d.detail_plan, 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, d.plan_status, d.score_1, d.score_2, d.score_3 ,d.file_url,d.file_name,d.timer,d.timer_need,s.dept_name
        from t_ts_flplan d
        left join sys_dept s on s.dept_id = d.dept_id
        where d.id = #{id}
    </select>

    <select id="selectTTsFlplanListByNewId" parameterType="TTsFlplan" resultMap="TTsFlplanResult">
        select d.score_pass,d.plan_start_data,d.plan_end_data,d.sort_tmpl,d.id, d.new_id, d.course_code, d.topic, d.content, d.course_day, d.course_hour, d.detail_plan, 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, d.plan_status, d.score_1, d.score_2, d.score_3 ,d.file_url,d.file_name,d.timer,d.timer_need,s.dept_name
        from t_ts_flplan d
        left join sys_dept s on s.dept_id = d.dept_id
        <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="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>
        order by d.sort_tmpl
    </select>

        
    <insert id="insertTTsFlplan" parameterType="TTsFlplan">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_ts_flplan.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_ts_flplan
        <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="detailPlan != null">detail_plan,</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>
            <if test="planStatus != null">plan_status,</if>
            <if test="score1 != null">score_1,</if>
            <if test="score2 != null">score_2,</if>
            <if test="score3 != null">score_3,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="fileName != null">file_name,</if>
            <if test="timer != null">timer,</if>
            <if test="timerNeed != null">timer_need,</if>
            <if test="sortTmpl != null">sort_tmpl,</if>
            <if test="scorePass != null">score_pass,</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="detailPlan != null">#{detailPlan},</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>
            <if test="planStatus != null">#{planStatus},</if>
            <if test="score1 != null">#{score1},</if>
            <if test="score2 != null">#{score2},</if>
            <if test="score3 != null">#{score3},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="timer != null">#{timer},</if>
            <if test="timerNeed != null">#{timerNeed},</if>
            <if test="sortTmpl != null">#{sortTmpl},</if>
            <if test="scorePass != null">#{scorePass},</if>
        </trim>
    </insert>

    <update id="updateTTsFlplan" parameterType="TTsFlplan">
        update t_ts_flplan
        <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="detailPlan != null">detail_plan = #{detailPlan},</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>
            <if test="score1 != null">score_1 = #{score1},</if>
            <if test="score2 != null">score_2 = #{score2},</if>
            <if test="score3 != null">score_3 = #{score3},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="timer != null">timer = #{timer},</if>
            <if test="timerNeed != null">timer_need = #{timerNeed},</if>
            <if test="sortTmpl != null">sort_tmpl=#{sortTmpl},</if>
            <if test="scorePass != null">score_pass=#{scorePass},</if>
        </trim>
        where id = #{id}
    </update>

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

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