kaiyu
2020-12-21 78380a1efa78bd88f5d1be502971eae6fef07cd0
src/main/resources/mapper/HistoryFiveMinutelyMapper.xml
@@ -2,11 +2,49 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.moral.mapper.HistoryFiveMinutelyMapper">
    <select id="getFiveMinutesDataByMacsAndTime" resultType="map">
        SELECT h.mac,json->'$.${sensorKey}' as #{sensorKey}
        SELECT h.mac,h.time,json->'$.${sensorKey}' as #{sensorKey}
        from history_five_minutely_${yearAndMonth} h
        where time = #{time} and mac IN
        <foreach collection="macs" separator="," open="(" close=")" item="mac">
            #{mac}
        </foreach>
    </select>
    <select id="getFiveMinutesDataByMac" resultType="java.util.LinkedHashMap">
        select
        <foreach collection="sensorKeys" separator="," item="sensorKey">
          json->'$.${sensorKey}' AS '${sensorKey}'
        </foreach>
        FROM
        history_five_minutely_${yearAndMonth} h
        where  h.time = #{time}
        and h.mac = #{mac}
    </select>
    <select id="getFiveMinutesSersorDataByMacsAndTime" resultType="map">
        SELECT h.mac,h.time,
        <foreach collection="sensorKeys" separator="," item="sensorKey">
            json->'$.${sensorKey}' AS '${sensorKey}'
        </foreach>
        from history_five_minutely_${yearAndMonth} h
        where time = #{time} and mac IN
        <foreach collection="macs" separator="," open="(" close=")" item="mac">
            #{mac}
        </foreach>
    </select>
    <select id="getFiveMinutesDataByMacsAndTimeSolt" resultType="map">
        select h.mac,h.time,
        <foreach collection="sensorKeys" separator="," item="sensorKey">
            json->'$.${sensorKey}' AS '${sensorKey}'
        </foreach>
        FROM history_five_minutely_${yearAndMonth} h
        WHERE mac IN
        <foreach collection="macs" separator="," open="(" close=")" item="mac">
            #{mac}
        </foreach>
        AND time BETWEEN #{startTime} AND #{endTime}
        ORDER BY h.time DESC
        LIMIT #{macNumber}
    </select>
</mapper>