<?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.RmAlarmPolicyMapper">
    
    <resultMap type="RmAlarmPolicy" id="RmAlarmPolicyResult">
        <result property="id"    column="id"    />
        <result property="alarmName"    column="alarm_name"    />
        <result property="alarmDescription"    column="alarm_description"    />
        <result property="resourceGroupId"    column="resource_group_id"    />
        <result property="status"    column="status"    />
        <result property="deployTime"    column="deploy_time"    />
        <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="selectRmAlarmPolicyVo">
        select id, alarm_name, alarm_description, resource_group_id, status, deploy_time, create_time, update_time, create_by, update_by from rm_alarm_policy
    </sql>

    <select id="selectRmAlarmPolicyList" parameterType="RmAlarmPolicy" resultMap="RmAlarmPolicyResult">
        <include refid="selectRmAlarmPolicyVo"/>
        <where>  
            <if test="alarmName != null  and alarmName != ''"> and alarm_name like concat('%', #{alarmName}, '%')</if>
            <if test="alarmDescription != null  and alarmDescription != ''"> and alarm_description = #{alarmDescription}</if>
            <if test="resourceGroupId != null "> and resource_group_id = #{resourceGroupId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="deployTime != null "> and deploy_time = #{deployTime}</if>
        </where>
    </select>
    
    <select id="selectRmAlarmPolicyById" parameterType="Long" resultMap="RmAlarmPolicyResult">
        <include refid="selectRmAlarmPolicyVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmAlarmPolicy" parameterType="RmAlarmPolicy" useGeneratedKeys="true" keyProperty="id">
        insert into rm_alarm_policy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="alarmName != null and alarmName != ''">alarm_name,</if>
            <if test="alarmDescription != null">alarm_description,</if>
            <if test="resourceGroupId != null">resource_group_id,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="deployTime != null">deploy_time,</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="alarmName != null and alarmName != ''">#{alarmName},</if>
            <if test="alarmDescription != null">#{alarmDescription},</if>
            <if test="resourceGroupId != null">#{resourceGroupId},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="deployTime != null">#{deployTime},</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="updateRmAlarmPolicy" parameterType="RmAlarmPolicy">
        update rm_alarm_policy
        <trim prefix="SET" suffixOverrides=",">
            <if test="alarmName != null and alarmName != ''">alarm_name = #{alarmName},</if>
            <if test="alarmDescription != null">alarm_description = #{alarmDescription},</if>
            <if test="resourceGroupId != null">resource_group_id = #{resourceGroupId},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="deployTime != null">deploy_time = #{deployTime},</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="deleteRmAlarmPolicyById" parameterType="Long">
        delete from rm_alarm_policy where id = #{id}
    </delete>

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