<?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.system.mapper.MtmMonitoringTemplateMapper">
    
    <resultMap type="MtmMonitoringTemplate" id="MtmMonitoringTemplateResult">
        <result property="id"    column="id"    />
        <result property="templateName"    column="template_name"    />
        <result property="description"    column="description"    />
        <result property="itemType"    column="item_type"    />
        <result property="includedResources"    column="included_resources"    />
        <result property="discoveryItemType"    column="discovery_item_type"    />
        <result property="itemName"    column="item_name"    />
        <result property="itemDescription"    column="item_description"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="creatorId"    column="creator_id"    />
        <result property="creatorName"    column="creator_name"    />
        <result property="updaterId"    column="updater_id"    />
        <result property="updaterName"    column="updater_name"    />
    </resultMap>

    <sql id="selectMtmMonitoringTemplateVo">
        select id, template_name, description, item_type, included_resources, discovery_item_type, item_name, item_description, create_time, update_time, creator_id, creator_name, updater_id, updater_name from mtm_monitoring_template
    </sql>

    <select id="selectMtmMonitoringTemplateList" parameterType="MtmMonitoringTemplate" resultMap="MtmMonitoringTemplateResult">
        <include refid="selectMtmMonitoringTemplateVo"/>
        <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="itemType != null  and itemType != ''"> and item_type = #{itemType}</if>
            <if test="includedResources != null  and includedResources != ''"> and included_resources = #{includedResources}</if>
            <if test="discoveryItemType != null  and discoveryItemType != ''"> and discovery_item_type = #{discoveryItemType}</if>
            <if test="itemName != null  and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
            <if test="itemDescription != null  and itemDescription != ''"> and item_description = #{itemDescription}</if>
            <if test="creatorId != null "> and creator_id = #{creatorId}</if>
            <if test="creatorName != null  and creatorName != ''"> and creator_name like concat('%', #{creatorName}, '%')</if>
            <if test="updaterId != null "> and updater_id = #{updaterId}</if>
            <if test="updaterName != null  and updaterName != ''"> and updater_name like concat('%', #{updaterName}, '%')</if>
        </where>
    </select>
    
    <select id="selectMtmMonitoringTemplateById" parameterType="Long" resultMap="MtmMonitoringTemplateResult">
        <include refid="selectMtmMonitoringTemplateVo"/>
        where id = #{id}
    </select>

    <insert id="insertMtmMonitoringTemplate" parameterType="MtmMonitoringTemplate" useGeneratedKeys="true" keyProperty="id">
        insert into mtm_monitoring_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateName != null">template_name,</if>
            <if test="description != null">description,</if>
            <if test="itemType != null">item_type,</if>
            <if test="includedResources != null">included_resources,</if>
            <if test="discoveryItemType != null">discovery_item_type,</if>
            <if test="itemName != null">item_name,</if>
            <if test="itemDescription != null">item_description,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="creatorId != null">creator_id,</if>
            <if test="creatorName != null">creator_name,</if>
            <if test="updaterId != null">updater_id,</if>
            <if test="updaterName != null">updater_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="templateName != null">#{templateName},</if>
            <if test="description != null">#{description},</if>
            <if test="itemType != null">#{itemType},</if>
            <if test="includedResources != null">#{includedResources},</if>
            <if test="discoveryItemType != null">#{discoveryItemType},</if>
            <if test="itemName != null">#{itemName},</if>
            <if test="itemDescription != null">#{itemDescription},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="creatorId != null">#{creatorId},</if>
            <if test="creatorName != null">#{creatorName},</if>
            <if test="updaterId != null">#{updaterId},</if>
            <if test="updaterName != null">#{updaterName},</if>
         </trim>
    </insert>

    <update id="updateMtmMonitoringTemplate" parameterType="MtmMonitoringTemplate">
        update mtm_monitoring_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateName != null">template_name = #{templateName},</if>
            <if test="description != null">description = #{description},</if>
            <if test="itemType != null">item_type = #{itemType},</if>
            <if test="includedResources != null">included_resources = #{includedResources},</if>
            <if test="discoveryItemType != null">discovery_item_type = #{discoveryItemType},</if>
            <if test="itemName != null">item_name = #{itemName},</if>
            <if test="itemDescription != null">item_description = #{itemDescription},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="creatorId != null">creator_id = #{creatorId},</if>
            <if test="creatorName != null">creator_name = #{creatorName},</if>
            <if test="updaterId != null">updater_id = #{updaterId},</if>
            <if test="updaterName != null">updater_name = #{updaterName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMtmMonitoringTemplateById" parameterType="Long">
        delete from mtm_monitoring_template where id = #{id}
    </delete>

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