DataRealTimeMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.usky.backend.mapper.DataRealTimeMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.usky.backend.domain.DataRealTime">
  6. <id column="id" property="id" />
  7. <result column="device_id" property="deviceId" />
  8. <result column="product_code" property="productCode" />
  9. <result column="device_type" property="deviceType" />
  10. <result column="attribute_name" property="attributeName" />
  11. <result column="attribute_data" property="attributeData" />
  12. <result column="data_time" property="dataTime" />
  13. <result column="insert_time" property="insertTime" />
  14. </resultMap>
  15. <!-- <insert id="insertHistoryTable" >-->
  16. <!-- insert into ${tableName} ( device_id, device_type, attribute_name, attribute_data, data_time, insert_time)-->
  17. <!-- values (#{dataInfo.deviceId}, #{dataInfo.deviceType}, #{dataInfo.name}, #{dataInfo.value}, #{dataInfo.timestamp}, #{curTime})-->
  18. <!-- </insert>-->
  19. <select id="QueryHistoryData" resultType="com.usky.backend.domain.MetricItemVo">
  20. SELECT
  21. attribute_data as value,data_time as timestamp
  22. FROM
  23. ${tableName}
  24. <where>
  25. <if test="deviceId != null">
  26. and device_id = #{deviceId}
  27. </if>
  28. <if test="metric != null">
  29. and attribute_name = #{metric}
  30. </if>
  31. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  32. and data_time BETWEEN #{startTime} AND #{endTime}
  33. </if>
  34. </where>
  35. </select>
  36. <select id="QueryDeviceTypeAbbrevia" resultType="java.lang.String">
  37. select
  38. type_abbrevia
  39. from data_config
  40. <where>
  41. <if test="1 == 1">
  42. and type_code = #{deviceType}
  43. </if>
  44. </where>
  45. </select>
  46. <select id="QueryEachHistoryTotalData" resultType="com.usky.backend.domain.DataHistoryTotalVO">
  47. select device_id as deviceId,attribute_name as attributeName,sum(attribute_data) as totalValue
  48. FROM ${tableName}
  49. WHERE data_time BETWEEN #{startTime} AND #{endTime} AND product_code = #{productCode}
  50. <if test="deviceIdList != null and deviceIdList.size() > 0">
  51. AND device_id in
  52. <foreach item="item" collection="deviceIdList" open="(" separator="," close=")">
  53. #{item}
  54. </foreach>
  55. </if>
  56. <if test="attributeNameList != null and attributeNameList.size() > 0">
  57. AND attribute_name in
  58. <foreach item="item" collection="attributeNameList" open="(" separator="," close=")">
  59. #{item}
  60. </foreach>
  61. </if>
  62. group by device_id,attribute_name
  63. </select>
  64. <select id="QueryTotalHistoryTotalData" resultType="com.usky.backend.domain.DataHistoryTotalVO">
  65. select "all" as deviceId,attribute_name as attributeName,sum(attribute_data) as totalValue
  66. FROM ${tableName}
  67. WHERE data_time BETWEEN #{startTime} AND #{endTime} AND product_code = #{productCode}
  68. <if test="attributeNameList != null and attributeNameList.size() > 0">
  69. AND attribute_name in
  70. <foreach item="item" collection="attributeNameList" open="(" separator="," close=")">
  71. #{item}
  72. </foreach>
  73. </if>
  74. group by attribute_name
  75. </select>
  76. <select id="QueryEachHistoryAvrgData" resultType="com.usky.backend.domain.DataHistoryAvergerVO">
  77. SELECT a.data_date as dataDate,a.device_id as deviceId, a.attribute_name as attributeName ,avg(a.attribute_data) as avrg
  78. from (select product_code,device_id,attribute_name,attribute_data,left(data_time,#{leftLen}) as data_date FROM ${tableName} WHERE data_time BETWEEN #{startTime} AND #{endTime}
  79. <if test="productCode != null">
  80. AND product_code = #{productCode}
  81. </if>
  82. <if test="deviceIdList != null and deviceIdList.size() > 0">
  83. AND device_id in
  84. <foreach item="item" collection="deviceIdList" open="(" separator="," close=")">
  85. #{item}
  86. </foreach>
  87. </if>
  88. <if test="attributeNameList != null and attributeNameList.size() > 0">
  89. AND attribute_name in
  90. <foreach item="item" collection="attributeNameList" open="(" separator="," close=")">
  91. #{item}
  92. </foreach>
  93. </if>) a
  94. GROUP BY a.data_date,a.device_id,a.attribute_name;
  95. </select>
  96. <select id="QueryTotalOptHistoryAvrgData" resultType="com.usky.backend.domain.DataHistoryAvergerVO">
  97. SELECT a.data_date as dataDate,'所选房间' as deviceId,a.attribute_name as attributeName ,avg(a.attribute_data) as avrg
  98. FROM (SELECT product_code,attribute_name,attribute_data,LEFT(data_time,#{leftLen}) AS data_date FROM ${tableName} WHERE data_time BETWEEN #{startTime} AND #{endTime} AND product_code = #{productCode}
  99. AND device_id != 'weather0001'
  100. <if test="deviceIdList != null and deviceIdList.size() > 0">
  101. AND device_id in
  102. <foreach item="item" collection="deviceIdList" open="(" separator="," close=")">
  103. #{item}
  104. </foreach>
  105. </if>
  106. <if test="attributeNameList != null and attributeNameList.size() > 0">
  107. AND attribute_name in
  108. <foreach item="item" collection="attributeNameList" open="(" separator="," close=")">
  109. #{item}
  110. </foreach>
  111. </if>
  112. and attribute_data != 0) a
  113. GROUP BY a.data_date,a.attribute_name;
  114. </select>
  115. <select id="QueryTotalHistoryAvrgData" resultType="com.usky.backend.domain.DataHistoryAvergerVO">
  116. SELECT a.data_date as dataDate,'所有房间' as deviceId,a.attribute_name as attributeName ,avg(a.attribute_data) as avrg
  117. FROM (SELECT product_code,attribute_name,attribute_data,LEFT(data_time,#{leftLen}) AS data_date FROM ${tableName} WHERE data_time BETWEEN #{startTime} AND #{endTime} AND product_code = #{productCode}
  118. AND device_id != 'weather0001'
  119. <if test="attributeNameList != null and attributeNameList.size() > 0">
  120. AND attribute_name in
  121. <foreach item="item" collection="attributeNameList" open="(" separator="," close=")">
  122. #{item}
  123. </foreach>
  124. </if>
  125. and attribute_data != 0) a
  126. GROUP BY a.data_date,a.attribute_name;
  127. </select>
  128. </mapper>