<?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.RmAlarmRuleTemplateMapper">
    
    <resultMap type="RmAlarmRuleTemplate" id="RmAlarmRuleTemplateResult">
        <result property="id"    column="id"    />
        <result property="ruleName"    column="rule_name"    />
        <result property="metricKey"    column="metric_key"    />
        <result property="resourceType"    column="resource_type"    />
        <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="selectRmAlarmRuleTemplateVo">
        select id, rule_name, metric_key, resource_type, create_time, update_time, create_by, update_by from rm_alarm_rule_template
    </sql>

    <select id="selectRmAlarmRuleTemplateList" parameterType="RmAlarmRuleTemplate" resultMap="RmAlarmRuleTemplateResult">
        <include refid="selectRmAlarmRuleTemplateVo"/>
        <where>  
            <if test="ruleName != null  and ruleName != ''"> and rule_name like concat('%', #{ruleName}, '%')</if>
            <if test="metricKey != null  and metricKey != ''"> and metric_key = #{metricKey}</if>
            <if test="resourceType != null  and resourceType != ''"> and resource_type = #{resourceType}</if>
        </where>
    </select>
    
    <select id="selectRmAlarmRuleTemplateById" parameterType="Long" resultMap="RmAlarmRuleTemplateResult">
        <include refid="selectRmAlarmRuleTemplateVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmAlarmRuleTemplate" parameterType="RmAlarmRuleTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into rm_alarm_rule_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ruleName != null">rule_name,</if>
            <if test="metricKey != null">metric_key,</if>
            <if test="resourceType != null">resource_type,</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="ruleName != null">#{ruleName},</if>
            <if test="metricKey != null">#{metricKey},</if>
            <if test="resourceType != null">#{resourceType},</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="updateRmAlarmRuleTemplate" parameterType="RmAlarmRuleTemplate">
        update rm_alarm_rule_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="ruleName != null">rule_name = #{ruleName},</if>
            <if test="metricKey != null">metric_key = #{metricKey},</if>
            <if test="resourceType != null">resource_type = #{resourceType},</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="deleteRmAlarmRuleTemplateById" parameterType="Long">
        delete from rm_alarm_rule_template where id = #{id}
    </delete>

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