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

    <sql id="sysAlarmColumns">
        a.object_id as "objectId",

        a.mac_id as "macId",

        a.full_name as "fullName",

        a.mac_name as "macName",

        a.alarmime as "alarmime",

        a.addtime as "addtime",

        a.speed as "speed",

        a.lat as "lat",

        a.lon as "lon",

        a.dir as "dir",

        a.describe as "describe",

        a.alarm_type as "alarmType",

        a.classify as "classify",

        a.status as "status",

        a.remark as "remark",

        a.id as "id",

        a.create_by as "createBy",

        a.create_dept as "createDept",

        a.create_time as "createTime",

        a.update_by as "updateBy",

        a.update_time as "updateTime",

        a.update_ip as "updateIp",

        a.version as "version",

        a.del_flag as "delFlag"

    </sql>

    <sql id="sysAlarmJoins">
    </sql>

    <select id="get" resultType="SysAlarm">
        SELECT
            <include refid="sysAlarmColumns"/>
        FROM sys_alarm a
        <include refid="sysAlarmJoins"/>
        WHERE a.id = #{id}
    </select>

    <select id="findList" resultType="SysAlarm">
        SELECT
            <include refid="sysAlarmColumns"/>
        FROM sys_alarm a
        <include refid="sysAlarmJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="objectId != null and objectId != ''">
                AND a.object_id = #{objectId}
            </if>
            <if test="macId != null and macId != ''">
                AND a.mac_id = #{macId}
            </if>
            <if test="fullName != null and fullName != ''">
                and a.full_name like concat('%', #{fullName}, '%')
            </if>
            <if test="macName != null and macName != ''">
                and a.mac_name like concat('%', #{macName}, '%')
            </if>
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
            </otherwise>
        </choose>
    </select>

    <select id="findListWithUnique" resultType="SysAlarm">
        SELECT
            a.id
        FROM sys_alarm a
        <include refid="sysAlarmJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="notEqualId != null and notEqualId != ''">
                AND id != #{notEqualId}
            </if>
        </where>
    </select>


    <insert id="insert">
        INSERT INTO sys_alarm(

            object_id,

            mac_id,

            full_name,

            mac_name,

            alarmime,

            addtime,

            speed,

            lat,

            lon,

            dir,

            `describe`,

            alarm_type,

            classify,

            `status`,

            remark,

            id,

            create_by,

            create_dept,

            create_time,

            update_by,

            update_time,

            update_ip,

            version,

            del_flag

        ) VALUES (

            #{objectId},

            #{macId},

            #{fullName},

            #{macName},

            #{alarmime},

            #{addtime},

            #{speed},

            #{lat},

            #{lon},

            #{dir},

            #{describe},

            #{alarmType},

            #{classify},

            #{status},

            #{remark},

            #{id},

            #{createBy},

            #{createDept},

            #{createTime},

            #{updateBy},

            #{updateTime},

            #{updateIp},

            #{version},

            #{delFlag}

        )
    </insert>

    <update id="update">
        UPDATE sys_alarm SET
            object_id = #{objectId},
            mac_id = #{macId},
            full_name = #{fullName},
            mac_name = #{macName},
            alarmime = #{alarmime},
            addtime = #{addtime},
            speed = #{speed},
            lat = #{lat},
            lon = #{lon},
            dir = #{dir},
            `describe` = #{describe},
            alarm_type = #{alarmType},
            classify = #{classify},
            `status` = #{status},
            remark = #{remark},
            update_by = #{updateBy},
            update_time = #{updateTime},
            update_ip = #{updateIp},
            version = version + 1
        WHERE id = #{id} and version = #{version}
    </update>

    <update id="updateStatus">
        UPDATE sys_alarm SET
            status = #{status},
            version = version + 1
        WHERE id = #{id}
    </update>

    <update id="delete">
        UPDATE sys_alarm SET
            del_flag = #{DEL_FLAG_DELETE}
        WHERE id = #{id}
    </update>

    <delete id="deleteSysAlarmByIds">
        UPDATE sys_alarm SET
            del_flag = #{DEL_FLAG_DELETE}
        WHERE id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
