<?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.RmAlarmRecordMapper">
    
    <resultMap type="RmAlarmRecord" id="RmAlarmRecordResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="resourceName"    column="resource_name"    />
        <result property="sourceIp"    column="source_ip"    />
        <result property="occurTime"    column="occur_time"    />
        <result property="content"    column="content"    />
        <result property="repeatCount"    column="repeat_count"    />
        <result property="status"    column="status"    />
        <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="selectRmAlarmRecordVo">
        select id, client_id, resource_name, source_ip, occur_time, content, repeat_count, status, create_time, update_time, create_by, update_by from rm_alarm_record
    </sql>

    <select id="selectRmAlarmRecordList" parameterType="RmAlarmRecord" resultMap="RmAlarmRecordResult">
        <include refid="selectRmAlarmRecordVo"/>
        <where>  
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="resourceName != null  and resourceName != ''"> and resource_name like concat('%', #{resourceName}, '%')</if>
            <if test="sourceIp != null  and sourceIp != ''"> and source_ip = #{sourceIp}</if>
            <if test="occurTime != null "> and occur_time = #{occurTime}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="repeatCount != null "> and repeat_count = #{repeatCount}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectRmAlarmRecordById" parameterType="Long" resultMap="RmAlarmRecordResult">
        <include refid="selectRmAlarmRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmAlarmRecord" parameterType="RmAlarmRecord" useGeneratedKeys="true" keyProperty="id">
        insert into rm_alarm_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="resourceName != null and resourceName != ''">resource_name,</if>
            <if test="sourceIp != null and sourceIp != ''">source_ip,</if>
            <if test="occurTime != null">occur_time,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="repeatCount != null">repeat_count,</if>
            <if test="status != null and status != ''">status,</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="resourceName != null and resourceName != ''">#{resourceName},</if>
            <if test="sourceIp != null and sourceIp != ''">#{sourceIp},</if>
            <if test="occurTime != null">#{occurTime},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="repeatCount != null">#{repeatCount},</if>
            <if test="status != null and status != ''">#{status},</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="updateRmAlarmRecord" parameterType="RmAlarmRecord">
        update rm_alarm_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="resourceName != null and resourceName != ''">resource_name = #{resourceName},</if>
            <if test="sourceIp != null and sourceIp != ''">source_ip = #{sourceIp},</if>
            <if test="occurTime != null">occur_time = #{occurTime},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="repeatCount != null">repeat_count = #{repeatCount},</if>
            <if test="status != null and status != ''">status = #{status},</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="deleteRmAlarmRecordById" parameterType="Long">
        delete from rm_alarm_record where id = #{id}
    </delete>

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