<?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.RmMonitorTemplateMapper">

    <resultMap type="RmMonitorTemplate" id="RmMonitorTemplateResult">
        <result property="id"    column="id"    />
        <result property="templateName"    column="template_name"    />
        <result property="description"    column="description"    />
        <result property="monitorItems"    column="monitor_items"    />
        <result property="discoveryRules"    column="discovery_rules"    />
        <result property="resourceGroupId"    column="resource_group_id"    />
        <result property="resourcyType"    column="resourcy_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="selectRmMonitorTemplateVo">
        select id, template_name, description, monitor_items, discovery_rules, resource_group_id, resourcy_type, create_time, update_time, create_by, update_by from rm_monitor_template
    </sql>

    <select id="selectRmMonitorTemplateList" parameterType="RmMonitorTemplate" resultMap="RmMonitorTemplateResult">
        <include refid="selectRmMonitorTemplateVo"/>
        <where>
            <if test="templateName != null  and templateName != ''"> and template_name like concat('%', #{templateName}, '%')</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="monitorItems != null  and monitorItems != ''"> and monitor_items = #{monitorItems}</if>
            <if test="discoveryRules != null  and discoveryRules != ''"> and discovery_rules = #{discoveryRules}</if>
            <if test="resourceGroupId != null "> and resource_group_id = #{resourceGroupId}</if>
            <if test="resourcyType != null  and resourcyType != ''"> and resourcy_type = #{resourcyType}</if>
        </where>
    </select>

    <select id="selectRmMonitorTemplateById" parameterType="Long" resultMap="RmMonitorTemplateResult">
        <include refid="selectRmMonitorTemplateVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmMonitorTemplate" parameterType="RmMonitorTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into rm_monitor_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateName != null and templateName != ''">template_name,</if>
            <if test="description != null">description,</if>
            <if test="monitorItems != null">monitor_items,</if>
            <if test="discoveryRules != null">discovery_rules,</if>
            <if test="resourceGroupId != null">resource_group_id,</if>
            <if test="resourcyType != null">resourcy_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="templateName != null and templateName != ''">#{templateName},</if>
            <if test="description != null">#{description},</if>
            <if test="monitorItems != null">#{monitorItems},</if>
            <if test="discoveryRules != null">#{discoveryRules},</if>
            <if test="resourceGroupId != null">#{resourceGroupId},</if>
            <if test="resourcyType != null">#{resourcyType},</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="updateRmMonitorTemplate" parameterType="RmMonitorTemplate">
        update rm_monitor_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateName != null and templateName != ''">template_name = #{templateName},</if>
            <if test="description != null">description = #{description},</if>
            <if test="monitorItems != null">monitor_items = #{monitorItems},</if>
            <if test="discoveryRules != null">discovery_rules = #{discoveryRules},</if>
            <if test="resourceGroupId != null">resource_group_id = #{resourceGroupId},</if>
            <if test="resourcyType != null">resourcy_type = #{resourcyType},</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="deleteRmMonitorTemplateById" parameterType="Long">
        delete from rm_monitor_template where id = #{id}
    </delete>

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

    <select id="getAllTemplate"  resultType="java.util.Map">
        select id, template_name templateName,resourcy_type resourceType from rm_monitor_template
    </select>
</mapper>