<?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.goldenwater.slaj.ttsa.mapper.BisTtsaExamPlanMapper">

    <resultMap type="com.goldenwater.slaj.ttsa.domain.BisTtsaExamPlan" id="BisTtsaExamPlanResult">
        <id property="guid" column="guid"/>
        <result property="planName" column="plan_name"/>
        <result property="estaOrgGuid" column="esta_org_guid"/>
        <result property="estaTime" column="esta_time"/>
        <result property="planCont" column="plan_cont"/>
        <result property="apprStat" column="appr_stat"/>
        <result property="apprOrgGuid" column="appr_org_guid"/>
        <result property="apprOpin" column="appr_opin"/>
        <result property="repStat" column="rep_stat"/>
        <result property="note" column="note"/>
        <result property="collTime" column="coll_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="recPers" column="rec_pers"/>
        <result property="punoGuid" column="puno_guid"/>
        <result property="applTime" column="appl_time"/>
        <result property="apprTime" column="appr_time"/>
    </resultMap>

    <sql id="selectBisTtsaExamPlanVo">
        select guid, plan_name, esta_org_guid, esta_time, plan_cont, appr_stat, appr_org_guid, appr_opin, rep_stat, note, coll_time, upd_time, rec_pers, puno_guid, appl_time, appr_time
        from bis_ttsa_exam_plan
    </sql>

    <select id="selectBisTtsaExamPlanAll" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaExamPlan" resultMap="BisTtsaExamPlanResult">
        <include refid="selectBisTtsaExamPlanVo"/>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaExamPlanList" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaExamPlan" resultMap="BisTtsaExamPlanResult">
        <include refid="selectBisTtsaExamPlanVo"/>
        <where>
            <if test="planName != null and planName != ''">and plan_name like '%' || #{planName} || '%'</if>
            <if test="apprStat != null and apprStat != ''">and appr_stat = #{apprStat}</if>
            <if test="repStat != null and repStat != ''">and rep_stat = #{repStat}</if>
            <if test="estaOrgGuid != null and estaOrgGuid != ''">and esta_org_guid = #{estaOrgGuid}</if>
        </where>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaExamPlanByGuid" parameterType="String" resultMap="BisTtsaExamPlanResult">
        <include refid="selectBisTtsaExamPlanVo"/>
        where guid = #{guid}
    </select>

    <insert id="insertBisTtsaExamPlan" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaExamPlan" useGeneratedKeys="true" keyProperty="guid">
        insert into bis_ttsa_exam_plan (
            guid, plan_name, esta_org_guid, esta_time, plan_cont, appr_stat, appr_org_guid, appr_opin, rep_stat, note, coll_time, upd_time, rec_pers, puno_guid, appl_time, appr_time
        ) values (
            #{guid}, #{planName}, #{estaOrgGuid}, #{estaTime}, #{planCont}, #{apprStat}, #{apprOrgGuid}, #{apprOpin}, #{repStat}, #{note}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, #{recPers}, #{punoGuid}, #{applTime}, #{apprTime}
        )
    </insert>

    <update id="updateBisTtsaExamPlan" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaExamPlan">
        update bis_ttsa_exam_plan
        <set>
            <if test="planName != null">plan_name = #{planName},</if>
            <if test="estaOrgGuid != null">esta_org_guid = #{estaOrgGuid},</if>
            <if test="estaTime != null">esta_time = #{estaTime},</if>
            <if test="planCont != null">plan_cont = #{planCont},</if>
            <if test="apprStat != null">appr_stat = #{apprStat},</if>
            <if test="apprOrgGuid != null">appr_org_guid = #{apprOrgGuid},</if>
            <if test="apprOpin != null">appr_opin = #{apprOpin},</if>
            <if test="repStat != null">rep_stat = #{repStat},</if>
            <if test="note != null">note = #{note},</if>
            <if test="punoGuid != null">puno_guid = #{punoGuid},</if>
            <if test="applTime != null">appl_time = #{applTime},</if>
            <if test="apprTime != null">appr_time = #{apprTime},</if>
            upd_time = CURRENT_TIMESTAMP
        </set>
        where guid = #{guid}
    </update>

    <delete id="deleteBisTtsaExamPlanByGuids" parameterType="String">
        delete from bis_ttsa_exam_plan where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </delete>

</mapper>
