xufenglei
2019-02-28 5f1807ece119b2337ed71b575292e47a447cd154
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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.mapper.HistoryDailyMapper">
    <select id="getEmissionsData" resultType="java.util.Map">
        SELECT
            SUM(hd.`json` ->'$.${sensorKey}[0]') AS '${sensorKey}',
            vdi.mac,
            mp.`name` 'name' 
        FROM
            history_daily hd,
            view_device_info vdi,
            monitor_point mp
        <where>
            hd.mac = vdi.mac
            AND vdi.monitor_point_id = mp.id
            AND vdi.device_tech = 1 
            <if test="start != null">
                AND hd.time >= #{start}
            </if>
            <if test="end != null">
                AND hd.time &lt; #{end}
            </if>
            <if test="regionCode != null">
                AND mp.${regionType}_code = #{regionCode}
            </if>
            <if test="orgIds != null and orgIds.size &gt; 0">
                AND mp.organization_id IN
                <foreach collection="orgIds" open="(" separator="," close=")"
                    item="listItem">
                    #{listItem}
                </foreach>
            </if>
        </where>
        GROUP BY mp.`name`, vdi.mac
    </select>
</mapper>