<?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.xzzn.ems.mapper.EmsFaultProtectionPlanMapper">

    <resultMap type="EmsFaultProtectionPlan" id="EmsFaultProtectionPlanResult">
        <result property="id"    column="id"    />
        <result property="siteId"    column="site_id"    />
        <result property="faultName"    column="fault_name"    />
        <result property="faultLevel"    column="fault_level"    />
        <result property="protectionSettings"    column="protection_settings"    />
        <result property="faultDelaySeconds"    column="fault_delay_seconds"    />
        <result property="protectionPlan"    column="protection_plan"    />
        <result property="releaseDelaySeconds"    column="release_delay_seconds"    />
        <result property="description"    column="description"    />
        <result property="isAlert"    column="is_alert"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectEmsFaultProtectionPlanVo">
        select id, site_id, fault_name, fault_level, protection_settings, fault_delay_seconds, protection_plan, release_delay_seconds, description, is_alert, status, create_by, create_time, update_by, update_time from ems_fault_protection_plan
    </sql>

    <select id="selectEmsFaultProtectionPlanList" parameterType="EmsFaultProtectionPlan" resultMap="EmsFaultProtectionPlanResult">
        <include refid="selectEmsFaultProtectionPlanVo"/>
        <where>
            <if test="siteId != null  and siteId != ''"> and site_id = #{siteId}</if>
            <if test="faultName != null  and faultName != ''"> and fault_name like concat('%', #{faultName}, '%')</if>
            <if test="faultLevel != null "> and fault_level = #{faultLevel}</if>
            <if test="protectionSettings != null  and protectionSettings != ''"> and protection_settings = #{protectionSettings}</if>
            <if test="faultDelaySeconds != null "> and fault_delay_seconds = #{faultDelaySeconds}</if>
            <if test="protectionPlan != null  and protectionPlan != ''"> and protection_plan = #{protectionPlan}</if>
            <if test="releaseDelaySeconds != null "> and release_delay_seconds = #{releaseDelaySeconds}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="isAlert != null "> and is_alert = #{isAlert}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectEmsFaultProtectionPlanById" parameterType="Long" resultMap="EmsFaultProtectionPlanResult">
        <include refid="selectEmsFaultProtectionPlanVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmsFaultProtectionPlan" parameterType="EmsFaultProtectionPlan" useGeneratedKeys="true" keyProperty="id">
        insert into ems_fault_protection_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="siteId != null">site_id,</if>
            <if test="faultName != null and faultName != ''">fault_name,</if>
            <if test="faultLevel != null">fault_level,</if>
            <if test="protectionSettings != null">protection_settings,</if>
            <if test="faultDelaySeconds != null">fault_delay_seconds,</if>
            <if test="protectionPlan != null">protection_plan,</if>
            <if test="releaseDelaySeconds != null">release_delay_seconds,</if>
            <if test="description != null">description,</if>
            <if test="isAlert != null">is_alert,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="siteId != null">#{siteId},</if>
            <if test="faultName != null and faultName != ''">#{faultName},</if>
            <if test="faultLevel != null">#{faultLevel},</if>
            <if test="protectionSettings != null">#{protectionSettings},</if>
            <if test="faultDelaySeconds != null">#{faultDelaySeconds},</if>
            <if test="protectionPlan != null">#{protectionPlan},</if>
            <if test="releaseDelaySeconds != null">#{releaseDelaySeconds},</if>
            <if test="description != null">#{description},</if>
            <if test="isAlert != null">#{isAlert},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateEmsFaultProtectionPlan" parameterType="EmsFaultProtectionPlan">
        update ems_fault_protection_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="faultName != null and faultName != ''">fault_name = #{faultName},</if>
            <if test="faultLevel != null">fault_level = #{faultLevel},</if>
            <if test="protectionSettings != null">protection_settings = #{protectionSettings},</if>
            <if test="faultDelaySeconds != null">fault_delay_seconds = #{faultDelaySeconds},</if>
            <if test="protectionPlan != null">protection_plan = #{protectionPlan},</if>
            <if test="releaseDelaySeconds != null">release_delay_seconds = #{releaseDelaySeconds},</if>
            <if test="description != null">description = #{description},</if>
            <if test="isAlert != null">is_alert = #{isAlert},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsFaultProtectionPlanById" parameterType="Long">
        delete from ems_fault_protection_plan where id = #{id}
    </delete>

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

    <delete id="deleteEmsFaultProtectionPlan">
        delete from ems_fault_protection_plan
        where site_id = #{siteId}
        and fault_name = #{faultName}
        and fault_level = #{faultLevel}
    </delete>
</mapper>