<?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.TTsApproveMapper">
    
    <resultMap type="TTsApprove" id="TTsApproveResult">
        <result property="id"    column="id"    />
        <result property="trainingId"    column="training_id"    />
        <result property="contentId"    column="content_id"    />
        <result property="apNo"    column="ap_no"    />
        <result property="processId"    column="process_id"    />
        <result property="applicant"    column="applicant"    />
        <result property="applicationTime"    column="application_time"    />
        <result property="applicantName"    column="applicant_name"    />
        <result property="approver"    column="approver"    />
        <result property="approveTime"    column="approve_time"    />
        <result property="approverName"    column="approver_name"    />
        <result property="status"    column="status"    />
        <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="planType"    column="plan_type"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTsApproveVo">
        select d.training_id,d.content_id,d.id, d.ap_no, d.process_id, d.applicant, d.application_time, d.applicant_name, d.approver, d.approve_time, d.approver_name, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.plan_type ,s.dept_name from t_ts_approve d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTsApproveList" parameterType="TTsApprove" resultMap="TTsApproveResult">
        <include refid="selectTTsApproveVo"/>
        <where>  
            <if test="apNo != null  and apNo != ''"> and ap_no = #{apNo}</if>
            <if test="trainingId != null  and trainingId != ''"> and training_id = #{trainingId}</if>
            <if test="contentId != null  and contentId != ''"> and content_id = #{contentId}</if>
            <if test="processId != null  and processId != ''"> and process_id = #{processId}</if>
            <if test="applicant != null  and applicant != ''"> and applicant = #{applicant}</if>
            <if test="applicationTime != null "> and application_time = #{applicationTime}</if>
            <if test="applicantName != null  and applicantName != ''"> and applicant_name like concat(concat('%', #{applicantName}), '%')</if>
            <if test="approver != null  and approver != ''"> and approver = #{approver}</if>
            <if test="approveTime != null "> and approve_time = #{approveTime}</if>
            <if test="approverName != null  and approverName != ''"> and approver_name like concat(concat('%', #{approverName}), '%')</if>
            <if test="status != null "> and status = #{status}</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="planType != null  and planType != ''"> and plan_type = #{planType}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTTsApproveById" parameterType="Long" resultMap="TTsApproveResult">
        <include refid="selectTTsApproveVo"/>
        where id = #{id}
    </select>

    <select id="selectTTsApproveByNewId" parameterType="Long" resultMap="TTsApproveResult">
        <include refid="selectTTsApproveVo"/>
        where training_id = #{trainingId}
    </select>

    <select id="selectTTsApproveByContentId" parameterType="Long" resultMap="TTsApproveResult">
        <include refid="selectTTsApproveVo"/>
        where content_id = #{contentId}
    </select>

    <insert id="insertTTsApprove" parameterType="TTsApprove">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_ts_approve.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_ts_approve
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="trainingId != null">training_id,</if>
            <if test="contentId != null">content_id,</if>
            <if test="apNo != null">ap_no,</if>
            <if test="processId != null">process_id,</if>
            <if test="applicant != null">applicant,</if>
            <if test="applicationTime != null">application_time,</if>
            <if test="applicantName != null">applicant_name,</if>
            <if test="approver != null">approver,</if>
            <if test="approveTime != null">approve_time,</if>
            <if test="approverName != null">approver_name,</if>
            <if test="status != null">status,</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="planType != null">plan_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="trainingId != null">#{trainingId},</if>
            <if test="contentId != null">#{contentId},</if>
            <if test="apNo != null">#{apNo},</if>
            <if test="processId != null">#{processId},</if>
            <if test="applicant != null">#{applicant},</if>
            <if test="applicationTime != null">#{applicationTime},</if>
            <if test="applicantName != null">#{applicantName},</if>
            <if test="approver != null">#{approver},</if>
            <if test="approveTime != null">#{approveTime},</if>
            <if test="approverName != null">#{approverName},</if>
            <if test="status != null">#{status},</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="planType != null">#{planType},</if>
         </trim>
    </insert>

    <update id="updateTTsApprove" parameterType="TTsApprove">
        update t_ts_approve
        <trim prefix="SET" suffixOverrides=",">
            <if test="trainingId != null">training_id = #{trainingId},</if>
            <if test="contentId != null">content_id = #{contentId},</if>
            <if test="apNo != null">ap_no = #{apNo},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="applicant != null">applicant = #{applicant},</if>
            <if test="applicationTime != null">application_time = #{applicationTime},</if>
            <if test="applicantName != null">applicant_name = #{applicantName},</if>
            <if test="approver != null">approver = #{approver},</if>
            <if test="approveTime != null">approve_time = #{approveTime},</if>
            <if test="approverName != null">approver_name = #{approverName},</if>
            <if test="status != null">status = #{status},</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="planType != null">plan_type = #{planType},</if>
        </trim>
        where id = #{id}
    </update>

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

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