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

    <resultMap type="com.goldenwater.slaj.ttsa.domain.BisTtsaTqueOpt" id="BisTtsaTqueOptResult">
        <id property="guid" column="guid"/>
        <result property="tqueGuid" column="tque_guid"/>
        <result property="optFlag" column="opt_flag"/>
        <result property="tqueOpt" column="tque_opt"/>
        <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="selectBisTtsaTqueOptVo">
        select guid, tque_guid, opt_flag, tque_opt, note, coll_time, upd_time, rec_pers
        from bis_ttsa_tque_opt
    </sql>

    <select id="selectBisTtsaTqueOptAll" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTqueOpt" resultMap="BisTtsaTqueOptResult">
        <include refid="selectBisTtsaTqueOptVo"/>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaTqueOptList" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTqueOpt" resultMap="BisTtsaTqueOptResult">
        <include refid="selectBisTtsaTqueOptVo"/>
        <where>
            <if test="tqueGuid != null and tqueGuid != ''">and tque_guid = #{tqueGuid}</if>
        </where>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaTqueOptByGuid" parameterType="String" resultMap="BisTtsaTqueOptResult">
        <include refid="selectBisTtsaTqueOptVo"/>
        where guid = #{guid}
    </select>

    <insert id="insertBisTtsaTqueOpt" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTqueOpt" useGeneratedKeys="true" keyProperty="guid">
        insert into bis_ttsa_tque_opt (
            guid, tque_guid, opt_flag, tque_opt, note, coll_time, upd_time, rec_pers
        ) values (
            #{guid}, #{tqueGuid}, #{optFlag}, #{tqueOpt}, #{note}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, #{recPers}
        )
    </insert>

    <update id="updateBisTtsaTqueOpt" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTqueOpt">
        update bis_ttsa_tque_opt
        <set>
            <if test="tqueGuid != null">tque_guid = #{tqueGuid},</if>
            <if test="optFlag != null">opt_flag = #{optFlag},</if>
            <if test="tqueOpt != null">tque_opt = #{tqueOpt},</if>
            <if test="note != null">note = #{note},</if>
            upd_time = CURRENT_TIMESTAMP
        </set>
        where guid = #{guid}
    </update>

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

</mapper>
