xufenglei
2018-04-18 b52c1e137107abbaee8cdea45964def25c952a7f
src/main/resources/mapper/HistoryMapper.xml
@@ -3,13 +3,12 @@
<mapper namespace="com.moral.mapper.HistoryMapper">
   <select id="getAreaAllDataByAccount" resultType="java.util.LinkedHashMap">
      SELECT
      <if test="macKey == 'all'">
         ${queryColumns}
      </if>
      <if test="macKey != 'all'">
         d.`name`,
         AVG( h.`value` -> ${macKey}) avg
      </if>
         <if test="macKey != null">
            d.`name`,
         </if>
         <foreach  collection="sensorKeys" separator="," item="sensorKey">
            AVG(h.`value` ->'$.${sensorKey}[0]') AS '${sensorKey}'
         </foreach>
      FROM
         history h,
         device d,
@@ -18,20 +17,17 @@
         mp.area_code = #{areaCode} 
         AND h.time >= #{start} 
         AND h.time &lt; #{end}
         AND h.mac = d.mac
         AND d.monitor_point_id = mp.id
      <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>
         AND h.mac = d.mac
         AND d.monitor_point_id = mp.id
      <if test="macKey != 'all'">
      <if test="macKey != null">
         GROUP BY d.id
         ORDER BY avg desc
         ORDER BY ${macKey} desc
      </if>   
   </select>
</mapper>