<?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.RmTcpdumpConfigMapper">
    
    <resultMap type="RmTcpdumpConfig" id="RmTcpdumpConfigResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="detectFlag"    column="detect_flag"    />
        <result property="frequency"    column="frequency"    />
        <result property="detectTimes"    column="detect_times"    />
        <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="selectRmTcpdumpConfigVo">
        select id, client_id, detect_flag, frequency, detect_times, create_time, update_time, create_by, update_by from rm_tcpdump_config
    </sql>

    <select id="selectRmTcpdumpConfigList" parameterType="RmTcpdumpConfig" resultMap="RmTcpdumpConfigResult">
        <include refid="selectRmTcpdumpConfigVo"/>
        <where>  
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="detectFlag != null "> and detect_flag = #{detectFlag}</if>
            <if test="frequency != null  and frequency != ''"> and frequency = #{frequency}</if>
            <if test="detectTimes != null  and detectTimes != ''"> and detect_times = #{detectTimes}</if>
        </where>
    </select>
    
    <select id="selectRmTcpdumpConfigById" parameterType="Long" resultMap="RmTcpdumpConfigResult">
        <include refid="selectRmTcpdumpConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmTcpdumpConfig" parameterType="RmTcpdumpConfig" useGeneratedKeys="true" keyProperty="id">
        insert into rm_tcpdump_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="detectFlag != null">detect_flag,</if>
            <if test="frequency != null">frequency,</if>
            <if test="detectTimes != null">detect_times,</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 and clientId != ''">#{clientId},</if>
            <if test="detectFlag != null">#{detectFlag},</if>
            <if test="frequency != null">#{frequency},</if>
            <if test="detectTimes != null">#{detectTimes},</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>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="detectFlag != null">detect_flag = #{detectFlag},</if>
            <if test="frequency != null">frequency = #{frequency},</if>
            detect_times = #{detectTimes},
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
    </insert>

    <update id="updateRmTcpdumpConfig" parameterType="RmTcpdumpConfig">
        update rm_tcpdump_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="detectFlag != null">detect_flag = #{detectFlag},</if>
            <if test="frequency != null">frequency = #{frequency},</if>
            <if test="detectTimes != null">detect_times = #{detectTimes},</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 id = #{id}
    </update>

    <delete id="deleteRmTcpdumpConfigById" parameterType="Long">
        delete from rm_tcpdump_config where id = #{id}
    </delete>

    <delete id="deleteRmTcpdumpConfigByIds" parameterType="String">
        delete from rm_tcpdump_config where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectRmTcpdumpConfigByClientId" parameterType="String" resultMap="RmTcpdumpConfigResult">
        <include refid="selectRmTcpdumpConfigVo"/>
        where client_id = #{clientId}
    </select>
</mapper>