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

    <resultMap type="RmTemplateSwitch" id="RmTemplateSwitchResult">
        <result property="id"    column="id"    />
        <result property="templateId"    column="template_id"    />
        <result property="policyId"    column="policy_id"    />
        <result property="itemType"    column="item_type"    />
        <result property="metricKey"    column="metric_key"    />
        <result property="metricName"    column="metric_name"    />
        <result property="oid"    column="oid"    />
        <result property="filterValue"    column="filter_value"    />
        <result property="switchDescription"    column="switch_description"    />
        <result property="dataType"    column="data_type"    />
        <result property="monitorStatus"    column="monitor_status"    />
        <result property="collectionCycle"    column="collection_cycle"    />
        <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="selectRmTemplateSwitchVo">
        select id, template_id, policy_id, item_type, metric_key, metric_name, oid, filter_value, switch_description, data_type, monitor_status, collection_cycle, create_time, update_time, create_by, update_by from rm_template_switch
    </sql>

    <select id="selectRmTemplateSwitchList" parameterType="RmTemplateSwitch" resultMap="RmTemplateSwitchResult">
        <include refid="selectRmTemplateSwitchVo"/>
        <where>
            <if test="templateId != null "> and template_id = #{templateId}</if>
            <if test="policyId != null "> and policy_id = #{policyId}</if>
            <if test="itemType != null  and itemType != ''"> and item_type = #{itemType}</if>
            <if test="metricKey != null  and metricKey != ''"> and metric_key = #{metricKey}</if>
            <if test="metricName != null  and metricName != ''"> and metric_name like concat('%', #{metricName}, '%')</if>
            <if test="oid != null  and oid != ''"> and oid = #{oid}</if>
            <if test="filterValue != null  and filterValue != ''"> and filter_value = #{filterValue}</if>
            <if test="switchDescription != null  and switchDescription != ''"> and switch_description = #{switchDescription}</if>
            <if test="dataType != null  and dataType != ''"> and data_type = #{dataType}</if>
            <if test="monitorStatus != null  and monitorStatus != ''"> and monitor_status = #{monitorStatus}</if>
            <if test="collectionCycle != null  and collectionCycle != ''"> and collection_cycle = #{collectionCycle}</if>
        </where>
    </select>

    <select id="selectRmTemplateSwitchById" parameterType="Long" resultMap="RmTemplateSwitchResult">
        <include refid="selectRmTemplateSwitchVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmTemplateSwitch" parameterType="RmTemplateSwitch" useGeneratedKeys="true" keyProperty="id">
        insert into rm_template_switch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateId != null">template_id,</if>
            <if test="policyId != null">policy_id,</if>
            <if test="itemType != null and itemType != ''">item_type,</if>
            <if test="metricKey != null and metricKey != ''">metric_key,</if>
            <if test="metricName != null and metricName != ''">metric_name,</if>
            <if test="oid != null and oid != ''">oid,</if>
            <if test="filterValue != null">filter_value,</if>
            <if test="switchDescription != null">switch_description,</if>
            <if test="dataType != null and dataType != ''">data_type,</if>
            <if test="monitorStatus != null">monitor_status,</if>
            <if test="collectionCycle != null">collection_cycle,</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="templateId != null">#{templateId},</if>
            <if test="policyId != null">#{policyId},</if>
            <if test="itemType != null and itemType != ''">#{itemType},</if>
            <if test="metricKey != null and metricKey != ''">#{metricKey},</if>
            <if test="metricName != null and metricName != ''">#{metricName},</if>
            <if test="oid != null and oid != ''">#{oid},</if>
            <if test="filterValue != null">#{filterValue},</if>
            <if test="switchDescription != null">#{switchDescription},</if>
            <if test="dataType != null and dataType != ''">#{dataType},</if>
            <if test="monitorStatus != null">#{monitorStatus},</if>
            <if test="collectionCycle != null">#{collectionCycle},</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="updateRmTemplateSwitch" parameterType="RmTemplateSwitch">
        update rm_template_switch
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="policyId != null">policy_id = #{policyId},</if>
            <if test="itemType != null and itemType != ''">item_type = #{itemType},</if>
            <if test="metricKey != null and metricKey != ''">metric_key = #{metricKey},</if>
            <if test="metricName != null and metricName != ''">metric_name = #{metricName},</if>
            <if test="oid != null and oid != ''">oid = #{oid},</if>
            <if test="filterValue != null">filter_value = #{filterValue},</if>
            <if test="switchDescription != null">switch_description = #{switchDescription},</if>
            <if test="dataType != null and dataType != ''">data_type = #{dataType},</if>
            <if test="monitorStatus != null">monitor_status = #{monitorStatus},</if>
            <if test="collectionCycle != null">collection_cycle = #{collectionCycle},</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="deleteRmTemplateSwitchById" parameterType="Long">
        delete from rm_template_switch where id = #{id}
    </delete>

    <delete id="deleteRmTemplateSwitchByIds" parameterType="String">
        delete from rm_template_switch where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="batchInsertRmTemplateSwitch" parameterType="list">
        INSERT INTO rm_template_switch
        (
        template_id,
        policy_id,
        item_type,
        metric_key,
        metric_name,
        oid,
        filter_value,
        switch_description,
        data_type,
        monitor_status,
        create_time,
        update_time,
        create_by,
        update_by
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.templateId},
            #{item.policyId},
            #{item.itemType},
            #{item.metricKey},
            #{item.metricName},
            #{item.oid},
            #{item.filterValue},
            #{item.switchDescription},
            #{item.dataType},
            #{item.monitorStatus},
            #{item.createTime},
            #{item.updateTime},
            #{item.createBy},
            #{item.updateBy}
            )
        </foreach>
    </insert>

    <delete id="deleteByTemplateId" parameterType="Long">
        delete from rm_template_switch where template_id = #{templateId}
    </delete>
    <update id="updateByTemplateId" parameterType="RmTemplateLinux">
        update rm_template_switch set collection_cycle = null
        where template_id = #{templateId}
    </update>
    <delete id="deleteByPolicyId" parameterType="Long">
        delete from rm_template_switch where policy_id = #{policyId}
    </delete>
    <update id="updateByPolicyId" parameterType="RmTemplateLinux">
        update rm_template_switch set collection_cycle = null
        where policy_id = #{policyId}
    </update>
</mapper>