<?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.ztmap.project.zhny.alarm.mapper.TAlarmMapper">
    
    <resultMap type="TAlarm" id="TAlarmResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="alarmlevel"    column="alarmlevel"    />
        <result property="alarmtype"    column="alarmtype"    />
        <result property="devietype"    column="devietype"    />
        <result property="build"    column="build"    />
        <result property="floor"    column="floor"    />
        <result property="x"    column="x"    />
        <result property="y"    column="y"    />
        <result property="z"    column="z"    />
        <result property="deviceid"    column="deviceid"    />
        <result property="description"    column="description"    />
        <result property="status"    column="status"    />
        <result property="address"    column="address"    />
        <result property="confirmtime"    column="confirmtime"    />
        <result property="imgurl"    column="imgurl"    />
        <result property="atime"    column="atime"    />
        <result property="hanlder"    column="hanlder"    />
        <result property="handtime"    column="handtime"    />
        <result property="comment"    column="comment"    />
        <result property="positiontype"    column="positiontype"    />
        <result property="sortId"    column="sort_id"    />
    </resultMap>

    <sql id="selectTAlarmVo">
        select id, name, alarmlevel, alarmtype, devietype, build, floor, x, y, z, deviceid, description, status, address, confirmtime, imgurl, atime, hanlder, handtime, comment, positiontype, sort_id from t_alarm
    </sql>

    <select id="selectTAlarmList" parameterType="TAlarm" resultMap="TAlarmResult">
        <include refid="selectTAlarmVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="alarmlevel != null "> and alarmlevel = #{alarmlevel}</if>
            <if test="alarmtype != null  and alarmtype != ''"> and alarmtype = #{alarmtype}</if>
            <if test="devietype != null "> and devietype = #{devietype}</if>
            <if test="build != null "> and build = #{build}</if>
            <if test="floor != null "> and floor = #{floor}</if>
            <if test="x != null "> and x = #{x}</if>
            <if test="y != null "> and y = #{y}</if>
            <if test="z != null "> and z = #{z}</if>
            <if test="deviceid != null "> and deviceid = #{deviceid}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="confirmtime != null  and confirmtime != ''"> and confirmtime = #{confirmtime}</if>
            <if test="imgurl != null  and imgurl != ''"> and imgurl = #{imgurl}</if>
            <if test="atime != null  and atime != ''"> and atime = #{atime}</if>
            <if test="hanlder != null  and hanlder != ''"> and hanlder = #{hanlder}</if>
            <if test="handtime != null  and handtime != ''"> and handtime = #{handtime}</if>
            <if test="comment != null  and comment != ''"> and comment = #{comment}</if>
            <if test="positiontype != null "> and positiontype = #{positiontype}</if>
            <if test="sortId != null "> and sort_id = #{sortId}</if>
        </where>
    </select>
    
    <select id="selectTAlarmById" parameterType="Long" resultMap="TAlarmResult">
        <include refid="selectTAlarmVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTAlarm" parameterType="TAlarm" useGeneratedKeys="true" keyProperty="id">
        insert into t_alarm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="alarmlevel != null">alarmlevel,</if>
            <if test="alarmtype != null">alarmtype,</if>
            <if test="devietype != null">devietype,</if>
            <if test="build != null">build,</if>
            <if test="floor != null">floor,</if>
            <if test="x != null">x,</if>
            <if test="y != null">y,</if>
            <if test="z != null">z,</if>
            <if test="deviceid != null">deviceid,</if>
            <if test="description != null">description,</if>
            <if test="status != null">status,</if>
            <if test="address != null">address,</if>
            <if test="confirmtime != null">confirmtime,</if>
            <if test="imgurl != null">imgurl,</if>
            <if test="atime != null">atime,</if>
            <if test="hanlder != null">hanlder,</if>
            <if test="handtime != null">handtime,</if>
            <if test="comment != null">comment,</if>
            <if test="positiontype != null">positiontype,</if>
            <if test="sortId != null">sort_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="alarmlevel != null">#{alarmlevel},</if>
            <if test="alarmtype != null">#{alarmtype},</if>
            <if test="devietype != null">#{devietype},</if>
            <if test="build != null">#{build},</if>
            <if test="floor != null">#{floor},</if>
            <if test="x != null">#{x},</if>
            <if test="y != null">#{y},</if>
            <if test="z != null">#{z},</if>
            <if test="deviceid != null">#{deviceid},</if>
            <if test="description != null">#{description},</if>
            <if test="status != null">#{status},</if>
            <if test="address != null">#{address},</if>
            <if test="confirmtime != null">#{confirmtime},</if>
            <if test="imgurl != null">#{imgurl},</if>
            <if test="atime != null">#{atime},</if>
            <if test="hanlder != null">#{hanlder},</if>
            <if test="handtime != null">#{handtime},</if>
            <if test="comment != null">#{comment},</if>
            <if test="positiontype != null">#{positiontype},</if>
            <if test="sortId != null">#{sortId},</if>
         </trim>
    </insert>

    <update id="updateTAlarm" parameterType="TAlarm">
        update t_alarm
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="alarmlevel != null">alarmlevel = #{alarmlevel},</if>
            <if test="alarmtype != null">alarmtype = #{alarmtype},</if>
            <if test="devietype != null">devietype = #{devietype},</if>
            <if test="build != null">build = #{build},</if>
            <if test="floor != null">floor = #{floor},</if>
            <if test="x != null">x = #{x},</if>
            <if test="y != null">y = #{y},</if>
            <if test="z != null">z = #{z},</if>
            <if test="deviceid != null">deviceid = #{deviceid},</if>
            <if test="description != null">description = #{description},</if>
            <if test="status != null">status = #{status},</if>
            <if test="address != null">address = #{address},</if>
            <if test="confirmtime != null">confirmtime = #{confirmtime},</if>
            <if test="imgurl != null">imgurl = #{imgurl},</if>
            <if test="atime != null">atime = #{atime},</if>
            <if test="hanlder != null">hanlder = #{hanlder},</if>
            <if test="handtime != null">handtime = #{handtime},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="positiontype != null">positiontype = #{positiontype},</if>
            <if test="sortId != null">sort_id = #{sortId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTAlarmById" parameterType="Long">
        delete from t_alarm where id = #{id}
    </delete>

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

</mapper>