<?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.AlarmStatisticsMapper">

    <insert id="insertIntoStatisticsFromDay" parameterType="uml.tech.bigdata.bean.AlarmStatisticsBean">
        replace
        into agri_alarm_statistics
        select did, vin, `level`, count(1) as level_count, ${month} as month
        from (
        <foreach collection="list" index="index" separator="UNION" item="item">
            select * from ${item}
        </foreach>
        ) t
        group by did, vin, `level`, `month`
    </insert>

    <select id="checkTableExist" resultType="java.lang.String">
        select TABLE_NAME
        from INFORMATION_SCHEMA.TABLES
        where TABLE_SCHEMA = 'bigdata'
          and TABLE_NAME = #{tb_name};
    </select>

    <update id="delOldData" parameterType="string">
        delete
        from agri_alarm_statistics
        where `month` = #{month}
    </update>
</mapper>