<?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="uml.tech.bigdata.mapper.FenceAlarmMapper">

    <insert id="insertBatchIntoFenceAlarm" parameterType="uml.tech.bigdata.domain.FenceAlarmEntity">
        insert into tb_fence_alarm(id,
        fence_id,did,vehicle_id,last_alarm_type,last_alarm_happen_time,last_alarm_lon,last_alarm_lat)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id},
            #{item.fenceId},
            #{item.did},
            #{item.vehicleId},
            #{item.lastAlarmType},
            #{item.lastAlarmHappenTime},
            #{item.lastAlarmLon},
            #{item.lastAlarmLat}
            )
        </foreach>
    </insert>

    <select id="selectLastAlarmTypeByDid" resultType="integer">
        select last_alarm_type
        from tb_fence_alarm
        where did = #{did}
          and fence_id = #{fenceId}
        order by last_alarm_happen_time desc limit 1
    </select>


</mapper>