<?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.tongran.rocketmq.mapper.InitialHeartbeatListenMapper">
    
    <resultMap type="InitialHeartbeatListen" id="InitialHeartbeatListenResult">
        <result property="clientId"    column="client_id"    />
        <result property="strength"    column="strength"    />
        <result property="timestamp"    column="timestamp"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectInitialHeartbeatListenVo">
        select client_id, strength, timestamp, create_time, update_time, create_by, update_by from initial_heartbeat_listen
    </sql>

    <select id="selectInitialHeartbeatListenList" parameterType="InitialHeartbeatListen" resultMap="InitialHeartbeatListenResult">
        <include refid="selectInitialHeartbeatListenVo"/>
        <where>  
            <if test="strength != null "> and strength = #{strength}</if>
            <if test="timestamp != null "> and timestamp = #{timestamp}</if>
        </where>
    </select>
    
    <select id="selectInitialHeartbeatListenByClientId" parameterType="String" resultMap="InitialHeartbeatListenResult">
        <include refid="selectInitialHeartbeatListenVo"/>
        where client_id = #{clientId}
    </select>

    <insert id="insertInitialHeartbeatListen" parameterType="InitialHeartbeatListen">
        insert into initial_heartbeat_listen
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null">client_id,</if>
            <if test="strength != null">strength,</if>
            <if test="timestamp != null">timestamp,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientId != null">#{clientId},</if>
            <if test="strength != null">#{strength},</if>
            <if test="timestamp != null">#{timestamp},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateInitialHeartbeatListen" parameterType="InitialHeartbeatListen">
        update initial_heartbeat_listen
        <trim prefix="SET" suffixOverrides=",">
            <if test="strength != null">strength = #{strength},</if>
            <if test="timestamp != null">timestamp = #{timestamp},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where client_id = #{clientId}
    </update>

    <delete id="deleteInitialHeartbeatListenByClientId" parameterType="String">
        delete from initial_heartbeat_listen where client_id = #{clientId}
    </delete>

    <delete id="deleteInitialHeartbeatListenByClientIds" parameterType="String">
        delete from initial_heartbeat_listen where client_id in 
        <foreach item="clientId" collection="array" open="(" separator="," close=")">
            #{clientId}
        </foreach>
    </delete>
</mapper>