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

    <resultMap type="com.goldenwater.slaj.ttsa.domain.BisTtsaCertChaTran" id="BisTtsaCertChaTranResult">
        <id property="guid" column="guid"/>
        <result property="chaApplGuid" column="cha_appl_guid"/>
        <result property="beforWiunGuid" column="befor_wiun_guid"/>
        <result property="afterWiunGuid" column="after_wiun_guid"/>
        <result property="note" column="note"/>
        <result property="collTime" column="coll_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="recPers" column="rec_pers"/>
    </resultMap>

    <sql id="selectBisTtsaCertChaTranVo">
        select guid, cha_appl_guid, befor_wiun_guid, after_wiun_guid, note, coll_time, upd_time, rec_pers
        from bis_ttsa_cert_cha_tran
    </sql>

    <select id="selectBisTtsaCertChaTranAll" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaCertChaTran" resultMap="BisTtsaCertChaTranResult">
        <include refid="selectBisTtsaCertChaTranVo"/>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaCertChaTranList" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaCertChaTran" resultMap="BisTtsaCertChaTranResult">
        <include refid="selectBisTtsaCertChaTranVo"/>
        <where>
            <if test="chaApplGuid != null and chaApplGuid != ''">and cha_appl_guid = #{chaApplGuid}</if>
        </where>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaCertChaTranByGuid" parameterType="String" resultMap="BisTtsaCertChaTranResult">
        <include refid="selectBisTtsaCertChaTranVo"/>
        where guid = #{guid}
    </select>

    <insert id="insertBisTtsaCertChaTran" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaCertChaTran" useGeneratedKeys="true" keyProperty="guid">
        insert into bis_ttsa_cert_cha_tran (
            guid, cha_appl_guid, befor_wiun_guid, after_wiun_guid, note, coll_time, upd_time, rec_pers
        ) values (
            #{guid}, #{chaApplGuid}, #{beforWiunGuid}, #{afterWiunGuid}, #{note}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, #{recPers}
        )
    </insert>

    <update id="updateBisTtsaCertChaTran" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaCertChaTran">
        update bis_ttsa_cert_cha_tran
        <set>
            <if test="chaApplGuid != null">cha_appl_guid = #{chaApplGuid},</if>
            <if test="beforWiunGuid != null">befor_wiun_guid = #{beforWiunGuid},</if>
            <if test="afterWiunGuid != null">after_wiun_guid = #{afterWiunGuid},</if>
            <if test="note != null">note = #{note},</if>
            upd_time = CURRENT_TIMESTAMP
        </set>
        where guid = #{guid}
    </update>

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

</mapper>
