ZhuDongming
2019-11-08 b284d078f196af80a105dc3bcb610d8ed37d9251
src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -17,4 +17,43 @@
            </if>
        </where>
    </select>
    <select id="getPollutionSourceDataByHour" resultType="java.util.Map">
        SELECT
        DATE_FORMAT(time,'%Y-%m-%d %H') time,
        <foreach collection="sensorKeys" separator="," item="sensorKey">
            AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}'
        </foreach>
        FROM
        history h
        <where>
            <if test="mac!=null">
                and h.mac=#{mac}
            </if>
        </where>
        GROUP BY
        DATE_FORMAT(time,'%Y-%m-%d %H')
        <if test="time!=null">
        having time=DATE_FORMAT(DATE_SUB(#{time}, INTERVAL 1 HOUR),'%Y-%m-%d %H')
        </if>
    </select>
    <select id="getPollutionSourceDataAll" resultType="java.util.Map">
    SELECT
    DATE_FORMAT(time,'%Y-%m-%d %H') time,
    <foreach collection="sensorKeys" separator="," item="sensorKey">
        AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}'
    </foreach>
    FROM
    history h
    <where>
        <if test="mac!=null">
            and h.mac=#{mac}
        </if>
    </where>
    GROUP BY
    DATE_FORMAT(time,'%Y-%m-%d %H')
    order by time desc
    limit 0,1
    </select>
</mapper>