<?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.hidd.mapper.BisHiddConsultMapper">

    <resultMap type="BisHiddConsult" id="BisHiddConsultResult">
        <id property="guid" column="guid"/>
        <result property="hiddGuid" column="hidd_guid"/>
        <result property="consTheme" column="cons_theme"/>
        <result property="consTime" column="cons_time"/>
        <result property="consPlace" column="cons_place"/>
        <result property="consHost" column="cons_host"/>
        <result property="consMembers" column="cons_members"/>
        <result property="consContent" column="cons_content"/>
        <result property="consResult" column="cons_result"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectBisHiddConsultVo">
        select guid, hidd_guid, cons_theme, cons_time, cons_place, cons_host, cons_members, cons_content, cons_result, create_time, update_time
        from bis_hidd_consult
    </sql>

    <select id="selectBisHiddConsultList" parameterType="BisHiddConsult" resultMap="BisHiddConsultResult">
        <include refid="selectBisHiddConsultVo"/>
        <where>
            <if test="hiddGuid != null and hiddGuid != ''">and hidd_guid = #{hiddGuid}</if>
            <if test="consTheme != null and consTheme != ''">and cons_theme like '%' || #{consTheme} || '%'</if>
            <if test="consTime != null and consTime != ''">and cons_time = #{consTime}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectBisHiddConsultByGuid" parameterType="String" resultMap="BisHiddConsultResult">
        <include refid="selectBisHiddConsultVo"/>
        where guid = #{guid}
    </select>

    <insert id="insertBisHiddConsult" parameterType="BisHiddConsult" useGeneratedKeys="true" keyProperty="guid">
        insert into bis_hidd_consult (
            guid, hidd_guid, cons_theme, cons_time, cons_place, 
            cons_host, cons_members, cons_content, cons_result, create_time
        ) values (
            #{guid}, #{hiddGuid}, #{consTheme}, #{consTime}, #{consPlace},
            #{consHost}, #{consMembers}, #{consContent}, #{consResult}, CURRENT_TIMESTAMP
        )
    </insert>

    <update id="updateBisHiddConsult" parameterType="BisHiddConsult">
        update bis_hidd_consult
        <set>
            <if test="hiddGuid != null">hidd_guid = #{hiddGuid},</if>
            <if test="consTheme != null">cons_theme = #{consTheme},</if>
            <if test="consTime != null">cons_time = #{consTime},</if>
            <if test="consPlace != null">cons_place = #{consPlace},</if>
            <if test="consHost != null">cons_host = #{consHost},</if>
            <if test="consMembers != null">cons_members = #{consMembers},</if>
            <if test="consContent != null">cons_content = #{consContent},</if>
            <if test="consResult != null">cons_result = #{consResult},</if>
            update_time = CURRENT_TIMESTAMP
        </set>
        where guid = #{guid}
    </update>

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

</mapper>
