<?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.mtragent.mapper.RmMtrPolicyConfigMapper">

    <resultMap type="RmMtrPolicyConfig" id="RmMtrPolicyConfigResult">
        <result property="id"    column="id"    />
        <result property="policyName"    column="policy_name"    />
        <result property="priority"    column="priority"    />
        <result property="mtrClientId"    column="mtr_client_id"    />
        <result property="serverGroup"    column="server_group"    />
        <result property="serveripGroup"    column="serverip_group"    />
        <result property="probeFlag"    column="probe_flag"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="probeFrequency"    column="probe_frequency"    />
        <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="selectRmMtrPolicyConfigVo">
        select id, policy_name, priority, mtr_client_id, server_group, serverip_group, probe_flag, start_time, end_time, probe_frequency, create_time, update_time, create_by, update_by from rm_mtr_policy_config
    </sql>

    <select id="selectRmMtrPolicyConfigList" parameterType="RmMtrPolicyConfig" resultMap="RmMtrPolicyConfigResult">
        <include refid="selectRmMtrPolicyConfigVo"/>
        <where>
            <if test="policyName != null  and policyName != ''"> and policy_name like concat('%', #{policyName}, '%')</if>
            <if test="priority != null "> and priority = #{priority}</if>
            <if test="mtrClientId != null  and mtrClientId != ''"> and mtr_client_id = #{mtrClientId}</if>
            <if test="serverGroup != null  and serverGroup != ''"> and server_group = #{serverGroup}</if>
            <if test="serveripGroup != null  and serveripGroup != ''"> and serverip_group = #{serveripGroup}</if>
            <if test="probeFlag != null "> and probe_flag = #{probeFlag}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="probeFrequency != null "> and probe_frequency = #{probeFrequency}</if>
        </where>
    </select>

    <select id="selectRmMtrPolicyConfigById" parameterType="Long" resultMap="RmMtrPolicyConfigResult">
        <include refid="selectRmMtrPolicyConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmMtrPolicyConfig" parameterType="RmMtrPolicyConfig" useGeneratedKeys="true" keyProperty="id">
        insert into rm_mtr_policy_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="policyName != null and policyName != ''">policy_name,</if>
            <if test="priority != null">priority,</if>
            <if test="mtrClientId != null and mtrClientId != ''">mtr_client_id,</if>
            <if test="serverGroup != null">server_group,</if>
            <if test="serveripGroup != null">serverip_group,</if>
            <if test="probeFlag != null">probe_flag,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="probeFrequency != null">probe_frequency,</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="policyName != null and policyName != ''">#{policyName},</if>
            <if test="priority != null">#{priority},</if>
            <if test="mtrClientId != null and mtrClientId != ''">#{mtrClientId},</if>
            <if test="serverGroup != null">#{serverGroup},</if>
            <if test="serveripGroup != null">#{serveripGroup},</if>
            <if test="probeFlag != null">#{probeFlag},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="probeFrequency != null">#{probeFrequency},</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="updateRmMtrPolicyConfig" parameterType="RmMtrPolicyConfig">
        update rm_mtr_policy_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="policyName != null and policyName != ''">policy_name = #{policyName},</if>
            <if test="priority != null">priority = #{priority},</if>
            <if test="mtrClientId != null and mtrClientId != ''">mtr_client_id = #{mtrClientId},</if>
            <if test="serverGroup != null">server_group = #{serverGroup},</if>
            <if test="serveripGroup != null">serverip_group = #{serveripGroup},</if>
            <if test="probeFlag != null">probe_flag = #{probeFlag},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="probeFrequency != null">probe_frequency = #{probeFrequency},</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="deleteRmMtrPolicyConfigById" parameterType="Long">
        delete from rm_mtr_policy_config where id = #{id}
    </delete>

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