OnlineMonitorMapper.xml 9.0 KB

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