<?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.ruoyi.rocketmq.mapper.RmAlarmLogMapper">
    
    <resultMap type="RmAlarmLog" id="RmAlarmLogResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="alarmTime"    column="alarm_time"    />
        <result property="mgmPublicIp"    column="mgm_public_ip"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="alarmContent"    column="alarm_content"    />
        <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="selectRmAlarmLogVo">
        select id, client_id, alarm_time, mgm_public_ip, alarm_type, alarm_content, create_time, update_time, create_by, update_by from rm_alarm_log
    </sql>

    <select id="selectRmAlarmLogList" parameterType="RmAlarmLog" resultMap="RmAlarmLogResult">
        <include refid="selectRmAlarmLogVo"/>
        <where>  
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="alarmTime != null "> and alarm_time = #{alarmTime}</if>
            <if test="mgmPublicIp != null  and mgmPublicIp != ''"> and mgm_public_ip = #{mgmPublicIp}</if>
            <if test="alarmType != null  and alarmType != ''"> and alarm_type = #{alarmType}</if>
            <if test="alarmContent != null  and alarmContent != ''"> and alarm_content = #{alarmContent}</if>
        </where>
        order by alarm_time desc
    </select>
    
    <select id="selectRmAlarmLogById" parameterType="Long" resultMap="RmAlarmLogResult">
        <include refid="selectRmAlarmLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmAlarmLog" parameterType="RmAlarmLog" useGeneratedKeys="true" keyProperty="id">
        insert into rm_alarm_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="alarmTime != null">alarm_time,</if>
            <if test="mgmPublicIp != null">mgm_public_ip,</if>
            <if test="alarmType != null">alarm_type,</if>
            <if test="alarmContent != null">alarm_content,</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="alarmTime != null">#{alarmTime},</if>
            <if test="mgmPublicIp != null">#{mgmPublicIp},</if>
            <if test="alarmType != null">#{alarmType},</if>
            <if test="alarmContent != null">#{alarmContent},</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="updateRmAlarmLog" parameterType="RmAlarmLog">
        update rm_alarm_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="mgmPublicIp != null">mgm_public_ip = #{mgmPublicIp},</if>
            <if test="alarmContent != null">alarm_content = #{alarmContent},</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>
            <choose>
                <when test="id != null">
                    and id = #[id]
                </when>
                <when test="clientId != null and alarmType != null">
                    and client_id = #{clientId} and alarm_type = #{alarmType}
                </when>
                <otherwise>
                    and 1=0
                </otherwise>
            </choose>
        </where>
    </update>

    <delete id="deleteRmAlarmLogById" parameterType="Long">
        delete from rm_alarm_log where id = #{id}
    </delete>

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