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

    <resultMap type="EmsAlarmMatchData" id="EmsAlarmMatchDataResult">
        <result property="id"    column="id"    />
        <result property="point"    column="point"    />
        <result property="alarmData"    column="alarm_data"    />
        <result property="alarmDescription"    column="alarm_description"    />
        <result property="siteId"    column="site_id"    />
        <result property="deviceCategory"    column="device_category"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectEmsAlarmMatchDataVo">
        select id, point, alarm_data, alarm_description, site_id, device_category, create_by, create_time, update_by, update_time, remark from ems_alarm_match_data
    </sql>

    <select id="selectEmsAlarmMatchDataList" parameterType="EmsAlarmMatchData" resultMap="EmsAlarmMatchDataResult">
        <include refid="selectEmsAlarmMatchDataVo"/>
        <where>
            <if test="point != null  and point != ''"> and point = #{point}</if>
            <if test="alarmData != null "> and alarm_data = #{alarmData}</if>
            <if test="alarmDescription != null  and alarmDescription != ''"> and alarm_description = #{alarmDescription}</if>
            <if test="siteId != null  and siteId != ''"> and site_id = #{siteId}</if>
            <if test="deviceCategory != null  and deviceCategory != ''"> and device_category = #{deviceCategory}</if>
        </where>
    </select>

    <select id="selectEmsAlarmMatchDataById" parameterType="Long" resultMap="EmsAlarmMatchDataResult">
        <include refid="selectEmsAlarmMatchDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmsAlarmMatchData" parameterType="EmsAlarmMatchData" useGeneratedKeys="true" keyProperty="id">
        insert into ems_alarm_match_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="point != null">point,</if>
            <if test="alarmData != null">alarm_data,</if>
            <if test="alarmDescription != null">alarm_description,</if>
            <if test="siteId != null">site_id,</if>
            <if test="deviceCategory != null">device_category,</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>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="point != null">#{point},</if>
            <if test="alarmData != null">#{alarmData},</if>
            <if test="alarmDescription != null">#{alarmDescription},</if>
            <if test="siteId != null">#{siteId},</if>
            <if test="deviceCategory != null">#{deviceCategory},</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>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateEmsAlarmMatchData" parameterType="EmsAlarmMatchData">
        update ems_alarm_match_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="point != null">point = #{point},</if>
            <if test="alarmData != null">alarm_data = #{alarmData},</if>
            <if test="alarmDescription != null">alarm_description = #{alarmDescription},</if>
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="deviceCategory != null">device_category = #{deviceCategory},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsAlarmMatchDataById" parameterType="Long">
        delete from ems_alarm_match_data where id = #{id}
    </delete>

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

    <select id="getAllMatchInfo"  resultType="java.util.Map">
        select point,alarm_description as description from ems_alarm_match_data GROUP BY point,alarm_description
    </select>
</mapper>