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

    <resultMap type="com.goldenwater.slaj.ttsa.domain.BisTtsaTque" id="BisTtsaTqueResult">
        <id property="guid" column="guid"/>
        <result property="tqueType" column="tque_type"/>
        <result property="queType" column="que_type"/>
        <result property="tqueGrad" column="tque_grad"/>
        <result property="tqueTitl" column="tque_titl"/>
        <result property="tqueAnsw" column="tque_answ"/>
        <result property="applType" column="appl_type"/>
        <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="selectBisTtsaTqueVo">
        select guid, tque_type, que_type, tque_grad, tque_titl, tque_answ, appl_type, note, coll_time, upd_time, rec_pers
        from bis_ttsa_tque
    </sql>

    <select id="selectBisTtsaTqueAll" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTque" resultMap="BisTtsaTqueResult">
        <include refid="selectBisTtsaTqueVo"/>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaTqueList" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTque" resultMap="BisTtsaTqueResult">
        <include refid="selectBisTtsaTqueVo"/>
        <where>
            <if test="tqueType != null and tqueType != ''">and tque_type = #{tqueType}</if>
            <if test="tqueGrad != null and tqueGrad != ''">and tque_grad = #{tqueGrad}</if>
            <if test="queType != null and queType != ''">and que_type = #{queType}</if>
            <if test="tqueTitl != null and tqueTitl != ''">and tque_titl like '%' || #{tqueTitl} || '%'</if>
        </where>
        order by coll_time desc
    </select>

    <select id="selectBisTtsaTqueByGuid" parameterType="String" resultMap="BisTtsaTqueResult">
        <include refid="selectBisTtsaTqueVo"/>
        where guid = #{guid}
    </select>

    <insert id="insertBisTtsaTque" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTque" useGeneratedKeys="true" keyProperty="guid">
        insert into bis_ttsa_tque (
            guid, tque_type, que_type, tque_grad, tque_titl, tque_answ, appl_type, note, coll_time, upd_time, rec_pers
        ) values (
            #{guid}, #{tqueType}, #{queType}, #{tqueGrad}, #{tqueTitl}, #{tqueAnsw}, #{applType}, #{note}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, #{recPers}
        )
    </insert>

    <update id="updateBisTtsaTque" parameterType="com.goldenwater.slaj.ttsa.domain.BisTtsaTque">
        update bis_ttsa_tque
        <set>
            <if test="tqueType != null">tque_type = #{tqueType},</if>
            <if test="queType != null">que_type = #{queType},</if>
            <if test="tqueGrad != null">tque_grad = #{tqueGrad},</if>
            <if test="tqueTitl != null">tque_titl = #{tqueTitl},</if>
            <if test="tqueAnsw != null">tque_answ = #{tqueAnsw},</if>
            <if test="applType != null">appl_type = #{applType},</if>
            <if test="note != null">note = #{note},</if>
            upd_time = CURRENT_TIMESTAMP
        </set>
        where guid = #{guid}
    </update>

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

</mapper>
