| <?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.moral.api.mapper.HistoryMinutelyMapper"> | 
|   | 
|     <update id="createTable" parameterType="String"> | 
|         CREATE TABLE  IF NOT EXISTS `history_minutely_${timeUnits}` ( | 
|             `mac` VARCHAR (30) DEFAULT NULL COMMENT '设备mac', | 
|             `time` datetime DEFAULT NULL COMMENT '数据时间', | 
|             `value` json DEFAULT NULL COMMENT '数据', | 
|             `version` INT (11) DEFAULT NULL COMMENT '型号', | 
|             KEY `idx_mac_time` (`mac`,`time`) | 
|             ) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT '分钟数据表' | 
|     </update> | 
|   | 
|     <select id="getHistoryMinutelyData" resultType="java.util.LinkedHashMap"> | 
|         SELECT | 
|         mac, `value`, version | 
|         FROM | 
|         history_minutely_${timeUnits} | 
|         WHERE `time` <![CDATA[>=]]> #{start} | 
|         AND `time` <![CDATA[<]]> #{end} | 
|         <if test="macs != null"> | 
|             AND mac IN | 
|             <foreach collection="macs" item="mac" open="(" close=")" separator=","> | 
|                 #{mac} | 
|             </foreach> | 
|         </if> | 
|     </select> | 
|   | 
|     <select id="getHistoryMinutelyMacData" resultType="java.lang.String"> | 
|         SELECT | 
|         mac | 
|         FROM | 
|         history_minutely_${timeUnits} | 
|         WHERE `time` <![CDATA[>=]]> #{start} | 
|         AND `time` <![CDATA[<]]> #{end} | 
|         <if test="macs != null"> | 
|             AND mac IN | 
|             <foreach collection="macs" item="mac" open="(" close=")" separator=","> | 
|                 #{mac} | 
|             </foreach> | 
|         </if> | 
|         group by mac | 
|     </select> | 
|   | 
|     <select id="getHourlyData" resultType="java.util.Map"> | 
|         SELECT mac, `time`, `value` | 
|         FROM history_minutely_${timeUnits} | 
|         WHERE `time` <![CDATA[>=]]> #{start} | 
|         AND `time` <![CDATA[<]]> #{end} | 
|     </select> | 
|   | 
| </mapper> |