<?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.system.mapper.RmMonitorConfigMapper">

    <resultMap type="RmMonitorConfig" id="RmMonitorConfigResult">
        <result property="id"    column="id"    />
        <result property="configName"    column="config_name"    />
        <result property="monitorStartTime"    column="monitor_start_time"    />
        <result property="resourceType"    column="resource_type"    />
        <result property="businessCode"    column="business_code"    />
        <result property="businessName"    column="business_name"    />
        <result property="deployDevice"    column="deploy_device"    />
        <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="selectRmMonitorConfigVo">
        select id, config_name, monitor_start_time, resource_type, business_code, business_name, deploy_device, create_time, update_time, create_by, update_by from rm_monitor_config
    </sql>

    <select id="selectRmMonitorConfigList" parameterType="RmMonitorConfig" resultMap="RmMonitorConfigResult">
        <include refid="selectRmMonitorConfigVo"/>
        <where>
            <if test="configName != null  and configName != ''"> and config_name = #{configName}</if>
            <if test="monitorStartTime != null  and monitorStartTime != ''"> and monitor_start_time = #{monitorStartTime}</if>
            <if test="resourceType != null  and resourceType != ''"> and resource_type = #{resourceType}</if>
            <if test="businessCode != null  and businessCode != ''"> and business_code = #{businessCode}</if>
            <if test="businessName != null  and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
            <if test="deployDevice != null  and deployDevice != ''"> and deploy_device = #{deployDevice}</if>
        </where>
    </select>

    <select id="selectRmMonitorConfigById" parameterType="Long" resultMap="RmMonitorConfigResult">
        <include refid="selectRmMonitorConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmMonitorConfig" parameterType="RmMonitorConfig" useGeneratedKeys="true" keyProperty="id">
        insert into rm_monitor_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="configName != null and configName != ''">config_name,</if>
            <if test="monitorStartTime != null and monitorStartTime != ''">monitor_start_time,</if>
            <if test="resourceType != null and resourceType != ''">resource_type,</if>
            <if test="businessCode != null">business_code,</if>
            <if test="businessName != null">business_name,</if>
            <if test="deployDevice != null and deployDevice != ''">deploy_device,</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="configName != null and configName != ''">#{configName},</if>
            <if test="monitorStartTime != null and monitorStartTime != ''">#{monitorStartTime},</if>
            <if test="resourceType != null and resourceType != ''">#{resourceType},</if>
            <if test="businessCode != null">#{businessCode},</if>
            <if test="businessName != null">#{businessName},</if>
            <if test="deployDevice != null and deployDevice != ''">#{deployDevice},</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="updateRmMonitorConfig" parameterType="RmMonitorConfig">
        update rm_monitor_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="configName != null and configName != ''">config_name = #{configName},</if>
            <if test="monitorStartTime != null and monitorStartTime != ''">monitor_start_time = #{monitorStartTime},</if>
            <if test="resourceType != null and resourceType != ''">resource_type = #{resourceType},</if>
            <if test="businessCode != null">business_code = #{businessCode},</if>
            <if test="businessName != null">business_name = #{businessName},</if>
            <if test="deployDevice != null and deployDevice != ''">deploy_device = #{deployDevice},</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="deleteRmMonitorConfigById" parameterType="Long">
        delete from rm_monitor_config where id = #{id}
    </delete>

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