OnlineMonitorMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.huaxu.dao.OnlineMonitorMapper">
  4. <!-- 结果集 -->
  5. <resultMap type="com.huaxu.dto.MonitorDataCollectDto" id="monitorDataMap">
  6. <result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
  7. <result property="sceneName" column="scene_name" jdbcType="VARCHAR"/>
  8. <result property="pointX" column="point_x" jdbcType="VARCHAR"/>
  9. <result property="pointY" column="point_y" jdbcType="VARCHAR"/>
  10. <result property="address" column="address" jdbcType="VARCHAR"/>
  11. <result property="sceneState" column="scene_state" jdbcType="INTEGER"/>
  12. <collection property="MonitorDataEntities" ofType="com.huaxu.dto.MonitorDataDto" javaType="list">
  13. <result property="deviceId" column="device_id" jdbcType="INTEGER"/>
  14. <result property="attributeId" column="attribute_id" jdbcType="INTEGER"/>
  15. <result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
  16. <result property="unit" column="unit" jdbcType="VARCHAR"/>
  17. <result property="isAlarm" column="is_Alarm" jdbcType="VARCHAR"/>
  18. <result property="attributeType" column="attribute_type" jdbcType="VARCHAR"/>
  19. <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
  20. <result property="sumValue" column="sum_value" jdbcType="VARCHAR"/>
  21. <result property="latestValue" column="latest_value" jdbcType="VARCHAR"/>
  22. </collection>
  23. </resultMap>
  24. <sql id="Base_Column_List">
  25. t1.id scene_Id,
  26. t1.scene_name ,
  27. t1.point_x ,
  28. t1.point_y,
  29. t1.address ,
  30. if (t7.alarm_count>0, 1, 0) scene_state,
  31. t5.device_id,
  32. t5.attribute_id ,
  33. ifnull(t5.remark, t5.`name`) attribute_name,
  34. t5.unit ,
  35. case when t5.attribute_id is null then null when t6.id is null then 0 else 1 end is_alarm,
  36. t5.attribute_type,
  37. if (t5.device_id is null, null, t4.device_code) device_code
  38. </sql>
  39. <sql id="sceneDeviceJoins">
  40. inner join sms_scene t2 on find_in_set(t1.id, t2.parent_scene_ids) and t2. status = 1
  41. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  42. left join sms_device t4 on t4.scene_id=t2.id
  43. </sql>
  44. <sql id="attributeJoins">
  45. select a1.device_id,a1.attribute_id,a1.remark,a1.seq,a2.name,a2.unit,a2.attribute_type
  46. from sms_device_parm a1
  47. inner join sms_device_attribute a2 on a1.attribute_id=a2.id
  48. where a1. status = 1 and a2.status = 1
  49. </sql>
  50. <sql id="alarmDetailsJoins">
  51. inner join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1
  52. </sql>
  53. <sql id="sceneAlarmJoins">
  54. left join (
  55. select substring_index(substring_index(a3.parent_scene_ids, ',', 2), ',', -1) one_scene_id,count(1) alarm_count
  56. from sms_device a1
  57. inner join sms_alarm_details a2 on a1.id=a2.device_id and a2.`status` = 1 and a2.state = 1
  58. inner join sms_scene a3 on a3.id=a1.scene_id and a3.`status` = 1
  59. where a1.`status` = 1 group by one_scene_id
  60. )t7 on t7.one_scene_id=t1.id
  61. </sql>
  62. <!--查询实时报警信息-->
  63. <select id="selectAlarmDetails" resultType="com.huaxu.dto.AlarmDetailsDto">
  64. select
  65. t1.scene_name as "sceneName",
  66. t6.alarm_content as "alarmContent",
  67. t6.alarm_start_time as "alarmStartTime"
  68. from sms_scene t1
  69. <include refid="sceneDeviceJoins"/>
  70. <include refid="alarmDetailsJoins"/>
  71. where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
  72. <if test="sceneIds != null and sceneIds.size() > 0">
  73. and t1.id in
  74. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  75. #{item}
  76. </foreach>
  77. </if>
  78. <if test="sceneName != null and sceneName != ''">
  79. and t1.scene_name like concat('%',#{sceneName},'%')
  80. </if>
  81. order by t1.scene_name
  82. </select>
  83. <!--查询实时报警数量-->
  84. <select id="selectAlarmCount" resultType="java.util.Map">
  85. select
  86. t1.scene_name as "sceneName",
  87. count(1) as "alalmCount"
  88. from sms_scene t1
  89. <include refid="sceneDeviceJoins"/>
  90. <include refid="alarmDetailsJoins"/>
  91. where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName} and t6.state=1
  92. <if test="sceneIds != null and sceneIds.size() > 0">
  93. and t1.id in
  94. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  95. #{item}
  96. </foreach>
  97. </if>
  98. <if test="sceneName != null and sceneName != ''">
  99. and t1.scene_name like concat('%',#{sceneName},'%')
  100. </if>
  101. group by t1.scene_name
  102. order by alalmCount desc
  103. </select>
  104. <!--查询地图悬浮数据-->
  105. <select id="selectMapSuspension" resultMap="monitorDataMap">
  106. select
  107. <include refid="Base_Column_List"/>
  108. from sms_scene t1
  109. <include refid="sceneDeviceJoins"/>
  110. <include refid="sceneAlarmJoins"/>
  111. left join(
  112. <include refid="attributeJoins"/> and a1.is_suspension = 1
  113. )t5 on t5.device_id=t4.id
  114. left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
  115. where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{sceneTypeName}
  116. <if test="sceneIds != null and sceneIds.size() > 0">
  117. and t1.id in
  118. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  119. #{item}
  120. </foreach>
  121. </if>
  122. order by t1.scene_name,t5.seq
  123. </select>
  124. <!--查询地图参数数据-->
  125. <select id="selectMapParam" resultMap="monitorDataMap">
  126. select
  127. <include refid="Base_Column_List"/>
  128. from sms_scene t1
  129. <include refid="sceneDeviceJoins"/>
  130. <include refid="sceneAlarmJoins"/>
  131. left join(
  132. <include refid="attributeJoins"/> and a1.is_map = 1
  133. )t5 on t5.device_id=t4.id
  134. left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
  135. where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{sceneId}
  136. <if test="sceneIds != null and sceneIds.size() > 0">
  137. and t1.id in
  138. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  139. #{item}
  140. </foreach>
  141. </if>
  142. order by t1.scene_name,t5.seq
  143. </select>
  144. <!--查询实时数据列表-->
  145. <select id="selectPage" resultType="com.huaxu.dto.OnlineDataDto">
  146. select t1.id scene_id,t1.scene_name,t1.address
  147. from sms_scene t1
  148. inner join sms_scene_type t3 on t3.id = t1.scene_type_id and t3. status = 1
  149. where t1.parent_scene_id = 0 and t1. status = 1 and t3.scene_type_name = #{onlineDataDto.sceneTypeName}
  150. <if test="onlineDataDto.sceneIds != null and onlineDataDto.sceneIds.size() > 0">
  151. and t1.id in
  152. <foreach collection="onlineDataDto.sceneIds" item="item" open="(" close=")" separator=",">
  153. #{item}
  154. </foreach>
  155. </if>
  156. <if test="onlineDataDto.sceneName != null and onlineDataDto.sceneName != ''">
  157. and t1.scene_name like concat('%',#{onlineDataDto.sceneName},'%')
  158. </if>
  159. order by t1.date_create
  160. </select>
  161. <!--查询设备报警分析-->
  162. <select id="selectAlarmStats" resultType="java.util.Map">
  163. select
  164. t4.id,
  165. t4.device_name as "deviceName",
  166. count(1) as "alarmCount",
  167. sum(timestampdiff(minute,t6.alarm_start_time,ifnull(t6.alarm_end_time,now()))) as "alarmDuration"
  168. from sms_scene t1
  169. <include refid="sceneDeviceJoins"/>
  170. <include refid="alarmDetailsJoins"/>
  171. where t1.parent_scene_id = 0 and t1. status = 1 and t1.id = #{id}
  172. <if test="sceneIds != null and sceneIds.size() > 0">
  173. and t1.id in
  174. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  175. #{item}
  176. </foreach>
  177. </if>
  178. <if test="days != null">
  179. and t6.alarm_start_time>DATE(NOW() + INTERVAL-#{days}+1 DAY)
  180. </if>
  181. group by t4.id,t4.device_name
  182. </select>
  183. <!--查询场景对应参数数据-->
  184. <select id="selectSceneParam" resultMap="monitorDataMap">
  185. select
  186. t1.id scene_Id,
  187. t1.scene_name ,
  188. t5.device_id,
  189. t5.attribute_id ,
  190. ifnull(t5.remark, t5.`name`) attribute_name,
  191. if(t6.id is null , 0 , 1 ) is_alarm,
  192. t5.attribute_type,
  193. if (t5.device_id is null, null, t4.device_code) device_code,
  194. t8.sum_value,
  195. t8.latest_value
  196. from sms_scene t1
  197. <include refid="sceneDeviceJoins"/>
  198. inner join(
  199. <include refid="attributeJoins"/>
  200. <if test="type == 1 ">
  201. and a2.attribute_type in(3,4,5,6)
  202. </if>
  203. <if test="type == 2 ">
  204. and a2.attribute_type in(2,3,4,5,6,7,8,9,10,11,12,13,14)
  205. </if>
  206. )t5 on t5.device_id=t4.id
  207. left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
  208. left join (
  209. select b1.device_id,b1.attribute_id,sum(sum_value) as sum_value,max(latest_value) latest_value from sms_day_report b1
  210. where b1.collect_date>=date(now())
  211. group by b1.device_id,b1.attribute_id
  212. )t8 on t8.attribute_id =t5.attribute_id and t8.device_id=t5.device_id
  213. where t1.parent_scene_id = 0 and t1. status = 1
  214. <if test="sceneTypeName != null and sceneTypeName != '' ">
  215. and t3.scene_type_name = #{sceneTypeName}
  216. </if>
  217. <if test="sceneId != null and sceneId != '' ">
  218. and t1.id = #{sceneId}
  219. </if>
  220. <if test="sceneIds != null and sceneIds.size() > 0">
  221. and t1.id in
  222. <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
  223. #{item}
  224. </foreach>
  225. </if>
  226. order by t1.scene_name,t5.seq
  227. </select>
  228. </mapper>