<?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.pm.waring.mapper.IbmsDeviceAlarmMapper">

    <resultMap type="pd" id="IbmsDeviceAlarmResult">
        <result property="id"    column="id"    />
        <result property="alarmCode"    column="alarm_code"    />
        <result property="deviceId"    column="device_id"    />
        <result property="pointId"    column="point_id"    />
        <result property="alarmLevel"    column="alarm_level"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="alarmTitle"    column="alarm_title"    />
        <result property="alarmContent"    column="alarm_content"    />
        <result property="triggerValue"    column="trigger_value"    />
        <result property="normalValue"    column="normal_value"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="duration"    column="duration"    />
        <result property="status"    column="status"    />
        <result property="handlerId"    column="handler_id"    />
        <result property="handlerName"    column="handler_name"    />
        <result property="handleTime"    column="handle_time"    />
        <result property="handleMethod"    column="handle_method"    />
        <result property="serviceOrderId"    column="service_order_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectIbmsDeviceAlarmVo">
        select id, alarm_code, device_id, point_id, alarm_level, alarm_type, alarm_title, alarm_content, trigger_value, normal_value, start_time, end_time, duration, status, handler_id, handler_name, handle_time, handle_method, service_order_id, create_time, update_time from ibms_device_alarm
    </sql>

    <select id="selectIbmsDeviceAlarmList" parameterType="pd" resultMap="IbmsDeviceAlarmResult">
        <include refid="selectIbmsDeviceAlarmVo"/>
        <where>
            <if test="alarmCode != null and alarmCode != ''"> and alarm_code = #{alarmCode}</if>
            <if test="alarmLevel != null and alarmLevel != ''"> and alarm_level = #{alarmLevel}</if>
            <if test="alarmType != null and alarmType != ''"> and alarm_type = #{alarmType}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectIbmsDeviceAlarmById" parameterType="pd" resultMap="IbmsDeviceAlarmResult">
        <include refid="selectIbmsDeviceAlarmVo"/>
        where id = #{id}
    </select>

    <insert id="insertIbmsDeviceAlarm" parameterType="pd" useGeneratedKeys="true" keyProperty="id">
        insert into ibms_device_alarm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="alarmCode != null and alarmCode != ''">alarm_code,</if>
            <if test="deviceId != null and deviceId != ''">device_id,</if>
            <if test="pointId != null and pointId != ''">point_id,</if>
            <if test="alarmLevel != null and alarmLevel != ''">alarm_level,</if>
            <if test="alarmType != null and alarmType != ''">alarm_type,</if>
            <if test="alarmTitle != null and alarmTitle != ''">alarm_title,</if>
            <if test="alarmContent != null and alarmContent != ''">alarm_content,</if>
            <if test="triggerValue != null and triggerValue != ''">trigger_value,</if>
            <if test="normalValue != null and normalValue != ''">normal_value,</if>
            <if test="startTime != null and startTime != ''">start_time,</if>
            <if test="endTime != null and endTime != ''">end_time,</if>
            <if test="duration != null and duration != ''">duration,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="handlerId != null and handlerId != ''">handler_id,</if>
            <if test="handlerName != null and handlerName != ''">handler_name,</if>
            <if test="handleTime != null and handleTime != ''">handle_time,</if>
            <if test="handleMethod != null and handleMethod != ''">handle_method,</if>
            <if test="serviceOrderId != null and serviceOrderId != ''">service_order_id,</if>
            <if test="createTime != null and createTime != ''">create_time,</if>
            <if test="updateTime != null and updateTime != ''">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="alarmCode != null and alarmCode != ''">#{alarmCode},</if>
            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
            <if test="pointId != null and pointId != ''">#{pointId},</if>
            <if test="alarmLevel != null and alarmLevel != ''">#{alarmLevel},</if>
            <if test="alarmType != null and alarmType != ''">#{alarmType},</if>
            <if test="alarmTitle != null and alarmTitle != ''">#{alarmTitle},</if>
            <if test="alarmContent != null and alarmContent != ''">#{alarmContent},</if>
            <if test="triggerValue != null and triggerValue != ''">#{triggerValue},</if>
            <if test="normalValue != null and normalValue != ''">#{normalValue},</if>
            <if test="startTime != null and startTime != ''">#{startTime},</if>
            <if test="endTime != null and endTime != ''">#{endTime},</if>
            <if test="duration != null and duration != ''">#{duration},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="handlerId != null and handlerId != ''">#{handlerId},</if>
            <if test="handlerName != null and handlerName != ''">#{handlerName},</if>
            <if test="handleTime != null and handleTime != ''">#{handleTime},</if>
            <if test="handleMethod != null and handleMethod != ''">#{handleMethod},</if>
            <if test="serviceOrderId != null and serviceOrderId != ''">#{serviceOrderId},</if>
            <if test="createTime != null and createTime != ''">#{createTime},</if>
            <if test="updateTime != null and updateTime != ''">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateIbmsDeviceAlarm" parameterType="pd">
        update ibms_device_alarm
        <trim prefix="SET" suffixOverrides=",">
            <if test="alarmCode != null and alarmCode != ''">alarm_code = #{alarmCode},</if>
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
            <if test="pointId != null and pointId != ''">point_id = #{pointId},</if>
            <if test="alarmLevel != null and alarmLevel != ''">alarm_level = #{alarmLevel},</if>
            <if test="alarmType != null and alarmType != ''">alarm_type = #{alarmType},</if>
            <if test="alarmTitle != null and alarmTitle != ''">alarm_title = #{alarmTitle},</if>
            <if test="alarmContent != null and alarmContent != ''">alarm_content = #{alarmContent},</if>
            <if test="triggerValue != null and triggerValue != ''">trigger_value = #{triggerValue},</if>
            <if test="normalValue != null and normalValue != ''">normal_value = #{normalValue},</if>
            <if test="startTime != null and startTime != ''">start_time = #{startTime},</if>
            <if test="endTime != null and endTime != ''">end_time = #{endTime},</if>
            <if test="duration != null and duration != ''">duration = #{duration},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="handlerId != null and handlerId != ''">handler_id = #{handlerId},</if>
            <if test="handlerName != null and handlerName != ''">handler_name = #{handlerName},</if>
            <if test="handleTime != null and handleTime != ''">handle_time = #{handleTime},</if>
            <if test="handleMethod != null and handleMethod != ''">handle_method = #{handleMethod},</if>
            <if test="serviceOrderId != null and serviceOrderId != ''">service_order_id = #{serviceOrderId},</if>
            <if test="createTime != null and createTime != ''">create_time = #{createTime},</if>
            <if test="updateTime != null and updateTime != ''">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIbmsDeviceAlarmById" parameterType="Long">
        delete from ibms_device_alarm where id = #{id}
    </delete>

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