<?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.uml.tech.mapper.AlarmMapper" >

    <select id="selectAll" resultType="com.uml.tech.bean.Alarm">
        select did,code,level,name,total,firstTime,lastTime,lastAddress,lastLon,lastLat from ${tb_name};
    </select>

    <insert id="insertDayFromList">
        replace into ${tb_name} (did,code,level,name,total,firstTime,lastTime,lastAddress,lastLon,lastLat,alarmList,updateTime)
        values
        <foreach collection="list" item="item" index="index" separator="," >
            (#{item.did},#{item.code},#{item.level},#{item.name},#{item.total},#{item.firstTime},#{item.lastTime},#{item.lastAddress},#{item.lastLon},#{item.lastLat},#{item.alarmList},NOW())
        </foreach>
    </insert>

    <insert id="insertAlarmFromList">
        replace into ${tb_name} (did,code,level,name,total,firstTime,lastTime,lastAddress,lastLon,lastLat)
        values
        <foreach collection="list" item="item" index="index" separator="," >
            (#{item.did},#{item.code},#{item.level},#{item.name},#{item.total},#{item.firstTime},#{item.lastTime},#{item.lastAddress},#{item.lastLon},#{item.lastLat})
        </foreach>
    </insert>

    <insert id="insertDayCarAlarmFromList">
        replace into ${tb_name} (did,total,lastTime,lastAddress,lastLon,lastLat,alarmList,updateTime)
        values
        <foreach collection="list" item="item" index="index" separator="," >
            (#{item.did},#{item.total},#{item.lastTime},#{item.lastAddress},#{item.lastLon},#{item.lastLat},#{item.alarmList},NOW())
        </foreach>
    </insert>
    <insert id="insertCarAlarmFromList">
        replace into ${tb_name} (did,total,lastTime,lastAddress,lastLon,lastLat)
        values
        <foreach collection="list" item="item" index="index" separator="," >
            (#{item.did},#{item.total},#{item.lastTime},#{item.lastAddress},#{item.lastLon},#{item.lastLat})
        </foreach>
    </insert>

    <select id="checkTnameExist" resultType="string">
        select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='bigdata' and TABLE_NAME= #{tb_name};
    </select>

    <select id="selectTableName" resultType="java.lang.String">
        select * from (select table_name from information_schema.tables where table_schema = 'bigdata' and table_type = 'base table') temp
        where table_name like #{regex}
    </select>
    <select id="selectCarAll" resultType="com.uml.tech.bean.Alarm">
        select did,total,lastTime,lastAddress,lastLon,lastLat from ${tb_name};
    </select>
</mapper>